@widget-js/cli 1.0.15 → 1.1.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/.idea/codeStyles/Project.xml +58 -0
- package/.idea/codeStyles/codeStyleConfig.xml +1 -1
- package/.idea/vcs.xml +1 -1
- package/lib/build-BTARJMCZ.js +31 -0
- package/lib/chunk-3GPAHQ6O.js +18 -0
- package/lib/chunk-SIAOIY3B.js +27 -0
- package/lib/createWidget-KWBUF3TN.js +193 -0
- package/lib/index.cjs +347 -166
- package/lib/index.d.ts +1 -0
- package/lib/index.js +20 -415
- package/lib/release-PBOWWLKA.js +206 -0
- package/lib/upgrade-ETO2LGMX.js +52 -0
- package/package.json +13 -13
- package/release.json +5 -0
- package/src/build/build.ts +35 -0
- package/src/index.ts +43 -28
- package/src/release/ftp.ts +18 -13
- package/src/upgrade/upgrade.ts +48 -0
- package/src/utils.ts +22 -6
- package/tsup.config.ts +2 -1
- package/babel.config.js +0 -20
package/lib/index.cjs
CHANGED
|
@@ -5,6 +5,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
8
15
|
var __copyProps = (to, from, except, desc) => {
|
|
9
16
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
17
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,63 +21,75 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
21
|
return to;
|
|
15
22
|
};
|
|
16
23
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
17
28
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
29
|
mod
|
|
19
30
|
));
|
|
20
31
|
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var import_commander = require("commander");
|
|
23
|
-
var import_fs6 = __toESM(require("fs"), 1);
|
|
24
|
-
var import_path4 = __toESM(require("path"), 1);
|
|
25
|
-
var process3 = __toESM(require("process"), 1);
|
|
26
|
-
|
|
27
|
-
// src/createWidget.ts
|
|
28
|
-
var import_path = __toESM(require("path"), 1);
|
|
29
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
30
|
-
var import_consola = __toESM(require("consola"), 1);
|
|
31
|
-
var import_url = require("url");
|
|
32
|
-
|
|
33
32
|
// src/promts/promptChecker.ts
|
|
34
|
-
var import_inquirer
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
var import_inquirer, promptChecker, promptChecker_default;
|
|
34
|
+
var init_promptChecker = __esm({
|
|
35
|
+
"src/promts/promptChecker.ts"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
import_inquirer = __toESM(require("inquirer"), 1);
|
|
38
|
+
promptChecker = async (prompt, checker) => {
|
|
39
|
+
const answer = await import_inquirer.default.prompt([prompt]);
|
|
40
|
+
if (checker) {
|
|
41
|
+
if (checker(answer)) {
|
|
42
|
+
return answer[prompt.name];
|
|
43
|
+
} else {
|
|
44
|
+
return promptChecker(prompt, checker);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
39
47
|
return answer[prompt.name];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
48
|
+
};
|
|
49
|
+
promptChecker_default = promptChecker;
|
|
43
50
|
}
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
var promptChecker_default = promptChecker;
|
|
47
|
-
|
|
48
|
-
// src/createWidget.ts
|
|
49
|
-
var import_change_case = require("change-case");
|
|
50
|
-
var import_inquirer2 = __toESM(require("inquirer"), 1);
|
|
51
|
-
var import_ejs = __toESM(require("ejs"), 1);
|
|
52
|
-
var import_shelljs = __toESM(require("shelljs"), 1);
|
|
51
|
+
});
|
|
53
52
|
|
|
54
53
|
// src/utils.ts
|
|
55
54
|
function exit(code = 0) {
|
|
56
55
|
if (exports.exitProcess) {
|
|
57
|
-
|
|
56
|
+
import_process.default.exit(code);
|
|
58
57
|
} else if (code > 0) {
|
|
59
58
|
throw new Error(`Process exited with code ${code}`);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
61
|
+
function getPackagePath() {
|
|
62
|
+
return import_path.default.join(import_process.default.cwd(), "package.json");
|
|
63
|
+
}
|
|
64
|
+
function getPackageJson() {
|
|
65
|
+
return JSON.parse(import_fs.default.readFileSync(getPackagePath()).toString());
|
|
66
|
+
}
|
|
67
|
+
function getPackageVersion() {
|
|
68
|
+
return getPackageJson()["version"];
|
|
69
|
+
}
|
|
70
|
+
var import_path, import_process, import_fs;
|
|
71
|
+
var init_utils = __esm({
|
|
72
|
+
"src/utils.ts"() {
|
|
73
|
+
"use strict";
|
|
74
|
+
import_path = __toESM(require("path"), 1);
|
|
75
|
+
import_process = __toESM(require("process"), 1);
|
|
76
|
+
import_fs = __toESM(require("fs"), 1);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
62
79
|
|
|
63
80
|
// src/createWidget.ts
|
|
64
|
-
var
|
|
65
|
-
|
|
81
|
+
var createWidget_exports = {};
|
|
82
|
+
__export(createWidget_exports, {
|
|
83
|
+
default: () => createWidget
|
|
84
|
+
});
|
|
66
85
|
async function createWidget() {
|
|
67
|
-
let widgetJson =
|
|
68
|
-
if (!
|
|
86
|
+
let widgetJson = import_path2.default.join(process.cwd(), "widget.json");
|
|
87
|
+
if (!import_fs2.default.existsSync(widgetJson)) {
|
|
69
88
|
import_consola.default.error("\u6CA1\u6709\u5728\u6839\u76EE\u5F55\u627E\u5230widget.json\u6587\u4EF6");
|
|
70
89
|
exit();
|
|
71
90
|
}
|
|
72
|
-
let widgetPackage = JSON.parse(
|
|
73
|
-
let widgetFolder =
|
|
91
|
+
let widgetPackage = JSON.parse(import_fs2.default.readFileSync(widgetJson).toString());
|
|
92
|
+
let widgetFolder = import_path2.default.join(process.cwd(), "./src/widgets");
|
|
74
93
|
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
75
94
|
if (devOptions["folder"]) {
|
|
76
95
|
widgetFolder = devOptions["folder"];
|
|
@@ -78,11 +97,11 @@ async function createWidget() {
|
|
|
78
97
|
} else {
|
|
79
98
|
import_consola.default.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetFolder}`);
|
|
80
99
|
}
|
|
81
|
-
if (!
|
|
82
|
-
|
|
100
|
+
if (!import_fs2.default.existsSync(widgetFolder)) {
|
|
101
|
+
import_fs2.default.mkdirSync(widgetFolder, { recursive: true });
|
|
83
102
|
}
|
|
84
103
|
const __filename2 = (0, import_url.fileURLToPath)(import_meta.url);
|
|
85
|
-
const __dirname2 =
|
|
104
|
+
const __dirname2 = import_path2.default.dirname(__filename2);
|
|
86
105
|
const getMiddleValue = (arr) => {
|
|
87
106
|
if (arr.length === 1) {
|
|
88
107
|
return arr[0];
|
|
@@ -163,9 +182,9 @@ async function createWidget() {
|
|
|
163
182
|
const snakeCaseName = (0, import_change_case.snakeCase)(name);
|
|
164
183
|
const paramCaseName = (0, import_change_case.paramCase)(name);
|
|
165
184
|
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
166
|
-
const widgetDir =
|
|
167
|
-
if (!
|
|
168
|
-
|
|
185
|
+
const widgetDir = import_path2.default.join(widgetFolder, paramCaseName);
|
|
186
|
+
if (!import_fs2.default.existsSync(widgetDir)) {
|
|
187
|
+
import_fs2.default.mkdirSync(widgetDir);
|
|
169
188
|
} else {
|
|
170
189
|
let answer = await import_inquirer2.default.prompt([{
|
|
171
190
|
type: "confirm",
|
|
@@ -191,32 +210,32 @@ async function createWidget() {
|
|
|
191
210
|
minWidth
|
|
192
211
|
};
|
|
193
212
|
function renderToFile(templateFile, outputFile, renderOptions2) {
|
|
194
|
-
const defineTemplatePath =
|
|
195
|
-
let defineTemplate =
|
|
196
|
-
|
|
213
|
+
const defineTemplatePath = import_path2.default.join(__dirname2, "../template", templateFile);
|
|
214
|
+
let defineTemplate = import_fs2.default.readFileSync(defineTemplatePath, "utf8");
|
|
215
|
+
import_fs2.default.writeFileSync(outputFile, import_ejs.default.render(defineTemplate, renderOptions2));
|
|
197
216
|
}
|
|
198
|
-
const widgetDefineFile =
|
|
199
|
-
const widgetFile =
|
|
200
|
-
const widgetViewFile =
|
|
201
|
-
const widgetRoutesFile =
|
|
217
|
+
const widgetDefineFile = import_path2.default.resolve(widgetDir, `${name}.widget.ts`);
|
|
218
|
+
const widgetFile = import_path2.default.resolve(widgetDir, `${name}Widget.vue`);
|
|
219
|
+
const widgetViewFile = import_path2.default.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
220
|
+
const widgetRoutesFile = import_path2.default.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
202
221
|
renderToFile("WidgetDefine.ejs", widgetDefineFile, renderOptions);
|
|
203
222
|
renderToFile("Widget.ejs", widgetFile, renderOptions);
|
|
204
223
|
renderToFile("WidgetView.ejs", widgetViewFile, renderOptions);
|
|
205
224
|
renderToFile("WidgetRoutes.ejs", widgetRoutesFile, renderOptions);
|
|
206
225
|
if (configurable) {
|
|
207
|
-
const configFile =
|
|
226
|
+
const configFile = import_path2.default.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
208
227
|
renderToFile("WidgetConfig.ejs", configFile, renderOptions);
|
|
209
228
|
}
|
|
210
229
|
if (devOptions["useStorybook"]) {
|
|
211
|
-
const storiesFile =
|
|
230
|
+
const storiesFile = import_path2.default.resolve(widgetDir, `${name}Widget.stories.ts`);
|
|
212
231
|
renderToFile("stories.ejs", storiesFile, renderOptions);
|
|
213
232
|
}
|
|
214
|
-
const routeFile =
|
|
233
|
+
const routeFile = import_path2.default.join(widgetFolder, "widget-router.ts");
|
|
215
234
|
let routeContent;
|
|
216
|
-
if (
|
|
217
|
-
routeContent =
|
|
235
|
+
if (import_fs2.default.existsSync(routeFile)) {
|
|
236
|
+
routeContent = import_fs2.default.readFileSync(routeFile, "utf8");
|
|
218
237
|
} else {
|
|
219
|
-
routeContent =
|
|
238
|
+
routeContent = import_fs2.default.readFileSync(import_path2.default.join(__dirname2, "../template/widget-router.ts"), "utf8");
|
|
220
239
|
}
|
|
221
240
|
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
222
241
|
const routeStr = `...${name}WidgetRoutes,`;
|
|
@@ -228,7 +247,7 @@ async function createWidget() {
|
|
|
228
247
|
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
229
248
|
//FBI WANING! ROUTE PLACE`);
|
|
230
249
|
}
|
|
231
|
-
|
|
250
|
+
import_fs2.default.writeFileSync(routeFile, routeContent);
|
|
232
251
|
let gitAdd = `git add ${widgetDir}`;
|
|
233
252
|
import_consola.default.info(import_chalk.default.grey(gitAdd));
|
|
234
253
|
import_shelljs.default.exec(gitAdd);
|
|
@@ -236,44 +255,141 @@ async function createWidget() {
|
|
|
236
255
|
import_consola.default.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
237
256
|
import_consola.default.success("Happy coding!");
|
|
238
257
|
}
|
|
258
|
+
var import_path2, import_fs2, import_consola, import_url, import_change_case, import_inquirer2, import_ejs, import_shelljs, import_chalk, import_meta;
|
|
259
|
+
var init_createWidget = __esm({
|
|
260
|
+
"src/createWidget.ts"() {
|
|
261
|
+
"use strict";
|
|
262
|
+
import_path2 = __toESM(require("path"), 1);
|
|
263
|
+
import_fs2 = __toESM(require("fs"), 1);
|
|
264
|
+
import_consola = __toESM(require("consola"), 1);
|
|
265
|
+
import_url = require("url");
|
|
266
|
+
init_promptChecker();
|
|
267
|
+
import_change_case = require("change-case");
|
|
268
|
+
import_inquirer2 = __toESM(require("inquirer"), 1);
|
|
269
|
+
import_ejs = __toESM(require("ejs"), 1);
|
|
270
|
+
import_shelljs = __toESM(require("shelljs"), 1);
|
|
271
|
+
init_utils();
|
|
272
|
+
import_chalk = __toESM(require("chalk"), 1);
|
|
273
|
+
import_meta = {};
|
|
274
|
+
}
|
|
275
|
+
});
|
|
239
276
|
|
|
240
|
-
// src/
|
|
241
|
-
var
|
|
242
|
-
|
|
277
|
+
// src/upgrade/upgrade.ts
|
|
278
|
+
var upgrade_exports = {};
|
|
279
|
+
__export(upgrade_exports, {
|
|
280
|
+
Upgrade: () => Upgrade
|
|
281
|
+
});
|
|
282
|
+
var import_package_json, import_ora, import_fs3, packages, spinner, Upgrade;
|
|
283
|
+
var init_upgrade = __esm({
|
|
284
|
+
"src/upgrade/upgrade.ts"() {
|
|
285
|
+
"use strict";
|
|
286
|
+
import_package_json = __toESM(require("package-json"), 1);
|
|
287
|
+
import_ora = __toESM(require("ora"), 1);
|
|
288
|
+
init_utils();
|
|
289
|
+
import_fs3 = __toESM(require("fs"), 1);
|
|
290
|
+
packages = {
|
|
291
|
+
"@widget-js/core": "",
|
|
292
|
+
"@widget-js/vue3": "",
|
|
293
|
+
"@widget-js/cli": "",
|
|
294
|
+
"@widget-js/vite-plugin-widget": ""
|
|
295
|
+
};
|
|
296
|
+
spinner = (0, import_ora.default)("Connecting");
|
|
297
|
+
Upgrade = class {
|
|
298
|
+
async start() {
|
|
299
|
+
spinner.start();
|
|
300
|
+
let json = getPackageJson();
|
|
301
|
+
let packageNames = Object.keys(packages);
|
|
302
|
+
let dependencies = json["dependencies"];
|
|
303
|
+
let devDependencies = json["devDependencies"];
|
|
304
|
+
await this.upgradePackage(dependencies, packageNames);
|
|
305
|
+
await this.upgradePackage(devDependencies, packageNames);
|
|
306
|
+
import_fs3.default.writeFileSync(getPackagePath(), JSON.stringify(json, null, 2));
|
|
307
|
+
spinner.succeed("Upgraded!");
|
|
308
|
+
}
|
|
309
|
+
async upgradePackage(dependencies, packageNames) {
|
|
310
|
+
let localPackages = Object.keys(dependencies);
|
|
311
|
+
for (let localPackage of localPackages) {
|
|
312
|
+
if (packageNames.indexOf(localPackage) > -1) {
|
|
313
|
+
let packageVersion = packages[localPackage];
|
|
314
|
+
if (!packageVersion) {
|
|
315
|
+
packageVersion = await this.getRemoteVersion(localPackage);
|
|
316
|
+
packages[localPackage] = packageVersion;
|
|
317
|
+
}
|
|
318
|
+
dependencies[localPackage] = `^${packageVersion}`;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async getRemoteVersion(packageName) {
|
|
323
|
+
spinner.info(`Fetching package version:${packageName}`);
|
|
324
|
+
const metadata = await (0, import_package_json.default)(packageName);
|
|
325
|
+
let version = metadata["version"];
|
|
326
|
+
spinner.info(`version:${version}`);
|
|
327
|
+
return version;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// src/build/build.ts
|
|
334
|
+
var build_exports = {};
|
|
335
|
+
__export(build_exports, {
|
|
336
|
+
build: () => build
|
|
337
|
+
});
|
|
338
|
+
function build() {
|
|
339
|
+
const preloadSpinner = (0, import_ora2.default)("Preload").start();
|
|
340
|
+
const mainSpinner = (0, import_ora2.default)("Main").start();
|
|
341
|
+
const build2 = (0, import_child_process.exec)("npm run build:preload").on("close", () => {
|
|
342
|
+
import_consola2.default.success("done");
|
|
343
|
+
});
|
|
344
|
+
build2.stdout.on("data", (data) => {
|
|
345
|
+
import_consola2.default.log("data", data);
|
|
346
|
+
});
|
|
347
|
+
(0, import_child_process.exec)("npm run build:main", (error, stdout, stderr) => {
|
|
348
|
+
if (error) {
|
|
349
|
+
import_consola2.default.error("error: " + error);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
import_consola2.default.log("stdout: " + stdout);
|
|
353
|
+
import_consola2.default.log("stderr: " + typeof stderr);
|
|
354
|
+
}).on("message", () => {
|
|
355
|
+
import_consola2.default.log("on-message");
|
|
356
|
+
}).on("data", () => {
|
|
357
|
+
import_consola2.default.log("on-data");
|
|
358
|
+
}).on("close", () => {
|
|
359
|
+
import_consola2.default.log("done");
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
var import_ora2, import_child_process, import_consola2;
|
|
363
|
+
var init_build = __esm({
|
|
364
|
+
"src/build/build.ts"() {
|
|
365
|
+
"use strict";
|
|
366
|
+
import_ora2 = __toESM(require("ora"), 1);
|
|
367
|
+
import_child_process = require("child_process");
|
|
368
|
+
import_consola2 = __toESM(require("consola"), 1);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
243
371
|
|
|
244
372
|
// src/release/update-zip.ts
|
|
245
|
-
var import_fs2 = __toESM(require("fs"), 1);
|
|
246
|
-
var import_archiver = __toESM(require("archiver"), 1);
|
|
247
373
|
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
248
374
|
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
249
|
-
const stream =
|
|
375
|
+
const stream = import_fs4.default.createWriteStream(outPath);
|
|
250
376
|
return new Promise((resolve, reject) => {
|
|
251
377
|
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
252
378
|
stream.on("close", () => resolve());
|
|
253
379
|
archive.finalize();
|
|
254
380
|
});
|
|
255
381
|
}
|
|
256
|
-
var
|
|
382
|
+
var import_fs4, import_archiver, update_zip_default;
|
|
383
|
+
var init_update_zip = __esm({
|
|
384
|
+
"src/release/update-zip.ts"() {
|
|
385
|
+
"use strict";
|
|
386
|
+
import_fs4 = __toESM(require("fs"), 1);
|
|
387
|
+
import_archiver = __toESM(require("archiver"), 1);
|
|
388
|
+
update_zip_default = zipDirectory;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
257
391
|
|
|
258
392
|
// src/release/oss.ts
|
|
259
|
-
var import_ali_oss = __toESM(require("ali-oss"), 1);
|
|
260
|
-
var import_fs3 = __toESM(require("fs"), 1);
|
|
261
|
-
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
262
|
-
var packageData = JSON.parse(import_fs3.default.readFileSync("./package.json").toString());
|
|
263
|
-
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
264
|
-
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
265
|
-
var headers = {
|
|
266
|
-
"x-oss-storage-class": "Standard",
|
|
267
|
-
"x-oss-object-acl": "public-read",
|
|
268
|
-
"x-oss-forbid-overwrite": "false",
|
|
269
|
-
"Cache-Control": "no-cache"
|
|
270
|
-
};
|
|
271
|
-
var clinet = new import_ali_oss.default({
|
|
272
|
-
region: "oss-cn-hangzhou",
|
|
273
|
-
accessKeyId: AccessKeyID,
|
|
274
|
-
accessKeySecret: AccessKeySecret,
|
|
275
|
-
bucket: "widget-fun"
|
|
276
|
-
});
|
|
277
393
|
async function put(ossPath, file) {
|
|
278
394
|
try {
|
|
279
395
|
const result = await clinet.put(ossPath, file, { headers });
|
|
@@ -290,23 +406,38 @@ async function copy(dist, src) {
|
|
|
290
406
|
console.error(e);
|
|
291
407
|
}
|
|
292
408
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
409
|
+
var import_ali_oss, import_fs5, import_chalk2, packageData, AccessKeyID, AccessKeySecret, headers, clinet;
|
|
410
|
+
var init_oss = __esm({
|
|
411
|
+
"src/release/oss.ts"() {
|
|
412
|
+
"use strict";
|
|
413
|
+
import_ali_oss = __toESM(require("ali-oss"), 1);
|
|
414
|
+
import_fs5 = __toESM(require("fs"), 1);
|
|
415
|
+
import_chalk2 = __toESM(require("chalk"), 1);
|
|
416
|
+
packageData = JSON.parse(import_fs5.default.readFileSync("./package.json").toString());
|
|
417
|
+
AccessKeyID = packageData.oss?.id ?? "default";
|
|
418
|
+
AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
419
|
+
headers = {
|
|
420
|
+
// 指定Object的存储类型。
|
|
421
|
+
"x-oss-storage-class": "Standard",
|
|
422
|
+
// 指定Object的访问权限。
|
|
423
|
+
"x-oss-object-acl": "public-read",
|
|
424
|
+
"x-oss-forbid-overwrite": "false",
|
|
425
|
+
"Cache-Control": "no-cache"
|
|
426
|
+
};
|
|
427
|
+
clinet = new import_ali_oss.default({
|
|
428
|
+
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
|
429
|
+
region: "oss-cn-hangzhou",
|
|
430
|
+
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
431
|
+
accessKeyId: AccessKeyID,
|
|
432
|
+
accessKeySecret: AccessKeySecret,
|
|
433
|
+
bucket: "widget-fun"
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
});
|
|
296
437
|
|
|
297
438
|
// src/release/ftp.ts
|
|
298
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
299
|
-
var import_fs4 = __toESM(require("fs"), 1);
|
|
300
|
-
var import_ssh_config = __toESM(require("@widget-js/ssh-config"), 1);
|
|
301
|
-
var import_os = __toESM(require("os"), 1);
|
|
302
|
-
var import_ssh2_sftp_client = __toESM(require("ssh2-sftp-client"), 1);
|
|
303
|
-
var import_consola2 = __toESM(require("consola"), 1);
|
|
304
|
-
var import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
305
|
-
var import_ora = __toESM(require("ora"), 1);
|
|
306
|
-
var process2 = __toESM(require("process"), 1);
|
|
307
|
-
var console2 = __toESM(require("console"), 1);
|
|
308
439
|
async function checkParentDir(ftpClient, file, onMkdir) {
|
|
309
|
-
let dir =
|
|
440
|
+
let dir = import_path3.default.dirname(file);
|
|
310
441
|
const dirExists = await ftpClient.exists(dir);
|
|
311
442
|
if (!dirExists) {
|
|
312
443
|
onMkdir(dir);
|
|
@@ -314,24 +445,27 @@ async function checkParentDir(ftpClient, file, onMkdir) {
|
|
|
314
445
|
}
|
|
315
446
|
}
|
|
316
447
|
function ftpUpload() {
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
448
|
+
const releaseJsonFilePath = import_path3.default.join(process3.cwd(), "release.json");
|
|
449
|
+
const packageVersion = getPackageVersion();
|
|
450
|
+
import_consola3.default.info("Package Version:", packageVersion);
|
|
451
|
+
let releaseJson = import_fs6.default.readFileSync(releaseJsonFilePath).toString().replaceAll("${version}", packageVersion);
|
|
452
|
+
const releaseConfig = JSON.parse(releaseJson);
|
|
453
|
+
const sshConfigFile = import_path3.default.resolve(import_os.default.homedir(), ".ssh/config");
|
|
454
|
+
import_consola3.default.info("SSH Config File Path:", sshConfigFile);
|
|
455
|
+
const sshConfigs = import_ssh_config.default.parse(import_fs6.default.readFileSync(sshConfigFile).toString());
|
|
322
456
|
let sshConfig = sshConfigs.compute(releaseConfig.ftpConfig.host);
|
|
323
457
|
if (!sshConfig) {
|
|
324
|
-
|
|
458
|
+
import_consola3.default.error(`SSH config ${releaseConfig.ftpConfig.host} not found`);
|
|
325
459
|
return;
|
|
326
460
|
}
|
|
327
|
-
|
|
461
|
+
import_consola3.default.info(sshConfig);
|
|
328
462
|
import_inquirer3.default.prompt([{ type: "password", name: "password", mask: "*", message: "Enter key pair password" }]).then(async (answer) => {
|
|
329
463
|
let ftpClient = new import_ssh2_sftp_client.default();
|
|
330
464
|
const port = sshConfig["Port"];
|
|
331
|
-
const key =
|
|
332
|
-
const
|
|
465
|
+
const key = import_fs6.default.readFileSync(import_path3.default.resolve(import_os.default.homedir(), ".ssh/id_rsa"));
|
|
466
|
+
const spinner2 = (0, import_ora3.default)("Connecting");
|
|
333
467
|
try {
|
|
334
|
-
|
|
468
|
+
spinner2.start();
|
|
335
469
|
await ftpClient.connect({
|
|
336
470
|
host: sshConfig["HostName"],
|
|
337
471
|
port: port ? parseInt(port) : 22,
|
|
@@ -344,29 +478,29 @@ function ftpUpload() {
|
|
|
344
478
|
if (typeof item.src == "string") {
|
|
345
479
|
if (item.remoteCopy) {
|
|
346
480
|
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
347
|
-
|
|
481
|
+
spinner2.warn(`Create Dir: ${dir}`);
|
|
348
482
|
});
|
|
349
483
|
let destExists = await ftpClient.exists(item.dest);
|
|
350
484
|
if (destExists) {
|
|
351
|
-
|
|
485
|
+
spinner2.warn(`Delete exists file:${item.dest}`);
|
|
352
486
|
await ftpClient.delete(item.dest);
|
|
353
487
|
}
|
|
354
|
-
|
|
488
|
+
spinner2.info(`Copying File: ${item.src} -> ${item.dest}`);
|
|
355
489
|
await ftpClient.rcopy(item.src, item.dest);
|
|
356
490
|
} else {
|
|
357
|
-
const localFile =
|
|
358
|
-
if (!item.remoteCopy && !
|
|
359
|
-
|
|
491
|
+
const localFile = import_path3.default.resolve(process3.cwd(), item.src);
|
|
492
|
+
if (!item.remoteCopy && !import_fs6.default.existsSync(localFile)) {
|
|
493
|
+
spinner2.warn(`Skip not exists file:${localFile}`);
|
|
360
494
|
continue;
|
|
361
495
|
}
|
|
362
|
-
if (
|
|
363
|
-
|
|
496
|
+
if (import_fs6.default.lstatSync(localFile).isDirectory()) {
|
|
497
|
+
spinner2.info(`Uploading Dir: ${localFile} -> ${item.dest}`);
|
|
364
498
|
await ftpClient.uploadDir(localFile, item.dest);
|
|
365
499
|
} else {
|
|
366
500
|
await checkParentDir(ftpClient, item.dest, (dir) => {
|
|
367
|
-
|
|
501
|
+
spinner2.warn(`Create Dir: ${dir}`);
|
|
368
502
|
});
|
|
369
|
-
|
|
503
|
+
spinner2.info(`Uploading File: ${localFile} -> ${item.dest}`);
|
|
370
504
|
await ftpClient.put(localFile, item.dest);
|
|
371
505
|
}
|
|
372
506
|
}
|
|
@@ -374,77 +508,124 @@ function ftpUpload() {
|
|
|
374
508
|
await ftpClient.put(Buffer.from(JSON.stringify(item.src), "utf-8"), item.dest);
|
|
375
509
|
}
|
|
376
510
|
}
|
|
377
|
-
|
|
511
|
+
spinner2.succeed("Files uploaded!");
|
|
378
512
|
await ftpClient.end();
|
|
379
513
|
} catch (e) {
|
|
380
|
-
|
|
514
|
+
spinner2.fail(`Connection error:${e}`);
|
|
381
515
|
await ftpClient.end();
|
|
382
516
|
}
|
|
383
517
|
});
|
|
384
518
|
}
|
|
519
|
+
var import_path3, import_fs6, import_ssh_config, import_os, import_ssh2_sftp_client, import_consola3, import_inquirer3, import_ora3, process3;
|
|
520
|
+
var init_ftp = __esm({
|
|
521
|
+
"src/release/ftp.ts"() {
|
|
522
|
+
"use strict";
|
|
523
|
+
import_path3 = __toESM(require("path"), 1);
|
|
524
|
+
import_fs6 = __toESM(require("fs"), 1);
|
|
525
|
+
import_ssh_config = __toESM(require("@widget-js/ssh-config"), 1);
|
|
526
|
+
import_os = __toESM(require("os"), 1);
|
|
527
|
+
import_ssh2_sftp_client = __toESM(require("ssh2-sftp-client"), 1);
|
|
528
|
+
import_consola3 = __toESM(require("consola"), 1);
|
|
529
|
+
import_inquirer3 = __toESM(require("inquirer"), 1);
|
|
530
|
+
import_ora3 = __toESM(require("ora"), 1);
|
|
531
|
+
process3 = __toESM(require("process"), 1);
|
|
532
|
+
init_utils();
|
|
533
|
+
}
|
|
534
|
+
});
|
|
385
535
|
|
|
386
536
|
// src/release/release.ts
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
537
|
+
var release_exports = {};
|
|
538
|
+
__export(release_exports, {
|
|
539
|
+
default: () => release_default
|
|
540
|
+
});
|
|
541
|
+
var import_fs7, import_path4, import_chalk3, release, release_default;
|
|
542
|
+
var init_release = __esm({
|
|
543
|
+
"src/release/release.ts"() {
|
|
544
|
+
"use strict";
|
|
545
|
+
import_fs7 = __toESM(require("fs"), 1);
|
|
546
|
+
import_path4 = __toESM(require("path"), 1);
|
|
547
|
+
init_promptChecker();
|
|
548
|
+
init_update_zip();
|
|
549
|
+
init_oss();
|
|
550
|
+
import_chalk3 = __toESM(require("chalk"), 1);
|
|
551
|
+
init_ftp();
|
|
552
|
+
release = async (options) => {
|
|
553
|
+
console.log();
|
|
554
|
+
if (options.type == "ftp") {
|
|
555
|
+
await ftpUpload();
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const packageJSON = JSON.parse(import_fs7.default.readFileSync("package.json", "utf-8"));
|
|
559
|
+
const changelogJSON = JSON.parse(import_fs7.default.readFileSync("changelog.json", "utf-8"));
|
|
560
|
+
const version = packageJSON["version"];
|
|
561
|
+
const changelog = changelogJSON[version];
|
|
562
|
+
let needUpdateElectron = await promptChecker_default({
|
|
563
|
+
type: "confirm",
|
|
564
|
+
name: "electron",
|
|
565
|
+
message: import_chalk3.default.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
566
|
+
});
|
|
567
|
+
const versionInfo = {
|
|
568
|
+
version,
|
|
569
|
+
releaseNote: changelog,
|
|
570
|
+
updateElectron: needUpdateElectron,
|
|
571
|
+
updateNodeModule: false,
|
|
572
|
+
updateWindowsApi: false,
|
|
573
|
+
downloadLink: ""
|
|
574
|
+
};
|
|
575
|
+
let installerPath = import_path4.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
576
|
+
if (!import_fs7.default.existsSync(installerPath)) {
|
|
577
|
+
installerPath = import_path4.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
578
|
+
}
|
|
579
|
+
const updateZipPath = import_path4.default.join(`./packaged/update.zip`);
|
|
580
|
+
console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
581
|
+
await update_zip_default("./release", updateZipPath);
|
|
582
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
583
|
+
await put("version/installer.exe", installerPath);
|
|
584
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
585
|
+
await put("version/update.zip", updateZipPath);
|
|
586
|
+
console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
587
|
+
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
588
|
+
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
589
|
+
await put("version/version.json", Buffer.from(versionJSON));
|
|
590
|
+
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
591
|
+
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
592
|
+
console.log(import_chalk3.default.yellow(versionJSON));
|
|
593
|
+
};
|
|
594
|
+
release_default = release;
|
|
413
595
|
}
|
|
414
|
-
|
|
415
|
-
console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
416
|
-
await update_zip_default("./release", updateZipPath);
|
|
417
|
-
console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
418
|
-
await put("version/installer.exe", installerPath);
|
|
419
|
-
console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
420
|
-
await put("version/update.zip", updateZipPath);
|
|
421
|
-
console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
422
|
-
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
423
|
-
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
424
|
-
await put("version/version.json", Buffer.from(versionJSON));
|
|
425
|
-
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
426
|
-
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
427
|
-
console.log(import_chalk3.default.yellow(versionJSON));
|
|
428
|
-
};
|
|
429
|
-
var release_default = release;
|
|
596
|
+
});
|
|
430
597
|
|
|
431
598
|
// src/index.ts
|
|
599
|
+
var import_commander = require("commander");
|
|
600
|
+
var import_fs8 = __toESM(require("fs"), 1);
|
|
601
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
602
|
+
var process4 = __toESM(require("process"), 1);
|
|
432
603
|
var import_url2 = require("url");
|
|
433
604
|
var import_figlet = __toESM(require("figlet"), 1);
|
|
434
605
|
var import_gradient_string = __toESM(require("gradient-string"), 1);
|
|
435
606
|
var import_meta2 = {};
|
|
436
607
|
var __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
437
|
-
var __dirname =
|
|
438
|
-
var packageJsonPath =
|
|
439
|
-
var cliPackage = JSON.parse(
|
|
608
|
+
var __dirname = import_path5.default.dirname(__filename);
|
|
609
|
+
var packageJsonPath = import_path5.default.join(__dirname, "../package.json");
|
|
610
|
+
var cliPackage = JSON.parse(import_fs8.default.readFileSync(packageJsonPath).toString());
|
|
440
611
|
console.log(import_gradient_string.default.pastel.multiline(import_figlet.default.textSync("widget-cli", { horizontalLayout: "full" })));
|
|
441
612
|
import_commander.program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
442
613
|
import_commander.program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
443
|
-
await
|
|
614
|
+
const createWidget2 = await Promise.resolve().then(() => (init_createWidget(), createWidget_exports));
|
|
615
|
+
await createWidget2.default();
|
|
616
|
+
});
|
|
617
|
+
import_commander.program.command("upgrade").description("\u5347\u7EA7\u4F9D\u8D56").action(async () => {
|
|
618
|
+
const upgrade = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
619
|
+
const instance = new upgrade.Upgrade();
|
|
620
|
+
await instance.start();
|
|
621
|
+
});
|
|
622
|
+
import_commander.program.command("build").description("\u6267\u884C\u7F16\u8BD1\u4EFB\u52A1").action(async () => {
|
|
623
|
+
const build2 = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
624
|
+
await build2.build();
|
|
444
625
|
});
|
|
445
626
|
var typeOption = new import_commander.Option("-t, --type <type>").choices(["ftp", "oss"]);
|
|
446
627
|
import_commander.program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).action(async (options, command) => {
|
|
447
|
-
|
|
448
|
-
await
|
|
628
|
+
let release2 = await Promise.resolve().then(() => (init_release(), release_exports));
|
|
629
|
+
await release2.default(options);
|
|
449
630
|
});
|
|
450
|
-
import_commander.program.parse(
|
|
631
|
+
import_commander.program.parse(process4.argv);
|