flaghoist 0.1.2 → 0.2.0

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.
Files changed (2) hide show
  1. package/dist/index.js +60 -7
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import { spawnSync } from "child_process";
11
11
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
12
12
  import { dirname, join } from "path";
13
+ import { createInterface } from "readline/promises";
13
14
  import { parseArgs } from "util";
14
15
 
15
16
  // src/admin.ts
@@ -332,13 +333,24 @@ function runInit(args) {
332
333
  console.log("Next: `flaghoist deploy` to ship it, or `flaghoist eject` to own the code.");
333
334
  }
334
335
  function writeProject(config, dir) {
335
- writeFileSafe(join(dir, "src/index.ts"), generateWorkerEntry(config));
336
- writeFileSafe(join(dir, "wrangler.toml"), generateWranglerToml(config));
337
- writeFileSafe(join(dir, "package.json"), generatePackageJson(config));
336
+ const files = [
337
+ ["src/index.ts", generateWorkerEntry(config)],
338
+ ["wrangler.toml", generateWranglerToml(config)],
339
+ ["package.json", generatePackageJson(config)]
340
+ ];
341
+ const existing = files.map(([name]) => name).filter((name) => existsSync(join(dir, name)));
342
+ if (existing.length > 0) {
343
+ throw new Error(
344
+ `Refusing to overwrite ${existing.join(", ")} in this directory.
345
+ Flaghoist deploys as its own service, so give it a directory of its own:
346
+ npm create flaghoist@latest team-flags`
347
+ );
348
+ }
349
+ for (const [name, contents] of files) writeFileSafe(join(dir, name), contents);
338
350
  }
339
351
  function runEject() {
340
352
  const config = loadConfig();
341
- if (existsSync("src/index.ts")) throw new Error("src/index.ts already exists \u2014 already ejected?");
353
+ if (existsSync("src/index.ts")) throw new Error("src/index.ts already exists. Already ejected?");
342
354
  writeProject(config, ".");
343
355
  console.log("Ejected to a code project you own: src/index.ts, wrangler.toml, package.json");
344
356
  if (config.storage === "cloudflare-kv") {
@@ -381,7 +393,48 @@ function ensureDependencies() {
381
393
  throw new Error("`npm install` failed. Run it yourself, then `flaghoist deploy` again.");
382
394
  }
383
395
  }
384
- function runDeploy() {
396
+ function parseDeployTarget(args) {
397
+ const i = args.indexOf("--target");
398
+ if (i < 0) return null;
399
+ const value = args[i + 1]?.toLowerCase();
400
+ if (value === "cloudflare" || value === "cf" || value === "workers") return "cloudflare";
401
+ return "other";
402
+ }
403
+ async function promptDeployTarget() {
404
+ console.log("Where do you want to deploy?");
405
+ console.log(" 1) Cloudflare Workers recommended, deploys in one command");
406
+ console.log(" 2) Another platform Render, a container, any Node host");
407
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
408
+ try {
409
+ const answer = (await rl.question("Choose [1]: ")).trim().toLowerCase();
410
+ return answer === "2" || answer.startsWith("o") || answer.startsWith("r") ? "other" : "cloudflare";
411
+ } finally {
412
+ rl.close();
413
+ }
414
+ }
415
+ function printOtherTargets() {
416
+ console.log(`
417
+ Flaghoist runs on any Node, Bun, Deno, or container host, not just Cloudflare.
418
+
419
+ The project scaffolded here is a Cloudflare Worker. To run it elsewhere you serve the same
420
+ createFlagServer() app on Node and point it at Postgres or Redis instead of Workers KV.
421
+
422
+ Guides:
423
+ Render https://docs.flaghoist.dev/deploy/render/
424
+ All targets https://docs.flaghoist.dev/deploy/overview/
425
+
426
+ More platforms are on the way. Missing one you need? Open an issue at
427
+ https://github.com/flaghoist/flaghoist/issues.`);
428
+ }
429
+ async function runDeploy(args) {
430
+ let target = parseDeployTarget(args);
431
+ if (target === null) {
432
+ target = process.stdin.isTTY ? await promptDeployTarget() : "cloudflare";
433
+ }
434
+ if (target === "other") {
435
+ printOtherTargets();
436
+ return;
437
+ }
385
438
  const config = loadConfig();
386
439
  if (!existsSync("src/index.ts")) writeProject(config, ".");
387
440
  ensureDependencies();
@@ -398,7 +451,7 @@ Usage: flaghoist <command>
398
451
  Scaffolding
399
452
  init [--name N] [--storage cloudflare-kv|redis|postgres|memory]
400
453
  eject Generate a code project you own
401
- deploy Deploy to Cloudflare via wrangler
454
+ deploy [--target T] Deploy (prompts for the platform; T is cloudflare or other)
402
455
 
403
456
  Flag management (needs --url/--token or FLAGS_URL/FLAGS_ADMIN_TOKEN)
404
457
  flag list
@@ -419,7 +472,7 @@ async function main() {
419
472
  case "eject":
420
473
  return runEject();
421
474
  case "deploy":
422
- return runDeploy();
475
+ return runDeploy(rest);
423
476
  case "-v":
424
477
  case "--version":
425
478
  return console.log(VERSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flaghoist",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Scaffold, deploy, and manage your Flaghoist feature-flag service from the terminal.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -23,12 +23,12 @@
23
23
  "node": ">=20"
24
24
  },
25
25
  "dependencies": {
26
- "smol-toml": "^1.7.1"
26
+ "smol-toml": "^1.8.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@flaghoist/adapter-memory": "0.1.1",
30
- "@flaghoist/core": "0.1.1",
31
- "@flaghoist/server": "0.1.1"
29
+ "@flaghoist/core": "0.1.2",
30
+ "@flaghoist/adapter-memory": "0.1.2",
31
+ "@flaghoist/server": "0.3.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"