mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
refactor: fix issues with docs scripts (#4893)
This commit is contained in:
parent
9a2e35d5ef
commit
8cec3ce769
@ -2,25 +2,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
const fs = require('fs-extra');
|
|
||||||
const path = require('path');
|
|
||||||
const util = require('util');
|
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const temp = require('temp');
|
||||||
|
const util = require('util');
|
||||||
const version = require('../../package.json').version;
|
const version = require('../../package.json').version;
|
||||||
|
|
||||||
const documentationPath = './docs/documentation';
|
const documentationPath = path.join(__dirname, '../../docs/documentation');
|
||||||
const outputPath = '/tmp/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) {
|
function execute(command) {
|
||||||
return new Promise((resolve, reject) => {
|
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) {
|
function readFiles(directory, filelist) {
|
||||||
if(directory[directory.length - 1] != '/') {
|
if(directory[directory.length - 1] != '/') {
|
||||||
directory = directory.concat('/');
|
directory = directory.concat('/');
|
||||||
@ -76,7 +63,7 @@ function copyFile(from, to, linksToReplace) {
|
|||||||
const r = new RegExp(str, 'gi');
|
const r = new RegExp(str, 'gi');
|
||||||
fileData = fileData.replace(r, link.newName);
|
fileData = fileData.replace(r, link.newName);
|
||||||
});
|
});
|
||||||
fs.outputFile(to, fileData, (error2) => {
|
fs.writeFile(to, fileData, (error2) => {
|
||||||
if (error2) {
|
if (error2) {
|
||||||
reject(error2);
|
reject(error2);
|
||||||
}
|
}
|
||||||
@ -89,7 +76,9 @@ function copyFile(from, to, linksToReplace) {
|
|||||||
function createFiles() {
|
function createFiles() {
|
||||||
const files = readFiles(documentationPath) || [];
|
const files = readFiles(documentationPath) || [];
|
||||||
const linksToReplace = checkNameLinks(files);
|
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);
|
return Promise.all(copies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,19 +96,17 @@ function checkNameLinks(files) {
|
|||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
(function() {
|
Promise.resolve()
|
||||||
Promise.resolve()
|
.then(() => console.log(`Documentation Path: ${documentationPath}`))
|
||||||
.then(() => createTempDirectory())
|
.then(() => console.log(`Wiki path: ${outputPath}`))
|
||||||
.then(() => gitClone('https://github.com/angular/angular-cli.wiki', outputPath))
|
.then(() => console.log('Cloning...'))
|
||||||
.then(() => createFiles())
|
.then(() => execute(`git clone "https://github.com/angular/angular-cli.wiki" ${outputPath}`))
|
||||||
.then(() => process.chdir(outputPath))
|
.then(() => console.log('Copying Files...'))
|
||||||
.then(() => execute('git add .'))
|
.then(() => createFiles())
|
||||||
.then(() => execute(`git commit -m ${version}`))
|
.then(() => process.chdir(outputPath))
|
||||||
.then(() => execute('git status'))
|
.then(() => console.log('Committing...'))
|
||||||
.then((data) => {
|
.then(() => execute('git add .'))
|
||||||
console.log(data);
|
.then(() => execute(`git commit -m "${version}"`))
|
||||||
})
|
.then(() => execute('git push'))
|
||||||
.catch((error) => {
|
.then(() => console.log('Done...'))
|
||||||
console.log('error', error);
|
.catch(err => console.error(`Error:\n${err.message}`));
|
||||||
})
|
|
||||||
})();
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user