flaghoist 0.1.1 → 0.1.3
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/dist/index.js +30 -9
- package/package.json +3 -3
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
|
"]"
|
|
@@ -332,18 +332,29 @@ function runInit(args) {
|
|
|
332
332
|
console.log("Next: `flaghoist deploy` to ship it, or `flaghoist eject` to own the code.");
|
|
333
333
|
}
|
|
334
334
|
function writeProject(config, dir) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
const files = [
|
|
336
|
+
["src/index.ts", generateWorkerEntry(config)],
|
|
337
|
+
["wrangler.toml", generateWranglerToml(config)],
|
|
338
|
+
["package.json", generatePackageJson(config)]
|
|
339
|
+
];
|
|
340
|
+
const existing = files.map(([name]) => name).filter((name) => existsSync(join(dir, name)));
|
|
341
|
+
if (existing.length > 0) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
`Refusing to overwrite ${existing.join(", ")} in this directory.
|
|
344
|
+
Flaghoist deploys as its own service, so give it a directory of its own:
|
|
345
|
+
npm create flaghoist@latest team-flags`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
for (const [name, contents] of files) writeFileSafe(join(dir, name), contents);
|
|
338
349
|
}
|
|
339
350
|
function runEject() {
|
|
340
351
|
const config = loadConfig();
|
|
341
|
-
if (existsSync("src/index.ts")) throw new Error("src/index.ts already exists
|
|
352
|
+
if (existsSync("src/index.ts")) throw new Error("src/index.ts already exists. Already ejected?");
|
|
342
353
|
writeProject(config, ".");
|
|
343
354
|
console.log("Ejected to a code project you own: src/index.ts, wrangler.toml, package.json");
|
|
344
355
|
if (config.storage === "cloudflare-kv") {
|
|
345
356
|
console.log("Create your KV namespace and paste the id into wrangler.toml:");
|
|
346
|
-
console.log(
|
|
357
|
+
console.log(` npx wrangler kv namespace create ${config.name}-FLAGS`);
|
|
347
358
|
}
|
|
348
359
|
console.log("Edit src/index.ts freely, then: npm install && npx wrangler deploy");
|
|
349
360
|
}
|
|
@@ -351,8 +362,9 @@ function ensureKvNamespace(config) {
|
|
|
351
362
|
if (config.storage !== "cloudflare-kv") return;
|
|
352
363
|
const toml = readFileSync("wrangler.toml", "utf8");
|
|
353
364
|
if (!needsKvNamespace(toml)) return;
|
|
354
|
-
|
|
355
|
-
|
|
365
|
+
const title = `${config.name}-FLAGS`;
|
|
366
|
+
console.log(`Creating the ${title} KV namespace...`);
|
|
367
|
+
const created = spawnSync("npx", ["wrangler", "kv", "namespace", "create", title], {
|
|
356
368
|
stdio: ["inherit", "pipe", "inherit"],
|
|
357
369
|
encoding: "utf8"
|
|
358
370
|
});
|
|
@@ -360,7 +372,7 @@ function ensureKvNamespace(config) {
|
|
|
360
372
|
if (output) process.stdout.write(output);
|
|
361
373
|
if (created.status !== 0) {
|
|
362
374
|
throw new Error(
|
|
363
|
-
|
|
375
|
+
`Could not create the KV namespace. Run \`npx wrangler kv namespace create ${title}\` yourself, then paste the id into wrangler.toml.`
|
|
364
376
|
);
|
|
365
377
|
}
|
|
366
378
|
const id = parseKvNamespaceId(output);
|
|
@@ -372,9 +384,18 @@ function ensureKvNamespace(config) {
|
|
|
372
384
|
writeFileSync("wrangler.toml", fillKvNamespaceId(toml, id));
|
|
373
385
|
console.log(`Bound FLAGS to namespace ${id} in wrangler.toml`);
|
|
374
386
|
}
|
|
387
|
+
function ensureDependencies() {
|
|
388
|
+
if (existsSync("node_modules")) return;
|
|
389
|
+
console.log("Installing dependencies...");
|
|
390
|
+
const result = spawnSync("npm", ["install", "--no-audit", "--no-fund"], { stdio: "inherit" });
|
|
391
|
+
if (result.status !== 0) {
|
|
392
|
+
throw new Error("`npm install` failed. Run it yourself, then `flaghoist deploy` again.");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
375
395
|
function runDeploy() {
|
|
376
396
|
const config = loadConfig();
|
|
377
397
|
if (!existsSync("src/index.ts")) writeProject(config, ".");
|
|
398
|
+
ensureDependencies();
|
|
378
399
|
ensureKvNamespace(config);
|
|
379
400
|
console.log("Deploying with wrangler...");
|
|
380
401
|
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.3",
|
|
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.
|
|
26
|
+
"smol-toml": "^1.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@flaghoist/adapter-memory": "0.1.1",
|
|
30
30
|
"@flaghoist/core": "0.1.1",
|
|
31
|
-
"@flaghoist/server": "0.1.
|
|
31
|
+
"@flaghoist/server": "0.1.2"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|