drop2run 0.2.1 → 0.3.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/dist/index.js
CHANGED
|
@@ -517,7 +517,7 @@ function renameOfLoneHtmlPage(paths) {
|
|
|
517
517
|
const lower = only.toLowerCase();
|
|
518
518
|
return lower.endsWith(".html") || lower.endsWith(".htm") ? only : null;
|
|
519
519
|
}
|
|
520
|
-
function formatBytes(bytes) {
|
|
520
|
+
function formatBytes$1(bytes) {
|
|
521
521
|
if (bytes < 1024) return `${bytes} B`;
|
|
522
522
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
523
523
|
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
@@ -548,7 +548,7 @@ function checkLimits(files, limits) {
|
|
|
548
548
|
if (oversized) {
|
|
549
549
|
throw new DeployError(
|
|
550
550
|
ClientErrorCode.FileTooLarge,
|
|
551
|
-
`${oversized.path} is ${formatBytes(oversized.bytes.length)}, and this plan allows ${formatBytes(limits.maxFileBytes)} per file.`,
|
|
551
|
+
`${oversized.path} is ${formatBytes$1(oversized.bytes.length)}, and this plan allows ${formatBytes$1(limits.maxFileBytes)} per file.`,
|
|
552
552
|
{
|
|
553
553
|
path: oversized.path,
|
|
554
554
|
limit: limits.maxFileBytes,
|
|
@@ -560,7 +560,7 @@ function checkLimits(files, limits) {
|
|
|
560
560
|
if (limits.maxSiteBytes !== null && total > limits.maxSiteBytes) {
|
|
561
561
|
throw new DeployError(
|
|
562
562
|
ClientErrorCode.TooLarge,
|
|
563
|
-
`That drop is ${formatBytes(total)}, and this plan allows ${formatBytes(limits.maxSiteBytes)}.`,
|
|
563
|
+
`That drop is ${formatBytes$1(total)}, and this plan allows ${formatBytes$1(limits.maxSiteBytes)}.`,
|
|
564
564
|
{ limit: limits.maxSiteBytes, actual: total }
|
|
565
565
|
);
|
|
566
566
|
}
|
|
@@ -698,7 +698,7 @@ async function uploadAll(targets, uploadUrl, files, onProgress, signal, deps = {
|
|
|
698
698
|
});
|
|
699
699
|
done += 1;
|
|
700
700
|
uploadedBytes += file.bytes.length;
|
|
701
|
-
onProgress?.(done, targets.length, uploadedBytes);
|
|
701
|
+
onProgress?.(done, targets.length, uploadedBytes, file.path);
|
|
702
702
|
}
|
|
703
703
|
};
|
|
704
704
|
const workers = Array.from(
|
|
@@ -793,12 +793,13 @@ async function deploy(source, siteId, onProgress, signal, options = {}) {
|
|
|
793
793
|
prepared.upload,
|
|
794
794
|
prepared.uploadUrl,
|
|
795
795
|
hashed,
|
|
796
|
-
(done, _total, bytes) => onProgress({
|
|
796
|
+
(done, _total, bytes, path) => onProgress({
|
|
797
797
|
type: "uploading",
|
|
798
798
|
done: prepared.reused + done,
|
|
799
799
|
total: prepared.total,
|
|
800
800
|
bytes,
|
|
801
|
-
reused: prepared.reused
|
|
801
|
+
reused: prepared.reused,
|
|
802
|
+
path
|
|
802
803
|
}),
|
|
803
804
|
signal,
|
|
804
805
|
options.upload
|
|
@@ -872,12 +873,12 @@ async function resolveSite(credentials, site) {
|
|
|
872
873
|
);
|
|
873
874
|
if (found === void 0) {
|
|
874
875
|
throw new Error(
|
|
875
|
-
`No site of yours is called "${site}". Leave the site out to publish to a new one, or
|
|
876
|
+
`No site of yours is called "${site}". Leave the site out to publish to a new one, or list your sites to see what exists.`
|
|
876
877
|
);
|
|
877
878
|
}
|
|
878
879
|
return found;
|
|
879
880
|
}
|
|
880
|
-
async function publish(credentials, source, site) {
|
|
881
|
+
async function publish(credentials, source, site, onProgress) {
|
|
881
882
|
const target = await resolveSite(credentials, site);
|
|
882
883
|
let files = 0;
|
|
883
884
|
let url = target.url;
|
|
@@ -895,6 +896,7 @@ async function publish(credentials, source, site) {
|
|
|
895
896
|
failure2 = event.message;
|
|
896
897
|
failureDetail = event.detail;
|
|
897
898
|
}
|
|
899
|
+
onProgress?.(event);
|
|
898
900
|
};
|
|
899
901
|
await deploy(source, target.siteId, record, void 0, {
|
|
900
902
|
baseUrl: credentials.apiBaseUrl,
|
|
@@ -908,8 +910,75 @@ async function publish(credentials, source, site) {
|
|
|
908
910
|
});
|
|
909
911
|
return { url, siteId: target.siteId, subdomain: target.subdomain, files, unchanged };
|
|
910
912
|
}
|
|
911
|
-
function publishDirectory(credentials, directory, site) {
|
|
912
|
-
return publish(credentials, directorySource(directory), site);
|
|
913
|
+
function publishDirectory(credentials, directory, site, onProgress) {
|
|
914
|
+
return publish(credentials, directorySource(directory), site, onProgress);
|
|
915
|
+
}
|
|
916
|
+
const silentProgress = Object.assign(() => {
|
|
917
|
+
}, { done: () => {
|
|
918
|
+
} });
|
|
919
|
+
const STEP = 1024;
|
|
920
|
+
const UNITS = ["B", "KB", "MB", "GB"];
|
|
921
|
+
function formatBytes(bytes) {
|
|
922
|
+
let value = bytes;
|
|
923
|
+
let unit = 0;
|
|
924
|
+
while (value >= STEP && unit < UNITS.length - 1) {
|
|
925
|
+
value /= STEP;
|
|
926
|
+
unit += 1;
|
|
927
|
+
}
|
|
928
|
+
return `${unit === 0 ? value : value.toFixed(1)} ${UNITS[unit]}`;
|
|
929
|
+
}
|
|
930
|
+
function shortenPath(path, width) {
|
|
931
|
+
if (path.length <= width) return path;
|
|
932
|
+
return `…${path.slice(path.length - width + 1)}`;
|
|
933
|
+
}
|
|
934
|
+
function describe(event, width = 80) {
|
|
935
|
+
switch (event.type) {
|
|
936
|
+
case "collecting":
|
|
937
|
+
return `Collected ${event.files.toLocaleString()} ${event.files === 1 ? "file" : "files"}`;
|
|
938
|
+
case "hashing":
|
|
939
|
+
return `Hashing ${event.done.toLocaleString()}/${event.total.toLocaleString()}`;
|
|
940
|
+
case "preparing":
|
|
941
|
+
return "Asking the server which files it already has";
|
|
942
|
+
case "uploading": {
|
|
943
|
+
const counted = `Uploading ${event.done.toLocaleString()}/${event.total.toLocaleString()}`;
|
|
944
|
+
const reused = event.reused === 0 ? "" : ` (${event.reused.toLocaleString()} already there)`;
|
|
945
|
+
const head = `${counted}${reused} · ${formatBytes(event.bytes)}`;
|
|
946
|
+
const room = width - head.length - 3;
|
|
947
|
+
return event.path === void 0 || room < 12 ? head : `${head} · ${shortenPath(event.path, room)}`;
|
|
948
|
+
}
|
|
949
|
+
case "completing":
|
|
950
|
+
return "Publishing";
|
|
951
|
+
// Both end the deploy, and the command prints the URL from the result it returns. Saying it here
|
|
952
|
+
// as well would print it twice, once on stderr and once on stdout.
|
|
953
|
+
case "done":
|
|
954
|
+
case "unchanged":
|
|
955
|
+
case "error":
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function progressWriter(write, isTerminal, width = 80) {
|
|
960
|
+
let painted = 0;
|
|
961
|
+
let lastStage = null;
|
|
962
|
+
const writer = ((event) => {
|
|
963
|
+
const line = describe(event, width - 1);
|
|
964
|
+
if (line === null) return;
|
|
965
|
+
if (!isTerminal) {
|
|
966
|
+
if (event.type === lastStage) return;
|
|
967
|
+
lastStage = event.type;
|
|
968
|
+
write(`${line}
|
|
969
|
+
`);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
lastStage = event.type;
|
|
973
|
+
write(`\r${line}${" ".repeat(Math.max(0, painted - line.length))}`);
|
|
974
|
+
painted = line.length;
|
|
975
|
+
});
|
|
976
|
+
writer.done = () => {
|
|
977
|
+
if (!isTerminal || painted === 0) return;
|
|
978
|
+
write(`\r${" ".repeat(painted)}\r`);
|
|
979
|
+
painted = 0;
|
|
980
|
+
};
|
|
981
|
+
return writer;
|
|
913
982
|
}
|
|
914
983
|
function failure(text) {
|
|
915
984
|
return { text, json: { error: text }, code: 1 };
|
|
@@ -1053,14 +1122,14 @@ async function list() {
|
|
|
1053
1122
|
code: 0
|
|
1054
1123
|
};
|
|
1055
1124
|
}
|
|
1056
|
-
async function deployCommand(directory, site) {
|
|
1125
|
+
async function deployCommand(directory, site, report = silentProgress) {
|
|
1057
1126
|
const found = credentialsOr();
|
|
1058
1127
|
if ("result" in found) return found.result;
|
|
1059
1128
|
const project = readProject();
|
|
1060
1129
|
const target = site ?? project?.siteId;
|
|
1061
1130
|
const folder = directory ?? project?.dir ?? ".";
|
|
1062
1131
|
try {
|
|
1063
|
-
const result = await publishDirectory(found.credentials, resolve(folder), target);
|
|
1132
|
+
const result = await publishDirectory(found.credentials, resolve(folder), target, report);
|
|
1064
1133
|
const what = result.unchanged ? "Already up to date — nothing needed publishing." : `Published ${result.files.toLocaleString()} ${result.files === 1 ? "file" : "files"}.`;
|
|
1065
1134
|
return {
|
|
1066
1135
|
text: `${what}
|
|
@@ -1070,6 +1139,8 @@ ${result.url}`,
|
|
|
1070
1139
|
};
|
|
1071
1140
|
} catch (error) {
|
|
1072
1141
|
return failureFrom(error);
|
|
1142
|
+
} finally {
|
|
1143
|
+
report.done();
|
|
1073
1144
|
}
|
|
1074
1145
|
}
|
|
1075
1146
|
async function init(directory, site) {
|
|
@@ -1258,7 +1329,7 @@ async function run(argv) {
|
|
|
1258
1329
|
const positional = argv.filter((argument) => !argument.startsWith("-"));
|
|
1259
1330
|
const [command, ...rest] = positional;
|
|
1260
1331
|
if (argv.includes("--version")) {
|
|
1261
|
-
const { version } = await import("./package-
|
|
1332
|
+
const { version } = await import("./package-B5PgBI_i.js").then(
|
|
1262
1333
|
(module) => module.default
|
|
1263
1334
|
);
|
|
1264
1335
|
return { text: version, json: { version }, code: 0 };
|
|
@@ -1288,8 +1359,14 @@ async function dispatch(command, rest, site, json, device, confirmed) {
|
|
|
1288
1359
|
return logout();
|
|
1289
1360
|
case "init":
|
|
1290
1361
|
return await init(rest[0] ?? ".", site);
|
|
1291
|
-
case "deploy":
|
|
1292
|
-
|
|
1362
|
+
case "deploy": {
|
|
1363
|
+
const report = json ? silentProgress : progressWriter(
|
|
1364
|
+
(text) => process.stderr.write(text),
|
|
1365
|
+
process.stderr.isTTY === true,
|
|
1366
|
+
process.stderr.columns ?? 80
|
|
1367
|
+
);
|
|
1368
|
+
return await deployCommand(rest[0], site, report);
|
|
1369
|
+
}
|
|
1293
1370
|
case "ls":
|
|
1294
1371
|
case "list":
|
|
1295
1372
|
return await list();
|