-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilddoc.mjs
106 lines (102 loc) · 3.43 KB
/
builddoc.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// import td from 'typedoc';
import * as td from 'typedoc';
// const path = require('path');
// const fs = require('fs');
import * as path from 'path';
import * as fs from 'fs';
import globby from 'globby';
import typedocJson from './typedoc.js';
// const typedocJson = require('./typedoc.js');
/**
* @param {Object} options
* @param {string} options.entryPoint
* @param {string} options.outDir
* @param {Partial<import('typedoc').TypeDocOptions>} [typeDocOptions]
*/
async function createTypeScriptApiDocs({ outDir }, options = {}) {
const currentPath = path.join(process.cwd());
let otherFiles = [];
const { includeSubDirDefinitions, ...typeDocOptions } = options;
if (includeSubDirDefinitions === true) {
otherFiles = await globby(
[
'packages/*/*/**/*.d.ts',
'!**/*.android.d.ts',
'!**/*.ios.d.ts',
'!**/*.common.d.ts',
'!**/*-common.d.ts',
'!**/node_modules',
'!**/vue/**/*',
'!**/angular/**/*',
'!**/svelte/**/*',
'!**/react/**/*'
],
{
absolute: true,
followSymbolicLinks: false,
cwd: currentPath
}
);
}
const files = await globby(['packages/**/package.json'], {
absolute: true,
followSymbolicLinks: false,
deep: 2,
cwd: currentPath
});
const actualTypings = files.map((p) => path.relative(path.join(currentPath, ''), path.join(path.dirname(p), JSON.parse(fs.readFileSync(p)).typings)));
const allFiles = actualTypings.concat(otherFiles);
console.log('createTypeScriptApiDocs', typeDocOptions, currentPath);
const app = await td.Application.bootstrapWithPlugins(
{
// logger: 'console',
readme: path.join(currentPath, 'README.md'),
disableSources: false,
excludeExternals: true,
cleanOutputDir: true,
tsconfig: 'tools/tsconfig.doc.json',
gitRevision: 'master',
logLevel: 'Verbose',
entryPointStrategy: td.EntryPointStrategy.Resolve,
entryPoints: allFiles,
navigationLinks: {
'Nativescript Doc': 'https://docs.nativescript.org'
},
...typedocJson,
...typeDocOptions
},
[new td.PackageJsonReader(), new td.TSConfigReader()]
);
// app.bootstrap();
//@ts-ignore
app.options.setCompilerOptions(allFiles, {
esModuleInterop: true
});
const project = app.converter.convert(app.getEntryPoints() ?? []);
if (project) {
await app.generateDocs(project, outDir);
} else {
throw new Error('Error creating the typedoc project');
}
}
// app.generateDocs(project, "./docs");
// app.generateJson(project, "./docs.json");
new Promise(async function (resolve, reject) {
try {
let docOptions = {};
try {
const config = JSON.parse(fs.readFileSync('./config.json'));
if (config.doc) {
docOptions = config.doc;
}
console.error('docOptions', config, docOptions);
} catch (error) {
console.error('error parsing config', error);
}
await createTypeScriptApiDocs({ outDir: 'docs' }, docOptions);
resolve();
} catch (err) {
console.error(err);
reject(err);
}
});