@hot-updater/cloudflare 0.31.3 → 0.32.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/iac/index.cjs +206 -92
- package/dist/iac/index.mjs +198 -84
- package/dist/index.cjs +214 -51
- package/dist/index.d.cts +46 -6
- package/dist/index.d.mts +46 -6
- package/dist/index.mjs +209 -47
- package/dist/worker/index.d.cts +4 -3
- package/dist/worker/index.d.mts +3 -2
- package/package.json +10 -7
- package/src/r2S3Storage.ts +197 -0
- package/src/r2Storage.spec.ts +316 -2
- package/src/r2Storage.ts +50 -110
- package/src/r2WranglerStorage.ts +193 -0
- package/worker/dist/README.md +1 -1
- package/worker/dist/index.js +85 -24
- package/worker/dist/index.js.map +4 -4
- package/worker/src/index.ts +0 -1
package/dist/iac/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJSMin = (cb, mod) => () => (mod ||
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
12
|
key = keys[i];
|
|
@@ -23,11 +23,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
25
|
let crypto = require("crypto");
|
|
26
|
-
crypto = __toESM(crypto
|
|
26
|
+
crypto = __toESM(crypto);
|
|
27
27
|
let fs_promises = require("fs/promises");
|
|
28
|
-
fs_promises = __toESM(fs_promises
|
|
28
|
+
fs_promises = __toESM(fs_promises);
|
|
29
29
|
let path = require("path");
|
|
30
|
-
path = __toESM(path
|
|
30
|
+
path = __toESM(path);
|
|
31
31
|
let _hot_updater_cli_tools = require("@hot-updater/cli-tools");
|
|
32
32
|
let cloudflare = require("cloudflare");
|
|
33
33
|
let node_url = require("node:url");
|
|
@@ -35,13 +35,13 @@ let node_child_process = require("node:child_process");
|
|
|
35
35
|
let node_string_decoder = require("node:string_decoder");
|
|
36
36
|
let node_util = require("node:util");
|
|
37
37
|
let node_process = require("node:process");
|
|
38
|
-
node_process = __toESM(node_process
|
|
38
|
+
node_process = __toESM(node_process);
|
|
39
39
|
let node_tty = require("node:tty");
|
|
40
|
-
node_tty = __toESM(node_tty
|
|
40
|
+
node_tty = __toESM(node_tty);
|
|
41
41
|
let node_path = require("node:path");
|
|
42
|
-
node_path = __toESM(node_path
|
|
42
|
+
node_path = __toESM(node_path);
|
|
43
43
|
let fs = require("fs");
|
|
44
|
-
fs = __toESM(fs
|
|
44
|
+
fs = __toESM(fs);
|
|
45
45
|
let node_timers_promises = require("node:timers/promises");
|
|
46
46
|
let node_os = require("node:os");
|
|
47
47
|
let node_events = require("node:events");
|
|
@@ -51,7 +51,7 @@ let node_stream_promises = require("node:stream/promises");
|
|
|
51
51
|
let node_stream = require("node:stream");
|
|
52
52
|
let node_buffer = require("node:buffer");
|
|
53
53
|
let os = require("os");
|
|
54
|
-
os = __toESM(os
|
|
54
|
+
os = __toESM(os);
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
57
57
|
var import_dayjs_min = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -10846,7 +10846,10 @@ const getConfigScaffold = (build) => {
|
|
|
10846
10846
|
configString: `r2Storage({
|
|
10847
10847
|
bucketName: process.env.HOT_UPDATER_CLOUDFLARE_R2_BUCKET_NAME!,
|
|
10848
10848
|
accountId: process.env.HOT_UPDATER_CLOUDFLARE_ACCOUNT_ID!,
|
|
10849
|
-
|
|
10849
|
+
credentials: {
|
|
10850
|
+
accessKeyId: process.env.HOT_UPDATER_CLOUDFLARE_R2_ACCESS_KEY_ID!,
|
|
10851
|
+
secretAccessKey: process.env.HOT_UPDATER_CLOUDFLARE_R2_SECRET_ACCESS_KEY!,
|
|
10852
|
+
},
|
|
10850
10853
|
})`
|
|
10851
10854
|
}).setDatabase({
|
|
10852
10855
|
imports: [{
|
|
@@ -10871,7 +10874,50 @@ export default HotUpdater.wrap({
|
|
|
10871
10874
|
baseURL: "%%source%%",
|
|
10872
10875
|
updateStrategy: "appVersion", // or "fingerprint"
|
|
10873
10876
|
})(App);`;
|
|
10874
|
-
const
|
|
10877
|
+
const HOT_UPDATER_ENV_PATH = ".env.hotupdater";
|
|
10878
|
+
const unquoteEnvValue = (value) => {
|
|
10879
|
+
const trimmed = value.trim();
|
|
10880
|
+
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
|
|
10881
|
+
return trimmed;
|
|
10882
|
+
};
|
|
10883
|
+
const readHotUpdaterEnv = async (cwd) => {
|
|
10884
|
+
const envPath = path.default.join(cwd, HOT_UPDATER_ENV_PATH);
|
|
10885
|
+
const content = await fs_promises.default.readFile(envPath, "utf-8").catch(() => "");
|
|
10886
|
+
const env = {};
|
|
10887
|
+
for (const line of content.split("\n")) {
|
|
10888
|
+
const trimmed = line.trim();
|
|
10889
|
+
if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
10890
|
+
const [key, ...valueParts] = trimmed.split("=");
|
|
10891
|
+
if (!key) continue;
|
|
10892
|
+
env[key.trim()] = unquoteEnvValue(valueParts.join("="));
|
|
10893
|
+
}
|
|
10894
|
+
return env;
|
|
10895
|
+
};
|
|
10896
|
+
const getEnvValue = (env, key) => {
|
|
10897
|
+
return process.env[key]?.trim() || env[key]?.trim() || void 0;
|
|
10898
|
+
};
|
|
10899
|
+
const inputR2ApiCredentials = async ({ accountId, bucketName, accessKeyId, secretAccessKey }) => {
|
|
10900
|
+
_hot_updater_cli_tools.p.log.step(`R2 API Tokens dashboard: ${(0, _hot_updater_cli_tools.link)(`https://dash.cloudflare.com/${accountId}/r2/api-tokens`)}`);
|
|
10901
|
+
_hot_updater_cli_tools.p.log.step("Required permission: Object Read & Write");
|
|
10902
|
+
_hot_updater_cli_tools.p.log.step(`Target bucket: ${bucketName}`);
|
|
10903
|
+
let resolvedAccessKeyId = accessKeyId;
|
|
10904
|
+
if (!resolvedAccessKeyId) {
|
|
10905
|
+
const inputR2AccessKeyId = await _hot_updater_cli_tools.p.password({ message: "Enter the R2 Access Key ID" });
|
|
10906
|
+
if (_hot_updater_cli_tools.p.isCancel(inputR2AccessKeyId)) process.exit(1);
|
|
10907
|
+
resolvedAccessKeyId = inputR2AccessKeyId;
|
|
10908
|
+
}
|
|
10909
|
+
let resolvedSecretAccessKey = secretAccessKey;
|
|
10910
|
+
if (!resolvedSecretAccessKey) {
|
|
10911
|
+
const inputR2SecretAccessKey = await _hot_updater_cli_tools.p.password({ message: "Enter the R2 Secret Access Key" });
|
|
10912
|
+
if (_hot_updater_cli_tools.p.isCancel(inputR2SecretAccessKey)) process.exit(1);
|
|
10913
|
+
resolvedSecretAccessKey = inputR2SecretAccessKey;
|
|
10914
|
+
}
|
|
10915
|
+
return {
|
|
10916
|
+
accessKeyId: resolvedAccessKeyId,
|
|
10917
|
+
secretAccessKey: resolvedSecretAccessKey
|
|
10918
|
+
};
|
|
10919
|
+
};
|
|
10920
|
+
const deployWorker = async (oauth_token, accountId, { d1DatabaseId, d1DatabaseName, r2BucketName, workerName }) => {
|
|
10875
10921
|
const cwd = (0, _hot_updater_cli_tools.getCwd)();
|
|
10876
10922
|
const cloudflarePackagePath = require.resolve("@hot-updater/cloudflare/package.json", { paths: [cwd] });
|
|
10877
10923
|
const { tmpDir, removeTmpDir } = await (0, _hot_updater_cli_tools.copyDirToTmp)(path.default.dirname(cloudflarePackagePath));
|
|
@@ -10903,14 +10949,19 @@ const deployWorker = async (oauth_token, accountId, { d1DatabaseId, d1DatabaseNa
|
|
|
10903
10949
|
await fs_promises.default.writeFile(filePath, (0, _hot_updater_cli_tools.transformTemplate)(content, { BUCKET_NAME: r2BucketName }));
|
|
10904
10950
|
}
|
|
10905
10951
|
await wrangler("d1", "migrations", "apply", d1DatabaseName, "--remote");
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10952
|
+
let resolvedWorkerName = workerName;
|
|
10953
|
+
if (resolvedWorkerName) _hot_updater_cli_tools.p.log.info("Using existing Cloudflare Worker name.");
|
|
10954
|
+
else {
|
|
10955
|
+
const inputWorkerName = await _hot_updater_cli_tools.p.text({
|
|
10956
|
+
message: "Enter the name of the worker",
|
|
10957
|
+
defaultValue: "hot-updater",
|
|
10958
|
+
placeholder: "hot-updater"
|
|
10959
|
+
});
|
|
10960
|
+
if (_hot_updater_cli_tools.p.isCancel(inputWorkerName)) process.exit(1);
|
|
10961
|
+
resolvedWorkerName = inputWorkerName;
|
|
10962
|
+
}
|
|
10963
|
+
await wrangler("deploy", "--name", resolvedWorkerName);
|
|
10964
|
+
return resolvedWorkerName;
|
|
10914
10965
|
} catch (error) {
|
|
10915
10966
|
throw new Error("Failed to deploy worker", { cause: error });
|
|
10916
10967
|
} finally {
|
|
@@ -10919,6 +10970,7 @@ const deployWorker = async (oauth_token, accountId, { d1DatabaseId, d1DatabaseNa
|
|
|
10919
10970
|
};
|
|
10920
10971
|
const runInit = async ({ build }) => {
|
|
10921
10972
|
const cwd = (0, _hot_updater_cli_tools.getCwd)();
|
|
10973
|
+
const existingEnv = await readHotUpdaterEnv(cwd);
|
|
10922
10974
|
let auth = getWranglerLoginAuthToken();
|
|
10923
10975
|
if (!auth || (0, import_dayjs_min.default)(auth?.expiration_time).isBefore((0, import_dayjs_min.default)())) {
|
|
10924
10976
|
await execa("npx", [
|
|
@@ -10936,70 +10988,117 @@ const runInit = async ({ build }) => {
|
|
|
10936
10988
|
if (!auth) throw new Error("'npx wrangler login' is required to use this command");
|
|
10937
10989
|
const cf = new cloudflare.Cloudflare({ apiToken: auth.oauth_token });
|
|
10938
10990
|
const createKey = `create/${Math.random().toString(36).substring(2, 15)}`;
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
|
|
10991
|
+
let accountId = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_ACCOUNT_ID");
|
|
10992
|
+
if (accountId) _hot_updater_cli_tools.p.log.info("Using existing Cloudflare account ID.");
|
|
10993
|
+
else {
|
|
10994
|
+
const accounts = [];
|
|
10995
|
+
try {
|
|
10996
|
+
await _hot_updater_cli_tools.p.tasks([{
|
|
10997
|
+
title: "Checking Account List...",
|
|
10998
|
+
task: async () => {
|
|
10999
|
+
accounts.push(...(await cf.accounts.list()).result.map((account) => ({
|
|
11000
|
+
id: account.id,
|
|
11001
|
+
name: account.name
|
|
11002
|
+
})));
|
|
11003
|
+
}
|
|
11004
|
+
}]);
|
|
11005
|
+
} catch (e) {
|
|
11006
|
+
if (e instanceof Error) _hot_updater_cli_tools.p.log.error(e.message);
|
|
11007
|
+
throw e;
|
|
11008
|
+
}
|
|
11009
|
+
const selectedAccountId = await _hot_updater_cli_tools.p.select({
|
|
11010
|
+
message: "Account List",
|
|
11011
|
+
options: accounts.map((account) => ({
|
|
11012
|
+
value: account.id,
|
|
11013
|
+
label: `${account.name} (${account.id})`
|
|
11014
|
+
}))
|
|
11015
|
+
});
|
|
11016
|
+
if (_hot_updater_cli_tools.p.isCancel(selectedAccountId)) process.exit(1);
|
|
11017
|
+
accountId = selectedAccountId;
|
|
10953
11018
|
}
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
10964
|
-
|
|
10965
|
-
|
|
10966
|
-
|
|
10967
|
-
|
|
10968
|
-
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
10975
|
-
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
|
|
11019
|
+
let apiToken = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_API_TOKEN");
|
|
11020
|
+
if (apiToken) _hot_updater_cli_tools.p.log.info("Using existing Cloudflare API token.");
|
|
11021
|
+
else {
|
|
11022
|
+
_hot_updater_cli_tools.p.log.step(`D1 API Token dashboard: ${(0, _hot_updater_cli_tools.link)(`https://dash.cloudflare.com/${accountId}/api-tokens`)}`);
|
|
11023
|
+
_hot_updater_cli_tools.p.log.step("Required permission: D1 Edit");
|
|
11024
|
+
_hot_updater_cli_tools.p.log.step("Used for bundle metadata writes after init.");
|
|
11025
|
+
const inputApiToken = await _hot_updater_cli_tools.p.password({ message: "Enter the D1 API Token" });
|
|
11026
|
+
if (_hot_updater_cli_tools.p.isCancel(inputApiToken)) process.exit(1);
|
|
11027
|
+
apiToken = inputApiToken;
|
|
11028
|
+
if (!apiToken) _hot_updater_cli_tools.p.log.warn("Skipping API Token. You can set it later in .env HOT_UPDATER_CLOUDFLARE_API_TOKEN file.");
|
|
11029
|
+
}
|
|
11030
|
+
const existingBucketName = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_R2_BUCKET_NAME");
|
|
11031
|
+
let selectedBucketName;
|
|
11032
|
+
if (existingBucketName) {
|
|
11033
|
+
selectedBucketName = existingBucketName;
|
|
11034
|
+
_hot_updater_cli_tools.p.log.info("Using existing Cloudflare R2 bucket name.");
|
|
11035
|
+
} else {
|
|
11036
|
+
const availableBuckets = [];
|
|
11037
|
+
try {
|
|
11038
|
+
await _hot_updater_cli_tools.p.tasks([{
|
|
11039
|
+
title: "Checking R2 Buckets...",
|
|
11040
|
+
task: async () => {
|
|
11041
|
+
const buckets = (await cf.r2.buckets.list({ account_id: accountId })).buckets ?? [];
|
|
11042
|
+
availableBuckets.push(...buckets.filter((bucket) => bucket.name).map((bucket) => ({ name: bucket.name })));
|
|
11043
|
+
}
|
|
11044
|
+
}]);
|
|
11045
|
+
} catch (e) {
|
|
11046
|
+
if (e instanceof Error) _hot_updater_cli_tools.p.log.error(e.message);
|
|
11047
|
+
throw e;
|
|
11048
|
+
}
|
|
11049
|
+
if (availableBuckets.length === 1) {
|
|
11050
|
+
selectedBucketName = availableBuckets[0].name;
|
|
11051
|
+
_hot_updater_cli_tools.p.log.info("Using the only Cloudflare R2 bucket.");
|
|
11052
|
+
} else {
|
|
11053
|
+
const selectedR2BucketName = await _hot_updater_cli_tools.p.select({
|
|
11054
|
+
message: "R2 List",
|
|
11055
|
+
options: [...availableBuckets.map((bucket) => ({
|
|
11056
|
+
value: bucket.name,
|
|
11057
|
+
label: bucket.name
|
|
11058
|
+
})), {
|
|
11059
|
+
value: createKey,
|
|
11060
|
+
label: "Create New R2 Bucket"
|
|
11061
|
+
}]
|
|
11062
|
+
});
|
|
11063
|
+
if (_hot_updater_cli_tools.p.isCancel(selectedR2BucketName)) process.exit(1);
|
|
11064
|
+
selectedBucketName = selectedR2BucketName;
|
|
11065
|
+
}
|
|
11066
|
+
if (selectedBucketName === createKey) {
|
|
11067
|
+
const name = await _hot_updater_cli_tools.p.text({ message: "Enter the name of the new R2 Bucket" });
|
|
11068
|
+
if (_hot_updater_cli_tools.p.isCancel(name)) process.exit(1);
|
|
11069
|
+
const newR2 = await cf.r2.buckets.create({
|
|
11070
|
+
account_id: accountId,
|
|
11071
|
+
name
|
|
11072
|
+
});
|
|
11073
|
+
if (!newR2.name) throw new Error("Failed to create new R2 Bucket");
|
|
11074
|
+
selectedBucketName = newR2.name;
|
|
11075
|
+
}
|
|
10979
11076
|
}
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
11077
|
+
_hot_updater_cli_tools.p.log.info(`Selected R2: ${selectedBucketName}`);
|
|
11078
|
+
const existingR2AccessKeyId = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_R2_ACCESS_KEY_ID");
|
|
11079
|
+
const existingR2SecretAccessKey = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_R2_SECRET_ACCESS_KEY");
|
|
11080
|
+
let r2AccessKeyId = existingR2AccessKeyId;
|
|
11081
|
+
let r2SecretAccessKey = existingR2SecretAccessKey;
|
|
11082
|
+
if (r2AccessKeyId && r2SecretAccessKey) _hot_updater_cli_tools.p.log.info("Using existing Cloudflare R2 API credentials.");
|
|
11083
|
+
else if (r2AccessKeyId || r2SecretAccessKey) {
|
|
11084
|
+
_hot_updater_cli_tools.p.log.warn("Existing Cloudflare R2 API credentials are incomplete.");
|
|
11085
|
+
const credentials = await inputR2ApiCredentials({
|
|
11086
|
+
accountId,
|
|
11087
|
+
bucketName: selectedBucketName,
|
|
11088
|
+
accessKeyId: r2AccessKeyId,
|
|
11089
|
+
secretAccessKey: r2SecretAccessKey
|
|
11090
|
+
});
|
|
11091
|
+
r2AccessKeyId = credentials.accessKeyId;
|
|
11092
|
+
r2SecretAccessKey = credentials.secretAccessKey;
|
|
11093
|
+
} else {
|
|
11094
|
+
const credentials = await inputR2ApiCredentials({
|
|
11095
|
+
accountId,
|
|
11096
|
+
bucketName: selectedBucketName
|
|
10997
11097
|
});
|
|
10998
|
-
|
|
10999
|
-
|
|
11098
|
+
r2AccessKeyId = credentials.accessKeyId;
|
|
11099
|
+
r2SecretAccessKey = credentials.secretAccessKey;
|
|
11000
11100
|
}
|
|
11001
|
-
|
|
11002
|
-
if ((await cf.r2.buckets.domains.managed.list(selectedBucketName, { account_id: accountId })).enabled) {
|
|
11101
|
+
if ((existingBucketName ? { enabled: false } : await cf.r2.buckets.domains.managed.list(selectedBucketName, { account_id: accountId })).enabled) {
|
|
11003
11102
|
if (await _hot_updater_cli_tools.p.confirm({ message: "Make R2 bucket private?" })) try {
|
|
11004
11103
|
await _hot_updater_cli_tools.p.tasks([{
|
|
11005
11104
|
title: "Making R2 bucket private...",
|
|
@@ -11031,17 +11130,27 @@ const runInit = async ({ build }) => {
|
|
|
11031
11130
|
if (e instanceof Error) _hot_updater_cli_tools.p.log.error(e.message);
|
|
11032
11131
|
throw e;
|
|
11033
11132
|
}
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11133
|
+
const existingD1DatabaseId = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_D1_DATABASE_ID");
|
|
11134
|
+
const hasExistingD1Database = availableD1List.some((d1) => d1.uuid === existingD1DatabaseId);
|
|
11135
|
+
let selectedD1DatabaseId;
|
|
11136
|
+
if (existingD1DatabaseId && hasExistingD1Database) {
|
|
11137
|
+
selectedD1DatabaseId = existingD1DatabaseId;
|
|
11138
|
+
_hot_updater_cli_tools.p.log.info("Using existing Cloudflare D1 database ID.");
|
|
11139
|
+
} else {
|
|
11140
|
+
if (existingD1DatabaseId) _hot_updater_cli_tools.p.log.warn("Existing Cloudflare D1 database ID was not found. Select a database again.");
|
|
11141
|
+
const selectedD1 = await _hot_updater_cli_tools.p.select({
|
|
11142
|
+
message: "D1 List",
|
|
11143
|
+
options: [...availableD1List.map((d1) => ({
|
|
11144
|
+
value: d1.uuid,
|
|
11145
|
+
label: `${d1.name} (${d1.uuid})`
|
|
11146
|
+
})), {
|
|
11147
|
+
value: createKey,
|
|
11148
|
+
label: "Create New D1 Database"
|
|
11149
|
+
}]
|
|
11150
|
+
});
|
|
11151
|
+
if (_hot_updater_cli_tools.p.isCancel(selectedD1)) process.exit(1);
|
|
11152
|
+
selectedD1DatabaseId = selectedD1;
|
|
11153
|
+
}
|
|
11045
11154
|
if (selectedD1DatabaseId === createKey) {
|
|
11046
11155
|
const name = await _hot_updater_cli_tools.p.text({ message: "Enter the name of the new D1 Database" });
|
|
11047
11156
|
if (_hot_updater_cli_tools.p.isCancel(name)) process.exit(1);
|
|
@@ -11060,17 +11169,22 @@ const runInit = async ({ build }) => {
|
|
|
11060
11169
|
const d1DatabaseName = availableD1List.find((d1) => d1.uuid === selectedD1DatabaseId)?.name;
|
|
11061
11170
|
if (!d1DatabaseName) throw new Error("Failed to get D1 Database name");
|
|
11062
11171
|
const subdomains = await cf.workers.subdomains.get({ account_id: accountId });
|
|
11172
|
+
const existingWorkerName = getEnvValue(existingEnv, "HOT_UPDATER_CLOUDFLARE_WORKER_NAME");
|
|
11063
11173
|
const workerName = await deployWorker(auth.oauth_token, accountId, {
|
|
11064
11174
|
d1DatabaseId: selectedD1DatabaseId,
|
|
11065
11175
|
d1DatabaseName,
|
|
11066
|
-
r2BucketName: selectedBucketName
|
|
11176
|
+
r2BucketName: selectedBucketName,
|
|
11177
|
+
workerName: existingWorkerName
|
|
11067
11178
|
});
|
|
11068
11179
|
const configWriteResult = await (0, _hot_updater_cli_tools.writeHotUpdaterConfig)(getConfigScaffold(build));
|
|
11069
11180
|
await (0, _hot_updater_cli_tools.makeEnv)({
|
|
11070
11181
|
HOT_UPDATER_CLOUDFLARE_API_TOKEN: apiToken,
|
|
11071
11182
|
HOT_UPDATER_CLOUDFLARE_ACCOUNT_ID: accountId,
|
|
11072
11183
|
HOT_UPDATER_CLOUDFLARE_R2_BUCKET_NAME: selectedBucketName,
|
|
11073
|
-
|
|
11184
|
+
HOT_UPDATER_CLOUDFLARE_R2_ACCESS_KEY_ID: r2AccessKeyId,
|
|
11185
|
+
HOT_UPDATER_CLOUDFLARE_R2_SECRET_ACCESS_KEY: r2SecretAccessKey,
|
|
11186
|
+
HOT_UPDATER_CLOUDFLARE_D1_DATABASE_ID: selectedD1DatabaseId,
|
|
11187
|
+
HOT_UPDATER_CLOUDFLARE_WORKER_NAME: workerName
|
|
11074
11188
|
});
|
|
11075
11189
|
_hot_updater_cli_tools.p.log.success("Generated '.env.hotupdater' file with Cloudflare settings.");
|
|
11076
11190
|
if (configWriteResult.status === "created") _hot_updater_cli_tools.p.log.success("Generated 'hot-updater.config.ts' file with Cloudflare settings.");
|