|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import lodash from 'lodash'; |
10 | | -import * as fs from 'node:fs'; |
| 10 | +import { readFile, writeFile } from 'node:fs/promises'; |
11 | 11 | import * as path from 'node:path'; |
12 | 12 | import { releasePackages } from './packages.mjs'; |
13 | 13 |
|
14 | 14 | const __dirname = import.meta.dirname; |
15 | 15 |
|
16 | | -async function _runTemplate(inputPath: string, outputPath: string) { |
| 16 | +async function runTemplate(inputPath: string, outputPath: string) { |
17 | 17 | inputPath = path.resolve(__dirname, inputPath); |
18 | 18 | outputPath = path.resolve(__dirname, outputPath); |
19 | 19 |
|
20 | 20 | console.info(`Building ${path.relative(path.dirname(__dirname), outputPath)}...`); |
21 | 21 |
|
22 | | - // TODO(ESM): Consider making this an actual import statement. |
23 | | - const { COMMIT_TYPES, ScopeRequirement } = await new Function( |
24 | | - `return import('@angular/ng-dev');`, |
25 | | - )(); |
| 22 | + const { COMMIT_TYPES, ScopeRequirement } = await import('@angular/ng-dev'); |
26 | 23 |
|
27 | | - const monorepo = JSON.parse(fs.readFileSync('./.monorepo.json', 'utf-8')); |
28 | | - const content = lodash.template(fs.readFileSync(inputPath, 'utf-8'))({ |
| 24 | + const [monorepoRaw, templateContent] = await Promise.all([ |
| 25 | + readFile('./.monorepo.json', 'utf-8'), |
| 26 | + readFile(inputPath, 'utf-8'), |
| 27 | + ]); |
| 28 | + |
| 29 | + const monorepo = JSON.parse(monorepoRaw); |
| 30 | + const content = lodash.template(templateContent)({ |
29 | 31 | monorepo, |
30 | 32 | packages: releasePackages.map(({ name }) => name), |
31 | | - encode: (x: string) => global.encodeURIComponent(x), |
| 33 | + encode: (x: string) => encodeURIComponent(x), |
32 | 34 | // Pass-through `ng-dev` ESM commit message information for the `contributing.ejs` |
33 | 35 | // template. EJS templates using the devkit template cannot use ESM. |
34 | 36 | COMMIT_TYPES: COMMIT_TYPES, |
35 | 37 | ScopeRequirement: ScopeRequirement, |
36 | 38 | }); |
37 | | - fs.writeFileSync(outputPath, content, 'utf-8'); |
| 39 | + await writeFile(outputPath, content, 'utf-8'); |
38 | 40 | } |
39 | 41 |
|
40 | | -export default async function (_options: {}): Promise<number> { |
| 42 | +export default async function (): Promise<number> { |
41 | 43 | await Promise.all([ |
42 | | - _runTemplate('./templates/readme.ejs', '../README.md'), |
43 | | - _runTemplate('./templates/contributing.ejs', '../CONTRIBUTING.md'), |
| 44 | + runTemplate('./templates/readme.ejs', '../README.md'), |
| 45 | + runTemplate('./templates/contributing.ejs', '../CONTRIBUTING.md'), |
44 | 46 | ]); |
45 | 47 |
|
46 | 48 | return 0; |
|
0 commit comments