create-widget 24.1.1-beta.9 → 26.7.21

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.
Files changed (83) hide show
  1. package/LICENSE +27 -27
  2. package/bin/index.js +277 -0
  3. package/eslint/eslint.config.js +12 -0
  4. package/package.json +24 -15
  5. package/readme.md +82 -0
  6. package/template/react/README.md +41 -0
  7. package/template/react/components.json +25 -0
  8. package/template/react/env.d.ts +1 -0
  9. package/template/react/index.html +13 -0
  10. package/template/react/package.json +42 -0
  11. package/template/react/public/apple-touch-icon.png +0 -0
  12. package/template/react/public/favicon-96x96.png +0 -0
  13. package/template/react/public/favicon.ico +0 -0
  14. package/template/react/public/favicon.svg +3 -0
  15. package/template/react/public/logo.png +0 -0
  16. package/template/react/public/site.webmanifest +21 -0
  17. package/template/react/public/web-app-manifest-192x192.png +0 -0
  18. package/template/react/public/web-app-manifest-512x512.png +0 -0
  19. package/template/{public → react/public}/widget.json +55 -50
  20. package/template/react/src/App.tsx +17 -0
  21. package/template/react/src/assets/main.css +221 -0
  22. package/template/react/src/components/ui/button.tsx +67 -0
  23. package/template/react/src/components/ui/card.tsx +103 -0
  24. package/template/react/src/components/ui/color-picker.tsx +171 -0
  25. package/template/react/src/components/ui/field.tsx +238 -0
  26. package/template/react/src/components/ui/input.tsx +19 -0
  27. package/template/react/src/components/ui/label.tsx +22 -0
  28. package/template/react/src/components/ui/separator.tsx +28 -0
  29. package/template/react/src/components/ui/slider.tsx +57 -0
  30. package/template/react/src/components/ui/switch.tsx +31 -0
  31. package/template/react/src/components/ui/tabs.tsx +88 -0
  32. package/template/react/src/lib/utils.ts +7 -0
  33. package/template/react/src/main.tsx +20 -0
  34. package/template/react/src/pages/home-page.tsx +66 -0
  35. package/template/react/src/widgets/clock/Clock.widget.ts +21 -0
  36. package/template/react/src/widgets/clock/ClockConfigView.tsx +112 -0
  37. package/template/react/src/widgets/clock/ClockWidgetRoutes.ts +25 -0
  38. package/template/react/src/widgets/clock/ClockWidgetView.tsx +104 -0
  39. package/template/react/src/widgets/widget-router.ts +11 -0
  40. package/template/react/tsconfig.app.json +26 -0
  41. package/template/react/tsconfig.json +17 -0
  42. package/template/react/tsconfig.node.json +23 -0
  43. package/template/react/vite.config.ts +27 -0
  44. package/template/{widget.package.ts → react/widget.package.ts} +5 -1
  45. package/template/{.vscode → vue/.vscode}/extensions.json +3 -3
  46. package/template/vue/README.md +34 -0
  47. package/template/{env.d.ts → vue/env.d.ts} +1 -1
  48. package/template/{index.html → vue/index.html} +13 -13
  49. package/template/vue/package.json +34 -0
  50. package/template/vue/public/apple-touch-icon.png +0 -0
  51. package/template/vue/public/favicon-96x96.png +0 -0
  52. package/template/vue/public/favicon.ico +0 -0
  53. package/template/vue/public/favicon.svg +3 -0
  54. package/template/vue/public/logo.png +0 -0
  55. package/template/vue/public/preview_clock.png +0 -0
  56. package/template/vue/public/site.webmanifest +21 -0
  57. package/template/vue/public/web-app-manifest-192x192.png +0 -0
  58. package/template/vue/public/web-app-manifest-512x512.png +0 -0
  59. package/template/{src → vue/src}/App.vue +9 -9
  60. package/template/vue/src/Home.vue +10 -0
  61. package/template/{src → vue/src}/main.ts +13 -12
  62. package/template/{src → vue/src}/router/index.ts +4 -0
  63. package/template/{src → vue/src}/widgets/clock/Clock.widget.ts +21 -21
  64. package/template/{src → vue/src}/widgets/clock/ClockConfigView.vue +37 -38
  65. package/template/{src → vue/src}/widgets/clock/ClockWidgetRoutes.ts +28 -28
  66. package/template/{src → vue/src}/widgets/clock/ClockWidgetView.vue +38 -35
  67. package/template/{src → vue/src}/widgets/widget-router.ts +3 -3
  68. package/template/{tsconfig.app.json → vue/tsconfig.app.json} +13 -13
  69. package/template/{tsconfig.json → vue/tsconfig.json} +11 -11
  70. package/template/{tsconfig.node.json → vue/tsconfig.node.json} +17 -17
  71. package/template/vue/vite.config.ts +29 -0
  72. package/template/vue/widget.package.ts +24 -0
  73. package/unocss/src/main.ts +13 -0
  74. package/unocss/uno.config.ts +5 -0
  75. package/unocss/vite.config.ts +31 -0
  76. package/index.cjs +0 -7913
  77. package/template/README.md +0 -40
  78. package/template/package.json +0 -29
  79. package/template/public/favicon.ico +0 -0
  80. package/template/src/widgets/clock/model/ClockModel.ts +0 -5
  81. package/template/vite.config.ts +0 -15
  82. /package/template/{public → react/public}/preview_clock.png +0 -0
  83. /package/template/{src → vue/src}/assets/main.css +0 -0
