| 24 | const { pathToFileURL } = require('node:url'); |
| 25 | |
| 26 | function parseArgs(argv) { |
| 27 | const args = { repoRoot: '.', ref: 'HEAD', outDir: '_Build/_SingleFileLibraries', all: false, library: null }; |
| 28 | for (let i = 2; i < argv.length; i++) { |
| 29 | const a = argv[i]; |
| 30 | if (a === '--repo-root') args.repoRoot = argv[++i]; |
| 31 | else if (a === '--ref') args.ref = argv[++i]; |
| 32 | else if (a === '--out') args.outDir = argv[++i]; |
| 33 | else if (a === '--all') args.all = true; |
| 34 | else if (a === '--library') args.library = argv[++i]; |
| 35 | else if (a === '-h' || a === '--help') { |
| 36 | console.log('Usage: cli.js --repo-root <path> --ref <branch|tag|sha> (--all | --library <name>) --out <dir>'); |
| 37 | process.exit(0); |
| 38 | } |
| 39 | } |
| 40 | if (!args.all && !args.library) { |
| 41 | console.error('Error: specify --all or --library <name>'); |
| 42 | process.exit(1); |
| 43 | } |
| 44 | return args; |
| 45 | } |
| 46 | |
| 47 | async function readText(path) { return await fsReadFile(path, 'utf8'); } |
| 48 | async function writeText(path, content) { await fsWriteFile(path, content); } |