Skip to content

refactor: fix issues with docs scripts #4893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 23 additions & 36 deletions scripts/publish/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
'use strict';

/* eslint-disable no-console */
const fs = require('fs-extra');
const exec = require('child_process').exec;
const fs = require('fs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be const fs = require('fs-extra');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't use anything from fs-extra anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I changed outputFile to writeFile. Since there's no directories in the wiki they're identical.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const path = require('path');
const temp = require('temp');
const util = require('util');
const exec = require('child_process').exec;
const version = require('../../package.json').version;

const documentationPath = './docs/documentation';
const outputPath = '/tmp/documentation/';
const documentationPath = path.join(__dirname, '../../docs/documentation');
const outputPath = temp.mkdirSync('angular-cli-docs');

function createTempDirectory() {
return new Promise((resolve, reject) => {
fs.emptyDir(outputPath, (error) => {
if (error) {
reject(error);
}
resolve();
})
});
}

function execute(command) {
return new Promise((resolve, reject) => {
Expand All @@ -33,10 +24,6 @@ function execute(command) {
});
}

function gitClone(url, directory) {
return execute(util.format('git clone %s %s', url, directory));
}

function readFiles(directory, filelist) {
if(directory[directory.length - 1] != '/') {
directory = directory.concat('/');
Expand Down Expand Up @@ -76,7 +63,7 @@ function copyFile(from, to, linksToReplace) {
const r = new RegExp(str, 'gi');
fileData = fileData.replace(r, link.newName);
});
fs.outputFile(to, fileData, (error2) => {
fs.writeFile(to, fileData, (error2) => {
if (error2) {
reject(error2);
}
Expand All @@ -89,7 +76,9 @@ function copyFile(from, to, linksToReplace) {
function createFiles() {
const files = readFiles(documentationPath) || [];
const linksToReplace = checkNameLinks(files);
const copies = files.map(({ originalPath, newPath }) => copyFile(originalPath, newPath, linksToReplace));
const copies = files.map(({ originalPath, newPath }) => {
return copyFile(originalPath, newPath, linksToReplace)
});
return Promise.all(copies);
}

Expand All @@ -107,19 +96,17 @@ function checkNameLinks(files) {
}, []);
}

(function() {
Promise.resolve()
.then(() => createTempDirectory())
.then(() => gitClone('https://github.com/angular/angular-cli.wiki', outputPath))
.then(() => createFiles())
.then(() => process.chdir(outputPath))
.then(() => execute('git add .'))
.then(() => execute(`git commit -m ${version}`))
.then(() => execute('git status'))
.then((data) => {
console.log(data);
})
.catch((error) => {
console.log('error', error);
})
})();
Promise.resolve()
.then(() => console.log(`Documentation Path: ${documentationPath}`))
.then(() => console.log(`Wiki path: ${outputPath}`))
.then(() => console.log('Cloning...'))
.then(() => execute(`git clone "https://github.com/angular/angular-cli.wiki" ${outputPath}`))
.then(() => console.log('Copying Files...'))
.then(() => createFiles())
.then(() => process.chdir(outputPath))
.then(() => console.log('Committing...'))
.then(() => execute('git add .'))
.then(() => execute(`git commit -m "${version}"`))
.then(() => execute('git push'))
.then(() => console.log('Done...'))
.catch(err => console.error(`Error:\n${err.message}`));