3d-docs building workflow (#4300)

This commit is contained in:
ColinCollins
2019-04-26 14:17:26 +08:00
committed by Weiliang Wang
parent f1d1186a08
commit a2d9dbff38
4 changed files with 145 additions and 43 deletions
+129
View File
@@ -0,0 +1,129 @@
const { spawn, spawnSync } = require('child_process');
const fs = require('fs');
let program = require('commander');
program
.version('1.0.0')
.option('-r --removeTags', 'Select the language tags you want to delete')
.parse(process.argv);
const mode = 'modules';
const docsName = 'Creator-3d-Docs';
const indexPath = `${process.cwd()}/index.ts`;
const outputPath = {
json: `${process.cwd()}/docs-3d/tempJson`,
zh: `${process.cwd()}/docs-3d/zh`,
en: `${process.cwd()}/docs-3d/en`
}
exports.tempJsonGenerate = function () {
// typedoc command
let command = [
indexPath,
'--mode',
mode,
'--generate-json',
outputPath.json,
'--tags',
'--disableOutputCheck',
'--ignoreCompilerErrors'
];
let child = spawnSync('typedoc', command, {
shell: true,
env: process.env,
});
executeTypeDocCommand(child);
}
exports.docsGeneratorZH = function () {
if (!checkJsonFileExists()) return;
// typedoc command
let command = [
indexPath,
'--mode',
mode,
"--generate-from-json",
outputPath.json,
'--out',
outputPath.zh,
'--name',
docsName,
'--tags',
'--disableOutputCheck',
'--ignoreCompilerErrors',
'--choiceLanguage',
'zh'
];
let child = spawn('typedoc', command, {
shell: true,
env: process.env,
});
executeTypeDocCommand(child);
}
exports.docsGeneratorEN = function (done) {
if (!checkJsonFileExists()) return;
// typedoc command
let command = [
indexPath,
'--mode',
mode,
"--generate-from-json",
outputPath.json,
'--out',
outputPath.en,
'--name',
docsName,
'--tags',
'--disableOutputCheck',
'--ignoreCompilerErrors',
'--choiceLanguage',
'en'
];
let child = spawn('typedoc', command, {
shell: true,
env: process.env,
});
executeTypeDocCommand(child);
}
exports.docsGeneratorDefault = function () {
this.docsGeneratorZH();
this.docsGeneratorEN();
}
function checkJsonFileExists () {
let existsSync = fs.accessSync || fs.existsSync;
try {
existsSync(outputPath.json)
}
catch {
console.warn(`Rendering is short of the relied file`);
return false;
}
return true;
}
function executeTypeDocCommand (child) {
// spawnSync
if (child.output && child.output.length > 0) {
for(let i = 0; i < child.output.length; i++) {
child.output[i] && console.log(child.output[i].toString());
}
console.log(`Json Generator Finished!`);
return;
}
child.stdout.on('data', function (data) {
console.log(data.toString());
});
child.stderr.on('data', function (data) {
console.error(`${data}`);
});
child.on('close', (code) => {
if (code !== 0) {
console.log('Temp File Generate Failed!');
return;
}
console.log('Temp File Generate Success!');
});
}
+13
View File
@@ -34,6 +34,7 @@ const Shell = require('gulp-shell');
const Engine = require('./gulp/tasks/engine');
const Test = require('./gulp/tasks/test');
const Watch = require('./gulp/tasks/watch');
const DocsBuilder = require('./gulp/util/docs-build');
/////////////
// engine //
@@ -194,3 +195,15 @@ gulp.task('test-in-ci', function () {
}
});
});
////////////
// docs //
////////////
gulp.task('build-3d-json-file', function () {
DocsBuilder.tempJsonGenerate();
});
gulp.task('build-3d-docs', ['build-3d-json-file'], function () {
DocsBuilder.docsGeneratorDefault();
});
+3 -1
View File
@@ -15,7 +15,7 @@
"build:min": "uglifyjs ./bin/cocos-3d.dev.js --mangle --source-map -o ./bin/cocos-3d.min.js",
"build-rollup": "tsc --build rollup/tsconfig.json",
"postinstall": "npm run build-rollup",
"buildDocs": "node ./scripts/build-docs"
"buildDocs": "gulp build-3d-docs"
},
"repository": {
"type": "git",
@@ -37,6 +37,7 @@
"babelify": "7.3.0",
"cannon": "^0.6.2",
"chalk": "1.1.0",
"commander": "^2.20.0",
"dat.gui": "^0.7.5",
"del": "1.2.0",
"event-stream": "3.3.2",
@@ -72,6 +73,7 @@
"rollup-watch": "^4.3.1",
"tslint": "^5.12.0",
"typedoc": "github:cocos-creator/typedoc#master",
"typedoc-plugin-localization": "github:cocos-creator/typedoc-plugin-localization#master",
"typescript": "^3.4.4",
"uglify-js": "^3.4.9",
"vconsole": "^3.3.0",
-42
View File
@@ -1,42 +0,0 @@
(function buildingDocs () {
let [index, out] = process.argv.slice(3);
const { spawn } = require('child_process');
let options = {
indexPath: index || `${process.cwd()}\\index.ts`,
mode: 'modules',
out: out || `${process.cwd()}\\docs-3d`,
name: 'Creator-3D-Docs'
};
// typedoc command
let command = [
options.indexPath,
'--mode', options.mode,
'--ignoreCompilerErrors',
'--disableOutputCheck',
'--includeDeclarations',
'--name',
options.name,
'--out',
options.out];
let child = spawn('typedoc', command, {
shell: true,
env: process.env,
});
child.stdout.on('data', function (data) {
console.log(data.toString());
});
child.stderr.on('data', function (data) {
console.error(`${data}`);
});
child.on('close', (code) => {
if (code !== 0) {
console.log('Building Failed!');
return;
}
console.log('Building Success!');
});
})();