From 8cec3ce769526b4785df1c889dc5a466a2f84181 Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 21 Feb 2017 16:24:01 -0800 Subject: [PATCH] refactor: fix issues with docs scripts (#4893) --- scripts/publish/docs.js | 59 ++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/scripts/publish/docs.js b/scripts/publish/docs.js index a56361937103..61961c4359a3 100644 --- a/scripts/publish/docs.js +++ b/scripts/publish/docs.js @@ -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'); 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) => { @@ -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('/'); @@ -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); } @@ -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); } @@ -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); - }) -})(); \ No newline at end of file +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}`));