hot-updater 0.1.4 → 0.1.6-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/chunk-P5MMNLL7.js +48 -0
- package/dist/config.js +4 -1
- package/dist/index.cjs +70 -75
- package/dist/index.js +92 -80
- package/dist/plugins/babel.cjs +15165 -0
- package/dist/plugins/babel.d.cts +5 -0
- package/dist/plugins/babel.d.ts +5 -0
- package/dist/plugins/babel.js +15127 -0
- package/package.json +25 -9
- package/dist/chunk-XCQPUXG2.js +0 -10
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
|
|
30
|
+
// ../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.42_@swc+helpers@0.5.15__jiti@1.21.6_postcss@8.4.47_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js
|
|
31
|
+
import { fileURLToPath } from "url";
|
|
32
|
+
import path from "path";
|
|
33
|
+
var getFilename, getDirname, __dirname;
|
|
34
|
+
var init_esm_shims = __esm({
|
|
35
|
+
"../../node_modules/.pnpm/tsup@8.3.0_@swc+core@1.7.42_@swc+helpers@0.5.15__jiti@1.21.6_postcss@8.4.47_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
38
|
+
getDirname = () => path.dirname(getFilename());
|
|
39
|
+
__dirname = /* @__PURE__ */ getDirname();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
__commonJS,
|
|
45
|
+
__toESM,
|
|
46
|
+
__dirname,
|
|
47
|
+
init_esm_shims
|
|
48
|
+
};
|
package/dist/config.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
// src/commands/console.ts
|
|
27
27
|
var import_node_server = require("@hono/node-server");
|
|
28
28
|
var import_console = __toESM(require("@hot-updater/console"), 1);
|
|
29
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
29
30
|
var openConsole = () => {
|
|
30
31
|
(0, import_node_server.serve)(
|
|
31
32
|
{
|
|
@@ -33,7 +34,11 @@ var openConsole = () => {
|
|
|
33
34
|
port: 1422
|
|
34
35
|
},
|
|
35
36
|
(info) => {
|
|
36
|
-
console.log(
|
|
37
|
+
console.log(
|
|
38
|
+
`Server running on ${import_picocolors.default.magenta(
|
|
39
|
+
import_picocolors.default.underline(`http://localhost:${info.port}`)
|
|
40
|
+
)}`
|
|
41
|
+
);
|
|
37
42
|
}
|
|
38
43
|
);
|
|
39
44
|
};
|
|
@@ -48,6 +53,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
|
|
|
48
53
|
var import_jszip = __toESM(require("jszip"), 1);
|
|
49
54
|
var createZip = async (dirPath, filename) => {
|
|
50
55
|
const zip = new import_jszip.default();
|
|
56
|
+
await import_promises.default.rm(import_path.default.join(dirPath, filename), { force: true });
|
|
51
57
|
async function addFiles(dir, zipFolder) {
|
|
52
58
|
const files = await import_promises.default.readdir(dir);
|
|
53
59
|
files.sort();
|
|
@@ -81,17 +87,6 @@ var createZip = async (dirPath, filename) => {
|
|
|
81
87
|
await import_promises.default.writeFile(filename, content);
|
|
82
88
|
};
|
|
83
89
|
|
|
84
|
-
// src/utils/formatDate.ts
|
|
85
|
-
var formatDate = (date) => {
|
|
86
|
-
const year = date.getFullYear();
|
|
87
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
88
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
89
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
90
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
91
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
92
|
-
return Number(`${year}${month}${day}${hours}${minutes}${seconds}`);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
90
|
// src/utils/getDefaultTargetVersion.ts
|
|
96
91
|
var import_child_process = require("child_process");
|
|
97
92
|
var import_path2 = __toESM(require("path"), 1);
|
|
@@ -174,9 +169,33 @@ var getFileHashFromFile = async (filepath) => {
|
|
|
174
169
|
}
|
|
175
170
|
};
|
|
176
171
|
|
|
172
|
+
// src/utils/git.ts
|
|
173
|
+
var import_child_process2 = require("child_process");
|
|
174
|
+
var getLatestGitCommitMessage = () => {
|
|
175
|
+
return new Promise((resolve) => {
|
|
176
|
+
(0, import_child_process2.exec)("git log --decorate --pretty=format:%s -1", (error, stdout) => {
|
|
177
|
+
if (error) {
|
|
178
|
+
resolve(null);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
resolve(stdout.trim());
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
var getGitCommitHash = () => {
|
|
186
|
+
return new Promise((resolve) => {
|
|
187
|
+
(0, import_child_process2.exec)("git rev-parse HEAD", (error, stdout) => {
|
|
188
|
+
if (error) {
|
|
189
|
+
resolve(null);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
resolve(stdout.trim());
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
177
197
|
// src/commands/deploy.ts
|
|
178
198
|
var import_plugin_core = require("@hot-updater/plugin-core");
|
|
179
|
-
var import_utils = require("@hot-updater/utils");
|
|
180
199
|
var deploy = async (options) => {
|
|
181
200
|
const s = (0, import_prompts.spinner)();
|
|
182
201
|
try {
|
|
@@ -185,9 +204,11 @@ var deploy = async (options) => {
|
|
|
185
204
|
console.error("No config found. Please run `hot-updater init` first.");
|
|
186
205
|
process.exit(1);
|
|
187
206
|
}
|
|
188
|
-
(0, import_prompts.intro)("Please provide a description for the bundle.");
|
|
189
|
-
const description = await (0, import_prompts.text)({ message: "Description" });
|
|
190
207
|
const cwd = (0, import_plugin_core.getCwd)();
|
|
208
|
+
const [gitCommitHash, gitMessage] = await Promise.all([
|
|
209
|
+
getGitCommitHash(),
|
|
210
|
+
getLatestGitCommitMessage()
|
|
211
|
+
]);
|
|
191
212
|
const targetVersion = options.targetVersion ?? await getDefaultTargetVersion(cwd, options.platform);
|
|
192
213
|
if (!targetVersion) {
|
|
193
214
|
throw new Error(
|
|
@@ -195,49 +216,35 @@ var deploy = async (options) => {
|
|
|
195
216
|
);
|
|
196
217
|
}
|
|
197
218
|
s.start("Build in progress");
|
|
198
|
-
const { buildPath } = await config.build({
|
|
219
|
+
const { buildPath, bundleId } = await config.build({
|
|
199
220
|
cwd,
|
|
200
221
|
platform: options.platform
|
|
201
222
|
});
|
|
202
223
|
s.message("Checking existing updates...");
|
|
203
224
|
await createZip(buildPath, "build.zip");
|
|
204
225
|
const bundlePath = buildPath.concat(".zip");
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const deployPlugin = config.deploy({
|
|
226
|
+
const fileHash = await getFileHashFromFile(bundlePath);
|
|
227
|
+
const databasePlugin = config.database({
|
|
208
228
|
cwd
|
|
209
229
|
});
|
|
210
|
-
const updateSources = await deployPlugin.getUpdateSources();
|
|
211
|
-
const targetVersions = (0, import_utils.filterTargetVersion)(
|
|
212
|
-
updateSources ?? [],
|
|
213
|
-
targetVersion,
|
|
214
|
-
options.platform
|
|
215
|
-
);
|
|
216
|
-
if (targetVersions.length > 0) {
|
|
217
|
-
const recentVersion = targetVersions[0];
|
|
218
|
-
const recentHash = recentVersion?.hash;
|
|
219
|
-
if (recentHash === hash) {
|
|
220
|
-
s.stop("The update already exists.", -1);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
230
|
s.message("Uploading bundle...");
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
await deployPlugin.appendUpdateSource({
|
|
231
|
+
const storagePlugin = config.storage({
|
|
232
|
+
cwd
|
|
233
|
+
});
|
|
234
|
+
const { fileUrl } = await storagePlugin.uploadBundle(bundleId, bundlePath);
|
|
235
|
+
await databasePlugin.appendBundle({
|
|
231
236
|
forceUpdate: options.forceUpdate,
|
|
232
237
|
platform: options.platform,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
fileUrl,
|
|
239
|
+
fileHash,
|
|
240
|
+
gitCommitHash,
|
|
241
|
+
message: gitMessage,
|
|
236
242
|
targetVersion,
|
|
237
|
-
|
|
243
|
+
id: bundleId,
|
|
238
244
|
enabled: true
|
|
239
245
|
});
|
|
240
|
-
await
|
|
246
|
+
await databasePlugin.commitBundle();
|
|
247
|
+
await databasePlugin.onUnmount?.();
|
|
241
248
|
await import_promises4.default.rm(bundlePath);
|
|
242
249
|
s.stop("Uploading Success !", 0);
|
|
243
250
|
} catch (e) {
|
|
@@ -262,7 +269,7 @@ var generateSecretKey = async () => {
|
|
|
262
269
|
var p = __toESM(require("@clack/prompts"), 1);
|
|
263
270
|
var import_plugin_core2 = require("@hot-updater/plugin-core");
|
|
264
271
|
var import_plugin_core3 = require("@hot-updater/plugin-core");
|
|
265
|
-
var prune = async (
|
|
272
|
+
var prune = async () => {
|
|
266
273
|
const s = p.spinner();
|
|
267
274
|
try {
|
|
268
275
|
const config = await (0, import_plugin_core3.loadConfig)();
|
|
@@ -271,26 +278,26 @@ var prune = async (options) => {
|
|
|
271
278
|
process.exit(1);
|
|
272
279
|
}
|
|
273
280
|
const cwd = (0, import_plugin_core2.getCwd)();
|
|
274
|
-
const
|
|
281
|
+
const databasePlugin = config.database({
|
|
275
282
|
cwd
|
|
276
|
-
// spinner: s,
|
|
277
283
|
});
|
|
278
284
|
s.start("Checking existing updates");
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
285
|
+
const bundles = await databasePlugin.getBundles();
|
|
286
|
+
const activeBundles = bundles.filter((bundle) => bundle.enabled);
|
|
287
|
+
const inactiveBundles = bundles.filter((bundle) => !bundle.enabled);
|
|
288
|
+
if (inactiveBundles.length === 0) {
|
|
283
289
|
s.stop("No inactive versions found", -1);
|
|
284
290
|
return;
|
|
285
291
|
}
|
|
286
292
|
s.message("Pruning updates");
|
|
287
|
-
await
|
|
288
|
-
await
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
await databasePlugin.setBundles(activeBundles);
|
|
294
|
+
await databasePlugin.commitBundle();
|
|
295
|
+
await databasePlugin.onUnmount?.();
|
|
296
|
+
const storagePlugin = config.storage({
|
|
297
|
+
cwd
|
|
298
|
+
});
|
|
299
|
+
for (const bundle of inactiveBundles) {
|
|
300
|
+
const key = await storagePlugin.deleteBundle(bundle.id);
|
|
294
301
|
p.log.info(`deleting: ${key}`);
|
|
295
302
|
}
|
|
296
303
|
s.stop("Done");
|
|
@@ -310,13 +317,13 @@ var version = packageJsonData?.packageJson.version;
|
|
|
310
317
|
|
|
311
318
|
// src/components/banner.tsx
|
|
312
319
|
var import_boxen = __toESM(require("boxen"), 1);
|
|
313
|
-
var
|
|
320
|
+
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
314
321
|
var banner = (0, import_boxen.default)(
|
|
315
322
|
[
|
|
316
|
-
`${
|
|
323
|
+
`${import_picocolors2.default.bold("Hot Updater - React Native OTA Solution")} v${version}`,
|
|
317
324
|
"",
|
|
318
|
-
`Github: ${
|
|
319
|
-
|
|
325
|
+
`Github: ${import_picocolors2.default.magenta(
|
|
326
|
+
import_picocolors2.default.underline("https://github.com/gronxb/hot-updater")
|
|
320
327
|
)}`,
|
|
321
328
|
"Give a \u2B50\uFE0F if you like it!"
|
|
322
329
|
].join("\n"),
|
|
@@ -379,17 +386,5 @@ program.command("app-version").description("get the current app version").action
|
|
|
379
386
|
import_plugin_core4.log.info(`Android version: ${androidVersion}`);
|
|
380
387
|
import_plugin_core4.log.info(`iOS version: ${iosVersion}`);
|
|
381
388
|
});
|
|
382
|
-
program.command("prune").description("prune all the inactive versions").
|
|
383
|
-
new import_commander.Option("-p, --platform <platform>", "specify the platform").choices([
|
|
384
|
-
"ios",
|
|
385
|
-
"android"
|
|
386
|
-
])
|
|
387
|
-
).action(async (options) => {
|
|
388
|
-
if (!options.platform) {
|
|
389
|
-
options.platform = await getPlatform(
|
|
390
|
-
"Which platform do you want to prune?"
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
prune(options);
|
|
394
|
-
});
|
|
389
|
+
program.command("prune").description("prune all the inactive versions").action(prune);
|
|
395
390
|
program.parse(process.argv);
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
__dirname
|
|
4
|
-
|
|
3
|
+
__dirname,
|
|
4
|
+
init_esm_shims
|
|
5
|
+
} from "./chunk-P5MMNLL7.js";
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
init_esm_shims();
|
|
5
9
|
|
|
6
10
|
// src/commands/console.ts
|
|
11
|
+
init_esm_shims();
|
|
7
12
|
import { serve } from "@hono/node-server";
|
|
8
13
|
import app from "@hot-updater/console";
|
|
14
|
+
import picocolors from "picocolors";
|
|
9
15
|
var openConsole = () => {
|
|
10
16
|
serve(
|
|
11
17
|
{
|
|
@@ -13,21 +19,28 @@ var openConsole = () => {
|
|
|
13
19
|
port: 1422
|
|
14
20
|
},
|
|
15
21
|
(info) => {
|
|
16
|
-
console.log(
|
|
22
|
+
console.log(
|
|
23
|
+
`Server running on ${picocolors.magenta(
|
|
24
|
+
picocolors.underline(`http://localhost:${info.port}`)
|
|
25
|
+
)}`
|
|
26
|
+
);
|
|
17
27
|
}
|
|
18
28
|
);
|
|
19
29
|
};
|
|
20
30
|
|
|
21
31
|
// src/commands/deploy.ts
|
|
32
|
+
init_esm_shims();
|
|
22
33
|
import fs4 from "node:fs/promises";
|
|
23
|
-
import {
|
|
34
|
+
import { spinner } from "@clack/prompts";
|
|
24
35
|
|
|
25
36
|
// src/utils/createZip.ts
|
|
37
|
+
init_esm_shims();
|
|
26
38
|
import path from "path";
|
|
27
39
|
import fs from "fs/promises";
|
|
28
40
|
import JSZip from "jszip";
|
|
29
41
|
var createZip = async (dirPath, filename) => {
|
|
30
42
|
const zip = new JSZip();
|
|
43
|
+
await fs.rm(path.join(dirPath, filename), { force: true });
|
|
31
44
|
async function addFiles(dir, zipFolder) {
|
|
32
45
|
const files = await fs.readdir(dir);
|
|
33
46
|
files.sort();
|
|
@@ -61,18 +74,8 @@ var createZip = async (dirPath, filename) => {
|
|
|
61
74
|
await fs.writeFile(filename, content);
|
|
62
75
|
};
|
|
63
76
|
|
|
64
|
-
// src/utils/formatDate.ts
|
|
65
|
-
var formatDate = (date) => {
|
|
66
|
-
const year = date.getFullYear();
|
|
67
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
68
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
69
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
70
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
71
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
72
|
-
return Number(`${year}${month}${day}${hours}${minutes}${seconds}`);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
77
|
// src/utils/getDefaultTargetVersion.ts
|
|
78
|
+
init_esm_shims();
|
|
76
79
|
import { exec } from "child_process";
|
|
77
80
|
import path2 from "path";
|
|
78
81
|
import util from "util";
|
|
@@ -136,6 +139,7 @@ var getDefaultTargetVersion = async (cwd, platform) => {
|
|
|
136
139
|
};
|
|
137
140
|
|
|
138
141
|
// src/utils/getFileHash.ts
|
|
142
|
+
init_esm_shims();
|
|
139
143
|
import crypto from "crypto";
|
|
140
144
|
import fs3 from "fs/promises";
|
|
141
145
|
var getFileHashFromFile = async (filepath) => {
|
|
@@ -154,9 +158,34 @@ var getFileHashFromFile = async (filepath) => {
|
|
|
154
158
|
}
|
|
155
159
|
};
|
|
156
160
|
|
|
161
|
+
// src/utils/git.ts
|
|
162
|
+
init_esm_shims();
|
|
163
|
+
import { exec as exec2 } from "child_process";
|
|
164
|
+
var getLatestGitCommitMessage = () => {
|
|
165
|
+
return new Promise((resolve) => {
|
|
166
|
+
exec2("git log --decorate --pretty=format:%s -1", (error, stdout) => {
|
|
167
|
+
if (error) {
|
|
168
|
+
resolve(null);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
resolve(stdout.trim());
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
var getGitCommitHash = () => {
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
exec2("git rev-parse HEAD", (error, stdout) => {
|
|
178
|
+
if (error) {
|
|
179
|
+
resolve(null);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
resolve(stdout.trim());
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
157
187
|
// src/commands/deploy.ts
|
|
158
188
|
import { getCwd, loadConfig } from "@hot-updater/plugin-core";
|
|
159
|
-
import { filterTargetVersion } from "@hot-updater/utils";
|
|
160
189
|
var deploy = async (options) => {
|
|
161
190
|
const s = spinner();
|
|
162
191
|
try {
|
|
@@ -165,9 +194,11 @@ var deploy = async (options) => {
|
|
|
165
194
|
console.error("No config found. Please run `hot-updater init` first.");
|
|
166
195
|
process.exit(1);
|
|
167
196
|
}
|
|
168
|
-
intro("Please provide a description for the bundle.");
|
|
169
|
-
const description = await text({ message: "Description" });
|
|
170
197
|
const cwd = getCwd();
|
|
198
|
+
const [gitCommitHash, gitMessage] = await Promise.all([
|
|
199
|
+
getGitCommitHash(),
|
|
200
|
+
getLatestGitCommitMessage()
|
|
201
|
+
]);
|
|
171
202
|
const targetVersion = options.targetVersion ?? await getDefaultTargetVersion(cwd, options.platform);
|
|
172
203
|
if (!targetVersion) {
|
|
173
204
|
throw new Error(
|
|
@@ -175,49 +206,35 @@ var deploy = async (options) => {
|
|
|
175
206
|
);
|
|
176
207
|
}
|
|
177
208
|
s.start("Build in progress");
|
|
178
|
-
const { buildPath } = await config.build({
|
|
209
|
+
const { buildPath, bundleId } = await config.build({
|
|
179
210
|
cwd,
|
|
180
211
|
platform: options.platform
|
|
181
212
|
});
|
|
182
213
|
s.message("Checking existing updates...");
|
|
183
214
|
await createZip(buildPath, "build.zip");
|
|
184
215
|
const bundlePath = buildPath.concat(".zip");
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const deployPlugin = config.deploy({
|
|
216
|
+
const fileHash = await getFileHashFromFile(bundlePath);
|
|
217
|
+
const databasePlugin = config.database({
|
|
188
218
|
cwd
|
|
189
219
|
});
|
|
190
|
-
const updateSources = await deployPlugin.getUpdateSources();
|
|
191
|
-
const targetVersions = filterTargetVersion(
|
|
192
|
-
updateSources ?? [],
|
|
193
|
-
targetVersion,
|
|
194
|
-
options.platform
|
|
195
|
-
);
|
|
196
|
-
if (targetVersions.length > 0) {
|
|
197
|
-
const recentVersion = targetVersions[0];
|
|
198
|
-
const recentHash = recentVersion?.hash;
|
|
199
|
-
if (recentHash === hash) {
|
|
200
|
-
s.stop("The update already exists.", -1);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
220
|
s.message("Uploading bundle...");
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
await deployPlugin.appendUpdateSource({
|
|
221
|
+
const storagePlugin = config.storage({
|
|
222
|
+
cwd
|
|
223
|
+
});
|
|
224
|
+
const { fileUrl } = await storagePlugin.uploadBundle(bundleId, bundlePath);
|
|
225
|
+
await databasePlugin.appendBundle({
|
|
211
226
|
forceUpdate: options.forceUpdate,
|
|
212
227
|
platform: options.platform,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
228
|
+
fileUrl,
|
|
229
|
+
fileHash,
|
|
230
|
+
gitCommitHash,
|
|
231
|
+
message: gitMessage,
|
|
216
232
|
targetVersion,
|
|
217
|
-
|
|
233
|
+
id: bundleId,
|
|
218
234
|
enabled: true
|
|
219
235
|
});
|
|
220
|
-
await
|
|
236
|
+
await databasePlugin.commitBundle();
|
|
237
|
+
await databasePlugin.onUnmount?.();
|
|
221
238
|
await fs4.rm(bundlePath);
|
|
222
239
|
s.stop("Uploading Success !", 0);
|
|
223
240
|
} catch (e) {
|
|
@@ -228,21 +245,23 @@ var deploy = async (options) => {
|
|
|
228
245
|
};
|
|
229
246
|
|
|
230
247
|
// src/commands/generateSecretKey.ts
|
|
248
|
+
init_esm_shims();
|
|
231
249
|
import crypto2 from "crypto";
|
|
232
|
-
import { text
|
|
250
|
+
import { text } from "@clack/prompts";
|
|
233
251
|
var generateSecretKey = async () => {
|
|
234
252
|
const secretKey = crypto2.randomBytes(32).toString("hex");
|
|
235
|
-
await
|
|
253
|
+
await text({
|
|
236
254
|
message: "Secret Key: ",
|
|
237
255
|
initialValue: secretKey
|
|
238
256
|
});
|
|
239
257
|
};
|
|
240
258
|
|
|
241
259
|
// src/commands/prune.ts
|
|
260
|
+
init_esm_shims();
|
|
242
261
|
import * as p from "@clack/prompts";
|
|
243
262
|
import { getCwd as getCwd2 } from "@hot-updater/plugin-core";
|
|
244
263
|
import { loadConfig as loadConfig2 } from "@hot-updater/plugin-core";
|
|
245
|
-
var prune = async (
|
|
264
|
+
var prune = async () => {
|
|
246
265
|
const s = p.spinner();
|
|
247
266
|
try {
|
|
248
267
|
const config = await loadConfig2();
|
|
@@ -251,26 +270,26 @@ var prune = async (options) => {
|
|
|
251
270
|
process.exit(1);
|
|
252
271
|
}
|
|
253
272
|
const cwd = getCwd2();
|
|
254
|
-
const
|
|
273
|
+
const databasePlugin = config.database({
|
|
255
274
|
cwd
|
|
256
|
-
// spinner: s,
|
|
257
275
|
});
|
|
258
276
|
s.start("Checking existing updates");
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
277
|
+
const bundles = await databasePlugin.getBundles();
|
|
278
|
+
const activeBundles = bundles.filter((bundle) => bundle.enabled);
|
|
279
|
+
const inactiveBundles = bundles.filter((bundle) => !bundle.enabled);
|
|
280
|
+
if (inactiveBundles.length === 0) {
|
|
263
281
|
s.stop("No inactive versions found", -1);
|
|
264
282
|
return;
|
|
265
283
|
}
|
|
266
284
|
s.message("Pruning updates");
|
|
267
|
-
await
|
|
268
|
-
await
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
285
|
+
await databasePlugin.setBundles(activeBundles);
|
|
286
|
+
await databasePlugin.commitBundle();
|
|
287
|
+
await databasePlugin.onUnmount?.();
|
|
288
|
+
const storagePlugin = config.storage({
|
|
289
|
+
cwd
|
|
290
|
+
});
|
|
291
|
+
for (const bundle of inactiveBundles) {
|
|
292
|
+
const key = await storagePlugin.deleteBundle(bundle.id);
|
|
274
293
|
p.log.info(`deleting: ${key}`);
|
|
275
294
|
}
|
|
276
295
|
s.stop("Done");
|
|
@@ -281,7 +300,11 @@ var prune = async (options) => {
|
|
|
281
300
|
}
|
|
282
301
|
};
|
|
283
302
|
|
|
303
|
+
// src/components/banner.tsx
|
|
304
|
+
init_esm_shims();
|
|
305
|
+
|
|
284
306
|
// src/packageJson.ts
|
|
307
|
+
init_esm_shims();
|
|
285
308
|
import { readPackageUpSync } from "read-package-up";
|
|
286
309
|
var packageJsonData = readPackageUpSync({
|
|
287
310
|
cwd: __dirname
|
|
@@ -290,13 +313,13 @@ var version = packageJsonData?.packageJson.version;
|
|
|
290
313
|
|
|
291
314
|
// src/components/banner.tsx
|
|
292
315
|
import boxen from "boxen";
|
|
293
|
-
import
|
|
316
|
+
import picocolors2 from "picocolors";
|
|
294
317
|
var banner = boxen(
|
|
295
318
|
[
|
|
296
|
-
`${
|
|
319
|
+
`${picocolors2.bold("Hot Updater - React Native OTA Solution")} v${version}`,
|
|
297
320
|
"",
|
|
298
|
-
`Github: ${
|
|
299
|
-
|
|
321
|
+
`Github: ${picocolors2.magenta(
|
|
322
|
+
picocolors2.underline("https://github.com/gronxb/hot-updater")
|
|
300
323
|
)}`,
|
|
301
324
|
"Give a \u2B50\uFE0F if you like it!"
|
|
302
325
|
].join("\n"),
|
|
@@ -309,6 +332,7 @@ var banner = boxen(
|
|
|
309
332
|
);
|
|
310
333
|
|
|
311
334
|
// src/prompts/getPlatform.ts
|
|
335
|
+
init_esm_shims();
|
|
312
336
|
import { select } from "@clack/prompts";
|
|
313
337
|
var getPlatform = async (message) => {
|
|
314
338
|
const platform = await select({
|
|
@@ -359,17 +383,5 @@ program.command("app-version").description("get the current app version").action
|
|
|
359
383
|
log2.info(`Android version: ${androidVersion}`);
|
|
360
384
|
log2.info(`iOS version: ${iosVersion}`);
|
|
361
385
|
});
|
|
362
|
-
program.command("prune").description("prune all the inactive versions").
|
|
363
|
-
new Option("-p, --platform <platform>", "specify the platform").choices([
|
|
364
|
-
"ios",
|
|
365
|
-
"android"
|
|
366
|
-
])
|
|
367
|
-
).action(async (options) => {
|
|
368
|
-
if (!options.platform) {
|
|
369
|
-
options.platform = await getPlatform(
|
|
370
|
-
"Which platform do you want to prune?"
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
prune(options);
|
|
374
|
-
});
|
|
386
|
+
program.command("prune").description("prune all the inactive versions").action(prune);
|
|
375
387
|
program.parse(process.argv);
|