@nimbus-sh/cli 0.1.0 → 0.1.2

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.
package/README.md CHANGED
@@ -29,8 +29,9 @@ Scaffolds a Nimbus-powered Workers project. `.` uses the current directory.
29
29
  nimbus init my-nimbus
30
30
  cd my-nimbus
31
31
  npm install
32
- wrangler secret put JWT_SECRET
33
- wrangler deploy
32
+ CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name my-nimbus
33
+ npx wrangler secret put JWT_SECRET
34
+ npx wrangler deploy
34
35
  ```
35
36
 
36
37
  ### `create-nimbus-app <name>`
@@ -41,8 +42,9 @@ Scaffolds a new Nimbus-powered Workers project.
41
42
  create-nimbus-app my-nimbus
42
43
  cd my-nimbus
43
44
  npm install
44
- wrangler secret put JWT_SECRET
45
- wrangler deploy
45
+ CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name my-nimbus
46
+ npx wrangler secret put JWT_SECRET
47
+ npx wrangler deploy
46
48
  ```
47
49
 
48
50
  Flags:
@@ -53,6 +55,27 @@ Flags:
53
55
  | `--template <name>` | `worker-only` | Only `worker-only` ships in v0.1. |
54
56
  | `--force` | off | Overwrite existing directory. |
55
57
 
58
+ ### `nimbus setup cloudflare`
59
+
60
+ Creates the R2 buckets referenced by the scaffolded `wrangler.jsonc` and
61
+ uploads the Python, Ruby, and clang runtime catalog.
62
+
63
+ ```bash
64
+ CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name my-nimbus
65
+ ```
66
+
67
+ If Wrangler reports Cloudflare R2 error `10042`, enable R2 in the
68
+ Cloudflare Dashboard once for the account, then rerun the setup command.
69
+
70
+ Flags:
71
+
72
+ | Flag | Default | What |
73
+ |---|---|---|
74
+ | `--name <worker-name>` | required | Worker name and default bucket prefix. |
75
+ | `--bucket-prefix <prefix>` | `--name` | Prefix for npm cache buckets. |
76
+ | `--runtime-bucket <bucket>` | `nimbus-runtime-cache-public` | Runtime catalog/blob bucket. |
77
+ | `--skip-runtimes` | off | Create buckets only. |
78
+
56
79
  ### `nimbus token mint`
57
80
 
58
81
  ```bash
package/dist/bin.js CHANGED
@@ -21,6 +21,7 @@
21
21
  import { mintToken, verifyTokenCmd } from './commands/token.js';
22
22
  import { syncRuntimes, listRuntimes } from './commands/runtime-sync.js';
23
23
  import { newSession } from './commands/session.js';
24
+ import { setupCloudflare } from './commands/setup.js';
24
25
  import { CLI_VERSION } from './version.js';
25
26
  const verbs = {
26
27
  token: {
@@ -34,6 +35,9 @@ const verbs = {
34
35
  session: {
35
36
  new: newSession,
36
37
  },
38
+ setup: {
39
+ cloudflare: setupCloudflare,
40
+ },
37
41
  };
38
42
  async function main(argv) {
39
43
  if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
@@ -64,6 +68,7 @@ Usage:
64
68
  nimbus runtime sync [--bucket <name>] [runtime[@version]...]
65
69
  nimbus runtime list
66
70
  nimbus session new [--endpoint <url>]
71
+ nimbus setup cloudflare --name <worker-name>
67
72
  nimbus init [directory]
68
73
 
69
74
  For embedder scaffolding:
@@ -1 +1 @@
1
- {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAkE9D"}
1
+ {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAsF9D"}
@@ -26,6 +26,20 @@ import { resolve, join, basename } from 'node:path';
26
26
  * `--force` overwrite existing files.
27
27
  */
28
28
  export async function scaffold(args) {
29
+ if (args[0] === '--help' || args[0] === '-h') {
30
+ process.stdout.write(`create-nimbus-app
31
+
32
+ Usage:
33
+ create-nimbus-app <project-name> [--name <worker-name>] [--force]
34
+ create-nimbus-app . --name <worker-name>
35
+
36
+ Options:
37
+ --name <worker-name> Deployed Cloudflare Worker name. Defaults to project name.
38
+ --template <name> Template to use. Only worker-only ships in v0.1.
39
+ --force Overwrite existing files.
40
+ `);
41
+ return 0;
42
+ }
29
43
  const rawProjectName = args[0];
30
44
  const projectName = rawProjectName === '.'
31
45
  ? basename(process.cwd())
@@ -65,6 +79,7 @@ export async function scaffold(args) {
65
79
  nextSteps: [
66
80
  `cd ${projectName}`,
67
81
  'npm install',
82
+ `CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name ${wranglerName}`,
68
83
  'npx wrangler secret put JWT_SECRET',
69
84
  'npx wrangler deploy',
70
85
  ],
@@ -75,11 +90,15 @@ export async function scaffold(args) {
75
90
  Next steps:
76
91
  cd ${projectName}
77
92
  npm install
93
+ CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name ${wranglerName}
78
94
  npx wrangler secret put JWT_SECRET # paste a 32+ char hex secret
79
95
  npx wrangler deploy
80
96
 
81
- Deploy will provision the DO + R2 buckets on first run. Visit the
82
- returned URL and hit "Launch" to mint a session.
97
+ If setup reports Cloudflare R2 error 10042, enable R2 in the Cloudflare
98
+ Dashboard once for this account, then rerun the setup command.
99
+
100
+ Deploy will provision the Durable Object on first run. Visit the returned
101
+ URL and hit "Launch" to mint a session.
83
102
 
84
103
  Docs: https://github.com/AshishKumar4/Nimbus#readme
85
104
  `);
