2019-05-13 17:41:02 +00:00
|
|
|
import * as plugins from './tsdoc.plugins';
|
2019-05-14 15:39:33 +00:00
|
|
|
import * as paths from './tsdoc.paths';
|
2019-05-13 17:41:02 +00:00
|
|
|
|
2019-05-14 15:39:33 +00:00
|
|
|
export class TypeDoc {
|
|
|
|
public smartshellInstance = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash',
|
2020-11-24 20:24:30 +00:00
|
|
|
pathDirectories: [paths.binDir],
|
2019-05-14 15:39:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Static
|
|
|
|
public static async isTypeDocDir(dirPathArg: string): Promise<boolean> {
|
|
|
|
const result = await plugins.smartfile.fs.fileExists(
|
|
|
|
plugins.path.join(dirPathArg, 'mkdocs.yml')
|
|
|
|
);
|
|
|
|
return !result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instance
|
|
|
|
public typedocDirectory: string;
|
|
|
|
constructor(dirPathArg) {
|
2019-05-15 19:23:45 +00:00
|
|
|
this.typedocDirectory = dirPathArg;
|
2019-05-14 15:39:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 12:02:57 +00:00
|
|
|
public async compile(options?: {
|
|
|
|
publicSubdir?: string;
|
|
|
|
}) {
|
2020-11-24 20:24:30 +00:00
|
|
|
const data = {
|
|
|
|
compilerOptions: {
|
|
|
|
target: 'es2017',
|
|
|
|
module: 'commonjs',
|
|
|
|
esModuleInterop: true,
|
|
|
|
experimentalDecorators: true,
|
|
|
|
},
|
|
|
|
include: [],
|
|
|
|
};
|
|
|
|
data.include = [plugins.path.join(paths.cwd, './ts/**/*')];
|
|
|
|
await plugins.smartfile.memory.toFs(JSON.stringify(data), paths.tsconfigFile);
|
2020-11-27 12:02:57 +00:00
|
|
|
let targetDir = paths.publicDir;
|
|
|
|
if (options?.publicSubdir) {
|
|
|
|
targetDir = plugins.path.join(targetDir, options.publicSubdir);
|
|
|
|
}
|
2019-05-15 19:23:45 +00:00
|
|
|
await this.smartshellInstance.exec(
|
2020-11-24 20:24:30 +00:00
|
|
|
`typedoc --tsconfig ${paths.tsconfigFile} --out ${paths.publicDir}`
|
2019-05-15 19:23:45 +00:00
|
|
|
);
|
2020-11-24 20:24:30 +00:00
|
|
|
plugins.smartfile.fs.remove(paths.tsconfigFile);
|
2019-05-14 15:39:33 +00:00
|
|
|
}
|
|
|
|
}
|