create-flaghoist 0.1.3 → 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 +18 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { STORAGE_KINDS as STORAGE_KINDS2 } from "flaghoist";
4
+ import { PLATFORM_KINDS as PLATFORM_KINDS2, STORAGE_KINDS as STORAGE_KINDS2 } from "flaghoist";
5
5
  import { parseArgs } from "util";
6
6
  import { relative } from "path";
7
7
 
8
8
  // src/scaffold.ts
9
9
  import {
10
+ asContainer,
10
11
  DEFAULT_CONFIG,
12
+ PLATFORM_KINDS,
11
13
  serializeConfig,
12
14
  STORAGE_KINDS
13
15
  } from "flaghoist";
@@ -18,6 +20,9 @@ function scaffold(options = {}) {
18
20
  if (options.storage && !STORAGE_KINDS.includes(options.storage)) {
19
21
  throw new Error(`Unknown storage "${options.storage}". One of: ${STORAGE_KINDS.join(", ")}.`);
20
22
  }
23
+ if (options.platform && !PLATFORM_KINDS.includes(options.platform)) {
24
+ throw new Error(`Unknown platform "${options.platform}". One of: ${PLATFORM_KINDS.join(", ")}.`);
25
+ }
21
26
  const dir = options.directory ? resolve(root, options.directory) : resolve(root);
22
27
  const existed = existsSync(dir);
23
28
  if (existed && readdirSync(dir).length > 0) {
@@ -26,12 +31,13 @@ function scaffold(options = {}) {
26
31
  );
27
32
  }
28
33
  if (!existed) mkdirSync(dir, { recursive: true });
29
- const config = {
34
+ const base = {
30
35
  ...DEFAULT_CONFIG,
31
36
  // The directory name is the natural project name; falling back keeps `.` usable.
32
37
  name: options.directory ?? DEFAULT_CONFIG.name,
33
38
  storage: options.storage ?? DEFAULT_CONFIG.storage
34
39
  };
40
+ const config = options.platform === "container" ? asContainer(base) : base;
35
41
  const configPath = join(dir, "flaghoist.toml");
36
42
  writeFileSync(configPath, serializeConfig(config));
37
43
  return { dir, configPath, createdDirectory: !existed, config };
@@ -42,11 +48,12 @@ function printHelp() {
42
48
  console.log(`create-flaghoist \u2014 scaffold a Flaghoist feature-flag service
43
49
 
44
50
  Usage:
45
- npm create flaghoist@latest <directory> [--storage <kind>]
51
+ npm create flaghoist@latest <directory> [--storage <kind>] [--platform <kind>]
46
52
 
47
53
  Options:
48
- --storage One of: ${STORAGE_KINDS2.join(", ")} (default: ${STORAGE_KINDS2[0]})
49
- -h, --help Show this message
54
+ --storage One of: ${STORAGE_KINDS2.join(", ")} (default: ${STORAGE_KINDS2[0]})
55
+ --platform One of: ${PLATFORM_KINDS2.join(", ")} (default: ${PLATFORM_KINDS2[0]})
56
+ -h, --help Show this message
50
57
 
51
58
  Omit <directory> to scaffold into the current directory (it must be empty).`);
52
59
  }
@@ -56,19 +63,22 @@ function main() {
56
63
  allowPositionals: true,
57
64
  options: {
58
65
  storage: { type: "string" },
66
+ platform: { type: "string" },
59
67
  help: { type: "boolean", short: "h" }
60
68
  }
61
69
  });
62
70
  if (values.help) return printHelp();
63
71
  const { dir, configPath, config } = scaffold({
64
72
  directory: positionals[0],
65
- storage: values.storage
73
+ storage: values.storage,
74
+ platform: values.platform
66
75
  });
67
76
  const shown = relative(process.cwd(), configPath) || "flaghoist.toml";
68
77
  console.log(`
69
78
  Created ${shown}`);
70
- console.log(` name ${config.name}`);
71
- console.log(` storage ${config.storage}
79
+ console.log(` name ${config.name}`);
80
+ console.log(` storage ${config.storage}`);
81
+ console.log(` platform ${config.platform}
72
82
  `);
73
83
  console.log("That file is the entire project. Next:\n");
74
84
  const cd = relative(process.cwd(), dir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-flaghoist",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Scaffold a Flaghoist feature-flag service — the package behind `npm create flaghoist`.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "scaffold"
22
22
  ],
23
23
  "dependencies": {
24
- "flaghoist": "0.1.3"
24
+ "flaghoist": "0.3.0"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"