Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improved Typedoc generation with async file handling and better error management #1112

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions scripts/generate-typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,38 @@
*
*/

const { readFileSync, writeFileSync } = require('fs');
const { promises: fs } = require('fs');
const path = require('path');
const { Application, TSConfigReader } = require('typedoc');

const output = path.resolve(process.cwd(), 'docs-react-native', 'typedoc.json');
const outputMin = path.resolve(process.cwd(), 'docs-react-native', 'typedoc.min.json');
const cwd = process.cwd();
const output = path.resolve(cwd, 'docs-react-native', 'typedoc.json');
const outputMin = path.resolve(cwd, 'docs-react-native', 'typedoc.min.json');

const app = new Application();
app.options.addReader(new TSConfigReader());

// https://github.com/TypeStrong/typedoc/issues/956
const { inputFiles } = app.bootstrap({
mode: 'file',
includeDeclarations: true,
excludeExternals: true,
exclude: '**/node_modules/**',
tsconfig: path.resolve(process.cwd(), 'tsconfig.docs.json'),
});
try {
// https://github.com/TypeStrong/typedoc/issues/956
const { inputFiles } = app.bootstrap({
mode: 'file',
includeDeclarations: true,
excludeExternals: true,
exclude: '**/node_modules/**',
tsconfig: path.resolve(cwd, 'tsconfig.docs.json'),
});

app.generateJson(inputFiles, output);
app.generateJson(inputFiles, output);

const sourceJson = readFileSync(output);
writeFileSync(outputMin, JSON.stringify(JSON.parse(sourceJson)));
// Minify the generated JSON
fs.readFile(output, 'utf8')
.then((data) => {
const minifiedJson = JSON.stringify(JSON.parse(data));
return fs.writeFile(outputMin, minifiedJson, 'utf8');
})
.then(() => console.log(`✅ Minified JSON saved at ${outputMin}`))
.catch((error) => console.error('Error while processing JSON:', error));

} catch (error) {
console.error('Error occurred while generating documentation:', error.message);
}
Loading