cogsbox-sync 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin/cli.ts
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import { fileURLToPath } from "url";
7
+ import { execSync } from "child_process";
8
+ import prompts from "prompts";
9
+ import { red, green, bold, cyan } from "kleur/colors";
10
+ var __filename = fileURLToPath(import.meta.url);
11
+ var __dirname = path.dirname(__filename);
12
+ async function main() {
13
+ console.log(bold(cyan("\n\u26A1 Cogsbox Sync Engine Setup \u26A1\n")));
14
+ const response = await prompts({
15
+ type: "text",
16
+ name: "dir",
17
+ message: "Where should we create the worker?",
18
+ initial: "sync-worker"
19
+ });
20
+ if (!response.dir) {
21
+ console.log(red("\u274C Operation cancelled"));
22
+ process.exit(0);
23
+ }
24
+ const targetDir = path.resolve(process.cwd(), response.dir);
25
+ const templateDir = path.resolve(__dirname, "../../templates/worker");
26
+ if (fs.existsSync(targetDir)) {
27
+ console.log(red(`\u274C Error: Directory "${response.dir}" already exists.`));
28
+ process.exit(1);
29
+ }
30
+ console.log(`
31
+ \u{1F4C2} Scaffolding worker in ${bold(targetDir)}...`);
32
+ try {
33
+ fs.copySync(templateDir, targetDir);
34
+ console.log(green("\u2714 Files created"));
35
+ } catch (e) {
36
+ console.error(red("\u274C Failed to copy template files."));
37
+ console.error(e);
38
+ process.exit(1);
39
+ }
40
+ console.log(bold("\n\u{1F4E6} Installing dependencies..."));
41
+ try {
42
+ execSync("npm install", { cwd: targetDir, stdio: "inherit" });
43
+ console.log(green("\u2714 Dependencies installed"));
44
+ } catch (e) {
45
+ console.error(red("\u274C npm install failed. Please run it manually."));
46
+ }
47
+ console.log(bold("\n\u{1F511} Setting up Secrets & Auth..."));
48
+ try {
49
+ execSync("npm run init", { cwd: targetDir, stdio: "inherit" });
50
+ console.log(green("\u2714 Configuration complete"));
51
+ } catch (e) {
52
+ console.log(red("\u26A0\uFE0F Automatic setup had issues. Check logs above."));
53
+ console.log('You can retry by running "npm run init" inside the folder.');
54
+ }
55
+ console.log(bold(green("\n\u{1F389} Ready to go!")));
56
+ console.log(`
57
+ Next steps:
58
+ cd ${response.dir}
59
+ npm run dev`);
60
+ }
61
+ main();