124 lines
3.5 KiB
JavaScript
124 lines
3.5 KiB
JavaScript
|
const TypeDoc = require("yh-designer-doc");
|
||
|
|
||
|
async function main(hyDocOptions) {
|
||
|
const app = new TypeDoc.Application();
|
||
|
|
||
|
// If you want TypeDoc to load tsconfig.json / typedoc.json files
|
||
|
app.options.addReader(new TypeDoc.TSConfigReader());
|
||
|
app.options.addReader(new TypeDoc.TypeDocReader());
|
||
|
|
||
|
app.bootstrap(hyDocOptions);
|
||
|
const project = app.convert();
|
||
|
|
||
|
if (project) {
|
||
|
// Project may not have converted correctly
|
||
|
// Rendered docs
|
||
|
await app.generateDocs(project, hyDocOptions.out);
|
||
|
// Alternatively generate JSON output
|
||
|
await app.generateJson(project, hyDocOptions.json);
|
||
|
// await app.generateDocs(project, outputDir);
|
||
|
// Alternatively generate JSON output
|
||
|
//await app.generateTypesTxt(project, hyDocOptions.out, hyDocOptions.typestxtPath);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var path = require("path");
|
||
|
var fs = require("fs");
|
||
|
|
||
|
/**
|
||
|
* 找文件
|
||
|
* @param {*} startPath
|
||
|
* @param {*} filter
|
||
|
* @returns
|
||
|
*/
|
||
|
function findtypesFile(startPath, filter) {
|
||
|
var ret = []
|
||
|
if (!fs.existsSync(startPath)) {
|
||
|
console.error("no dir ", startPath);
|
||
|
return ret;
|
||
|
}
|
||
|
var files = fs.readdirSync(startPath);
|
||
|
for (var i = 0; i < files.length; i++) {
|
||
|
var filename = path.join(startPath, files[i]);
|
||
|
var stat = fs.lstatSync(filename);
|
||
|
if (stat.isDirectory()) {
|
||
|
ret = ret.concat(findtypesFile(filename, filter));
|
||
|
}
|
||
|
else if (filename.indexOf(filter) >= 0 && filename.indexOf('_gsdata_') == -1) {
|
||
|
ret.push(filename);
|
||
|
};
|
||
|
};
|
||
|
return ret;
|
||
|
}
|
||
|
/**
|
||
|
*合并文件
|
||
|
* @param {Object} sourceFiles 文件数组
|
||
|
* @param {Object} callback
|
||
|
*/
|
||
|
function combinFiles(sourceFiles, targetFile) {
|
||
|
targetFile = path.resolve(__dirname, targetFile);
|
||
|
for (let i = 0; i < sourceFiles.length; i++) {
|
||
|
let filename = path.resolve(__dirname, sourceFiles[i]);
|
||
|
let content = fs.readFileSync(filename, 'utf-8')
|
||
|
fs.appendFileSync(targetFile, content)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 把每个模块的types.txt合并成一个并放到 dist/types.txt
|
||
|
* 用于在设计器内的动态组件的属性,函数等等显示提示信息.
|
||
|
*/
|
||
|
var typesFile = findtypesFile('./node_modules', "types.txt")
|
||
|
var sortby = [
|
||
|
'yh-designer',
|
||
|
'yh-standard',
|
||
|
'yh-sqldatasource',
|
||
|
'yh-table',
|
||
|
'yh-business',
|
||
|
'yh-bigscreen',
|
||
|
'yh-chart',
|
||
|
'yh-map',
|
||
|
'yh-moble',
|
||
|
'yh-player',
|
||
|
'yh-wangeditor'];
|
||
|
typesFile.sort(function (a, b) {
|
||
|
a = a.replace('node_modules\\', '')
|
||
|
a = a.replace('\\dist\\types.txt', '')
|
||
|
b = b.replace('node_modules\\', '')
|
||
|
b = b.replace('\\dist\\types.txt', '')
|
||
|
if (sortby.indexOf(a) > sortby.indexOf(b)) {
|
||
|
return 1
|
||
|
}
|
||
|
if (sortby.indexOf(a) < sortby.indexOf(b)) {
|
||
|
return -1
|
||
|
}
|
||
|
return 0
|
||
|
})
|
||
|
for (let index = 0; index < typesFile.length; index++) {
|
||
|
const f = typesFile[index];
|
||
|
console.log('found: ', f);
|
||
|
}
|
||
|
fs.unlink('./dist/types.txt', function (err) { });
|
||
|
combinFiles(typesFile, './dist/types.txt');
|
||
|
|
||
|
main({
|
||
|
// typedoc options here
|
||
|
name: " 快搭科技(上海)有限公司-界面设计器API文档说明",
|
||
|
entryPoints: [
|
||
|
"./src",
|
||
|
],
|
||
|
out: './dist/docs/',
|
||
|
// exclude: '**/node_modules/**/*.*',
|
||
|
// excludeExternals: true,
|
||
|
theme: "minimal",
|
||
|
version: true,
|
||
|
json: './src/docs.json',
|
||
|
typestxtPath: './dist/types.txt',
|
||
|
toc: ["EntryClass", "ImportantInterface"]
|
||
|
}).catch(console.error);
|
||
|
//清除掉docs.json'文件的内容 减少体积
|
||
|
fs.exists('./dist/docs.json', function (exists) {
|
||
|
exists ? fs.unlinkSync('./dist/docs.json') : "";
|
||
|
});
|
||
|
|