diff --git a/gulp/util/docs-build.js b/gulp/util/docs-build.js new file mode 100644 index 0000000000..ad4e556b08 --- /dev/null +++ b/gulp/util/docs-build.js @@ -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!'); + }); +} diff --git a/gulpfile.js b/gulpfile.js index e130bfcf72..23cd9ddf86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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(); +}); diff --git a/package.json b/package.json index e13fd1e4f1..31f0f87767 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/build-docs.js b/scripts/build-docs.js deleted file mode 100644 index 0c00ea2b67..0000000000 --- a/scripts/build-docs.js +++ /dev/null @@ -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!'); - }); -})();