angular/tools/manual_api_docs/generate_block_api_json.ts
Jeremy Elbourn 64db486edc build: add rules for generating block/element API data (#52480)
Adds build rules for "artificially" generating `DocEntry` collections for block and element APIs. The two rules are very similar, but _just_ different enough that it's worth having two separate implementations.

PR Close #52480
2023-11-02 11:02:08 -07:00

33 lines
1,005 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {DocEntry, EntryType} from '@angular/compiler-cli';
import {readFileSync, writeFileSync} from 'fs';
import {basename} from 'path';
function main() {
const [paramFilePath] = process.argv.slice(2);
const rawParamLines = readFileSync(paramFilePath, {encoding: 'utf8'}).split('\n');
const [srcs, outputFileExecRootRelativePath] = rawParamLines;
const entries: DocEntry[] = srcs.split(',').map(sourceFilePath => {
const fileContent = readFileSync(sourceFilePath, {encoding: 'utf8'});
return {
name: `@${basename(sourceFilePath, '.md')}`,
entryType: EntryType.Block,
description: fileContent,
rawComment: fileContent,
jsdocTags: [],
};
});
writeFileSync(outputFileExecRootRelativePath, JSON.stringify(entries), {encoding: 'utf8'});
}
main();