-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbatchPublish.ts
68 lines (55 loc) · 2.03 KB
/
batchPublish.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { exec } from "node:child_process";
import { readdir } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
// This script requires commenting out questions about namespaces, git url and tags because
// we not ask them unconditionally.
const execPromise = promisify(exec);
// Function to recursively walk through directory tree
const walkDirectory = async (dir: string, accumulator: string[]) => {
// Read directory contents
const entries = await readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
// Recursively walk into directories
await walkDirectory(fullPath, accumulator);
} else if (entry.name === ".codemodrc.json") {
// If the entry is a .codemodrc.json file, accumulate the directory path
accumulator.push(dir);
}
}
};
const oraCheckmark = "✔";
// Main function to execute the script
(async () => {
const args = process.argv.slice(2);
if (args.length === 0) {
console.error("Error: Please provide the target path as an argument.");
process.exit(1);
}
const targetPath = args[0];
const accumulator: string[] = [];
await walkDirectory(targetPath, accumulator);
for (let i = 0; i < accumulator.length; i++) {
const dir = accumulator[i].replace(/(\s+)/g, "\\$1");
console.log(`Publishing ${dir}`);
const { stderr, stdout } = await execPromise(
`apps/cli/dist/index.cjs publish --source ${dir}`,
);
const output = stdout.trim();
const errors = stderr.trim();
if (
!output.includes("Codemod was successfully published to the registry")
) {
console.error(`Failed to publish ${dir}`);
console.error(errors);
break;
}
console.log("OUTPUT:", output);
console.log("ERRORS: ", errors);
console.log(`\nSuccessfully published ${dir}?`);
console.log(`Published ${i + 1} of ${accumulator.length} directories`);
console.log("=====================================\n");
}
})();