package/LICENSE CHANGED
@@ -1,27 +1,27 @@
1
- # create-widget core license
2
-
3
- create-widget is released under the MIT license:
4
-
5
- MIT License
6
-
7
- Copyright (c) 2023-present widgetjs
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- SOFTWARE.
26
-
27
-
1
+ # create-widget core license
2
+
3
+ create-widget is released under the MIT license:
4
+
5
+ MIT License
6
+
7
+ Copyright (c) 2023-present widgetjs
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+
package/bin/index.js ADDED
@@ -0,0 +1,277 @@
1
+ #!/usr/bin/env node
2
+
3
+ // node_modules/.pnpm/tsup@8.5.1_postcss@8.4.47_t_a3098b86ca89ebd8b3a1e5607680eacc/node_modules/tsup/assets/esm_shims.js
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+
10
+ // src/index.ts
11
+ import fs3 from "fs";
12
+ import path3 from "path";
13
+ import * as process from "process";
14
+ import chalk from "chalk";
15
+ import gradient from "gradient-string";
16
+ import minimist from "minimist";
17
+ import prompts from "prompts";
18
+
19
+ // src/utils/directoryTraverse.ts
20
+ import fs from "fs";
21
+ import path2 from "path";
22
+ function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
23
+ for (const filename of fs.readdirSync(dir)) {
24
+ if (filename === ".git") {
25
+ continue;
26
+ }
27
+ const fullpath = path2.resolve(dir, filename);
28
+ if (fs.lstatSync(fullpath).isDirectory()) {
29
+ postOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
30
+ dirCallback(fullpath);
31
+ continue;
32
+ }
33
+ fileCallback(fullpath);
34
+ }
35
+ }
36
+
37
+ // src/utils/FileUtils.ts
38
+ import * as fs2 from "fs";
39
+ import { copy, ensureDir } from "fs-extra";
40
+ var FileUtils = class {
41
+ static async copyFolderRecursive(src, dest) {
42
+ try {
43
+ await ensureDir(dest);
44
+ const items = await fs2.promises.readdir(src);
45
+ for (const item of items) {
46
+ const srcPath = `${src}/${item}`;
47
+ const destPath = `${dest}/${item}`;
48
+ const stats = await fs2.promises.stat(srcPath);
49
+ if (stats.isDirectory()) {
50
+ await this.copyFolderRecursive(srcPath, destPath);
51
+ } else {
52
+ await copy(srcPath, destPath, { overwrite: true });
53
+ }
54
+ }
55
+ } catch (error) {
56
+ console.error(`Error copying folder: ${error.message}`);
57
+ }
58
+ }
59
+ };
60
+
61
+ // src/utils/getCommand.ts
62
+ function getCommand(packageManager, scriptName, args) {
63
+ if (scriptName === "install") {
64
+ return packageManager === "yarn" ? "yarn" : `${packageManager} install`;
65
+ }
66
+ if (args) {
67
+ return packageManager === "npm" ? `npm run ${scriptName} -- ${args}` : `${packageManager} ${scriptName} ${args}`;
68
+ } else {
69
+ return packageManager === "npm" ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`;
70
+ }
71
+ }
72
+
73
+ // src/index.ts
74
+ function canSkipEmptying(dir) {
75
+ if (!fs3.existsSync(dir)) {
76
+ return true;
77
+ }
78
+ const files = fs3.readdirSync(dir);
79
+ if (files.length === 0) {
80
+ return true;
81
+ }
82
+ if (files.length === 1 && files[0] === ".git") {
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ function emptyDir(dir) {
88
+ if (!fs3.existsSync(dir)) {
89
+ return;
90
+ }
91
+ postOrderDirectoryTraverse(
92
+ dir,
93
+ (dir2) => fs3.rmdirSync(dir2),
94
+ (file) => fs3.unlinkSync(file)
95
+ );
96
+ }
97
+ function printInstallInstructions(root, cwd2, installCommand) {
98
+ console.log(`
99
+ Done. Now run:
100
+ `);
101
+ if (root !== cwd2) {
102
+ const cdProjectName = path3.relative(cwd2, root);
103
+ console.log(
104
+ ` ${chalk.bold(
105
+ chalk.green(
106
+ `cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`
107
+ )
108
+ )}`
109
+ );
110
+ }
111
+ console.log(` ${chalk.bold(chalk.green(installCommand))}`);
112
+ }
113
+ async function init() {
114
+ console.log();
115
+ const defaultBanner = "Widget.js - The Desktop Widget Framework";
116
+ const gradientBanner = gradient([
117
+ { color: "#42d392", pos: 0 },
118
+ { color: "#42d392", pos: 0.1 },
119
+ { color: "#647eff", pos: 1 }
120
+ ])(defaultBanner);
121
+ console.log(
122
+ process.stdout.isTTY && process.stdout.getColorDepth() > 8 ? gradientBanner : defaultBanner
123
+ );
124
+ console.log();
125
+ const argv2 = minimist(process.argv.slice(2), {
126
+ alias: {
127
+ "typescript": ["ts"],
128
+ "with-tests": ["tests"],
129
+ "router": ["vue-router"]
130
+ },
131
+ string: ["_"],
132
+ // all arguments are treated as booleans
133
+ boolean: true
134
+ });
135
+ let targetDir = argv2._[0];
136
+ const defaultProjectName = !targetDir ? "widget-project" : targetDir;
137
+ const forceOverwrite = argv2.force;
138
+ const unocss = argv2.unocss;
139
+ const vueuse = argv2.vueuse;
140
+ const iconpark = argv2.iconpark;
141
+ const githubPage = argv2.githubPage;
142
+ const eslintConfig = argv2.eslintConfig;
143
+ const cwd2 = process.cwd();
144
+ let selectedTemplateType = "react";
145
+ let result = {};
146
+ result = await prompts(
147
+ [
148
+ {
149
+ name: "projectName",
150
+ type: targetDir ? null : "text",
151
+ message: "Project name:",
152
+ initial: defaultProjectName,
153
+ onState: (state) => targetDir = String(state.value).trim() || defaultProjectName
154
+ },
155
+ {
156
+ name: "templateType",
157
+ type: "select",
158
+ message: "Select a template:",
159
+ initial: 0,
160
+ onState: (state) => selectedTemplateType = state.value,
161
+ choices: [
162
+ { title: "react", value: "react" },
163
+ { title: "vue3 (Deprecate)", value: "vue3" }
164
+ ]
165
+ },
166
+ {
167
+ name: "shouldOverwrite",
168
+ type: () => canSkipEmptying(targetDir) || forceOverwrite ? null : "confirm",
169
+ message: () => {
170
+ const dirForPrompt = targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`;
171
+ return `${dirForPrompt} is not empty. Remove existing files and continue?`;
172
+ }
173
+ },
174
+ {
175
+ name: "useVueUse",
176
+ type: () => selectedTemplateType === "react" || vueuse ? null : "confirm",
177
+ message: () => {
178
+ return `Use VueUse (Collection of Essential Vue Composition Utilities)?`;
179
+ }
180
+ },
181
+ {
182
+ name: "useUnoCss",
183
+ type: () => selectedTemplateType === "react" || unocss ? null : "confirm",
184
+ message: () => {
185
+ return `Use Unocss(Atomic CSS Engine)?`;
186
+ }
187
+ },
188
+ {
189
+ name: "useIconPark",
190
+ type: () => selectedTemplateType === "react" || iconpark ? null : "confirm",
191
+ message: () => {
192
+ return `Use IconPark (2000+ high-quality icons)?`;
193
+ }
194
+ },
195
+ {
196
+ name: "useGithubPage",
197
+ type: () => selectedTemplateType === "react" || githubPage ? null : "confirm",
198
+ message: () => {
199
+ return `Use GitHub Page to deploy your project?`;
200
+ }
201
+ },
202
+ {
203
+ name: "useEslintConfig",
204
+ type: () => selectedTemplateType === "react" || eslintConfig ? null : "confirm",
205
+ message: () => {
206
+ return `Use @antfu/eslint-config (Anthony's ESLint config preset)?`;
207
+ }
208
+ }
209
+ ],
210
+ {
211
+ onCancel: () => {
212
+ throw new Error(`${chalk.red("\u2716")} Operation cancelled`);
213
+ }
214
+ }
215
+ );
216
+ const {
217
+ projectName,
218
+ templateType = "react",
219
+ shouldOverwrite = argv2.force,
220
+ useVueUse = argv2.vueuse,
221
+ useUnoCss = argv2.unocss,
222
+ useIconPark = argv2.iconpark,
223
+ useGithubPage = argv2.githubPage,
224
+ useEslintConfig = argv2.eslintConfig
225
+ } = result;
226
+ const root = path3.join(cwd2, targetDir);
227
+ if (fs3.existsSync(root) && shouldOverwrite) {
228
+ emptyDir(root);
229
+ } else if (!fs3.existsSync(root)) {
230
+ fs3.mkdirSync(root);
231
+ }
232
+ console.log(`
233
+ Scaffolding project in ${root}...`);
234
+ if (templateType === "react") {
235
+ const reactTemplateRoot = path3.join(__dirname, "../template/react");
236
+ await FileUtils.copyFolderRecursive(reactTemplateRoot, root);
237
+ printInstallInstructions(root, cwd2, "npm install");
238
+ return;
239
+ }
240
+ const templateRoot = path3.join(__dirname, "../template/vue");
241
+ await FileUtils.copyFolderRecursive(templateRoot, root);
242
+ const packageJsonPath = path3.resolve(`${root}/package.json`);
243
+ const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath).toString());
244
+ if (useVueUse) {
245
+ packageJson.dependencies["@vueuse/core"] = "latest";
246
+ }
247
+ if (useUnoCss) {
248
+ packageJson.devDependencies.unocss = "latest";
249
+ const unocssTemplateRoot = path3.join(__dirname, "../unocss");
250
+ await FileUtils.copyFolderRecursive(unocssTemplateRoot, root);
251
+ }
252
+ if (useIconPark) {
253
+ packageJson.dependencies["@icon-park/vue-next"] = "latest";
254
+ }
255
+ if (useEslintConfig) {
256
+ packageJson.devDependencies["@antfu/eslint-config"] = "latest";
257
+ packageJson.devDependencies.eslint = "latest";
258
+ packageJson.scripts = {
259
+ ...packageJson.scripts,
260
+ "lint": "eslint .",
261
+ "lint:fix": "eslint . --fix"
262
+ };
263
+ const eslintTemplateRoot = path3.join(__dirname, "../eslint");
264
+ await FileUtils.copyFolderRecursive(eslintTemplateRoot, root);
265
+ }
266
+ fs3.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
267
+ if (useGithubPage) {
268
+ const githubPageTemplateRoot = path3.join(__dirname, "../github-page");
269
+ await FileUtils.copyFolderRecursive(githubPageTemplateRoot, root);
270
+ }
271
+ const userAgent = process.env.npm_config_user_agent ?? "";
272
+ const packageManager = /pnpm/.test(userAgent) ? "pnpm" : /yarn/.test(userAgent) ? "yarn" : "npm";
273
+ printInstallInstructions(root, cwd2, getCommand(packageManager, "install"));
274
+ }
275
+ init().catch((e) => {
276
+ console.error(e);
277
+ });
@@ -0,0 +1,12 @@
1
+ import antfu from '@antfu/eslint-config'
2
+
3
+ export default antfu({
4
+ stylistic: {
5
+ indent: 2,
6
+ quotes: 'single',
7
+ },
8
+ typescript: true,
9
+ vue: true,
10
+ jsonc: false,
11
+ yaml: false,
12
+ })
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "create-widget",
3
- "version": "24.1.1-beta.9",
3
+ "version": "26.7.21",
4
4
  "private": false,
