Skip to content
Merged
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
28 changes: 15 additions & 13 deletions scripts/templates.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,42 @@
*/

import lodash from 'lodash';
import * as fs from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import { releasePackages } from './packages.mjs';

const __dirname = import.meta.dirname;

async function _runTemplate(inputPath: string, outputPath: string) {
async function runTemplate(inputPath: string, outputPath: string) {
inputPath = path.resolve(__dirname, inputPath);
outputPath = path.resolve(__dirname, outputPath);

console.info(`Building ${path.relative(path.dirname(__dirname), outputPath)}...`);

// TODO(ESM): Consider making this an actual import statement.
const { COMMIT_TYPES, ScopeRequirement } = await new Function(
`return import('@angular/ng-dev');`,
)();
const { COMMIT_TYPES, ScopeRequirement } = await import('@angular/ng-dev');

const monorepo = JSON.parse(fs.readFileSync('./.monorepo.json', 'utf-8'));
const content = lodash.template(fs.readFileSync(inputPath, 'utf-8'))({
const [monorepoRaw, templateContent] = await Promise.all([
readFile('./.monorepo.json', 'utf-8'),
readFile(inputPath, 'utf-8'),
]);

const monorepo = JSON.parse(monorepoRaw);
const content = lodash.template(templateContent)({
monorepo,
packages: releasePackages.map(({ name }) => name),
encode: (x: string) => global.encodeURIComponent(x),
encode: (x: string) => encodeURIComponent(x),
// Pass-through `ng-dev` ESM commit message information for the `contributing.ejs`
// template. EJS templates using the devkit template cannot use ESM.
COMMIT_TYPES: COMMIT_TYPES,
ScopeRequirement: ScopeRequirement,
});
fs.writeFileSync(outputPath, content, 'utf-8');
await writeFile(outputPath, content, 'utf-8');
}

export default async function (_options: {}): Promise<number> {
export default async function (): Promise<number> {
await Promise.all([
_runTemplate('./templates/readme.ejs', '../README.md'),
_runTemplate('./templates/contributing.ejs', '../CONTRIBUTING.md'),
runTemplate('./templates/readme.ejs', '../README.md'),
runTemplate('./templates/contributing.ejs', '../CONTRIBUTING.md'),
]);

return 0;
Expand Down