@widget-js/cli 1.0.8 → 1.0.10
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/lib/index.cjs +356 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +334 -0
- package/package.json +18 -13
- package/readme.md +1 -1
- package/{lib/createWidget.js → src/createWidget.ts} +29 -25
- package/{bin/widget.js → src/index.ts} +14 -4
- package/src/promts/promptChecker.ts +15 -0
- package/{lib/release/oss.js → src/release/oss.ts} +3 -3
- package/{lib/release/release.js → src/release/release.ts} +11 -15
- package/src/release/update-zip.ts +19 -0
- package/src/utils.ts +7 -0
- package/template/WidgetDefine.ejs +13 -3
- package/template/WidgetRoutes.ejs +2 -2
- package/tsconfig.json +5 -1
- package/tsup.config.ts +5 -0
- package/lib/promts/promptChecker.js +0 -15
- package/lib/release/update-zip.js +0 -19
- package/tools/cleanup.js +0 -29
- package/tools/packagejson.js +0 -25
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var import_commander = require("commander");
|
|
23
|
+
var import_fs5 = __toESM(require("fs"), 1);
|
|
24
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
25
|
+
var process2 = __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
|
+
// src/promts/promptChecker.ts
|
|
34
|
+
var import_inquirer = __toESM(require("inquirer"), 1);
|
|
35
|
+
var promptChecker = async (prompt, checker) => {
|
|
36
|
+
const answer = await import_inquirer.default.prompt([prompt]);
|
|
37
|
+
if (checker) {
|
|
38
|
+
if (checker(answer)) {
|
|
39
|
+
return answer[prompt.name];
|
|
40
|
+
} else {
|
|
41
|
+
return promptChecker(prompt, checker);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return answer[prompt.name];
|
|
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);
|
|
53
|
+
|
|
54
|
+
// src/utils.ts
|
|
55
|
+
function exit(code = 0) {
|
|
56
|
+
if (exports.exitProcess) {
|
|
57
|
+
process.exit(code);
|
|
58
|
+
} else if (code > 0) {
|
|
59
|
+
throw new Error(`Process exited with code ${code}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/createWidget.ts
|
|
64
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
65
|
+
var import_meta = {};
|
|
66
|
+
async function createWidget() {
|
|
67
|
+
let widgetJson = import_path.default.join(process.cwd(), "widget.json");
|
|
68
|
+
if (!import_fs.default.existsSync(widgetJson)) {
|
|
69
|
+
import_consola.default.error("\u6CA1\u6709\u5728\u6839\u76EE\u5F55\u627E\u5230widget.json\u6587\u4EF6");
|
|
70
|
+
exit();
|
|
71
|
+
}
|
|
72
|
+
let widgetPackage = JSON.parse(import_fs.default.readFileSync(widgetJson).toString());
|
|
73
|
+
let widgetFolder = import_path.default.join(process.cwd(), "./src/widgets");
|
|
74
|
+
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
75
|
+
if (devOptions["folder"]) {
|
|
76
|
+
widgetFolder = devOptions["folder"];
|
|
77
|
+
import_consola.default.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetFolder}`);
|
|
78
|
+
} else {
|
|
79
|
+
import_consola.default.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetFolder}`);
|
|
80
|
+
}
|
|
81
|
+
if (!import_fs.default.existsSync(widgetFolder)) {
|
|
82
|
+
import_fs.default.mkdirSync(widgetFolder, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
const __filename2 = (0, import_url.fileURLToPath)(import_meta.url);
|
|
85
|
+
const __dirname2 = import_path.default.dirname(__filename2);
|
|
86
|
+
const getMiddleValue = (arr) => {
|
|
87
|
+
if (arr.length === 1) {
|
|
88
|
+
return arr[0];
|
|
89
|
+
} else if (arr.length === 2) {
|
|
90
|
+
return Math.max(...arr);
|
|
91
|
+
} else {
|
|
92
|
+
const max = Math.max(...arr);
|
|
93
|
+
const min = Math.min(...arr);
|
|
94
|
+
const sum = arr[0] + arr[1] + arr[2];
|
|
95
|
+
return sum - max - min;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
let name = await promptChecker_default({
|
|
99
|
+
type: "input",
|
|
100
|
+
name: "name",
|
|
101
|
+
message: import_chalk.default.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
|
|
102
|
+
}, (answer) => {
|
|
103
|
+
const name2 = answer.name;
|
|
104
|
+
if (name2 == null || name2 === "") {
|
|
105
|
+
import_consola.default.log(import_chalk.default.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
});
|
|
110
|
+
import_consola.default.log(import_chalk.default.green(name));
|
|
111
|
+
let title = await promptChecker_default({
|
|
112
|
+
type: "input",
|
|
113
|
+
name: "title",
|
|
114
|
+
message: import_chalk.default.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
115
|
+
});
|
|
116
|
+
import_consola.default.log(import_chalk.default.green(title));
|
|
117
|
+
let answerW = await promptChecker_default({
|
|
118
|
+
type: "checkbox",
|
|
119
|
+
name: "w",
|
|
120
|
+
message: import_chalk.default.blue("\u8BF7\u9009\u62E9\u7EC4\u4EF6\u5BBD\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D2,4,6\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u5BBD\u4E3A2\uFF0C\u9ED8\u8BA4\u5BBD\u4E3A4\uFF0C\u6700\u5927\u5BBD\u4E3A6\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"),
|
|
121
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
122
|
+
}, (answer) => {
|
|
123
|
+
if (answer.w.length === 0) {
|
|
124
|
+
import_consola.default.log(import_chalk.default.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (answer.w.length > 3) {
|
|
128
|
+
import_consola.default.log(import_chalk.default.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
133
|
+
import_consola.default.log(import_chalk.default.green(answerW));
|
|
134
|
+
let answerH = await promptChecker_default({
|
|
135
|
+
type: "checkbox",
|
|
136
|
+
name: "h",
|
|
137
|
+
message: import_chalk.default.blue("\u8BF7\u9009\u62E9\u7EC4\u4EF6\u9AD8\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D1,2\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u4E3A1\uFF0C\u9ED8\u8BA4\u9AD8\u4E3A2\uFF0C\u6700\u5927\u9AD8\u4E3A2\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"),
|
|
138
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
139
|
+
}, (answer) => {
|
|
140
|
+
if (answer.h.length === 0) {
|
|
141
|
+
import_consola.default.log(import_chalk.default.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (answer.h.length > 3) {
|
|
145
|
+
import_consola.default.log(import_chalk.default.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
import_consola.default.log(import_chalk.default.green(answerH));
|
|
151
|
+
let configurable = await promptChecker_default({
|
|
152
|
+
type: "confirm",
|
|
153
|
+
name: "configurable",
|
|
154
|
+
message: import_chalk.default.blue("\u7EC4\u4EF6\u662F\u5426\u53EF\u914D\u7F6E\uFF0C\u4F8B\u5982\u4FEE\u6539\u80CC\u666F\u989C\u8272\uFF0C\u5B57\u4F53\u5927\u5C0F\u7B49")
|
|
155
|
+
});
|
|
156
|
+
import_consola.default.log(import_chalk.default.green(configurable));
|
|
157
|
+
const width = getMiddleValue(answerW);
|
|
158
|
+
const height = getMiddleValue(answerH);
|
|
159
|
+
const minWidth = Math.min(...answerW);
|
|
160
|
+
const maxWidth = Math.max(...answerW);
|
|
161
|
+
const minHeight = Math.min(...answerH);
|
|
162
|
+
const maxHeight = Math.max(...answerH);
|
|
163
|
+
const snakeCaseName = (0, import_change_case.snakeCase)(name);
|
|
164
|
+
const paramCaseName = (0, import_change_case.paramCase)(name);
|
|
165
|
+
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
166
|
+
const widgetDir = import_path.default.join(widgetFolder, paramCaseName);
|
|
167
|
+
if (!import_fs.default.existsSync(widgetDir)) {
|
|
168
|
+
import_fs.default.mkdirSync(widgetDir);
|
|
169
|
+
} else {
|
|
170
|
+
let answer = await import_inquirer2.default.prompt([{
|
|
171
|
+
type: "confirm",
|
|
172
|
+
name: "override",
|
|
173
|
+
message: import_chalk.default.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
|
|
174
|
+
}]);
|
|
175
|
+
if (!answer.override) {
|
|
176
|
+
exit();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const renderOptions = {
|
|
180
|
+
name,
|
|
181
|
+
snakeCaseName,
|
|
182
|
+
paramCaseName,
|
|
183
|
+
packageName,
|
|
184
|
+
title,
|
|
185
|
+
configurable,
|
|
186
|
+
width,
|
|
187
|
+
height,
|
|
188
|
+
maxWidth,
|
|
189
|
+
minHeight,
|
|
190
|
+
maxHeight,
|
|
191
|
+
minWidth
|
|
192
|
+
};
|
|
193
|
+
function renderToFile(templateFile, outputFile, renderOptions2) {
|
|
194
|
+
const defineTemplatePath = import_path.default.join(__dirname2, "../template", templateFile);
|
|
195
|
+
let defineTemplate = import_fs.default.readFileSync(defineTemplatePath, "utf8");
|
|
196
|
+
import_fs.default.writeFileSync(outputFile, import_ejs.default.render(defineTemplate, renderOptions2));
|
|
197
|
+
}
|
|
198
|
+
const widgetDefineFile = import_path.default.resolve(widgetDir, `${name}.widget.ts`);
|
|
199
|
+
const widgetFile = import_path.default.resolve(widgetDir, `${name}Widget.vue`);
|
|
200
|
+
const widgetViewFile = import_path.default.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
201
|
+
const widgetRoutesFile = import_path.default.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
202
|
+
renderToFile("WidgetDefine.ejs", widgetDefineFile, renderOptions);
|
|
203
|
+
renderToFile("Widget.ejs", widgetFile, renderOptions);
|
|
204
|
+
renderToFile("WidgetView.ejs", widgetViewFile, renderOptions);
|
|
205
|
+
renderToFile("WidgetRoutes.ejs", widgetRoutesFile, renderOptions);
|
|
206
|
+
if (configurable) {
|
|
207
|
+
const configFile = import_path.default.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
208
|
+
renderToFile("WidgetConfig.ejs", configFile, renderOptions);
|
|
209
|
+
}
|
|
210
|
+
if (devOptions["useStorybook"]) {
|
|
211
|
+
const storiesFile = import_path.default.resolve(widgetDir, `${name}Widget.stories.ts`);
|
|
212
|
+
renderToFile("stories.ejs", storiesFile, renderOptions);
|
|
213
|
+
}
|
|
214
|
+
const routeFile = import_path.default.join(widgetFolder, "widget-router.ts");
|
|
215
|
+
let routeContent;
|
|
216
|
+
if (import_fs.default.existsSync(routeFile)) {
|
|
217
|
+
routeContent = import_fs.default.readFileSync(routeFile, "utf8");
|
|
218
|
+
} else {
|
|
219
|
+
routeContent = import_fs.default.readFileSync(import_path.default.join(__dirname2, "../template/widget-router.ts"), "utf8");
|
|
220
|
+
}
|
|
221
|
+
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
222
|
+
const routeStr = `...${name}WidgetRoutes,`;
|
|
223
|
+
if (!routeContent.includes(importRouteStr)) {
|
|
224
|
+
routeContent = routeContent.replaceAll("//FBI WANING! IMPORT PLACE", `${importRouteStr}
|
|
225
|
+
//FBI WANING! IMPORT PLACE`);
|
|
226
|
+
}
|
|
227
|
+
if (!routeContent.includes(routeStr)) {
|
|
228
|
+
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
229
|
+
//FBI WANING! ROUTE PLACE`);
|
|
230
|
+
}
|
|
231
|
+
import_fs.default.writeFileSync(routeFile, routeContent);
|
|
232
|
+
let gitAdd = `git add ${widgetDir}`;
|
|
233
|
+
import_consola.default.info(import_chalk.default.grey(gitAdd));
|
|
234
|
+
import_shelljs.default.exec(gitAdd);
|
|
235
|
+
import_consola.default.log("=================");
|
|
236
|
+
import_consola.default.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
237
|
+
import_consola.default.success("Happy coding!");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/release/release.ts
|
|
241
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
242
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
243
|
+
|
|
244
|
+
// src/release/update-zip.ts
|
|
245
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
246
|
+
var import_archiver = __toESM(require("archiver"), 1);
|
|
247
|
+
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
248
|
+
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
249
|
+
const stream = import_fs2.default.createWriteStream(outPath);
|
|
250
|
+
return new Promise((resolve, reject) => {
|
|
251
|
+
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
252
|
+
stream.on("close", () => resolve());
|
|
253
|
+
archive.finalize();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
var update_zip_default = zipDirectory;
|
|
257
|
+
|
|
258
|
+
// 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
|
+
async function put(ossPath, file) {
|
|
278
|
+
try {
|
|
279
|
+
const result = await clinet.put(ossPath, file, { headers });
|
|
280
|
+
console.log(import_chalk2.default.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
|
|
281
|
+
} catch (e) {
|
|
282
|
+
console.log(e);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async function copy(dist, src) {
|
|
286
|
+
try {
|
|
287
|
+
const result = await clinet.copy(dist, src, { headers });
|
|
288
|
+
console.log(import_chalk2.default.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
|
|
289
|
+
} catch (e) {
|
|
290
|
+
console.error(e);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/release/release.ts
|
|
295
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
296
|
+
var release = async () => {
|
|
297
|
+
const packageJSON = JSON.parse(import_fs4.default.readFileSync("package.json", "utf-8"));
|
|
298
|
+
const changelogJSON = JSON.parse(import_fs4.default.readFileSync("changelog.json", "utf-8"));
|
|
299
|
+
const version = packageJSON["version"];
|
|
300
|
+
const changelog = changelogJSON[version];
|
|
301
|
+
let needUpdateElectron = await promptChecker_default({
|
|
302
|
+
type: "confirm",
|
|
303
|
+
name: "electron",
|
|
304
|
+
message: import_chalk3.default.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
305
|
+
});
|
|
306
|
+
const versionInfo = {
|
|
307
|
+
version,
|
|
308
|
+
releaseNote: changelog,
|
|
309
|
+
updateElectron: needUpdateElectron,
|
|
310
|
+
updateNodeModule: false,
|
|
311
|
+
updateWindowsApi: false,
|
|
312
|
+
downloadLink: ""
|
|
313
|
+
};
|
|
314
|
+
let installerPath = import_path2.default.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
315
|
+
if (!import_fs4.default.existsSync(installerPath)) {
|
|
316
|
+
installerPath = import_path2.default.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
317
|
+
}
|
|
318
|
+
const updateZipPath = import_path2.default.join(`./packaged/update.zip`);
|
|
319
|
+
console.log(import_chalk3.default.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
320
|
+
await update_zip_default("./release", updateZipPath);
|
|
321
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
322
|
+
await put("version/installer.exe", installerPath);
|
|
323
|
+
console.log(import_chalk3.default.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
324
|
+
await put("version/update.zip", updateZipPath);
|
|
325
|
+
console.log(import_chalk3.default.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
326
|
+
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
327
|
+
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
328
|
+
await put("version/version.json", Buffer.from(versionJSON));
|
|
329
|
+
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
330
|
+
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
331
|
+
console.log(import_chalk3.default.yellow(versionJSON));
|
|
332
|
+
};
|
|
333
|
+
var release_default = release;
|
|
334
|
+
|
|
335
|
+
// src/index.ts
|
|
336
|
+
var import_url2 = require("url");
|
|
337
|
+
var import_figlet = __toESM(require("figlet"), 1);
|
|
338
|
+
var import_gradient_string = __toESM(require("gradient-string"), 1);
|
|
339
|
+
var import_meta2 = {};
|
|
340
|
+
var __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
341
|
+
var __dirname = import_path3.default.dirname(__filename);
|
|
342
|
+
var packageJsonPath = import_path3.default.join(__dirname, "../package.json");
|
|
343
|
+
var cliPackage = JSON.parse(import_fs5.default.readFileSync(packageJsonPath).toString());
|
|
344
|
+
console.log(
|
|
345
|
+
import_gradient_string.default.pastel.multiline(
|
|
346
|
+
import_figlet.default.textSync("widget-cli", { horizontalLayout: "full" })
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
import_commander.program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
350
|
+
import_commander.program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
351
|
+
await createWidget();
|
|
352
|
+
});
|
|
353
|
+
import_commander.program.command("release").description("\u53D1\u5E03\u5E94\u7528\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
|
|
354
|
+
await release_default();
|
|
355
|
+
});
|
|
356
|
+
import_commander.program.parse(process2.argv);
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import fs5 from "fs";
|
|
4
|
+
import path3 from "path";
|
|
5
|
+
import * as process2 from "process";
|
|
6
|
+
|
|
7
|
+
// src/createWidget.ts
|
|
8
|
+
import path from "path";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import consola from "consola";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
|
|
13
|
+
// src/promts/promptChecker.ts
|
|
14
|
+
import inquirer from "inquirer";
|
|
15
|
+
var promptChecker = async (prompt, checker) => {
|
|
16
|
+
const answer = await inquirer.prompt([prompt]);
|
|
17
|
+
if (checker) {
|
|
18
|
+
if (checker(answer)) {
|
|
19
|
+
return answer[prompt.name];
|
|
20
|
+
} else {
|
|
21
|
+
return promptChecker(prompt, checker);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return answer[prompt.name];
|
|
25
|
+
};
|
|
26
|
+
var promptChecker_default = promptChecker;
|
|
27
|
+
|
|
28
|
+
// src/createWidget.ts
|
|
29
|
+
import { paramCase, snakeCase } from "change-case";
|
|
30
|
+
import inquirer2 from "inquirer";
|
|
31
|
+
import ejs from "ejs";
|
|
32
|
+
import shell from "shelljs";
|
|
33
|
+
|
|
34
|
+
// src/utils.ts
|
|
35
|
+
function exit(code = 0) {
|
|
36
|
+
if (exports.exitProcess) {
|
|
37
|
+
process.exit(code);
|
|
38
|
+
} else if (code > 0) {
|
|
39
|
+
throw new Error(`Process exited with code ${code}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/createWidget.ts
|
|
44
|
+
import chalk from "chalk";
|
|
45
|
+
async function createWidget() {
|
|
46
|
+
let widgetJson = path.join(process.cwd(), "widget.json");
|
|
47
|
+
if (!fs.existsSync(widgetJson)) {
|
|
48
|
+
consola.error("\u6CA1\u6709\u5728\u6839\u76EE\u5F55\u627E\u5230widget.json\u6587\u4EF6");
|
|
49
|
+
exit();
|
|
50
|
+
}
|
|
51
|
+
let widgetPackage = JSON.parse(fs.readFileSync(widgetJson).toString());
|
|
52
|
+
let widgetFolder = path.join(process.cwd(), "./src/widgets");
|
|
53
|
+
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
54
|
+
if (devOptions["folder"]) {
|
|
55
|
+
widgetFolder = devOptions["folder"];
|
|
56
|
+
consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetFolder}`);
|
|
57
|
+
} else {
|
|
58
|
+
consola.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetFolder}`);
|
|
59
|
+
}
|
|
60
|
+
if (!fs.existsSync(widgetFolder)) {
|
|
61
|
+
fs.mkdirSync(widgetFolder, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
const __filename2 = fileURLToPath(import.meta.url);
|
|
64
|
+
const __dirname2 = path.dirname(__filename2);
|
|
65
|
+
const getMiddleValue = (arr) => {
|
|
66
|
+
if (arr.length === 1) {
|
|
67
|
+
return arr[0];
|
|
68
|
+
} else if (arr.length === 2) {
|
|
69
|
+
return Math.max(...arr);
|
|
70
|
+
} else {
|
|
71
|
+
const max = Math.max(...arr);
|
|
72
|
+
const min = Math.min(...arr);
|
|
73
|
+
const sum = arr[0] + arr[1] + arr[2];
|
|
74
|
+
return sum - max - min;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
let name = await promptChecker_default({
|
|
78
|
+
type: "input",
|
|
79
|
+
name: "name",
|
|
80
|
+
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
|
|
81
|
+
}, (answer) => {
|
|
82
|
+
const name2 = answer.name;
|
|
83
|
+
if (name2 == null || name2 === "") {
|
|
84
|
+
consola.log(chalk.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
});
|
|
89
|
+
consola.log(chalk.green(name));
|
|
90
|
+
let title = await promptChecker_default({
|
|
91
|
+
type: "input",
|
|
92
|
+
name: "title",
|
|
93
|
+
message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
|
|
94
|
+
});
|
|
95
|
+
consola.log(chalk.green(title));
|
|
96
|
+
let answerW = await promptChecker_default({
|
|
97
|
+
type: "checkbox",
|
|
98
|
+
name: "w",
|
|
99
|
+
message: chalk.blue("\u8BF7\u9009\u62E9\u7EC4\u4EF6\u5BBD\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D2,4,6\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u5BBD\u4E3A2\uFF0C\u9ED8\u8BA4\u5BBD\u4E3A4\uFF0C\u6700\u5927\u5BBD\u4E3A6\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"),
|
|
100
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
101
|
+
}, (answer) => {
|
|
102
|
+
if (answer.w.length === 0) {
|
|
103
|
+
consola.log(chalk.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (answer.w.length > 3) {
|
|
107
|
+
consola.log(chalk.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
});
|
|
112
|
+
consola.log(chalk.green(answerW));
|
|
113
|
+
let answerH = await promptChecker_default({
|
|
114
|
+
type: "checkbox",
|
|
115
|
+
name: "h",
|
|
116
|
+
message: chalk.blue("\u8BF7\u9009\u62E9\u7EC4\u4EF6\u9AD8\u5EA6\uFF0C\u6700\u591A\u90093\u4E2A\uFF0C\u4F8B\u5982\u9009\u4E2D1,2\uFF0C\u4EE3\u8868\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u4E3A1\uFF0C\u9ED8\u8BA4\u9AD8\u4E3A2\uFF0C\u6700\u5927\u9AD8\u4E3A2\uFF0C\u5355\u9009\u4EE3\u8868\u4E0D\u53EF\u62C9\u4F38"),
|
|
117
|
+
choices: [1, 2, 3, 4, 5, 6]
|
|
118
|
+
}, (answer) => {
|
|
119
|
+
if (answer.h.length === 0) {
|
|
120
|
+
consola.log(chalk.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (answer.h.length > 3) {
|
|
124
|
+
consola.log(chalk.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
consola.log(chalk.green(answerH));
|
|
130
|
+
let configurable = await promptChecker_default({
|
|
131
|
+
type: "confirm",
|
|
132
|
+
name: "configurable",
|
|
133
|
+
message: chalk.blue("\u7EC4\u4EF6\u662F\u5426\u53EF\u914D\u7F6E\uFF0C\u4F8B\u5982\u4FEE\u6539\u80CC\u666F\u989C\u8272\uFF0C\u5B57\u4F53\u5927\u5C0F\u7B49")
|
|
134
|
+
});
|
|
135
|
+
consola.log(chalk.green(configurable));
|
|
136
|
+
const width = getMiddleValue(answerW);
|
|
137
|
+
const height = getMiddleValue(answerH);
|
|
138
|
+
const minWidth = Math.min(...answerW);
|
|
139
|
+
const maxWidth = Math.max(...answerW);
|
|
140
|
+
const minHeight = Math.min(...answerH);
|
|
141
|
+
const maxHeight = Math.max(...answerH);
|
|
142
|
+
const snakeCaseName = snakeCase(name);
|
|
143
|
+
const paramCaseName = paramCase(name);
|
|
144
|
+
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
145
|
+
const widgetDir = path.join(widgetFolder, paramCaseName);
|
|
146
|
+
if (!fs.existsSync(widgetDir)) {
|
|
147
|
+
fs.mkdirSync(widgetDir);
|
|
148
|
+
} else {
|
|
149
|
+
let answer = await inquirer2.prompt([{
|
|
150
|
+
type: "confirm",
|
|
151
|
+
name: "override",
|
|
152
|
+
message: chalk.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
|
|
153
|
+
}]);
|
|
154
|
+
if (!answer.override) {
|
|
155
|
+
exit();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const renderOptions = {
|
|
159
|
+
name,
|
|
160
|
+
snakeCaseName,
|
|
161
|
+
paramCaseName,
|
|
162
|
+
packageName,
|
|
163
|
+
title,
|
|
164
|
+
configurable,
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
maxWidth,
|
|
168
|
+
minHeight,
|
|
169
|
+
maxHeight,
|
|
170
|
+
minWidth
|
|
171
|
+
};
|
|
172
|
+
function renderToFile(templateFile, outputFile, renderOptions2) {
|
|
173
|
+
const defineTemplatePath = path.join(__dirname2, "../template", templateFile);
|
|
174
|
+
let defineTemplate = fs.readFileSync(defineTemplatePath, "utf8");
|
|
175
|
+
fs.writeFileSync(outputFile, ejs.render(defineTemplate, renderOptions2));
|
|
176
|
+
}
|
|
177
|
+
const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`);
|
|
178
|
+
const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
|
|
179
|
+
const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
|
|
180
|
+
const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
|
|
181
|
+
renderToFile("WidgetDefine.ejs", widgetDefineFile, renderOptions);
|
|
182
|
+
renderToFile("Widget.ejs", widgetFile, renderOptions);
|
|
183
|
+
renderToFile("WidgetView.ejs", widgetViewFile, renderOptions);
|
|
184
|
+
renderToFile("WidgetRoutes.ejs", widgetRoutesFile, renderOptions);
|
|
185
|
+
if (configurable) {
|
|
186
|
+
const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`);
|
|
187
|
+
renderToFile("WidgetConfig.ejs", configFile, renderOptions);
|
|
188
|
+
}
|
|
189
|
+
if (devOptions["useStorybook"]) {
|
|
190
|
+
const storiesFile = path.resolve(widgetDir, `${name}Widget.stories.ts`);
|
|
191
|
+
renderToFile("stories.ejs", storiesFile, renderOptions);
|
|
192
|
+
}
|
|
193
|
+
const routeFile = path.join(widgetFolder, "widget-router.ts");
|
|
194
|
+
let routeContent;
|
|
195
|
+
if (fs.existsSync(routeFile)) {
|
|
196
|
+
routeContent = fs.readFileSync(routeFile, "utf8");
|
|
197
|
+
} else {
|
|
198
|
+
routeContent = fs.readFileSync(path.join(__dirname2, "../template/widget-router.ts"), "utf8");
|
|
199
|
+
}
|
|
200
|
+
const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
|
|
201
|
+
const routeStr = `...${name}WidgetRoutes,`;
|
|
202
|
+
if (!routeContent.includes(importRouteStr)) {
|
|
203
|
+
routeContent = routeContent.replaceAll("//FBI WANING! IMPORT PLACE", `${importRouteStr}
|
|
204
|
+
//FBI WANING! IMPORT PLACE`);
|
|
205
|
+
}
|
|
206
|
+
if (!routeContent.includes(routeStr)) {
|
|
207
|
+
routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
|
|
208
|
+
//FBI WANING! ROUTE PLACE`);
|
|
209
|
+
}
|
|
210
|
+
fs.writeFileSync(routeFile, routeContent);
|
|
211
|
+
let gitAdd = `git add ${widgetDir}`;
|
|
212
|
+
consola.info(chalk.grey(gitAdd));
|
|
213
|
+
shell.exec(gitAdd);
|
|
214
|
+
consola.log("=================");
|
|
215
|
+
consola.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
|
|
216
|
+
consola.success("Happy coding!");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/release/release.ts
|
|
220
|
+
import fs4 from "fs";
|
|
221
|
+
import path2 from "path";
|
|
222
|
+
|
|
223
|
+
// src/release/update-zip.ts
|
|
224
|
+
import fs2 from "fs";
|
|
225
|
+
import archiver from "archiver";
|
|
226
|
+
function zipDirectory(sourceDir, outPath, ignoreDir) {
|
|
227
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
228
|
+
const stream = fs2.createWriteStream(outPath);
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
archive.glob("**/*", { cwd: sourceDir, ignore: ["node_modules/**"] }).on("error", (err) => reject(err)).pipe(stream);
|
|
231
|
+
stream.on("close", () => resolve());
|
|
232
|
+
archive.finalize();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
var update_zip_default = zipDirectory;
|
|
236
|
+
|
|
237
|
+
// src/release/oss.ts
|
|
238
|
+
import OSS from "ali-oss";
|
|
239
|
+
import fs3 from "fs";
|
|
240
|
+
import chalk2 from "chalk";
|
|
241
|
+
var packageData = JSON.parse(fs3.readFileSync("./package.json").toString());
|
|
242
|
+
var AccessKeyID = packageData.oss?.id ?? "default";
|
|
243
|
+
var AccessKeySecret = packageData.oss?.secret ?? "default";
|
|
244
|
+
var headers = {
|
|
245
|
+
"x-oss-storage-class": "Standard",
|
|
246
|
+
"x-oss-object-acl": "public-read",
|
|
247
|
+
"x-oss-forbid-overwrite": "false",
|
|
248
|
+
"Cache-Control": "no-cache"
|
|
249
|
+
};
|
|
250
|
+
var clinet = new OSS({
|
|
251
|
+
region: "oss-cn-hangzhou",
|
|
252
|
+
accessKeyId: AccessKeyID,
|
|
253
|
+
accessKeySecret: AccessKeySecret,
|
|
254
|
+
bucket: "widget-fun"
|
|
255
|
+
});
|
|
256
|
+
async function put(ossPath, file) {
|
|
257
|
+
try {
|
|
258
|
+
const result = await clinet.put(ossPath, file, { headers });
|
|
259
|
+
console.log(chalk2.green(`\u4E0A\u4F20\u6210\u529F\uFF1A${file}->${ossPath}`));
|
|
260
|
+
} catch (e) {
|
|
261
|
+
console.log(e);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function copy(dist, src) {
|
|
265
|
+
try {
|
|
266
|
+
const result = await clinet.copy(dist, src, { headers });
|
|
267
|
+
console.log(chalk2.green(`\u590D\u5236\u6210\u529F\uFF1A${src}->${dist}`));
|
|
268
|
+
} catch (e) {
|
|
269
|
+
console.error(e);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/release/release.ts
|
|
274
|
+
import chalk3 from "chalk";
|
|
275
|
+
var release = async () => {
|
|
276
|
+
const packageJSON = JSON.parse(fs4.readFileSync("package.json", "utf-8"));
|
|
277
|
+
const changelogJSON = JSON.parse(fs4.readFileSync("changelog.json", "utf-8"));
|
|
278
|
+
const version = packageJSON["version"];
|
|
279
|
+
const changelog = changelogJSON[version];
|
|
280
|
+
let needUpdateElectron = await promptChecker_default({
|
|
281
|
+
type: "confirm",
|
|
282
|
+
name: "electron",
|
|
283
|
+
message: chalk3.blue("\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u65B0Electron?")
|
|
284
|
+
});
|
|
285
|
+
const versionInfo = {
|
|
286
|
+
version,
|
|
287
|
+
releaseNote: changelog,
|
|
288
|
+
updateElectron: needUpdateElectron,
|
|
289
|
+
updateNodeModule: false,
|
|
290
|
+
updateWindowsApi: false,
|
|
291
|
+
downloadLink: ""
|
|
292
|
+
};
|
|
293
|
+
let installerPath = path2.join(`./packaged/widgets-${version}-setup-win-x64.exe`);
|
|
294
|
+
if (!fs4.existsSync(installerPath)) {
|
|
295
|
+
installerPath = path2.join(`./packaged/electron-${version}-setup-win-x64.exe`);
|
|
296
|
+
}
|
|
297
|
+
const updateZipPath = path2.join(`./packaged/update.zip`);
|
|
298
|
+
console.log(chalk3.blue("\u538B\u7F29\u66F4\u65B0\u6587\u4EF6\u4E2D"));
|
|
299
|
+
await update_zip_default("./release", updateZipPath);
|
|
300
|
+
console.log(chalk3.blue("\u4E0A\u4F20installer.exe\u5230OSS"));
|
|
301
|
+
await put("version/installer.exe", installerPath);
|
|
302
|
+
console.log(chalk3.blue("\u4E0A\u4F20update.zip\u5230OSS"));
|
|
303
|
+
await put("version/update.zip", updateZipPath);
|
|
304
|
+
console.log(chalk3.blue("\u66F4\u65B0\u7248\u672C\u4FE1\u606F"));
|
|
305
|
+
versionInfo.downloadLink = "https://widget-fun.oss-cn-hangzhou.aliyuncs.com/version/update.zip";
|
|
306
|
+
const versionJSON = JSON.stringify(versionInfo, null, 2);
|
|
307
|
+
await put("version/version.json", Buffer.from(versionJSON));
|
|
308
|
+
copy(`version/history/${version}.exe`, "version/installer.exe");
|
|
309
|
+
copy(`version/history/update-${version}.zip`, "version/update.zip");
|
|
310
|
+
console.log(chalk3.yellow(versionJSON));
|
|
311
|
+
};
|
|
312
|
+
var release_default = release;
|
|
313
|
+
|
|
314
|
+
// src/index.ts
|
|
315
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
316
|
+
import figlet from "figlet";
|
|
317
|
+
import gradient from "gradient-string";
|
|
318
|
+
var __filename = fileURLToPath2(import.meta.url);
|
|
319
|
+
var __dirname = path3.dirname(__filename);
|
|
320
|
+
var packageJsonPath = path3.join(__dirname, "../package.json");
|
|
321
|
+
var cliPackage = JSON.parse(fs5.readFileSync(packageJsonPath).toString());
|
|
322
|
+
console.log(
|
|
323
|
+
gradient.pastel.multiline(
|
|
324
|
+
figlet.textSync("widget-cli", { horizontalLayout: "full" })
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
|
|
328
|
+
program.command("create").description("\u521B\u5EFA\u65B0\u7684\u7EC4\u4EF6").action(async () => {
|
|
329
|
+
await createWidget();
|
|
330
|
+
});
|
|
331
|
+
program.command("release").description("\u53D1\u5E03\u5E94\u7528\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").action(async () => {
|
|
332
|
+
await release_default();
|
|
333
|
+
});
|
|
334
|
+
program.parse(process2.argv);
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widget-js/cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
5
|
"author": "Neo Fu",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
8
|
"bin": {
|
|
9
|
-
"widget": "
|
|
9
|
+
"widget": "lib/index.js"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup src/index.ts --dts --format esm,cjs ",
|
|
14
|
+
"build:run": "npm run build && npm run widget",
|
|
15
|
+
"widget": "node ./lib/index.js"
|
|
16
|
+
},
|
|
12
17
|
"publishConfig": {
|
|
13
18
|
"access": "public"
|
|
14
19
|
},
|
|
@@ -16,6 +21,8 @@
|
|
|
16
21
|
"node": "^12.0.0 || >= 14.0.0"
|
|
17
22
|
},
|
|
18
23
|
"dependencies": {
|
|
24
|
+
"@types/archiver": "^5.3.1",
|
|
25
|
+
"@types/gradient-string": "^1.1.2",
|
|
19
26
|
"@vue/cli-shared-utils": "^5.0.8",
|
|
20
27
|
"@widget-js/core": "^0.1.14",
|
|
21
28
|
"ali-oss": "^6.17.1",
|
|
@@ -25,6 +32,8 @@
|
|
|
25
32
|
"commander": "^9.4.1",
|
|
26
33
|
"consola": "^2.15.3",
|
|
27
34
|
"ejs": "^3.1.8",
|
|
35
|
+
"figlet": "^1.5.2",
|
|
36
|
+
"gradient-string": "^2.0.2",
|
|
28
37
|
"inquirer": "^9.1.4",
|
|
29
38
|
"shelljs": "^0.8.5",
|
|
30
39
|
"ws": "^8.11.0"
|
|
@@ -34,7 +43,9 @@
|
|
|
34
43
|
"@babel/core": "^7.20.2",
|
|
35
44
|
"@babel/node": "^7.20.2",
|
|
36
45
|
"@babel/preset-env": "^7.20.2",
|
|
46
|
+
"@types/ali-oss": "^6.16.7",
|
|
37
47
|
"@types/ejs": "latest",
|
|
48
|
+
"@types/figlet": "^1.5.5",
|
|
38
49
|
"@types/inquirer": "latest",
|
|
39
50
|
"@types/jest": "^29.2.3",
|
|
40
51
|
"@types/node": "^18.11.13",
|
|
@@ -42,16 +53,10 @@
|
|
|
42
53
|
"pinst": "^3.0.0",
|
|
43
54
|
"ts-jest": "^29.0.3",
|
|
44
55
|
"ts-loader": "^9.4.1",
|
|
45
|
-
"
|
|
56
|
+
"ts-node": "^10.9.1",
|
|
57
|
+
"tsup": "^6.5.0",
|
|
58
|
+
"typescript": "^4.9.4",
|
|
46
59
|
"webpack": "^5.75.0",
|
|
47
60
|
"webpack-cli": "^5.0.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"widget": "node ./bin/widget.js",
|
|
51
|
-
"build": "npm run build:esm && npm run build:types && npm run build:cjs && npm run build:umd",
|
|
52
|
-
"build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json",
|
|
53
|
-
"build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
|
|
54
|
-
"build:umd": "node tools/cleanup umd && webpack --config config/webpack.config.js",
|
|
55
|
-
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json"
|
|
56
61
|
}
|
|
57
|
-
}
|
|
62
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import consola from "consola";
|
|
4
|
-
import {exit, exitProcess} from "@vue/cli-shared-utils/lib/exit.js";
|
|
5
4
|
import {fileURLToPath} from "url";
|
|
6
|
-
import promptChecker from "./promts/promptChecker
|
|
7
|
-
import {chalk} from "@vue/cli-shared-utils";
|
|
5
|
+
import promptChecker from "./promts/promptChecker";
|
|
8
6
|
import {paramCase, snakeCase} from "change-case";
|
|
9
7
|
import inquirer from "inquirer";
|
|
10
8
|
import ejs from "ejs";
|
|
11
9
|
import shell from "shelljs";
|
|
12
|
-
|
|
10
|
+
import exit from "./utils.js";
|
|
11
|
+
import chalk from "chalk";
|
|
12
|
+
interface RenderOptions {
|
|
13
|
+
name: string,
|
|
14
|
+
snakeCaseName: string,
|
|
15
|
+
paramCaseName: string,
|
|
16
|
+
packageName: string,
|
|
17
|
+
title: string,
|
|
18
|
+
configurable: string,
|
|
19
|
+
width: number,
|
|
20
|
+
height: number,
|
|
21
|
+
maxWidth: number,
|
|
22
|
+
minHeight: number,
|
|
23
|
+
maxHeight: number,
|
|
24
|
+
minWidth: number
|
|
25
|
+
}
|
|
13
26
|
export default async function createWidget() {
|
|
14
27
|
let widgetJson = path.join(process.cwd(), "widget.json");
|
|
15
28
|
if (!fs.existsSync(widgetJson)) {
|
|
@@ -17,7 +30,7 @@ export default async function createWidget() {
|
|
|
17
30
|
exit();
|
|
18
31
|
}
|
|
19
32
|
|
|
20
|
-
let widgetPackage = JSON.parse(fs.readFileSync(widgetJson));
|
|
33
|
+
let widgetPackage = JSON.parse(fs.readFileSync(widgetJson).toString());
|
|
21
34
|
|
|
22
35
|
let widgetFolder = path.join(process.cwd(), "./src/widgets");
|
|
23
36
|
let devOptions = widgetPackage["devOptions"] ?? {};
|
|
@@ -35,22 +48,14 @@ export default async function createWidget() {
|
|
|
35
48
|
const __filename = fileURLToPath(import.meta.url);
|
|
36
49
|
const __dirname = path.dirname(__filename);
|
|
37
50
|
|
|
38
|
-
|
|
39
|
-
return Math.max.apply(null, this);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
Array.prototype.min = function () {
|
|
43
|
-
return Math.min.apply(null, this);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const getMiddleValue = (arr) => {
|
|
51
|
+
const getMiddleValue = (arr:number[]) => {
|
|
47
52
|
if (arr.length === 1) {
|
|
48
53
|
return arr[0];
|
|
49
54
|
} else if (arr.length === 2) {
|
|
50
|
-
return
|
|
55
|
+
return Math.max(...arr);
|
|
51
56
|
} else {
|
|
52
|
-
const max =
|
|
53
|
-
const min =
|
|
57
|
+
const max = Math.max(...arr);
|
|
58
|
+
const min = Math.min(...arr);
|
|
54
59
|
const sum = arr[0] + arr[1] + arr[2];
|
|
55
60
|
return sum - max - min;
|
|
56
61
|
}
|
|
@@ -77,7 +82,6 @@ export default async function createWidget() {
|
|
|
77
82
|
message: chalk.blue("请输入组件标题,如:倒计时")
|
|
78
83
|
})
|
|
79
84
|
consola.log(chalk.green(title))
|
|
80
|
-
|
|
81
85
|
let answerW = await promptChecker({
|
|
82
86
|
type: "checkbox",
|
|
83
87
|
name: 'w',
|
|
@@ -127,10 +131,10 @@ export default async function createWidget() {
|
|
|
127
131
|
|
|
128
132
|
const width = getMiddleValue(answerW);
|
|
129
133
|
const height = getMiddleValue(answerH);
|
|
130
|
-
const minWidth =
|
|
131
|
-
const maxWidth =
|
|
132
|
-
const minHeight =
|
|
133
|
-
const maxHeight =
|
|
134
|
+
const minWidth = Math.min(...answerW);
|
|
135
|
+
const maxWidth = Math.max(...answerW);
|
|
136
|
+
const minHeight = Math.min(...answerH);
|
|
137
|
+
const maxHeight = Math.max(...answerH);
|
|
134
138
|
const snakeCaseName = snakeCase(name);
|
|
135
139
|
const paramCaseName = paramCase(name);
|
|
136
140
|
const packageName = "com.wisdom.widgets." + snakeCaseName;
|
|
@@ -145,11 +149,11 @@ export default async function createWidget() {
|
|
|
145
149
|
message: chalk.red('组件名已存在,是否继续?')
|
|
146
150
|
}])
|
|
147
151
|
if (!answer.override) {
|
|
148
|
-
|
|
152
|
+
exit()
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
|
|
152
|
-
const renderOptions = {
|
|
156
|
+
const renderOptions:RenderOptions = {
|
|
153
157
|
name: name,
|
|
154
158
|
snakeCaseName: snakeCaseName,
|
|
155
159
|
paramCaseName: paramCaseName,
|
|
@@ -164,7 +168,7 @@ export default async function createWidget() {
|
|
|
164
168
|
minWidth: minWidth
|
|
165
169
|
}
|
|
166
170
|
|
|
167
|
-
function renderToFile(templateFile, outputFile, renderOptions) {
|
|
171
|
+
function renderToFile(templateFile:string, outputFile:string, renderOptions:RenderOptions) {
|
|
168
172
|
const defineTemplatePath = path.join(__dirname, '../template', templateFile)
|
|
169
173
|
let defineTemplate = fs.readFileSync(defineTemplatePath, 'utf8');
|
|
170
174
|
fs.writeFileSync(outputFile, ejs.render(defineTemplate, renderOptions))
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import {program} from 'commander';
|
|
2
|
-
import createWidget from "../lib/createWidget.js";
|
|
3
|
-
import release from "../lib/release/release.js";
|
|
4
2
|
import fs from "fs";
|
|
5
3
|
import path from "path";
|
|
6
|
-
import
|
|
4
|
+
import * as process from "process";
|
|
5
|
+
import createWidget from "./createWidget";
|
|
6
|
+
import release from './release/release'
|
|
7
|
+
|
|
8
|
+
import {fileURLToPath} from 'url';
|
|
9
|
+
import figlet from 'figlet';
|
|
10
|
+
import gradient from "gradient-string";
|
|
11
|
+
|
|
7
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
13
|
const __dirname = path.dirname(__filename);
|
|
9
|
-
|
|
14
|
+
//
|
|
10
15
|
const packageJsonPath = path.join(__dirname, '../package.json');
|
|
11
16
|
let cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
|
12
17
|
|
|
18
|
+
console.log(
|
|
19
|
+
gradient.pastel.multiline(
|
|
20
|
+
figlet.textSync('widget-cli', { horizontalLayout: 'full' })
|
|
21
|
+
)
|
|
22
|
+
);
|
|
13
23
|
program
|
|
14
24
|
.version(`@widget-js/cli ${cliPackage.version}`)
|
|
15
25
|
.usage('<command> [options]')
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import inquirer, {Answers, Question} from "inquirer";
|
|
2
|
+
|
|
3
|
+
const promptChecker = async <T extends Question>(prompt:T, checker?:(answer:any)=>boolean):Promise<any> => {
|
|
4
|
+
const answer:Answers = await inquirer.prompt([prompt]);
|
|
5
|
+
if (checker) {
|
|
6
|
+
if (checker(answer)) {
|
|
7
|
+
return answer[prompt.name!];
|
|
8
|
+
} else {
|
|
9
|
+
return promptChecker(prompt, checker);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return answer[prompt.name!];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default promptChecker;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import OSS from "ali-oss";
|
|
2
|
-
import {chalk} from "@vue/cli-shared-utils";
|
|
3
2
|
import fs from "fs";
|
|
3
|
+
import chalk from "chalk";
|
|
4
4
|
|
|
5
5
|
let packageData = JSON.parse(fs.readFileSync("./package.json").toString());
|
|
6
6
|
export const AccessKeyID = packageData.oss?.id ?? "default";
|
|
@@ -24,7 +24,7 @@ const clinet = new OSS({
|
|
|
24
24
|
bucket: 'widget-fun',
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
export async function put(ossPath, file) {
|
|
27
|
+
export async function put(ossPath:string, file:any) {
|
|
28
28
|
try {
|
|
29
29
|
// 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
|
|
30
30
|
// 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
|
|
@@ -35,7 +35,7 @@ export async function put(ossPath, file) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export async function copy(dist, src) {
|
|
38
|
+
export async function copy(dist:string, src:string) {
|
|
39
39
|
try {
|
|
40
40
|
// 填写OSS文件完整路径和本地文件的完整路径。OSS文件完整路径中不能包含Bucket名称。
|
|
41
41
|
// 如果本地文件的完整路径中未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {chalk} from "@vue/cli-shared-utils";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import promptChecker from "../promts/promptChecker.js";
|
|
5
4
|
import zipDirectory from "./update-zip.js";
|
|
6
5
|
import {copy, put} from "./oss.js";
|
|
6
|
+
import chalk from "chalk";
|
|
7
7
|
|
|
8
|
-
async function delay(time) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
8
|
+
async function delay(time:number) {
|
|
9
|
+
return new Promise<void>((resolve, reject) => {
|
|
10
10
|
setTimeout(() => {
|
|
11
11
|
resolve();
|
|
12
12
|
}, time);
|
|
@@ -24,18 +24,18 @@ const release = async () => {
|
|
|
24
24
|
name: 'electron',
|
|
25
25
|
message: chalk.blue("用户是否需要更新Electron?")
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
let needUpdateNodeModule = await promptChecker({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
27
|
+
//
|
|
28
|
+
// let needUpdateNodeModule = await promptChecker({
|
|
29
|
+
// type: "confirm",
|
|
30
|
+
// name: 'electron',
|
|
31
|
+
// message: chalk.blue("用户是否需要更新node_module?")
|
|
32
|
+
// });
|
|
33
33
|
|
|
34
34
|
const versionInfo = {
|
|
35
35
|
version: version,
|
|
36
36
|
releaseNote: changelog,
|
|
37
37
|
updateElectron: needUpdateElectron,
|
|
38
|
-
updateNodeModule:
|
|
38
|
+
updateNodeModule: false,
|
|
39
39
|
updateWindowsApi: false,
|
|
40
40
|
downloadLink: ''
|
|
41
41
|
};
|
|
@@ -47,11 +47,7 @@ const release = async () => {
|
|
|
47
47
|
const updateZipPath = path.join(`./packaged/update.zip`)
|
|
48
48
|
|
|
49
49
|
console.log(chalk.blue("压缩更新文件中"))
|
|
50
|
-
|
|
51
|
-
await zipDirectory("packaged/win-unpacked/resources/app", updateZipPath);
|
|
52
|
-
} else {
|
|
53
|
-
await zipDirectory("release", updateZipPath);
|
|
54
|
-
}
|
|
50
|
+
await zipDirectory("./release", updateZipPath);
|
|
55
51
|
|
|
56
52
|
console.log(chalk.blue("上传installer.exe到OSS"))
|
|
57
53
|
await put("version/installer.exe", installerPath)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import archiver from "archiver";
|
|
3
|
+
|
|
4
|
+
function zipDirectory(sourceDir:string, outPath:string, ignoreDir?:string[]) {
|
|
5
|
+
const archive = archiver('zip', {zlib: {level: 9}});
|
|
6
|
+
const stream = fs.createWriteStream(outPath);
|
|
7
|
+
|
|
8
|
+
return new Promise<void>((resolve, reject) => {
|
|
9
|
+
archive
|
|
10
|
+
.glob("**/*", {cwd: sourceDir, ignore: ['node_modules/**']})
|
|
11
|
+
.on('error', err => reject(err))
|
|
12
|
+
.pipe(stream);
|
|
13
|
+
|
|
14
|
+
stream.on('close', () => resolve());
|
|
15
|
+
archive.finalize();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default zipDirectory;
|
package/src/utils.ts
ADDED
|
@@ -18,14 +18,24 @@ const <%= name %>WidgetDefine = new Widget({
|
|
|
18
18
|
description: description,
|
|
19
19
|
keywords: keywords,
|
|
20
20
|
lang: "zh",
|
|
21
|
-
url: url,
|
|
22
|
-
configUrl: configUrl,
|
|
23
21
|
width: <%= width %>,
|
|
24
22
|
height: <%= height %>,
|
|
25
23
|
minWidth: <%= minWidth %>,
|
|
26
24
|
maxWidth: <%= maxWidth %>,
|
|
27
25
|
minHeight: <%= minHeight %>,
|
|
28
|
-
maxHeight: <%= maxHeight
|
|
26
|
+
maxHeight: <%= maxHeight %>,
|
|
27
|
+
routes: [
|
|
28
|
+
{
|
|
29
|
+
url: url,
|
|
30
|
+
name: 'index'
|
|
31
|
+
},
|
|
32
|
+
<% if (configurable) { %>
|
|
33
|
+
{
|
|
34
|
+
url: configUrl,
|
|
35
|
+
name: 'config'
|
|
36
|
+
},
|
|
37
|
+
<% } %>
|
|
38
|
+
]
|
|
29
39
|
})
|
|
30
40
|
|
|
31
41
|
export default <%= name %>WidgetDefine;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import <%= name %>WidgetDefine from "./<%= name %>.widget";
|
|
2
2
|
|
|
3
|
-
const url = <%= name %>WidgetDefine.url;
|
|
3
|
+
const url = <%= name %>WidgetDefine.getIndexRoute().url;
|
|
4
4
|
const name = <%= name %>WidgetDefine.name;
|
|
5
5
|
<% if (configurable) { %>
|
|
6
|
-
const configUrl = <%= name %>WidgetDefine.
|
|
6
|
+
const configUrl = <%= name %>WidgetDefine.getConfigRoute()!.url;
|
|
7
7
|
|
|
8
8
|
const <%= name %>WidgetRoutes = [
|
|
9
9
|
{
|
package/tsconfig.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/* Basic Options */
|
|
6
6
|
// "incremental": true, /* Enable incremental compilation */
|
|
7
7
|
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
8
|
-
|
|
8
|
+
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
9
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
10
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
11
|
// "checkJs": true, /* Report errors in .js files. */
|
|
@@ -68,6 +68,10 @@
|
|
|
68
68
|
|
|
69
69
|
/* Skip type checking of declaration files. */
|
|
70
70
|
"skipLibCheck": true,
|
|
71
|
+
"types": ["node"],
|
|
72
|
+
"rootDir": "src",
|
|
73
|
+
"outDir": "lib",
|
|
74
|
+
"lib": ["esnext"],
|
|
71
75
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
72
76
|
},
|
|
73
77
|
"include": ["src/**/*"],
|
package/tsup.config.ts
ADDED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import inquirer from "inquirer";
|
|
2
|
-
|
|
3
|
-
const promptChecker = async (prompt, checker) => {
|
|
4
|
-
let answer = await inquirer.prompt([prompt]);
|
|
5
|
-
if (checker) {
|
|
6
|
-
if (checker(answer)) {
|
|
7
|
-
return answer[prompt.name];
|
|
8
|
-
} else {
|
|
9
|
-
return promptChecker(prompt, checker);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return answer[prompt.name];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default promptChecker;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import archiver from "archiver";
|
|
3
|
-
|
|
4
|
-
function zipDirectory(sourceDir, outPath) {
|
|
5
|
-
const archive = archiver('zip', { zlib: { level: 9 }});
|
|
6
|
-
const stream = fs.createWriteStream(outPath);
|
|
7
|
-
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
archive
|
|
10
|
-
.directory(sourceDir, false)
|
|
11
|
-
.on('error', err => reject(err))
|
|
12
|
-
.pipe(stream)
|
|
13
|
-
;
|
|
14
|
-
|
|
15
|
-
stream.on('close', () => resolve());
|
|
16
|
-
archive.finalize();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export default zipDirectory;
|
package/tools/cleanup.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const Path = require('path')
|
|
4
|
-
/* eslint-enable */
|
|
5
|
-
|
|
6
|
-
const deleteFolderRecursive = (path) => {
|
|
7
|
-
if (fs.existsSync(path)) {
|
|
8
|
-
fs.readdirSync(path).forEach((file) => {
|
|
9
|
-
const curPath = Path.join(path, file)
|
|
10
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
|
11
|
-
deleteFolderRecursive(curPath)
|
|
12
|
-
} else {
|
|
13
|
-
fs.unlinkSync(curPath)
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
fs.rmdirSync(path)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const folder = process.argv.slice(2)[0]
|
|
21
|
-
|
|
22
|
-
if (folder) {
|
|
23
|
-
deleteFolderRecursive(Path.join(__dirname, '../dist', folder))
|
|
24
|
-
} else {
|
|
25
|
-
deleteFolderRecursive(Path.join(__dirname, '../dist/cjs'))
|
|
26
|
-
deleteFolderRecursive(Path.join(__dirname, '../dist/esm'))
|
|
27
|
-
deleteFolderRecursive(Path.join(__dirname, '../dist/umd'))
|
|
28
|
-
deleteFolderRecursive(Path.join(__dirname, '../dist/types'))
|
|
29
|
-
}
|
package/tools/packagejson.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const Path = require('path')
|
|
4
|
-
const fileName = '../package.json'
|
|
5
|
-
const file = require(fileName)
|
|
6
|
-
/* eslint-enable */
|
|
7
|
-
|
|
8
|
-
const args = process.argv.slice(2)
|
|
9
|
-
|
|
10
|
-
for (let i = 0, l = args.length; i < l; i++) {
|
|
11
|
-
if (i % 2 === 0) {
|
|
12
|
-
file[args[i]] = args[i + 1]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
fs.writeFile(
|
|
17
|
-
Path.join(__dirname, fileName),
|
|
18
|
-
JSON.stringify(file, null, 2),
|
|
19
|
-
(err) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
return console.log(err)
|
|
22
|
-
}
|
|
23
|
-
console.log('Writing to ' + fileName)
|
|
24
|
-
}
|
|
25
|
-
)
|