5
5
  "description": "An easy way to start a Widget project",
6
6
  "author": "Neo Fu <rtugeek@gmail.com>",
7
7
  "license": "MIT",
8
8
  "main": "lib/index.js",
9
+ "type": "module",
9
10
  "bin": {
10
- "create-widget": "index.cjs"
11
+ "create-widget": "bin/index.js"
11
12
  },
12
13
  "files": [
13
- "index.cjs",
14
- "template"
14
+ "bin/index.js",
15
+ "template",
16
+ "unocss",
17
+ "github-page",
18
+ "eslint"
15
19
  ],
16
20
  "engines": {
17
21
  "node": ">=v16.20.0"
@@ -21,34 +25,39 @@
21
25
  },
22
26
  "dependencies": {
23
27
  "chalk": "^4.1.2",
24
- "consola": "^2.15.3",
25
- "ejs": "^3.1.8",
28
+ "create-widget": "link:",
26
29
  "fs-extra": "^11.2.0",
27
30
  "gradient-string": "^2.0.2",
28
31
  "minimist": "^1.2.8",
29
32
  "prompts": "^2.4.2"
30
33
  },
31
34
  "devDependencies": {
35
+ "@antfu/eslint-config": "^3.8.0",
32
36
  "@tsconfig/node18": "^18.2.2",
37
+ "@tsconfig/node22": "^22.0.5",
33
38
  "@types/ejs": "latest",
34
39
  "@types/fs-extra": "^11.0.4",
35
40
  "@types/gradient-string": "^1.1.2",
36
41
  "@types/minimist": "^1.2.5",
37
42
  "@types/node": "^18.11.13",
38
43
  "@types/prompts": "^2.4.9",
39
- "esbuild": "^0.20.2",
40
- "ts-loader": "^9.4.1",
41
- "ts-node": "^10.9.1",
42
- "tsup": "^6.5.0",
44
+ "eslint": "8.48.0",
45
+ "esno": "^4.0.0",
46
+ "ora": "^6.2.0",
47
+ "package-json": "^10.0.1",
48
+ "tsup": "^8.3.5",
43
49
  "typescript": "^5.2.2",
44
- "vitest": "^0.34.6",
45
- "zx": "^7.2.3"
50
+ "vitest": "^0.34.6"
46
51
  },
