Skip to content

Commit 8cec3ce

Browse files
authored
refactor: fix issues with docs scripts (angular#4893)
1 parent 9a2e35d commit 8cec3ce

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

scripts/publish/docs.js

+23-36
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
'use strict';
33

44
/* eslint-disable no-console */
5-
const fs = require('fs-extra');
5+
const exec = require('child_process').exec;
6+
const fs = require('fs');
67
const path = require('path');
8+
const temp = require('temp');
79
const util = require('util');
8-
const exec = require('child_process').exec;
910
const version = require('../../package.json').version;
1011

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

14-
function createTempDirectory() {
15-
return new Promise((resolve, reject) => {
16-
fs.emptyDir(outputPath, (error) => {
17-
if (error) {
18-
reject(error);
19-
}
20-
resolve();
21-
})
22-
});
23-
}
2415

2516
function execute(command) {
2617
return new Promise((resolve, reject) => {
@@ -33,10 +24,6 @@ function execute(command) {
3324
});
3425
}
3526

36-
function gitClone(url, directory) {
37-
return execute(util.format('git clone %s %s', url, directory));
38-
}
39-
4027
function readFiles(directory, filelist) {
4128
if(directory[directory.length - 1] != '/') {
4229
directory = directory.concat('/');
@@ -76,7 +63,7 @@ function copyFile(from, to, linksToReplace) {
7663
const r = new RegExp(str, 'gi');
7764
fileData = fileData.replace(r, link.newName);
7865
});
79-
fs.outputFile(to, fileData, (error2) => {
66+
fs.writeFile(to, fileData, (error2) => {
8067
if (error2) {
8168
reject(error2);
8269
}
@@ -89,7 +76,9 @@ function copyFile(from, to, linksToReplace) {
8976
function createFiles() {
9077
const files = readFiles(documentationPath) || [];
9178
const linksToReplace = checkNameLinks(files);
92-
const copies = files.map(({ originalPath, newPath }) => copyFile(originalPath, newPath, linksToReplace));
79+
const copies = files.map(({ originalPath, newPath }) => {
80+
return copyFile(originalPath, newPath, linksToReplace)
81+
});
9382
return Promise.all(copies);
9483
}
9584

@@ -107,19 +96,17 @@ function checkNameLinks(files) {
10796
}, []);
10897
}
10998

110-
(function() {
111-
Promise.resolve()
112-
.then(() => createTempDirectory())
113-
.then(() => gitClone('https://github.com/angular/angular-cli.wiki', outputPath))
114-
.then(() => createFiles())
115-
.then(() => process.chdir(outputPath))
116-
.then(() => execute('git add .'))
117-
.then(() => execute(`git commit -m ${version}`))
118-
.then(() => execute('git status'))
119-
.then((data) => {
120-
console.log(data);
121-
})
122-
.catch((error) => {
123-
console.log('error', error);
124-
})
125-
})();
99+
Promise.resolve()
100+
.then(() => console.log(`Documentation Path: ${documentationPath}`))
101+
.then(() => console.log(`Wiki path: ${outputPath}`))
102+
.then(() => console.log('Cloning...'))
103+
.then(() => execute(`git clone "https://github.com/angular/angular-cli.wiki" ${outputPath}`))
104+
.then(() => console.log('Copying Files...'))
105+
.then(() => createFiles())
106+
.then(() => process.chdir(outputPath))
107+
.then(() => console.log('Committing...'))
108+
.then(() => execute('git add .'))
109+
.then(() => execute(`git commit -m "${version}"`))
110+
.then(() => execute('git push'))
111+
.then(() => console.log('Done...'))
112+
.catch(err => console.error(`Error:\n${err.message}`));

0 commit comments

Comments
 (0)