@i2bskn/workers-deploy 0.1.0 → 0.1.1
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 +4 -2
- package/package.json +1 -1
- package/src/deploy.js +15 -7
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Run it from the root of the project. The bindings are read from the Wrangler con
|
|
|
33
33
|
extends with `node_modules/.bin`.
|
|
34
34
|
|
|
35
35
|
```
|
|
36
|
-
Usage: workers-deploy [--require-existing-databases]
|
|
36
|
+
Usage: workers-deploy [--require-existing-databases] [--keep-vars]
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
## Environment variables
|
|
@@ -51,6 +51,7 @@ In Workers Builds, set them as build variables.
|
|
|
51
51
|
| flag | effect |
|
|
52
52
|
| --- | --- |
|
|
53
53
|
| `--require-existing-databases` | Stops with an error, before creating or deploying anything, when a D1 database of the configuration does not exist. Without it, `wrangler deploy` would create a new, empty database. A D1 binding without both `database_name` and `database_id` counts as missing. R2 buckets are still created as usual. |
|
|
54
|
+
| `--keep-vars` | Passes `--keep-vars` to `wrangler deploy`, so that the variables set in the dashboard are kept. It is not passed to the other wrangler commands. |
|
|
54
55
|
| `--help`, `-h` | Prints the usage. |
|
|
55
56
|
|
|
56
57
|
Any other argument is an error.
|
|
@@ -74,7 +75,8 @@ Any other argument is an error.
|
|
|
74
75
|
deploys, so that new code never runs against missing tables. If any of them is missing, deploys first so that
|
|
75
76
|
`wrangler deploy` creates it, and then applies the migrations. In that case the new Worker runs without tables for a
|
|
76
77
|
few seconds, which is harmless on a first deploy.
|
|
77
|
-
8. Deploys with `wrangler deploy`, adding `--domains <hostname>` for each hostname of `CUSTOM_DOMAINS
|
|
78
|
+
8. Deploys with `wrangler deploy`, adding `--domains <hostname>` for each hostname of `CUSTOM_DOMAINS`, and
|
|
79
|
+
`--keep-vars` at the end when `--keep-vars` is given.
|
|
78
80
|
|
|
79
81
|
Existing databases and buckets are never moved: their location cannot be changed.
|
|
80
82
|
|
package/package.json
CHANGED
package/src/deploy.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// exist yet, this command deploys first and applies the migrations right after. In that case the new Worker runs
|
|
8
8
|
// without tables for a few seconds, which is harmless because nobody uses it yet. With --require-existing-databases,
|
|
9
9
|
// a missing database is an error instead, so that `wrangler deploy` never creates a new, empty one.
|
|
10
|
+
// With --keep-vars, `wrangler deploy` gets --keep-vars, so that the variables set in the dashboard are kept.
|
|
10
11
|
//
|
|
11
12
|
// On later deploys the migrations are applied before `wrangler deploy`, so that new code never runs against missing
|
|
12
13
|
// tables.
|
|
@@ -27,16 +28,21 @@
|
|
|
27
28
|
// Every side effect is injected, so that this module can be imported and tested without wrangler.
|
|
28
29
|
import path from "node:path";
|
|
29
30
|
|
|
30
|
-
export const USAGE = "Usage: workers-deploy [--require-existing-databases]";
|
|
31
|
+
export const USAGE = "Usage: workers-deploy [--require-existing-databases] [--keep-vars]";
|
|
31
32
|
|
|
32
33
|
const HELP = `${USAGE}
|
|
33
34
|
|
|
35
|
+
Flags:
|
|
36
|
+
--require-existing-databases Fail without deploying anything when a D1 database does not exist.
|
|
37
|
+
--keep-vars Pass --keep-vars to wrangler deploy, keeping the variables set in the dashboard.
|
|
38
|
+
|
|
34
39
|
Environment variables:
|
|
35
40
|
LOCATION_HINT Location of the D1 databases and R2 buckets to create: weur, eeur, apac, oc, wnam or enam.
|
|
36
41
|
CUSTOM_DOMAINS Hostnames passed to wrangler deploy --domains, separated by commas or spaces.
|
|
37
42
|
`;
|
|
38
43
|
|
|
39
44
|
const REQUIRE_EXISTING_DATABASES = "--require-existing-databases";
|
|
45
|
+
const KEEP_VARS = "--keep-vars";
|
|
40
46
|
const LOCATIONS = ["weur", "eeur", "apac", "oc", "wnam", "enam"];
|
|
41
47
|
const MISSING_DATABASE = /Couldn't find (a|an auto-provisioned) D1 DB/;
|
|
42
48
|
const MISSING_BUCKET = "[code: 10006]";
|
|
@@ -60,21 +66,24 @@ function output(result) {
|
|
|
60
66
|
/**
|
|
61
67
|
* Parses the command line arguments.
|
|
62
68
|
* @param {string[]} argv
|
|
63
|
-
* @returns {{ help: true } | { help: false, requireExistingDatabases: boolean } | { error: string }}
|
|
69
|
+
* @returns {{ help: true } | { help: false, requireExistingDatabases: boolean, keepVars: boolean } | { error: string }}
|
|
64
70
|
*/
|
|
65
71
|
export function parseArgs(argv) {
|
|
66
72
|
if (argv.includes("--help") || argv.includes("-h")) {
|
|
67
73
|
return { help: true };
|
|
68
74
|
}
|
|
69
75
|
let requireExistingDatabases = false;
|
|
76
|
+
let keepVars = false;
|
|
70
77
|
for (const arg of argv) {
|
|
71
78
|
if (arg === REQUIRE_EXISTING_DATABASES) {
|
|
72
79
|
requireExistingDatabases = true;
|
|
80
|
+
} else if (arg === KEEP_VARS) {
|
|
81
|
+
keepVars = true;
|
|
73
82
|
} else {
|
|
74
83
|
return { error: `Unknown argument "${arg}". ${USAGE}` };
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
|
-
return { help: false, requireExistingDatabases };
|
|
86
|
+
return { help: false, requireExistingDatabases, keepVars };
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
/**
|
|
@@ -298,11 +307,10 @@ async function deploy({ argv, env, readConfig, wrangler, exists, cwd, log, warn,
|
|
|
298
307
|
function deployWorker() {
|
|
299
308
|
if (domains.length === 0) {
|
|
300
309
|
log("Deploying the Worker. CUSTOM_DOMAINS is not set: no Custom Domains are passed to wrangler deploy.");
|
|
301
|
-
|
|
302
|
-
|
|
310
|
+
} else {
|
|
311
|
+
log(`Deploying the Worker with the Custom Domains ${domains.join(", ")}.`);
|
|
303
312
|
}
|
|
304
|
-
|
|
305
|
-
run(["deploy", ...domains.flatMap((domain) => ["--domains", domain])]);
|
|
313
|
+
run(["deploy", ...domains.flatMap((domain) => ["--domains", domain]), ...(args.keepVars ? [KEEP_VARS] : [])]);
|
|
306
314
|
}
|
|
307
315
|
|
|
308
316
|
const missing = migrated.filter((db) => !databaseExists.get(db.binding));
|