@@ -215,12 +234,16 @@ A Nimbus-powered Cloudflare Worker.
215
234
 
216
235
  \`\`\`bash
217
236
  npm install
237
+ CLOUDFLARE_ACCOUNT_ID=<account-id> npx @nimbus-sh/cli setup cloudflare --name ${wranglerName}
218
238
  npx wrangler secret put JWT_SECRET # paste a 32+ char hex secret
219
239
  npx wrangler deploy
220
240
  \`\`\`
221
241
 
222
242
  Then visit the URL wrangler prints. Click "Launch" to mint a session.
223
243
 
244
+ If setup reports Cloudflare R2 error 10042, enable R2 in the Cloudflare
245
+ Dashboard once for this account, then rerun the setup command.
246
+
224
247
  ## Custom auth
225
248
 
226
249
  By default tokens are enforced (\`JWT_SECRET\` set). To mint:
@@ -0,0 +1,2 @@
1
+ export declare function setupCloudflare(args: string[]): Promise<number>;
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAUA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAmDrE"}
@@ -0,0 +1,119 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { syncRuntimes } from './runtime-sync.js';
3
+ export async function setupCloudflare(args) {
4
+ if (args[0] === '--help' || args[0] === '-h') {
5
+ printHelp();
6
+ return 0;
7
+ }
8
+ const opts = parseFlags(args);
9
+ if (!opts.name) {
10
+ process.stderr.write('nimbus setup cloudflare: --name <worker-name> required\n');
11
+ printHelp();
12
+ return 64;
13
+ }
14
+ if (!process.env.CLOUDFLARE_ACCOUNT_ID) {
15
+ process.stderr.write('nimbus setup cloudflare: CLOUDFLARE_ACCOUNT_ID env var required\n');
16
+ return 78;
17
+ }
18
+ const prefix = opts.bucketPrefix || opts.name;
19
+ const runtimeBucket = opts.runtimeBucket || 'nimbus-runtime-cache-public';
20
+ const buckets = [
21
+ `${prefix}-npm-cache`,
22
+ `${prefix}-npm-packument-cache`,
23
+ runtimeBucket,
24
+ ];
25
+ process.stderr.write(`nimbus: preparing Cloudflare account for ${opts.name}\n`);
26
+ for (const bucket of buckets) {
27
+ const code = await runWrangler(['r2', 'bucket', 'create', bucket], {
28
+ okOnAlreadyExists: true,
29
+ });
30
+ if (code !== 0) {
31
+ process.stderr.write('nimbus setup cloudflare: R2 bucket setup failed. If Wrangler printed code 10042, enable R2 in the Cloudflare Dashboard and rerun this command.\n');
32
+ return code;
33
+ }
34
+ }
35
+ if (!opts.skipRuntimes) {
36
+ const code = await syncRuntimes(['--bucket', runtimeBucket, 'clang', 'python', 'ruby']);
37
+ if (code !== 0)
38
+ return code;
39
+ }
40
+ process.stdout.write(JSON.stringify({
41
+ ok: true,
42
+ worker: opts.name,
43
+ buckets,
44
+ runtimeBucket,
45
+ runtimesSynced: !opts.skipRuntimes,
46
+ }) + '\n');
47
+ return 0;
48
+ }
49
+ function parseFlags(args) {
50
+ const out = { skipRuntimes: false };
51
+ for (let i = 0; i < args.length; i++) {
52
+ const a = args[i];
53
+ if (a === '--name') {
54
+ out.name = args[++i] || '';
55
+ continue;
56
+ }
57
+ if (a === '--bucket-prefix') {
58
+ out.bucketPrefix = args[++i] || '';
59
+ continue;
60
+ }
61
+ if (a === '--runtime-bucket') {
62
+ out.runtimeBucket = args[++i] || '';
63
+ continue;
64
+ }
65
+ if (a === '--skip-runtimes') {
66
+ out.skipRuntimes = true;
67
+ continue;
68
+ }
69
+ }
70
+ return out;
71
+ }
72
+ function runWrangler(args, opts = {}) {
73
+ return new Promise((resolveExit) => {
74
+ const child = spawn('npx', ['wrangler', ...args], {
75
+ env: process.env,
76
+ shell: process.platform === 'win32',
77
+ stdio: ['ignore', 'pipe', 'pipe'],
78
+ });
79
+ let combined = '';
80
+ child.stdout.on('data', (chunk) => {
81
+ const text = String(chunk);
82
+ combined += text;
83
+ process.stderr.write(text);
84
+ });
85
+ child.stderr.on('data', (chunk) => {
86
+ const text = String(chunk);
87
+ combined += text;
88
+ process.stderr.write(text);
89
+ });
90
+ child.on('exit', (code) => {
91
+ if (code === 0)
92
+ return resolveExit(0);
93
+ if (opts.okOnAlreadyExists && /already exists|bucket.*exists/i.test(combined)) {
94
+ return resolveExit(0);
95
+ }
96
+ return resolveExit(code ?? 1);
97
+ });
98
+ child.on('error', (e) => {
99
+ process.stderr.write(`nimbus setup cloudflare: failed to run wrangler: ${e.message}\n`);
100
+ resolveExit(70);
101
+ });
102
+ });
103
+ }
104
+ function printHelp() {
105
+ process.stdout.write(`nimbus setup cloudflare
106
+
107
+ Usage:
108
+ nimbus setup cloudflare --name <worker-name>
109
+
110
+ Options:
111
+ --name <worker-name> Deployed Cloudflare Worker name. Required.
112
+ --bucket-prefix <prefix> Prefix for npm cache buckets. Defaults to --name.
113
+ --runtime-bucket <bucket> Runtime cache bucket. Defaults to nimbus-runtime-cache-public.
114
+ --skip-runtimes Create buckets only; do not upload Python/Ruby/clang runtime blobs.
115
+
116
+ Env:
117
+ CLOUDFLARE_ACCOUNT_ID Cloudflare account to prepare. Required.
118
+ `);
119
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @nimbus-sh/cli — Programmatic surface.
3
3
  *
4
- * The CLI's `bin` entries (`nimbus`, `create-nimbus-app`) call these
4
+ * The CLI's `bin` entries (`nimbus`, `cli`, `create-nimbus-app`) call these
5
5
  * functions. Embedders building custom dev tooling can import them
6
6
  * directly:
7
7
  *
@@ -11,5 +11,6 @@
11
11
  */
12
12
  export { mintToken } from './commands/token.js';
13
13
  export { syncRuntimes } from './commands/runtime-sync.js';
14
+ export { setupCloudflare } from './commands/setup.js';
14
15
  export { scaffold } from './commands/scaffold.js';
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @nimbus-sh/cli — Programmatic surface.
3
3
  *
4
- * The CLI's `bin` entries (`nimbus`, `create-nimbus-app`) call these
4
+ * The CLI's `bin` entries (`nimbus`, `cli`, `create-nimbus-app`) call these
5
5
  * functions. Embedders building custom dev tooling can import them
6
6
  * directly:
7
7
  *
@@ -11,4 +11,5 @@
11
11
  */
12
12
  export { mintToken } from './commands/token.js';
13
13
  export { syncRuntimes } from './commands/runtime-sync.js';
14
+ export { setupCloudflare } from './commands/setup.js';
14
15
  export { scaffold } from './commands/scaffold.js';
package/dist/version.d.ts CHANGED
@@ -3,5 +3,5 @@
3
3
  * `require('./package.json')` because that breaks under bun's
4
4
  * single-file binary mode.
5
5
  */
6
- export declare const CLI_VERSION = "0.1.0";
6
+ export declare const CLI_VERSION = "0.1.2";
7
7
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * `require('./package.json')` because that breaks under bun's
4
4
  * single-file binary mode.
5
5
  */
6
- export const CLI_VERSION = '0.1.0';
6
+ export const CLI_VERSION = '0.1.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimbus-sh/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Nimbus CLI — `create-nimbus-app` scaffolder + `token mint` + `runtime sync`.",
5
5
  "homepage": "https://github.com/AshishKumar4/Nimbus",
6
6
  "repository": {
@@ -12,6 +12,7 @@
12
12
  "license": "MIT",
13
13
  "type": "module",
14
14
  "bin": {
15
+ "cli": "./dist/bin.js",
15
16
  "nimbus": "./dist/bin.js",
16
17
  "create-nimbus-app": "./dist/scaffold-bin.js"
17
18
  },