flaghoist 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 +52 -0
- package/dist/index.js +15 -5
- package/package.json +22 -4
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# flaghoist
|
|
2
|
+
|
|
3
|
+
Feature flags you run yourself. This is the command line tool for setting up a Flaghoist server and
|
|
4
|
+
managing the flags on it.
|
|
5
|
+
|
|
6
|
+
Your whole project is one `flaghoist.toml` file. The CLI turns that into a Cloudflare Worker, or
|
|
7
|
+
hands you the code if you would rather own it.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm create flaghoist@latest team-flags
|
|
11
|
+
cd team-flags
|
|
12
|
+
npx flaghoist deploy
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That gives you an OFREP read API, an admin API, and a dashboard at `/admin`, all from a single
|
|
16
|
+
deploy. On Cloudflare KV, the first deploy also creates the KV namespace for you and writes its id
|
|
17
|
+
into `wrangler.toml`.
|
|
18
|
+
|
|
19
|
+
## Managing flags
|
|
20
|
+
|
|
21
|
+
Point the CLI at your server with `--url` and `--token`, or set `FLAGS_URL` and
|
|
22
|
+
`FLAGS_ADMIN_TOKEN`.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
flaghoist flag list
|
|
26
|
+
flaghoist flag create new-checkout --desc "The redesigned checkout"
|
|
27
|
+
flaghoist flag toggle new-checkout --on
|
|
28
|
+
flaghoist flag rollout new-checkout 25
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Rollouts are sticky. A user who lands inside 25 percent stays inside it as you go to 50, so nobody
|
|
32
|
+
flickers in and out between deploys.
|
|
33
|
+
|
|
34
|
+
## Owning the code
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx flaghoist eject
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Writes `src/index.ts`, `wrangler.toml` and `package.json` into your project. From there it is a
|
|
41
|
+
normal Worker and the CLI steps out of the way.
|
|
42
|
+
|
|
43
|
+
Flags are boolean only. There are no multivariate flags, experiments or scheduled rules, and there
|
|
44
|
+
is no plan to imply otherwise.
|
|
45
|
+
|
|
46
|
+
## Status
|
|
47
|
+
|
|
48
|
+
Pre-alpha, built and maintained by one person. The API can still change without notice, and
|
|
49
|
+
production use is not recommended yet. If you try it and something breaks, an issue is genuinely
|
|
50
|
+
useful.
|
|
51
|
+
|
|
52
|
+
Apache-2.0. Part of [Flaghoist](https://github.com/flaghoist/flaghoist).
|
package/dist/index.js
CHANGED
|
@@ -164,7 +164,7 @@ function generateWranglerToml(config) {
|
|
|
164
164
|
if (config.storage === "cloudflare-kv") {
|
|
165
165
|
lines.push(
|
|
166
166
|
"",
|
|
167
|
-
|
|
167
|
+
`# Created for you by \`flaghoist deploy\`, or by: npx wrangler kv namespace create ${config.name}-FLAGS`,
|
|
168
168
|
"kv_namespaces = [",
|
|
169
169
|
` { binding = "FLAGS", id = ${JSON.stringify(KV_NAMESPACE_PLACEHOLDER)} }`,
|
|
170
170
|
"]"
|
|
@@ -343,7 +343,7 @@ function runEject() {
|
|
|
343
343
|
console.log("Ejected to a code project you own: src/index.ts, wrangler.toml, package.json");
|
|
344
344
|
if (config.storage === "cloudflare-kv") {
|
|
345
345
|
console.log("Create your KV namespace and paste the id into wrangler.toml:");
|
|
346
|
-
console.log(
|
|
346
|
+
console.log(` npx wrangler kv namespace create ${config.name}-FLAGS`);
|
|
347
347
|
}
|
|
348
348
|
console.log("Edit src/index.ts freely, then: npm install && npx wrangler deploy");
|
|
349
349
|
}
|
|
@@ -351,8 +351,9 @@ function ensureKvNamespace(config) {
|
|
|
351
351
|
if (config.storage !== "cloudflare-kv") return;
|
|
352
352
|
const toml = readFileSync("wrangler.toml", "utf8");
|
|
353
353
|
if (!needsKvNamespace(toml)) return;
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
const title = `${config.name}-FLAGS`;
|
|
355
|
+
console.log(`Creating the ${title} KV namespace...`);
|
|
356
|
+
const created = spawnSync("npx", ["wrangler", "kv", "namespace", "create", title], {
|
|
356
357
|
stdio: ["inherit", "pipe", "inherit"],
|
|
357
358
|
encoding: "utf8"
|
|
358
359
|
});
|
|
@@ -360,7 +361,7 @@ function ensureKvNamespace(config) {
|
|
|
360
361
|
if (output) process.stdout.write(output);
|
|
361
362
|
if (created.status !== 0) {
|
|
362
363
|
throw new Error(
|
|
363
|
-
|
|
364
|
+
`Could not create the KV namespace. Run \`npx wrangler kv namespace create ${title}\` yourself, then paste the id into wrangler.toml.`
|
|
364
365
|
);
|
|
365
366
|
}
|
|
366
367
|
const id = parseKvNamespaceId(output);
|
|
@@ -372,9 +373,18 @@ function ensureKvNamespace(config) {
|
|
|
372
373
|
writeFileSync("wrangler.toml", fillKvNamespaceId(toml, id));
|
|
373
374
|
console.log(`Bound FLAGS to namespace ${id} in wrangler.toml`);
|
|
374
375
|
}
|
|
376
|
+
function ensureDependencies() {
|
|
377
|
+
if (existsSync("node_modules")) return;
|
|
378
|
+
console.log("Installing dependencies...");
|
|
379
|
+
const result = spawnSync("npm", ["install", "--no-audit", "--no-fund"], { stdio: "inherit" });
|
|
380
|
+
if (result.status !== 0) {
|
|
381
|
+
throw new Error("`npm install` failed. Run it yourself, then `flaghoist deploy` again.");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
375
384
|
function runDeploy() {
|
|
376
385
|
const config = loadConfig();
|
|
377
386
|
if (!existsSync("src/index.ts")) writeProject(config, ".");
|
|
387
|
+
ensureDependencies();
|
|
378
388
|
ensureKvNamespace(config);
|
|
379
389
|
console.log("Deploying with wrangler...");
|
|
380
390
|
const result = spawnSync("npx", ["wrangler", "deploy"], { stdio: "inherit" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flaghoist",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
@@ -26,13 +26,31 @@
|
|
|
26
26
|
"smol-toml": "^1.7.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@flaghoist/adapter-memory": "0.1.
|
|
30
|
-
"@flaghoist/core": "0.1.
|
|
31
|
-
"@flaghoist/server": "0.1.
|
|
29
|
+
"@flaghoist/adapter-memory": "0.1.1",
|
|
30
|
+
"@flaghoist/core": "0.1.1",
|
|
31
|
+
"@flaghoist/server": "0.1.1"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"feature-flags",
|
|
38
|
+
"feature-toggles",
|
|
39
|
+
"openfeature",
|
|
40
|
+
"ofrep",
|
|
41
|
+
"cloudflare-workers",
|
|
42
|
+
"self-hosted",
|
|
43
|
+
"cli"
|
|
44
|
+
],
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/flaghoist/flaghoist.git",
|
|
48
|
+
"directory": "packages/cli"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/flaghoist/flaghoist#readme",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/flaghoist/flaghoist/issues"
|
|
53
|
+
},
|
|
36
54
|
"scripts": {
|
|
37
55
|
"build": "tsup src/index.ts src/lib.ts --format esm --dts --clean",
|
|
38
56
|
"test": "vitest run --passWithNoTests",
|