drop2run 0.3.0 → 0.4.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.
- package/README.md +15 -2
- package/dist/index.js +71 -23
- package/dist/{package-B5PgBI_i.js → package-Cz51eZ2C.js} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ drop2run login [--device] Sign in and store a token
|
|
|
16
16
|
drop2run logout Remove the stored token
|
|
17
17
|
drop2run init [dir] [--site <subdomain>] Tie this folder to a site
|
|
18
18
|
drop2run deploy [dir] [--site <subdomain>] Publish a folder
|
|
19
|
+
drop2run init|deploy --subdomain <name> Create a new site under a name you pick
|
|
19
20
|
drop2run ls List your sites
|
|
20
21
|
drop2run open [site] Open a site in a browser
|
|
21
22
|
drop2run rollback <deployId> [--site X] Put an earlier version back live
|
|
@@ -30,14 +31,26 @@ drop2run --version Print the version
|
|
|
30
31
|
|
|
31
32
|
## Which site a command acts on
|
|
32
33
|
|
|
33
|
-
`--site`, then `drop2run.json`, then a new
|
|
34
|
-
normal project:
|
|
34
|
+
`--subdomain` creates one under the name you give; otherwise `--site`, then `drop2run.json`, then a new
|
|
35
|
+
site with a generated name. `init` writes that file, so this is the whole of a normal project:
|
|
35
36
|
|
|
36
37
|
```bash
|
|
37
38
|
drop2run init dist # creates a site, writes drop2run.json
|
|
38
39
|
drop2run deploy # publishes dist to it, no arguments
|
|
39
40
|
```
|
|
40
41
|
|
|
42
|
+
```bash
|
|
43
|
+
drop2run init dist --subdomain my-docs # same, but you choose the address
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Lowercase letters, digits and hyphens, not starting or ending with one. A name that is taken, reserved,
|
|
47
|
+
or past the number of self-picked names your plan allows is refused with the reason. It cannot be changed
|
|
48
|
+
later — a site is reached by the address it was created with — so a wrong name means deleting the site,
|
|
49
|
+
which is not undoable.
|
|
50
|
+
|
|
51
|
+
`--site` never creates anything: it finds a site you already have, and fails when nothing matches. That
|
|
52
|
+
is what keeps a subdomain typed one letter wrong from quietly becoming a second site.
|
|
53
|
+
|
|
41
54
|
`deploy` never creates a second site while a `drop2run.json` sits next to it — that would leave the real
|
|
42
55
|
site untouched and you looking at a URL you did not expect.
|
|
43
56
|
|
package/dist/index.js
CHANGED
|
@@ -55,11 +55,17 @@ async function listSites(credentials) {
|
|
|
55
55
|
const body = await call(credentials, "sites");
|
|
56
56
|
return body.sites;
|
|
57
57
|
}
|
|
58
|
-
async function createSite(credentials) {
|
|
58
|
+
async function createSite(credentials, subdomain) {
|
|
59
59
|
const created = await call(
|
|
60
60
|
credentials,
|
|
61
61
|
"sites",
|
|
62
|
-
{
|
|
62
|
+
{
|
|
63
|
+
method: "POST",
|
|
64
|
+
// An absent field rather than a null one, because the API reads null, empty and missing the
|
|
65
|
+
// same way and a body carrying only what was asked for is the one that reads correctly in a
|
|
66
|
+
// log.
|
|
67
|
+
body: JSON.stringify(subdomain === void 0 ? {} : { subdomain })
|
|
68
|
+
}
|
|
63
69
|
);
|
|
64
70
|
return { ...created, name: null };
|
|
65
71
|
}
|
|
@@ -369,6 +375,7 @@ const ClientErrorCode = {
|
|
|
369
375
|
/** An upload kept failing after every retry. */
|
|
370
376
|
UploadFailed: "upload_failed"
|
|
371
377
|
};
|
|
378
|
+
const ACCOUNT_HEADER = "X-Drop2Run-Account";
|
|
372
379
|
const CLAIM_TOKEN_HEADER = "X-Claim-Token";
|
|
373
380
|
async function prepareDeploy(siteId, files, options, signal) {
|
|
374
381
|
const manifest = files.map((file) => ({
|
|
@@ -405,6 +412,7 @@ async function request(path, body, options, signal) {
|
|
|
405
412
|
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
406
413
|
if (options.claimToken) headers[CLAIM_TOKEN_HEADER] = options.claimToken;
|
|
407
414
|
if (options.token) headers.Authorization = `Bearer ${options.token}`;
|
|
415
|
+
if (options.accountId) headers[ACCOUNT_HEADER] = options.accountId;
|
|
408
416
|
const response = await doFetch(`${base}/${path}`, {
|
|
409
417
|
method: "POST",
|
|
410
418
|
headers,
|
|
@@ -865,7 +873,15 @@ function escapesRoot(root, candidate) {
|
|
|
865
873
|
const inside = relative(root, candidate);
|
|
866
874
|
return inside === "" || inside.startsWith("..");
|
|
867
875
|
}
|
|
868
|
-
async function resolveSite(credentials, site) {
|
|
876
|
+
async function resolveSite(credentials, site, subdomain) {
|
|
877
|
+
if (subdomain !== void 0) {
|
|
878
|
+
if (site !== void 0) {
|
|
879
|
+
throw new Error(
|
|
880
|
+
"Give either an existing site or a subdomain for a new one, not both: publishing over a site and creating one are different requests."
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
return await createSite(credentials, subdomain);
|
|
884
|
+
}
|
|
869
885
|
if (site === void 0) return await createSite(credentials);
|
|
870
886
|
const wanted = site.trim().toLowerCase();
|
|
871
887
|
const found = (await listSites(credentials)).find(
|
|
@@ -878,8 +894,8 @@ async function resolveSite(credentials, site) {
|
|
|
878
894
|
}
|
|
879
895
|
return found;
|
|
880
896
|
}
|
|
881
|
-
async function publish(credentials, source, site, onProgress) {
|
|
882
|
-
const target = await resolveSite(credentials, site);
|
|
897
|
+
async function publish(credentials, source, site, onProgress, subdomain) {
|
|
898
|
+
const target = await resolveSite(credentials, site, subdomain);
|
|
883
899
|
let files = 0;
|
|
884
900
|
let url = target.url;
|
|
885
901
|
let unchanged = false;
|
|
@@ -910,8 +926,8 @@ async function publish(credentials, source, site, onProgress) {
|
|
|
910
926
|
});
|
|
911
927
|
return { url, siteId: target.siteId, subdomain: target.subdomain, files, unchanged };
|
|
912
928
|
}
|
|
913
|
-
function publishDirectory(credentials, directory, site, onProgress) {
|
|
914
|
-
return publish(credentials, directorySource(directory), site, onProgress);
|
|
929
|
+
function publishDirectory(credentials, directory, site, onProgress, subdomain) {
|
|
930
|
+
return publish(credentials, directorySource(directory), site, onProgress, subdomain);
|
|
915
931
|
}
|
|
916
932
|
const silentProgress = Object.assign(() => {
|
|
917
933
|
}, { done: () => {
|
|
@@ -1122,14 +1138,20 @@ async function list() {
|
|
|
1122
1138
|
code: 0
|
|
1123
1139
|
};
|
|
1124
1140
|
}
|
|
1125
|
-
async function deployCommand(directory, site, report = silentProgress) {
|
|
1141
|
+
async function deployCommand(directory, site, report = silentProgress, subdomain) {
|
|
1126
1142
|
const found = credentialsOr();
|
|
1127
1143
|
if ("result" in found) return found.result;
|
|
1128
1144
|
const project = readProject();
|
|
1129
|
-
const target = site ?? project?.siteId;
|
|
1130
1145
|
const folder = directory ?? project?.dir ?? ".";
|
|
1146
|
+
const target = subdomain === void 0 ? site ?? project?.siteId : void 0;
|
|
1131
1147
|
try {
|
|
1132
|
-
const result = await publishDirectory(
|
|
1148
|
+
const result = await publishDirectory(
|
|
1149
|
+
found.credentials,
|
|
1150
|
+
resolve(folder),
|
|
1151
|
+
target,
|
|
1152
|
+
report,
|
|
1153
|
+
subdomain
|
|
1154
|
+
);
|
|
1133
1155
|
const what = result.unchanged ? "Already up to date — nothing needed publishing." : `Published ${result.files.toLocaleString()} ${result.files === 1 ? "file" : "files"}.`;
|
|
1134
1156
|
return {
|
|
1135
1157
|
text: `${what}
|
|
@@ -1143,7 +1165,7 @@ ${result.url}`,
|
|
|
1143
1165
|
report.done();
|
|
1144
1166
|
}
|
|
1145
1167
|
}
|
|
1146
|
-
async function init(directory, site) {
|
|
1168
|
+
async function init(directory, site, subdomain) {
|
|
1147
1169
|
const found = credentialsOr();
|
|
1148
1170
|
if ("result" in found) return found.result;
|
|
1149
1171
|
if (readProject() !== null) {
|
|
@@ -1152,7 +1174,7 @@ async function init(directory, site) {
|
|
|
1152
1174
|
);
|
|
1153
1175
|
}
|
|
1154
1176
|
try {
|
|
1155
|
-
const target = site === void 0 ? await createSite(found.credentials) : await findSite(found.credentials, site);
|
|
1177
|
+
const target = site === void 0 ? await createSite(found.credentials, subdomain) : await findSite(found.credentials, site);
|
|
1156
1178
|
const project = {
|
|
1157
1179
|
siteId: target.siteId,
|
|
1158
1180
|
subdomain: target.subdomain,
|
|
@@ -1290,6 +1312,7 @@ const HELP = `drop2run — publish a static site from the command line
|
|
|
1290
1312
|
drop2run logout Remove the stored token
|
|
1291
1313
|
drop2run init [dir] [--site <subdomain>] Tie this folder to a site (writes drop2run.json)
|
|
1292
1314
|
drop2run deploy [dir] [--site <subdomain>] Publish a folder (default: . or drop2run.json)
|
|
1315
|
+
drop2run init|deploy --subdomain <name> Create a new site under a name you pick
|
|
1293
1316
|
drop2run ls List your sites
|
|
1294
1317
|
drop2run open [site] Open a site in a browser
|
|
1295
1318
|
drop2run rollback <deployId> [--site X] Put an earlier version back live
|
|
@@ -1300,14 +1323,19 @@ const HELP = `drop2run — publish a static site from the command line
|
|
|
1300
1323
|
drop2run --version Print the version
|
|
1301
1324
|
|
|
1302
1325
|
Flags
|
|
1303
|
-
--json
|
|
1304
|
-
--site X
|
|
1305
|
-
--
|
|
1306
|
-
--
|
|
1326
|
+
--json Print machine-readable output instead of text
|
|
1327
|
+
--site X Act on an existing site rather than the one in drop2run.json
|
|
1328
|
+
--subdomain X Create a new site under this name (init and deploy only)
|
|
1329
|
+
--device Sign in by approving a code on another machine
|
|
1330
|
+
--yes Confirm a deletion, which cannot be undone
|
|
1307
1331
|
|
|
1308
1332
|
Where a site comes from
|
|
1309
|
-
--
|
|
1310
|
-
|
|
1333
|
+
--subdomain creates one under the name you give. Otherwise: --site, then
|
|
1334
|
+
drop2run.json, then a new site with a generated name. \`init\` writes that
|
|
1335
|
+
file, so \`deploy\` in the same folder needs no arguments at all.
|
|
1336
|
+
|
|
1337
|
+
--site only ever finds a site you already have; it never creates one, so a
|
|
1338
|
+
subdomain typed wrong fails instead of quietly becoming a second site.
|
|
1311
1339
|
|
|
1312
1340
|
Signing in
|
|
1313
1341
|
\`login\` opens a browser and listens on 127.0.0.1, so it needs both on this
|
|
@@ -1324,12 +1352,25 @@ function flagValue(args, flag) {
|
|
|
1324
1352
|
const value = args[at + 1];
|
|
1325
1353
|
return value === void 0 || value.startsWith("-") ? void 0 : value;
|
|
1326
1354
|
}
|
|
1355
|
+
function subdomainFlagProblem(argv, command, site, subdomain) {
|
|
1356
|
+
if (!argv.includes("--subdomain")) return void 0;
|
|
1357
|
+
if (subdomain === void 0) {
|
|
1358
|
+
return "`--subdomain` needs a name after it, for example `--subdomain my-docs`.";
|
|
1359
|
+
}
|
|
1360
|
+
if (site !== void 0) {
|
|
1361
|
+
return "`--site` and `--subdomain` cannot both be given: `--site` publishes to a site you already have, and `--subdomain` creates a new one. Drop whichever is not what you meant.";
|
|
1362
|
+
}
|
|
1363
|
+
if (command !== "init" && command !== "deploy") {
|
|
1364
|
+
return `\`--subdomain\` only applies to \`init\` and \`deploy\`, which can create a site. Use \`--site\` to tell \`${command}\` which of your sites to act on.`;
|
|
1365
|
+
}
|
|
1366
|
+
return void 0;
|
|
1367
|
+
}
|
|
1327
1368
|
async function run(argv) {
|
|
1328
1369
|
const json = argv.includes("--json");
|
|
1329
1370
|
const positional = argv.filter((argument) => !argument.startsWith("-"));
|
|
1330
1371
|
const [command, ...rest] = positional;
|
|
1331
1372
|
if (argv.includes("--version")) {
|
|
1332
|
-
const { version } = await import("./package-
|
|
1373
|
+
const { version } = await import("./package-Cz51eZ2C.js").then(
|
|
1333
1374
|
(module) => module.default
|
|
1334
1375
|
);
|
|
1335
1376
|
return { text: version, json: { version }, code: 0 };
|
|
@@ -1338,17 +1379,24 @@ async function run(argv) {
|
|
|
1338
1379
|
if (askedForHelp) return { text: HELP, json: { help: HELP }, code: 0 };
|
|
1339
1380
|
if (command === void 0) return { text: HELP, json: { help: HELP }, code: 1 };
|
|
1340
1381
|
const site = flagValue(argv, "--site");
|
|
1382
|
+
const subdomain = flagValue(argv, "--subdomain");
|
|
1383
|
+
const refusal = subdomainFlagProblem(argv, command, site, subdomain);
|
|
1384
|
+
if (refusal !== void 0) {
|
|
1385
|
+
const failed = { text: refusal, json: { error: refusal }, code: 1 };
|
|
1386
|
+
return json ? { ...failed, text: JSON.stringify(failed.json, null, 2) } : failed;
|
|
1387
|
+
}
|
|
1341
1388
|
const result = await dispatch(
|
|
1342
1389
|
command,
|
|
1343
1390
|
rest,
|
|
1344
1391
|
site,
|
|
1345
1392
|
json,
|
|
1346
1393
|
argv.includes("--device"),
|
|
1347
|
-
argv.includes("--yes")
|
|
1394
|
+
argv.includes("--yes"),
|
|
1395
|
+
subdomain
|
|
1348
1396
|
);
|
|
1349
1397
|
return json ? { ...result, text: JSON.stringify(result.json, null, 2) } : result;
|
|
1350
1398
|
}
|
|
1351
|
-
async function dispatch(command, rest, site, json, device, confirmed) {
|
|
1399
|
+
async function dispatch(command, rest, site, json, device, confirmed, subdomain) {
|
|
1352
1400
|
switch (command) {
|
|
1353
1401
|
case "login": {
|
|
1354
1402
|
const print = json ? () => {
|
|
@@ -1358,14 +1406,14 @@ async function dispatch(command, rest, site, json, device, confirmed) {
|
|
|
1358
1406
|
case "logout":
|
|
1359
1407
|
return logout();
|
|
1360
1408
|
case "init":
|
|
1361
|
-
return await init(rest[0] ?? ".", site);
|
|
1409
|
+
return await init(rest[0] ?? ".", site, subdomain);
|
|
1362
1410
|
case "deploy": {
|
|
1363
1411
|
const report = json ? silentProgress : progressWriter(
|
|
1364
1412
|
(text) => process.stderr.write(text),
|
|
1365
1413
|
process.stderr.isTTY === true,
|
|
1366
1414
|
process.stderr.columns ?? 80
|
|
1367
1415
|
);
|
|
1368
|
-
return await deployCommand(rest[0], site, report);
|
|
1416
|
+
return await deployCommand(rest[0], site, report, subdomain);
|
|
1369
1417
|
}
|
|
1370
1418
|
case "ls":
|
|
1371
1419
|
case "list":
|