返回 reveal.js
add-banner.js
根目录 / scripts / add-banner.js
1 import { readFile, writeFile } from 'fs/promises';
2 import { dirname, resolve } from 'path';
3 import { fileURLToPath } from 'url';
4 import { LICENSE_BANNER } from './banner.js';
5
6 const __filename = fileURLToPath(import.meta.url);
7 const __dirname = dirname(__filename);
8 const root = resolve(__dirname, '..');
9
10 const targets = process.argv.slice(2);
11
12 for (const target of targets) {
13 const absolutePath = resolve(root, target);
14 const contents = await readFile(absolutePath, 'utf8');
15 const withoutBanner = contents.startsWith(LICENSE_BANNER)
16 ? contents.slice(LICENSE_BANNER.length).trimStart()
17 : contents.trimStart();
18
19 await writeFile(absolutePath, `${LICENSE_BANNER}\n${withoutBanner}`, 'utf8');
20 }
21
21 lines JAVASCRIPT