@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.
@@ -0,0 +1,58 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <HTMLCodeStyleSettings>
4
+ <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
+ <option name="HTML_ENFORCE_QUOTES" value="true" />
6
+ </HTMLCodeStyleSettings>
7
+ <JSCodeStyleSettings version="0">
8
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
9
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
10
+ <option name="FORCE_QUOTE_STYlE" value="true" />
11
+ <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
12
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
13
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
14
+ </JSCodeStyleSettings>
15
+ <TypeScriptCodeStyleSettings version="0">
16
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
17
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
18
+ <option name="FORCE_QUOTE_STYlE" value="true" />
19
+ <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
20
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
21
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
22
+ </TypeScriptCodeStyleSettings>
23
+ <VueCodeStyleSettings>
24
+ <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
25
+ <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
26
+ </VueCodeStyleSettings>
27
+ <codeStyleSettings language="HTML">
28
+ <option name="SOFT_MARGINS" value="80" />
29
+ <indentOptions>
30
+ <option name="INDENT_SIZE" value="2" />
31
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
32
+ <option name="TAB_SIZE" value="2" />
33
+ </indentOptions>
34
+ </codeStyleSettings>
35
+ <codeStyleSettings language="JavaScript">
36
+ <option name="SOFT_MARGINS" value="80" />
37
+ <indentOptions>
38
+ <option name="INDENT_SIZE" value="2" />
39
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
40
+ <option name="TAB_SIZE" value="2" />
41
+ </indentOptions>
42
+ </codeStyleSettings>
43
+ <codeStyleSettings language="TypeScript">
44
+ <option name="SOFT_MARGINS" value="80" />
45
+ <indentOptions>
46
+ <option name="INDENT_SIZE" value="2" />
47
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
48
+ <option name="TAB_SIZE" value="2" />
49
+ </indentOptions>
50
+ </codeStyleSettings>
51
+ <codeStyleSettings language="Vue">
52
+ <option name="SOFT_MARGINS" value="80" />
53
+ <indentOptions>
54
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
55
+ </indentOptions>
56
+ </codeStyleSettings>
57
+ </code_scheme>
58
+ </component>
@@ -1,5 +1,5 @@
1
1
  <component name="ProjectCodeStyleConfiguration">
2
2
  <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
4
  </state>
5
5
  </component>
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
4
+ <mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
5
5
  </component>
6
6
  </project>
