create-widget 24.1.1-beta.9 → 26.7.22
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/LICENSE +27 -27
- package/bin/index.js +216 -0
- package/eslint/eslint.config.js +12 -0
- package/package.json +24 -15
- package/readme.md +80 -0
- package/template/react/README.md +41 -0
- package/template/react/components.json +25 -0
- package/template/react/env.d.ts +1 -0
- package/template/react/index.html +13 -0
- package/template/react/package.json +42 -0
- package/template/react/public/apple-touch-icon.png +0 -0
- package/template/react/public/favicon-96x96.png +0 -0
- package/template/react/public/favicon.ico +0 -0
- package/template/react/public/favicon.svg +3 -0
- package/template/react/public/logo.png +0 -0
- package/template/react/public/site.webmanifest +21 -0
- package/template/react/public/web-app-manifest-192x192.png +0 -0
- package/template/react/public/web-app-manifest-512x512.png +0 -0
- package/template/{public → react/public}/widget.json +55 -50
- package/template/react/src/App.tsx +17 -0
- package/template/react/src/assets/main.css +221 -0
- package/template/react/src/components/ui/button.tsx +67 -0
- package/template/react/src/components/ui/card.tsx +103 -0
- package/template/react/src/components/ui/color-picker.tsx +171 -0
- package/template/react/src/components/ui/field.tsx +238 -0
- package/template/react/src/components/ui/input.tsx +19 -0
- package/template/react/src/components/ui/label.tsx +22 -0
- package/template/react/src/components/ui/separator.tsx +28 -0
- package/template/react/src/components/ui/slider.tsx +57 -0
- package/template/react/src/components/ui/switch.tsx +31 -0
- package/template/react/src/components/ui/tabs.tsx +88 -0
- package/template/react/src/lib/utils.ts +7 -0
- package/template/react/src/main.tsx +20 -0
- package/template/react/src/pages/home-page.tsx +66 -0
- package/template/react/src/widgets/clock/Clock.widget.ts +21 -0
- package/template/react/src/widgets/clock/ClockConfigView.tsx +112 -0
- package/template/react/src/widgets/clock/ClockWidgetRoutes.ts +25 -0
- package/template/react/src/widgets/clock/ClockWidgetView.tsx +104 -0
- package/template/react/src/widgets/widget-router.ts +11 -0
- package/template/react/tsconfig.app.json +26 -0
- package/template/react/tsconfig.json +17 -0
- package/template/react/tsconfig.node.json +23 -0
- package/template/react/vite.config.ts +27 -0
- package/template/{widget.package.ts → react/widget.package.ts} +5 -1
- package/template/{.vscode → vue/.vscode}/extensions.json +3 -3
- package/template/vue/README.md +34 -0
- package/template/{env.d.ts → vue/env.d.ts} +1 -1
- package/template/{index.html → vue/index.html} +13 -13
- package/template/vue/package.json +34 -0
- package/template/vue/public/apple-touch-icon.png +0 -0
- package/template/vue/public/favicon-96x96.png +0 -0
- package/template/vue/public/favicon.ico +0 -0
- package/template/vue/public/favicon.svg +3 -0
- package/template/vue/public/logo.png +0 -0
- package/template/vue/public/preview_clock.png +0 -0
- package/template/vue/public/site.webmanifest +21 -0
- package/template/vue/public/web-app-manifest-192x192.png +0 -0
- package/template/vue/public/web-app-manifest-512x512.png +0 -0
- package/template/{src → vue/src}/App.vue +9 -9
- package/template/vue/src/Home.vue +10 -0
- package/template/{src → vue/src}/main.ts +13 -12
- package/template/{src → vue/src}/router/index.ts +4 -0
- package/template/{src → vue/src}/widgets/clock/Clock.widget.ts +21 -21
- package/template/{src → vue/src}/widgets/clock/ClockConfigView.vue +37 -38
- package/template/{src → vue/src}/widgets/clock/ClockWidgetRoutes.ts +28 -28
- package/template/{src → vue/src}/widgets/clock/ClockWidgetView.vue +38 -35
- package/template/{src → vue/src}/widgets/widget-router.ts +3 -3
- package/template/{tsconfig.app.json → vue/tsconfig.app.json} +13 -13
- package/template/{tsconfig.json → vue/tsconfig.json} +11 -11
- package/template/{tsconfig.node.json → vue/tsconfig.node.json} +17 -17
- package/template/vue/vite.config.ts +29 -0
- package/template/vue/widget.package.ts +24 -0
- package/unocss/src/main.ts +13 -0
- package/unocss/uno.config.ts +5 -0
- package/unocss/vite.config.ts +31 -0
- package/index.cjs +0 -7913
- package/template/README.md +0 -40
- package/template/package.json +0 -29
- package/template/public/favicon.ico +0 -0
- package/template/src/widgets/clock/model/ClockModel.ts +0 -5
- package/template/vite.config.ts +0 -15
- /package/template/{public → react/public}/preview_clock.png +0 -0
- /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,216 @@
|
|
|
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 npmmirror = argv2.npmmirror;
|
|
139
|
+
const cwd2 = process.cwd();
|
|
140
|
+
let selectedTemplateType = "react";
|
|
141
|
+
let result = {};
|
|
142
|
+
result = await prompts(
|
|
143
|
+
[
|
|
144
|
+
{
|
|
145
|
+
name: "projectName",
|
|
146
|
+
type: targetDir ? null : "text",
|
|
147
|
+
message: "Project name:",
|
|
148
|
+
initial: defaultProjectName,
|
|
149
|
+
onState: (state) => targetDir = String(state.value).trim() || defaultProjectName
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "templateType",
|
|
153
|
+
type: "select",
|
|
154
|
+
message: "Select a template:",
|
|
155
|
+
initial: 0,
|
|
156
|
+
onState: (state) => selectedTemplateType = state.value,
|
|
157
|
+
choices: [
|
|
158
|
+
{ title: "react", value: "react" },
|
|
159
|
+
{ title: "vue3 (Deprecate)", value: "vue3" }
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "useNpmMirror",
|
|
164
|
+
type: npmmirror ? null : "confirm",
|
|
165
|
+
message: "Use npmmirror registry? (Recommended for users in mainland China)"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "shouldOverwrite",
|
|
169
|
+
type: () => canSkipEmptying(targetDir) || forceOverwrite ? null : "confirm",
|
|
170
|
+
message: () => {
|
|
171
|
+
const dirForPrompt = targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`;
|
|
172
|
+
return `${dirForPrompt} is not empty. Remove existing files and continue?`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
{
|
|
177
|
+
onCancel: () => {
|
|
178
|
+
throw new Error(`${chalk.red("\u2716")} Operation cancelled`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
const {
|
|
183
|
+
projectName,
|
|
184
|
+
templateType = "react",
|
|
185
|
+
useNpmMirror = argv2.npmmirror,
|
|
186
|
+
shouldOverwrite = argv2.force
|
|
187
|
+
} = result;
|
|
188
|
+
const root = path3.join(cwd2, targetDir);
|
|
189
|
+
if (fs3.existsSync(root) && shouldOverwrite) {
|
|
190
|
+
emptyDir(root);
|
|
191
|
+
} else if (!fs3.existsSync(root)) {
|
|
192
|
+
fs3.mkdirSync(root);
|
|
193
|
+
}
|
|
194
|
+
console.log(`
|
|
195
|
+
Scaffolding project in ${root}...`);
|
|
196
|
+
if (templateType === "react") {
|
|
197
|
+
const reactTemplateRoot = path3.join(__dirname, "../template/react");
|
|
198
|
+
await FileUtils.copyFolderRecursive(reactTemplateRoot, root);
|
|
199
|
+
if (useNpmMirror) {
|
|
200
|
+
fs3.writeFileSync(path3.join(root, ".npmrc"), "registry=https://registry.npmmirror.com\n");
|
|
201
|
+
}
|
|
202
|
+
printInstallInstructions(root, cwd2, "npm install");
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const templateRoot = path3.join(__dirname, "../template/vue");
|
|
206
|
+
await FileUtils.copyFolderRecursive(templateRoot, root);
|
|
207
|
+
if (useNpmMirror) {
|
|
208
|
+
fs3.writeFileSync(path3.join(root, ".npmrc"), "registry=https://registry.npmmirror.com\n");
|
|
209
|
+
}
|
|
210
|
+
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
211
|
+
const packageManager = /pnpm/.test(userAgent) ? "pnpm" : /yarn/.test(userAgent) ? "yarn" : "npm";
|
|
212
|
+
printInstallInstructions(root, cwd2, getCommand(packageManager, "install"));
|
|
213
|
+
}
|
|
214
|
+
init().catch((e) => {
|
|
215
|
+
console.error(e);
|
|
216
|
+
});
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-widget",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.7.22",
|
|
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.
|
|
11
|
+
"create-widget": "bin/index.js"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
|
-
"index.
|
|
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
|
-
"
|
|
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
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
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
|
-
"
|
|
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
|
|
56
|
+
"build:run": "npm run build && npm exec create-widget",
|
|
51
57
|
"test": "node index.cjs",
|
|
52
|
-
"
|
|
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,80 @@
|
|
|
1
|
+
# 创建桌面组件项目
|
|
2
|
+
|
|
3
|
+
## AI使用
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npx skills@latest add create-widget
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 创建桌面组件项目
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
- 熟悉命令行
|
|
15
|
+
- 已安装 18.0 或更高版本的 [Node.js](https://nodejs.org/)
|
|
16
|
+
- 熟悉 [Vue3](https://cn.vuejs.org/guide/quick-start.html)
|
|
17
|
+
|
|
18
|
+
在命令行中运行以下命令,创建桌面组件项目
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm create widget@latest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
这一指令将会安装并执行 create-widget,输入下项目名称即可:
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
✔ Project name: … <your-project-name>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
完成创建后,项目目录结构如下:
|
|
31
|
+
|
|
32
|
+
```shell{8-13,15,25}
|
|
33
|
+
.
|
|
34
|
+
├── public
|
|
35
|
+
├── src
|
|
36
|
+
│ ├── App.vue
|
|
37
|
+
│ ├── assets
|
|
38
|
+
│ ├── main.ts
|
|
39
|
+
│ ├── router
|
|
40
|
+
│ ├── widgets # 👈 组件文件存放目录
|
|
41
|
+
│ │ ├── clock # 👈 这是一个简单的示例组件
|
|
42
|
+
│ │ │ ├── Clock.widget.ts # 👈 组件信息文件
|
|
43
|
+
│ │ │ ├── ClockConfigView.vue # 👈 组件设置页面
|
|
44
|
+
│ │ │ ├── ClockWidgetRoutes.ts # 👈 组件路由
|
|
45
|
+
│ │ │ ├── ClockWidgetView.vue # 👈 组件页面
|
|
46
|
+
│ │ │ ├── model
|
|
47
|
+
│ │ │ │ └── ClockModel.ts # 👈 组件数据模型
|
|
48
|
+
│ │ └── widget-router.ts
|
|
49
|
+
├── .vscode
|
|
50
|
+
├── env.d.ts
|
|
51
|
+
├── index.html
|
|
52
|
+
├── package.json
|
|
53
|
+
├── README.md
|
|
54
|
+
├── tsconfig.app.json
|
|
55
|
+
├── tsconfig.json
|
|
56
|
+
├── vite.config.ts
|
|
57
|
+
├── widget.package.ts # 👈 组件包信息,记得修改
|
|
58
|
+
└── ...
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
记得更新下依赖
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
cd <your-project-name>
|
|
65
|
+
npm install
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 运行项目
|
|
69
|
+
|
|
70
|
+
开启vite服务
|
|
71
|
+
|
|
72
|
+
```shell
|
|
73
|
+
npm run dev
|
|
74
|
+
```
|
|
75
|
+
控制台会打印以下信息,代表组件已经注册成功。
|
|
76
|
+
```shell
|
|
77
|
+
i Register widgets at: 2024-01-06T14:13:30.214Z 22:13:30
|
|
78
|
+
i Register widget: cn.example.widget.clock, path: /widget/clock 22:13:30
|
|
79
|
+
i Widget size:1
|
|
80
|
+
```
|
|
@@ -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": "latest",
|
|
37
|
+
"@widget-js/vite-plugin-widget": "latest",
|
|
38
|
+
"tailwindcss": "^4.3.3",
|
|
39
|
+
"typescript": "latest",
|
|
40
|
+
"vite": "latest"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|