-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
executable file
·38 lines (29 loc) · 900 Bytes
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env zx
const packages = await glob(['./**/package.json']);
const dryRun = argv['dry-run'] || argv.dryRun || process.argv.includes('--dry-run');
if (dryRun) {
console.log(chalk.black.bgYellow(`[DRY RUN]`), 'no files will be modified');
}
for (const pkg of packages) {
let json = {};
try {
json = await fs.readJson(pkg);
} catch {
console.log(chalk.black.bgRed(`[ERROR]`), 'failed to read', pkg);
continue;
}
if (json.name) continue;
json = { name: path.basename(path.dirname(pkg)), ...json };
try {
if (!dryRun) {
await fs.writeJson(pkg, json, { spaces: 2 });
}
} catch {
console.log(chalk.black.bgRed(`[ERROR]`), 'failed to write', pkg);
continue;
}
console.log(chalk.black.bgGreen(`[UPDATED]`), "added property 'name' to", pkg);
}
if (dryRun) {
console.log(chalk.black.bgYellow(`[DRY RUN]`), 'no files were modified');
}