@@ -0,0 +1,31 @@
1
+ // src/build/build.ts
2
+ import ora from "ora";
3
+ import { exec } from "child_process";
4
+ import consola from "consola";
5
+ function build() {
6
+ const preloadSpinner = ora("Preload").start();
7
+ const mainSpinner = ora("Main").start();
8
+ const build2 = exec("npm run build:preload").on("close", () => {
9
+ consola.success("done");
10
+ });
11
+ build2.stdout.on("data", (data) => {
12
+ consola.log("data", data);
13
+ });
14
+ exec("npm run build:main", (error, stdout, stderr) => {
15
+ if (error) {
16
+ consola.error("error: " + error);
17
+ return;
18
+ }
19
+ consola.log("stdout: " + stdout);
20
+ consola.log("stderr: " + typeof stderr);
21
+ }).on("message", () => {
22
+ consola.log("on-message");
23
+ }).on("data", () => {
24
+ consola.log("on-data");
25
+ }).on("close", () => {
26
+ consola.log("done");
27
+ });
28
+ }
29
+ export {
30
+ build
31
+ };
@@ -0,0 +1,18 @@
1
+ // src/promts/promptChecker.ts
2
+ import inquirer from "inquirer";
3
+ var promptChecker = async (prompt, checker) => {
4
+ const 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
+ var promptChecker_default = promptChecker;
15
+
16
+ export {
17
+ promptChecker_default
18
+ };
@@ -0,0 +1,27 @@
1
+ // src/utils.ts
2
+ import path from "path";
3
+ import process from "process";
4
+ import fs from "fs";
5
+ function exit(code = 0) {
6
+ if (exports.exitProcess) {
7
+ process.exit(code);
8
+ } else if (code > 0) {
9
+ throw new Error(`Process exited with code ${code}`);
10
+ }
11
+ }
12
+ function getPackagePath() {
13
+ return path.join(process.cwd(), "package.json");
14
+ }
15
+ function getPackageJson() {
16
+ return JSON.parse(fs.readFileSync(getPackagePath()).toString());
17
+ }
18
+ function getPackageVersion() {
19
+ return getPackageJson()["version"];
20
+ }
21
+
22
+ export {
23
+ exit,
24
+ getPackagePath,
25
+ getPackageJson,
26
+ getPackageVersion
27
+ };
@@ -0,0 +1,193 @@
1
+ import {
2
+ promptChecker_default
3
+ } from "./chunk-3GPAHQ6O.js";
4
+ import {
5
+ exit
6
+ } from "./chunk-SIAOIY3B.js";
7
+
8
+ // src/createWidget.ts
9
+ import path from "path";
10
+ import fs from "fs";
11
+ import consola from "consola";
12
+ import { fileURLToPath } from "url";
13
+ import { paramCase, snakeCase } from "change-case";
14
+ import inquirer from "inquirer";
15
+ import ejs from "ejs";
16
+ import shell from "shelljs";
17
+ import chalk from "chalk";
18
+ async function createWidget() {
19
+ let widgetJson = path.join(process.cwd(), "widget.json");
20
+ if (!fs.existsSync(widgetJson)) {
21
+ consola.error("\u6CA1\u6709\u5728\u6839\u76EE\u5F55\u627E\u5230widget.json\u6587\u4EF6");
22
+ exit();
23
+ }
24
+ let widgetPackage = JSON.parse(fs.readFileSync(widgetJson).toString());
25
+ let widgetFolder = path.join(process.cwd(), "./src/widgets");
26
+ let devOptions = widgetPackage["devOptions"] ?? {};
27
+ if (devOptions["folder"]) {
28
+ widgetFolder = devOptions["folder"];
29
+ consola.info(`\u7EC4\u4EF6\u8DEF\u5F84\uFF1A${widgetFolder}`);
30
+ } else {
31
+ consola.info(`\u6CA1\u6709\u914D\u7F6EdevOptions.folder\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u8DEF\u5F84${widgetFolder}`);
32
+ }
33
+ if (!fs.existsSync(widgetFolder)) {
34
+ fs.mkdirSync(widgetFolder, { recursive: true });
35
+ }
36
+ const __filename = fileURLToPath(import.meta.url);
37
+ const __dirname = path.dirname(__filename);
38
+ const getMiddleValue = (arr) => {
39
+ if (arr.length === 1) {
40
+ return arr[0];
41
+ } else if (arr.length === 2) {
42
+ return Math.max(...arr);
43
+ } else {
44
+ const max = Math.max(...arr);
45
+ const min = Math.min(...arr);
46
+ const sum = arr[0] + arr[1] + arr[2];
47
+ return sum - max - min;
48
+ }
49
+ };
50
+ let name = await promptChecker_default({
51
+ type: "input",
52
+ name: "name",
53
+ message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u540D(\u5927\u9A7C\u5CF0\u5F0F)\uFF0C\u5982\uFF1ACountdownClock")
54
+ }, (answer) => {
55
+ const name2 = answer.name;
56
+ if (name2 == null || name2 === "") {
57
+ consola.log(chalk.red("\u7EC4\u4EF6\u540D\u4E0D\u80FD\u4E3A\u7A7A"));
58
+ return false;
59
+ }
60
+ return true;
61
+ });
62
+ consola.log(chalk.green(name));
63
+ let title = await promptChecker_default({
64
+ type: "input",
65
+ name: "title",
66
+ message: chalk.blue("\u8BF7\u8F93\u5165\u7EC4\u4EF6\u6807\u9898\uFF0C\u5982\uFF1A\u5012\u8BA1\u65F6")
67
+ });
68
+ consola.log(chalk.green(title));
69
+ let answerW = await promptChecker_default({
70
+ type: "checkbox",
71
+ name: "w",
72
+ 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"),
73
+ choices: [1, 2, 3, 4, 5, 6]
74
+ }, (answer) => {
75
+ if (answer.w.length === 0) {
76
+ consola.log(chalk.red("\u5BBD\u5EA6\u5FC5\u987B\u9009\u62E9"));
77
+ return false;
78
+ }
79
+ if (answer.w.length > 3) {
80
+ consola.log(chalk.red("\u5BBD\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
81
+ return false;
82
+ }
83
+ return true;
84
+ });
85
+ consola.log(chalk.green(answerW));
86
+ let answerH = await promptChecker_default({
87
+ type: "checkbox",
88
+ name: "h",
89
+ 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"),
90
+ choices: [1, 2, 3, 4, 5, 6]
91
+ }, (answer) => {
92
+ if (answer.h.length === 0) {
93
+ consola.log(chalk.red("\u9AD8\u5EA6\u5FC5\u987B\u9009\u62E9"));
94
+ return false;
95
+ }
96
+ if (answer.h.length > 3) {
97
+ consola.log(chalk.red("\u9AD8\u5EA6\u6700\u591A\u9009\u62E93\u4E2A"));
98
+ return false;
99
+ }
100
+ return true;
101
+ });
102
+ consola.log(chalk.green(answerH));
103
+ let configurable = await promptChecker_default({
104
+ type: "confirm",
105
+ name: "configurable",
106
+ 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")
107
+ });
108
+ consola.log(chalk.green(configurable));
109
+ const width = getMiddleValue(answerW);
110
+ const height = getMiddleValue(answerH);
111
+ const minWidth = Math.min(...answerW);
112
+ const maxWidth = Math.max(...answerW);
113
+ const minHeight = Math.min(...answerH);
114
+ const maxHeight = Math.max(...answerH);
115
+ const snakeCaseName = snakeCase(name);
116
+ const paramCaseName = paramCase(name);
117
+ const packageName = "com.wisdom.widgets." + snakeCaseName;
118
+ const widgetDir = path.join(widgetFolder, paramCaseName);
119
+ if (!fs.existsSync(widgetDir)) {
120
+ fs.mkdirSync(widgetDir);
121
+ } else {
122
+ let answer = await inquirer.prompt([{
123
+ type: "confirm",
124
+ name: "override",
125
+ message: chalk.red("\u7EC4\u4EF6\u540D\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u7EE7\u7EED?")
126
+ }]);
127
+ if (!answer.override) {
128
+ exit();
129
+ }
130
+ }
131
+ const renderOptions = {
132
+ name,
133
+ snakeCaseName,
134
+ paramCaseName,
135
+ packageName,
136
+ title,
137
+ configurable,
138
+ width,
139
+ height,
140
+ maxWidth,
141
+ minHeight,
142
+ maxHeight,
143
+ minWidth
144
+ };
145
+ function renderToFile(templateFile, outputFile, renderOptions2) {
146
+ const defineTemplatePath = path.join(__dirname, "../template", templateFile);
147
+ let defineTemplate = fs.readFileSync(defineTemplatePath, "utf8");
148
+ fs.writeFileSync(outputFile, ejs.render(defineTemplate, renderOptions2));
149
+ }
150
+ const widgetDefineFile = path.resolve(widgetDir, `${name}.widget.ts`);
151
+ const widgetFile = path.resolve(widgetDir, `${name}Widget.vue`);
152
+ const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
153
+ const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
154
+ renderToFile("WidgetDefine.ejs", widgetDefineFile, renderOptions);
155
+ renderToFile("Widget.ejs", widgetFile, renderOptions);
156
+ renderToFile("WidgetView.ejs", widgetViewFile, renderOptions);
157
+ renderToFile("WidgetRoutes.ejs", widgetRoutesFile, renderOptions);
158
+ if (configurable) {
159
+ const configFile = path.resolve(widgetDir, `${name}ConfigView.vue`);
160
+ renderToFile("WidgetConfig.ejs", configFile, renderOptions);
161
+ }
162
+ if (devOptions["useStorybook"]) {
163
+ const storiesFile = path.resolve(widgetDir, `${name}Widget.stories.ts`);
164
+ renderToFile("stories.ejs", storiesFile, renderOptions);
165
+ }
166
+ const routeFile = path.join(widgetFolder, "widget-router.ts");
167
+ let routeContent;
168
+ if (fs.existsSync(routeFile)) {
169
+ routeContent = fs.readFileSync(routeFile, "utf8");
170
+ } else {
171
+ routeContent = fs.readFileSync(path.join(__dirname, "../template/widget-router.ts"), "utf8");
172
+ }
173
+ const importRouteStr = `import ${name}WidgetRoutes from "./${paramCaseName}/${name}WidgetRoutes";`;
174
+ const routeStr = `...${name}WidgetRoutes,`;
175
+ if (!routeContent.includes(importRouteStr)) {
176
+ routeContent = routeContent.replaceAll("//FBI WANING! IMPORT PLACE", `${importRouteStr}
177
+ //FBI WANING! IMPORT PLACE`);
178
+ }
179
+ if (!routeContent.includes(routeStr)) {
180
+ routeContent = routeContent.replaceAll("//FBI WANING! ROUTE PLACE", `${routeStr}
181
+ //FBI WANING! ROUTE PLACE`);
182
+ }
183
+ fs.writeFileSync(routeFile, routeContent);
184
+ let gitAdd = `git add ${widgetDir}`;
185
+ consola.info(chalk.grey(gitAdd));
186
+ shell.exec(gitAdd);
187
+ consola.log("=================");
188
+ consola.info(`\u5DF2\u521B\u5EFA\u7EC4\u4EF6\uFF1A${widgetDir}`);
189
+ consola.success("Happy coding!");
190
+ }
191
+ export {
192
+ createWidget as default
193
+ };