flaghoist 0.1.1 → 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/dist/index.js +15 -5
- package/package.json +1 -1
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" });
|