47
52
  "scripts": {
48
- "build": "zx ./scripts/build.mjs",
53
+ "prebuild": "release --date-version",
54
+ "build": "tsup-node build src/index.ts",
49
55
  "watch": "tsup-node src/index.ts --format cjs --watch",
50
- "build:run": "npm run build && npm run create-widget",
56
+ "build:run": "npm run build && npm exec create-widget",
51
57
  "test": "node index.cjs",
52
- "pnpm:publish": "npm run build && pnpm publish --no-git-checks"
58
+ "update:version": "esno scripts/updateVersion.ts",
59
+ "pnpm:publish": "npm run build && pnpm publish --no-git-checks",
60
+ "link": "pnpm link --global",
61
+ "lint:fix": "eslint"
53
62
  }
54
63
  }
package/readme.md ADDED
@@ -0,0 +1,82 @@
1
+ # 创建桌面组件项目
2
+
3
+ ## AI使用
4
+
5
+ ```shell
6
+ npx skills@latest add create-widget
7
+ ```
8
+
9
+
10
+
11
+ ### 创建桌面组件项目
12
+
13
+ :::tip 前提条件
14
+
15
+ - 熟悉命令行
16
+ - 已安装 18.0 或更高版本的 [Node.js](https://nodejs.org/)
17
+ - 熟悉 [Vue3](https://cn.vuejs.org/guide/quick-start.html)
18
+ :::
19
+
20
+ 在命令行中运行以下命令,创建桌面组件项目
21
+
22
+ ```bash
23
+ npm create widget@latest
24
+ ```
25
+
26
+ 这一指令将会安装并执行 create-widget,输入下项目名称即可:
27
+
28
+ ```shell
29
+ ✔ Project name: … <your-project-name>
30
+ ```
31
+
32
+ 完成创建后,项目目录结构如下:
33
+
34
+ ```shell{8-13,15,25}
35
+ .
36
+ ├── public
37
+ ├── src
38
+ │ ├── App.vue
39
+ │ ├── assets
40
+ │ ├── main.ts
41
+ │ ├── router
42
+ │ ├── widgets # 👈 组件文件存放目录
43
+ │ │ ├── clock # 👈 这是一个简单的示例组件
44
+ │ │ │ ├── Clock.widget.ts # 👈 组件信息文件
45
+ │ │ │ ├── ClockConfigView.vue # 👈 组件设置页面
46
+ │ │ │ ├── ClockWidgetRoutes.ts # 👈 组件路由
47
+ │ │ │ ├── ClockWidgetView.vue # 👈 组件页面
48
+ │ │ │ ├── model
49
+ │ │ │ │ └── ClockModel.ts # 👈 组件数据模型
50
+ │ │ └── widget-router.ts
51
+ ├── .vscode
52
+ ├── env.d.ts
53
+ ├── index.html
54
+ ├── package.json
55
+ ├── README.md
56
+ ├── tsconfig.app.json
57
+ ├── tsconfig.json
58
+ ├── vite.config.ts
59
+ ├── widget.package.ts # 👈 组件包信息,记得修改
60
+ └── ...
61
+ ```
62
+
63
+ 记得更新下依赖
64
+
65
+ ```shell
66
+ cd <your-project-name>
67
+ npm install
68
+ ```
69
+
70
+ ### 运行项目
71
+
72
+ 开启vite服务
73
+
74
+ ```shell
75
+ npm run dev
76
+ ```
77
+ 控制台会打印以下信息,代表组件已经注册成功。
78
+ ```shell
79
+ i Register widgets at: 2024-01-06T14:13:30.214Z 22:13:30
80
+ i Register widget: cn.example.widget.clock, path: /widget/clock 22:13:30
81
+ i Widget size:1
82
+ ```
@@ -0,0 +1,41 @@
1
+ # Hello Widget React Example
2
+
3
+ 这是一个基于 `Vite + React + TypeScript` 的 WidgetJS 示例项目。
4
+
5
+ ## 项目特性
6
+
7
+ - 使用 `react-router-dom` 管理首页、组件页和配置页
8
+ - 直接复用 `@widget-js/react` 的 `WidgetWrapper`、`useWidget`、`useWidgetStorage`、`useWidgetTheme`
9
+ - 保留 `@widget-js/vite-plugin-widget` 打包流程,支持在线构建和离线 zip 构建
10
+
11
+ ## 开发命令
12
+
13
+ ### 安装依赖
14
+
15
+ ```bash
16
+ npm install
17
+ ```
18
+
19
+ ### 启动开发环境
20
+
21
+ ```bash
22
+ npm run dev
23
+ ```
24
+
25
+ ### 构建在线包
26
+
27
+ ```bash
28
+ npm run build
29
+ ```
30
+
31
+ ### 构建离线 zip 包
32
+
33
+ ```bash
34
+ npm run build:offline
35
+ ```
36
+
37
+ ### 更新 WidgetJS 相关依赖
38
+
39
+ ```bash
40
+ npm run update:widgetjs
41
+ ```
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "radix-nova",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/assets/main.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "menuColor": "default",
23
+ "menuAccent": "subtle",
24
+ "registries": {}
25
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <link rel="icon" href="/favicon.ico">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Widget</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "hello-widget",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "preview": "vite preview",
9
+ "build": "vite build",
10
+ "build:offline": "vite build --mode offline",
11
+ "update:widgetjs": "widget dependencies -t remote"
12
+ },
13
+ "dependencies": {
14
+ "@fontsource-variable/geist": "^5.3.0",
15
+ "@widget-js/core": "latest",
16
+ "@widget-js/react": "latest",
17
+ "class-variance-authority": "^0.7.1",
18
+ "clsx": "^2.1.1",
19
+ "lucide-react": "^1.25.0",
20
+ "radix-ui": "^1.6.3",
21
+ "react": "^19.2.0",
22
+ "react-dom": "^19.2.0",
23
+ "react-router-dom": "^7.9.1",
24
+ "shadcn": "^4.13.1",
25
+ "styled-components": "^6.4.4",
26
+ "tailwind-merge": "^3.6.0",
27
+ "tw-animate-css": "^1.4.0",
28
+ "zustand": "^5.0.14"
29
+ },
30
+ "devDependencies": {
31
+ "@tailwindcss/vite": "^4.3.3",
32
+ "@types/node": "latest",
33
+ "@types/react": "^19.2.7",
34
+ "@types/react-dom": "^19.2.3",
35
+ "@vitejs/plugin-react": "^5.1.1",
36
+ "@widget-js/cli": "24.1.1-beta.72",
37
+ "@widget-js/vite-plugin-widget": "24.1.1-beta.72",
38
+ "tailwindcss": "^4.3.3",
39
+ "typescript": "latest",
40
+ "vite": "latest"
41
+ }
42
+ }