create-weapp-vite 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CI2UMYKK.js +277 -0
- package/dist/cli.cjs +280 -11
- package/dist/cli.js +12 -9
- package/dist/index.cjs +317 -0
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +8 -0
- package/package.json +6 -3
- package/templates/default/.editorconfig +9 -0
- package/templates/default/.vscode/settings.json +5 -0
- package/templates/default/README.md +28 -0
- package/templates/default/auto-import-components.json +3 -0
- package/templates/default/gitignore +35 -0
- package/templates/default/package.json +31 -0
- package/templates/default/project.config.json +42 -0
- package/templates/default/project.private.config.json +8 -0
- package/templates/default/public/logo.png +0 -0
- package/templates/default/src/app.json +10 -0
- package/templates/default/src/app.scss +0 -0
- package/templates/default/src/app.ts +6 -0
- package/templates/default/src/components/HelloWorld/HelloWorld.json +6 -0
- package/templates/default/src/components/HelloWorld/HelloWorld.scss +47 -0
- package/templates/default/src/components/HelloWorld/HelloWorld.ts +61 -0
- package/templates/default/src/components/HelloWorld/HelloWorld.wxml +16 -0
- package/templates/default/src/pages/index/index.json +7 -0
- package/templates/default/src/pages/index/index.scss +0 -0
- package/templates/default/src/pages/index/index.ts +24 -0
- package/templates/default/src/pages/index/index.wxml +14 -0
- package/templates/default/src/sitemap.json +10 -0
- package/templates/default/src/theme.json +5 -0
- package/templates/default/src/utils/util.ts +3 -0
- package/templates/default/src/vite-env.d.ts +1 -0
- package/templates/default/tsconfig.app.json +57 -0
- package/templates/default/tsconfig.json +11 -0
- package/templates/default/tsconfig.node.json +33 -0
- package/templates/default/vite.config.ts +39 -0
- package/templates/tailwindcss/.editorconfig +9 -0
- package/templates/tailwindcss/.vscode/settings.json +5 -0
- package/templates/tailwindcss/README.md +28 -0
- package/templates/tailwindcss/auto-import-components.json +3 -0
- package/templates/tailwindcss/gitignore +35 -0
- package/templates/tailwindcss/package.json +38 -0
- package/templates/tailwindcss/postcss.config.js +6 -0
- package/templates/tailwindcss/project.config.json +43 -0
- package/templates/tailwindcss/project.private.config.json +8 -0
- package/templates/tailwindcss/public/icon0.png +0 -0
- package/templates/tailwindcss/public/icon0s.png +0 -0
- package/templates/tailwindcss/public/icon1.png +0 -0
- package/templates/tailwindcss/public/icon1s.png +0 -0
- package/templates/tailwindcss/public/logo.png +0 -0
- package/templates/tailwindcss/src/app.json +31 -0
- package/templates/tailwindcss/src/app.scss +3 -0
- package/templates/tailwindcss/src/app.ts +6 -0
- package/templates/tailwindcss/src/components/HelloWorld/HelloWorld.json +7 -0
- package/templates/tailwindcss/src/components/HelloWorld/HelloWorld.scss +1 -0
- package/templates/tailwindcss/src/components/HelloWorld/HelloWorld.ts +61 -0
- package/templates/tailwindcss/src/components/HelloWorld/HelloWorld.wxml +16 -0
- package/templates/tailwindcss/src/pages/index/index.json +7 -0
- package/templates/tailwindcss/src/pages/index/index.scss +0 -0
- package/templates/tailwindcss/src/pages/index/index.ts +48 -0
- package/templates/tailwindcss/src/pages/index/index.wxml +24 -0
- package/templates/tailwindcss/src/pages/profile/index.json +7 -0
- package/templates/tailwindcss/src/pages/profile/index.scss +0 -0
- package/templates/tailwindcss/src/pages/profile/index.ts +19 -0
- package/templates/tailwindcss/src/pages/profile/index.wxml +11 -0
- package/templates/tailwindcss/src/sitemap.json +10 -0
- package/templates/tailwindcss/src/theme.json +5 -0
- package/templates/tailwindcss/src/utils/util.ts +3 -0
- package/templates/tailwindcss/src/vite-env.d.ts +1 -0
- package/templates/tailwindcss/tailwind.config.ts +22 -0
- package/templates/tailwindcss/tsconfig.app.json +57 -0
- package/templates/tailwindcss/tsconfig.json +11 -0
- package/templates/tailwindcss/tsconfig.node.json +33 -0
- package/templates/tailwindcss/vite.config.ts +37 -0
- package/templates/tdesign/.editorconfig +9 -0
- package/templates/tdesign/.vscode/settings.json +5 -0
- package/templates/tdesign/README.md +28 -0
- package/templates/tdesign/gitignore +35 -0
- package/templates/tdesign/package.json +41 -0
- package/templates/tdesign/postcss.config.js +6 -0
- package/templates/tdesign/project.config.json +45 -0
- package/templates/tdesign/project.private.config.json +8 -0
- package/templates/tdesign/public/logo.png +0 -0
- package/templates/tdesign/src/app.json +10 -0
- package/templates/tdesign/src/app.scss +3 -0
- package/templates/tdesign/src/app.ts +6 -0
- package/templates/tdesign/src/components/HelloWorld/HelloWorld.json +8 -0
- package/templates/tdesign/src/components/HelloWorld/HelloWorld.scss +1 -0
- package/templates/tdesign/src/components/HelloWorld/HelloWorld.ts +64 -0
- package/templates/tdesign/src/components/HelloWorld/HelloWorld.wxml +17 -0
- package/templates/tdesign/src/pages/index/index.json +7 -0
- package/templates/tdesign/src/pages/index/index.scss +0 -0
- package/templates/tdesign/src/pages/index/index.ts +97 -0
- package/templates/tdesign/src/pages/index/index.wxml +24 -0
- package/templates/tdesign/src/sitemap.json +10 -0
- package/templates/tdesign/src/theme.json +5 -0
- package/templates/tdesign/src/utils/util.ts +3 -0
- package/templates/tdesign/src/vite-env.d.ts +1 -0
- package/templates/tdesign/tailwind.config.ts +22 -0
- package/templates/tdesign/tsconfig.app.json +60 -0
- package/templates/tdesign/tsconfig.json +11 -0
- package/templates/tdesign/tsconfig.node.json +33 -0
- package/templates/tdesign/vite.config.ts +41 -0
- package/templates/vant/.editorconfig +9 -0
- package/templates/vant/.vscode/settings.json +5 -0
- package/templates/vant/README.md +28 -0
- package/templates/vant/gitignore +35 -0
- package/templates/vant/package.json +41 -0
- package/templates/vant/postcss.config.js +6 -0
- package/templates/vant/project.config.json +42 -0
- package/templates/vant/project.private.config.json +8 -0
- package/templates/vant/public/logo.png +0 -0
- package/templates/vant/src/app.json +10 -0
- package/templates/vant/src/app.scss +3 -0
- package/templates/vant/src/app.ts +6 -0
- package/templates/vant/src/components/HelloWorld/HelloWorld.json +9 -0
- package/templates/vant/src/components/HelloWorld/HelloWorld.scss +1 -0
- package/templates/vant/src/components/HelloWorld/HelloWorld.ts +61 -0
- package/templates/vant/src/components/HelloWorld/HelloWorld.wxml +19 -0
- package/templates/vant/src/pages/index/index.json +7 -0
- package/templates/vant/src/pages/index/index.scss +0 -0
- package/templates/vant/src/pages/index/index.ts +57 -0
- package/templates/vant/src/pages/index/index.wxml +28 -0
- package/templates/vant/src/sitemap.json +10 -0
- package/templates/vant/src/theme.json +5 -0
- package/templates/vant/src/utils/util.ts +3 -0
- package/templates/vant/src/vite-env.d.ts +1 -0
- package/templates/vant/tailwind.config.ts +22 -0
- package/templates/vant/tsconfig.app.json +60 -0
- package/templates/vant/tsconfig.json +11 -0
- package/templates/vant/tsconfig.node.json +33 -0
- package/templates/vant/vite.config.ts +41 -0
- package/templates/wevu/.editorconfig +9 -0
- package/templates/wevu/.vscode/settings.json +5 -0
- package/templates/wevu/README.md +29 -0
- package/templates/wevu/auto-import-components.json +1 -0
- package/templates/wevu/gitignore +35 -0
- package/templates/wevu/package.json +30 -0
- package/templates/wevu/project.config.json +43 -0
- package/templates/wevu/project.private.config.json +8 -0
- package/templates/wevu/public/logo.png +0 -0
- package/templates/wevu/src/app.vue +36 -0
- package/templates/wevu/src/components/HelloWorld/index.vue +45 -0
- package/templates/wevu/src/pages/index/index.vue +138 -0
- package/templates/wevu/src/sitemap.json +10 -0
- package/templates/wevu/src/theme.json +5 -0
- package/templates/wevu/src/vite-env.d.ts +1 -0
- package/templates/wevu/tsconfig.app.json +57 -0
- package/templates/wevu/tsconfig.json +11 -0
- package/templates/wevu/tsconfig.node.json +33 -0
- package/templates/wevu/vite.config.ts +8 -0
- package/templates/wevu-tdesign/.editorconfig +9 -0
- package/templates/wevu-tdesign/.vscode/settings.json +5 -0
- package/templates/wevu-tdesign/README.md +29 -0
- package/templates/wevu-tdesign/auto-import-components.json +83 -0
- package/templates/wevu-tdesign/components.d.ts +183 -0
- package/templates/wevu-tdesign/gitignore +35 -0
- package/templates/wevu-tdesign/package.json +40 -0
- package/templates/wevu-tdesign/postcss.config.js +6 -0
- package/templates/wevu-tdesign/project.config.json +43 -0
- package/templates/wevu-tdesign/project.private.config.json +8 -0
- package/templates/wevu-tdesign/public/logo.png +0 -0
- package/templates/wevu-tdesign/src/app.vue +35 -0
- package/templates/wevu-tdesign/src/components/HelloWorld/index.vue +23 -0
- package/templates/wevu-tdesign/src/pages/index/index.vue +161 -0
- package/templates/wevu-tdesign/src/sitemap.json +10 -0
- package/templates/wevu-tdesign/src/theme.json +5 -0
- package/templates/wevu-tdesign/src/vite-env.d.ts +1 -0
- package/templates/wevu-tdesign/tailwind.config.ts +22 -0
- package/templates/wevu-tdesign/tsconfig.app.json +62 -0
- package/templates/wevu-tdesign/tsconfig.json +11 -0
- package/templates/wevu-tdesign/tsconfig.node.json +33 -0
- package/templates/wevu-tdesign/typed-components.d.ts +943 -0
- package/templates/wevu-tdesign/vite.config.ts +43 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// src/createProject.ts
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import logger2 from "@weapp-core/logger";
|
|
4
|
+
import fs2 from "fs-extra";
|
|
5
|
+
import path2 from "pathe";
|
|
6
|
+
|
|
7
|
+
// ../weapp-vite/package.json
|
|
8
|
+
var version = "6.1.4";
|
|
9
|
+
|
|
10
|
+
// ../wevu/package.json
|
|
11
|
+
var version2 = "1.0.1";
|
|
12
|
+
|
|
13
|
+
// src/enums.ts
|
|
14
|
+
var TemplateName = /* @__PURE__ */ ((TemplateName2) => {
|
|
15
|
+
TemplateName2["default"] = "default";
|
|
16
|
+
TemplateName2["wevu"] = "wevu";
|
|
17
|
+
TemplateName2["tailwindcss"] = "tailwindcss";
|
|
18
|
+
TemplateName2["vant"] = "vant";
|
|
19
|
+
TemplateName2["tdesign"] = "tdesign";
|
|
20
|
+
TemplateName2["wevuTdesign"] = "wevu-tdesign";
|
|
21
|
+
return TemplateName2;
|
|
22
|
+
})(TemplateName || {});
|
|
23
|
+
|
|
24
|
+
// src/npm.ts
|
|
25
|
+
import https from "https";
|
|
26
|
+
function getLatestVersionFromNpm(packageName) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
29
|
+
https.get(url, (res) => {
|
|
30
|
+
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
31
|
+
res?.resume();
|
|
32
|
+
reject(new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let data = "";
|
|
36
|
+
res.setEncoding("utf8");
|
|
37
|
+
res.on("data", (chunk) => data += chunk);
|
|
38
|
+
res.on("end", () => {
|
|
39
|
+
try {
|
|
40
|
+
const json = JSON.parse(data);
|
|
41
|
+
if (!json.version || typeof json.version !== "string") {
|
|
42
|
+
reject(new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
resolve(json.version);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
reject(err);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
res.on("error", reject);
|
|
51
|
+
}).on("error", reject);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
55
|
+
try {
|
|
56
|
+
const resolved = await fetch(packageName);
|
|
57
|
+
if (!resolved) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return `${prefix}${resolved}`;
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/updateGitignore.ts
|
|
67
|
+
import logger from "@weapp-core/logger";
|
|
68
|
+
import path from "pathe";
|
|
69
|
+
|
|
70
|
+
// src/gitignore.ts
|
|
71
|
+
var DEFAULT_GITIGNORE = `# dependencies
|
|
72
|
+
node_modules
|
|
73
|
+
.pnp
|
|
74
|
+
.pnp.js
|
|
75
|
+
|
|
76
|
+
# testing
|
|
77
|
+
coverage
|
|
78
|
+
|
|
79
|
+
# next.js
|
|
80
|
+
.next/
|
|
81
|
+
out/
|
|
82
|
+
build
|
|
83
|
+
|
|
84
|
+
# misc
|
|
85
|
+
.DS_Store
|
|
86
|
+
*.pem
|
|
87
|
+
|
|
88
|
+
# debug
|
|
89
|
+
npm-debug.log*
|
|
90
|
+
yarn-debug.log*
|
|
91
|
+
yarn-error.log*
|
|
92
|
+
.pnpm-debug.log*
|
|
93
|
+
|
|
94
|
+
# local env files
|
|
95
|
+
.env.local
|
|
96
|
+
.env.development.local
|
|
97
|
+
.env.test.local
|
|
98
|
+
.env.production.local
|
|
99
|
+
|
|
100
|
+
# turbo
|
|
101
|
+
.turbo
|
|
102
|
+
|
|
103
|
+
dist
|
|
104
|
+
dist-plugin
|
|
105
|
+
dist-web
|
|
106
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
107
|
+
function normalizeLineEndings(value) {
|
|
108
|
+
return value.replace(/\r\n/g, "\n");
|
|
109
|
+
}
|
|
110
|
+
function trimTrailingBlankLines(lines) {
|
|
111
|
+
let end = lines.length;
|
|
112
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
113
|
+
end -= 1;
|
|
114
|
+
}
|
|
115
|
+
return lines.slice(0, end);
|
|
116
|
+
}
|
|
117
|
+
function ensureTrailingNewline(value) {
|
|
118
|
+
return value.endsWith("\n") ? value : `${value}
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
function mergeGitignore(existing) {
|
|
122
|
+
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
123
|
+
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
124
|
+
const merged = [...existingLines];
|
|
125
|
+
while (merged.length > 0 && merged[merged.length - 1] === "") {
|
|
126
|
+
merged.pop();
|
|
127
|
+
}
|
|
128
|
+
const seen = new Set(merged);
|
|
129
|
+
let appendedNonBlank = false;
|
|
130
|
+
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
131
|
+
const isBlank = line.length === 0;
|
|
132
|
+
if (isBlank) {
|
|
133
|
+
if (merged.length === 0 || merged[merged.length - 1] === "") {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
merged.push("");
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (seen.has(line)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (!appendedNonBlank && merged.length > 0 && merged[merged.length - 1] !== "") {
|
|
143
|
+
merged.push("");
|
|
144
|
+
}
|
|
145
|
+
merged.push(line);
|
|
146
|
+
seen.add(line);
|
|
147
|
+
appendedNonBlank = true;
|
|
148
|
+
}
|
|
149
|
+
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/utils/fs.ts
|
|
153
|
+
import fs from "fs-extra";
|
|
154
|
+
var FsReadError = class extends Error {
|
|
155
|
+
constructor(filepath, cause) {
|
|
156
|
+
super(`Failed to read ${filepath}`);
|
|
157
|
+
this.filepath = filepath;
|
|
158
|
+
this.cause = cause;
|
|
159
|
+
this.name = "FsReadError";
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var FsWriteError = class extends Error {
|
|
163
|
+
constructor(filepath, cause) {
|
|
164
|
+
super(`Failed to write ${filepath}`);
|
|
165
|
+
this.filepath = filepath;
|
|
166
|
+
this.cause = cause;
|
|
167
|
+
this.name = "FsWriteError";
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
async function readFileIfExists(filepath) {
|
|
171
|
+
try {
|
|
172
|
+
return await fs.readFile(filepath, "utf8");
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error?.code === "ENOENT") {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
throw new FsReadError(filepath, error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
181
|
+
try {
|
|
182
|
+
await fs.outputJSON(filepath, data, {
|
|
183
|
+
spaces
|
|
184
|
+
});
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw new FsWriteError(filepath, error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function writeFile(filepath, contents) {
|
|
190
|
+
try {
|
|
191
|
+
await fs.outputFile(filepath, contents, "utf8");
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new FsWriteError(filepath, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/updateGitignore.ts
|
|
198
|
+
async function updateGitIgnore(options) {
|
|
199
|
+
const { root, write = true } = options;
|
|
200
|
+
const gitignorePath = path.resolve(root, ".gitignore");
|
|
201
|
+
const existing = await readFileIfExists(gitignorePath);
|
|
202
|
+
const merged = mergeGitignore(existing);
|
|
203
|
+
if (write && merged !== (existing ?? "")) {
|
|
204
|
+
await writeFile(gitignorePath, merged);
|
|
205
|
+
logger.log(`\u2728 \u66F4\u65B0 ${path.relative(root, gitignorePath)} \u6210\u529F!`);
|
|
206
|
+
}
|
|
207
|
+
return merged;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/createProject.ts
|
|
211
|
+
var moduleDir = path2.dirname(fileURLToPath(import.meta.url));
|
|
212
|
+
async function ensureDotGitignore(root) {
|
|
213
|
+
const gitignorePath = path2.resolve(root, "gitignore");
|
|
214
|
+
const dotGitignorePath = path2.resolve(root, ".gitignore");
|
|
215
|
+
if (!await fs2.pathExists(gitignorePath)) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (await fs2.pathExists(dotGitignorePath)) {
|
|
219
|
+
await fs2.remove(gitignorePath);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await fs2.move(gitignorePath, dotGitignorePath);
|
|
223
|
+
}
|
|
224
|
+
function createEmptyPackageJson() {
|
|
225
|
+
return {
|
|
226
|
+
name: "weapp-vite-app",
|
|
227
|
+
homepage: "https://vite.icebreaker.top/",
|
|
228
|
+
type: "module",
|
|
229
|
+
scripts: {},
|
|
230
|
+
devDependencies: {}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
234
|
+
if (!pkgJson.devDependencies) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
238
|
+
if (resolved) {
|
|
239
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
240
|
+
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
241
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function upsertExistingDependencyVersion(pkgJson, packageName, resolvedVersion) {
|
|
245
|
+
if (pkgJson.dependencies?.[packageName]) {
|
|
246
|
+
pkgJson.dependencies[packageName] = resolvedVersion;
|
|
247
|
+
}
|
|
248
|
+
if (pkgJson.devDependencies?.[packageName]) {
|
|
249
|
+
pkgJson.devDependencies[packageName] = resolvedVersion;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
253
|
+
const targetTemplateDir = path2.resolve(moduleDir, "../templates", templateName);
|
|
254
|
+
if (!await fs2.pathExists(targetTemplateDir)) {
|
|
255
|
+
logger2.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
await fs2.copy(targetTemplateDir, targetDir);
|
|
259
|
+
const templatePackagePath = path2.resolve(targetTemplateDir, "package.json");
|
|
260
|
+
const packageJsonPath = path2.resolve(targetDir, "package.json");
|
|
261
|
+
await ensureDotGitignore(targetDir);
|
|
262
|
+
const pkgJson = await fs2.pathExists(templatePackagePath) ? await fs2.readJSON(templatePackagePath) : createEmptyPackageJson();
|
|
263
|
+
if (!pkgJson.devDependencies) {
|
|
264
|
+
pkgJson.devDependencies = {};
|
|
265
|
+
}
|
|
266
|
+
upsertExistingDependencyVersion(pkgJson, "weapp-vite", version);
|
|
267
|
+
upsertExistingDependencyVersion(pkgJson, "wevu", version2);
|
|
268
|
+
await upsertTailwindcssVersion(pkgJson);
|
|
269
|
+
await writeJsonFile(packageJsonPath, pkgJson);
|
|
270
|
+
await updateGitIgnore({ root: targetDir, write: true });
|
|
271
|
+
logger2.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export {
|
|
275
|
+
TemplateName,
|
|
276
|
+
createProject
|
|
277
|
+
};
|
package/dist/cli.cjs
CHANGED
|
@@ -33,55 +33,324 @@ __export(cli_exports, {
|
|
|
33
33
|
run: () => run
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(cli_exports);
|
|
36
|
+
|
|
37
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.8_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
|
|
38
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
39
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
|
|
41
|
+
// src/cli.ts
|
|
36
42
|
var import_node_path = __toESM(require("path"), 1);
|
|
37
43
|
var import_node_process = __toESM(require("process"), 1);
|
|
38
44
|
var import_prompts = require("@inquirer/prompts");
|
|
39
|
-
var
|
|
45
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
46
|
+
|
|
47
|
+
// src/createProject.ts
|
|
48
|
+
var import_node_url = require("url");
|
|
49
|
+
var import_logger2 = __toESM(require("@weapp-core/logger"), 1);
|
|
50
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
51
|
+
var import_pathe2 = __toESM(require("pathe"), 1);
|
|
52
|
+
|
|
53
|
+
// ../weapp-vite/package.json
|
|
54
|
+
var version = "6.1.4";
|
|
55
|
+
|
|
56
|
+
// ../wevu/package.json
|
|
57
|
+
var version2 = "1.0.1";
|
|
58
|
+
|
|
59
|
+
// src/npm.ts
|
|
60
|
+
var import_node_https = __toESM(require("https"), 1);
|
|
61
|
+
function getLatestVersionFromNpm(packageName) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
64
|
+
import_node_https.default.get(url, (res) => {
|
|
65
|
+
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
66
|
+
res?.resume();
|
|
67
|
+
reject(new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let data = "";
|
|
71
|
+
res.setEncoding("utf8");
|
|
72
|
+
res.on("data", (chunk) => data += chunk);
|
|
73
|
+
res.on("end", () => {
|
|
74
|
+
try {
|
|
75
|
+
const json = JSON.parse(data);
|
|
76
|
+
if (!json.version || typeof json.version !== "string") {
|
|
77
|
+
reject(new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
resolve(json.version);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
reject(err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
res.on("error", reject);
|
|
86
|
+
}).on("error", reject);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
90
|
+
try {
|
|
91
|
+
const resolved = await fetch(packageName);
|
|
92
|
+
if (!resolved) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return `${prefix}${resolved}`;
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/updateGitignore.ts
|
|
102
|
+
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
103
|
+
var import_pathe = __toESM(require("pathe"), 1);
|
|
104
|
+
|
|
105
|
+
// src/gitignore.ts
|
|
106
|
+
var DEFAULT_GITIGNORE = `# dependencies
|
|
107
|
+
node_modules
|
|
108
|
+
.pnp
|
|
109
|
+
.pnp.js
|
|
110
|
+
|
|
111
|
+
# testing
|
|
112
|
+
coverage
|
|
113
|
+
|
|
114
|
+
# next.js
|
|
115
|
+
.next/
|
|
116
|
+
out/
|
|
117
|
+
build
|
|
118
|
+
|
|
119
|
+
# misc
|
|
120
|
+
.DS_Store
|
|
121
|
+
*.pem
|
|
122
|
+
|
|
123
|
+
# debug
|
|
124
|
+
npm-debug.log*
|
|
125
|
+
yarn-debug.log*
|
|
126
|
+
yarn-error.log*
|
|
127
|
+
.pnpm-debug.log*
|
|
128
|
+
|
|
129
|
+
# local env files
|
|
130
|
+
.env.local
|
|
131
|
+
.env.development.local
|
|
132
|
+
.env.test.local
|
|
133
|
+
.env.production.local
|
|
134
|
+
|
|
135
|
+
# turbo
|
|
136
|
+
.turbo
|
|
137
|
+
|
|
138
|
+
dist
|
|
139
|
+
dist-plugin
|
|
140
|
+
dist-web
|
|
141
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
142
|
+
function normalizeLineEndings(value) {
|
|
143
|
+
return value.replace(/\r\n/g, "\n");
|
|
144
|
+
}
|
|
145
|
+
function trimTrailingBlankLines(lines) {
|
|
146
|
+
let end = lines.length;
|
|
147
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
148
|
+
end -= 1;
|
|
149
|
+
}
|
|
150
|
+
return lines.slice(0, end);
|
|
151
|
+
}
|
|
152
|
+
function ensureTrailingNewline(value) {
|
|
153
|
+
return value.endsWith("\n") ? value : `${value}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
function mergeGitignore(existing) {
|
|
157
|
+
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
158
|
+
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
159
|
+
const merged = [...existingLines];
|
|
160
|
+
while (merged.length > 0 && merged[merged.length - 1] === "") {
|
|
161
|
+
merged.pop();
|
|
162
|
+
}
|
|
163
|
+
const seen = new Set(merged);
|
|
164
|
+
let appendedNonBlank = false;
|
|
165
|
+
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
166
|
+
const isBlank = line.length === 0;
|
|
167
|
+
if (isBlank) {
|
|
168
|
+
if (merged.length === 0 || merged[merged.length - 1] === "") {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
merged.push("");
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (seen.has(line)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!appendedNonBlank && merged.length > 0 && merged[merged.length - 1] !== "") {
|
|
178
|
+
merged.push("");
|
|
179
|
+
}
|
|
180
|
+
merged.push(line);
|
|
181
|
+
seen.add(line);
|
|
182
|
+
appendedNonBlank = true;
|
|
183
|
+
}
|
|
184
|
+
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/utils/fs.ts
|
|
40
188
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
189
|
+
var FsReadError = class extends Error {
|
|
190
|
+
constructor(filepath, cause) {
|
|
191
|
+
super(`Failed to read ${filepath}`);
|
|
192
|
+
this.filepath = filepath;
|
|
193
|
+
this.cause = cause;
|
|
194
|
+
this.name = "FsReadError";
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var FsWriteError = class extends Error {
|
|
198
|
+
constructor(filepath, cause) {
|
|
199
|
+
super(`Failed to write ${filepath}`);
|
|
200
|
+
this.filepath = filepath;
|
|
201
|
+
this.cause = cause;
|
|
202
|
+
this.name = "FsWriteError";
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
async function readFileIfExists(filepath) {
|
|
206
|
+
try {
|
|
207
|
+
return await import_fs_extra.default.readFile(filepath, "utf8");
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (error?.code === "ENOENT") {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
throw new FsReadError(filepath, error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
216
|
+
try {
|
|
217
|
+
await import_fs_extra.default.outputJSON(filepath, data, {
|
|
218
|
+
spaces
|
|
219
|
+
});
|
|
220
|
+
} catch (error) {
|
|
221
|
+
throw new FsWriteError(filepath, error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function writeFile(filepath, contents) {
|
|
225
|
+
try {
|
|
226
|
+
await import_fs_extra.default.outputFile(filepath, contents, "utf8");
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw new FsWriteError(filepath, error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/updateGitignore.ts
|
|
233
|
+
async function updateGitIgnore(options) {
|
|
234
|
+
const { root, write = true } = options;
|
|
235
|
+
const gitignorePath = import_pathe.default.resolve(root, ".gitignore");
|
|
236
|
+
const existing = await readFileIfExists(gitignorePath);
|
|
237
|
+
const merged = mergeGitignore(existing);
|
|
238
|
+
if (write && merged !== (existing ?? "")) {
|
|
239
|
+
await writeFile(gitignorePath, merged);
|
|
240
|
+
import_logger.default.log(`\u2728 \u66F4\u65B0 ${import_pathe.default.relative(root, gitignorePath)} \u6210\u529F!`);
|
|
241
|
+
}
|
|
242
|
+
return merged;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/createProject.ts
|
|
246
|
+
var moduleDir = import_pathe2.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
247
|
+
async function ensureDotGitignore(root) {
|
|
248
|
+
const gitignorePath = import_pathe2.default.resolve(root, "gitignore");
|
|
249
|
+
const dotGitignorePath = import_pathe2.default.resolve(root, ".gitignore");
|
|
250
|
+
if (!await import_fs_extra2.default.pathExists(gitignorePath)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (await import_fs_extra2.default.pathExists(dotGitignorePath)) {
|
|
254
|
+
await import_fs_extra2.default.remove(gitignorePath);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
await import_fs_extra2.default.move(gitignorePath, dotGitignorePath);
|
|
258
|
+
}
|
|
259
|
+
function createEmptyPackageJson() {
|
|
260
|
+
return {
|
|
261
|
+
name: "weapp-vite-app",
|
|
262
|
+
homepage: "https://vite.icebreaker.top/",
|
|
263
|
+
type: "module",
|
|
264
|
+
scripts: {},
|
|
265
|
+
devDependencies: {}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
269
|
+
if (!pkgJson.devDependencies) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
273
|
+
if (resolved) {
|
|
274
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
275
|
+
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
276
|
+
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function upsertExistingDependencyVersion(pkgJson, packageName, resolvedVersion) {
|
|
280
|
+
if (pkgJson.dependencies?.[packageName]) {
|
|
281
|
+
pkgJson.dependencies[packageName] = resolvedVersion;
|
|
282
|
+
}
|
|
283
|
+
if (pkgJson.devDependencies?.[packageName]) {
|
|
284
|
+
pkgJson.devDependencies[packageName] = resolvedVersion;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
288
|
+
const targetTemplateDir = import_pathe2.default.resolve(moduleDir, "../templates", templateName);
|
|
289
|
+
if (!await import_fs_extra2.default.pathExists(targetTemplateDir)) {
|
|
290
|
+
import_logger2.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
await import_fs_extra2.default.copy(targetTemplateDir, targetDir);
|
|
294
|
+
const templatePackagePath = import_pathe2.default.resolve(targetTemplateDir, "package.json");
|
|
295
|
+
const packageJsonPath = import_pathe2.default.resolve(targetDir, "package.json");
|
|
296
|
+
await ensureDotGitignore(targetDir);
|
|
297
|
+
const pkgJson = await import_fs_extra2.default.pathExists(templatePackagePath) ? await import_fs_extra2.default.readJSON(templatePackagePath) : createEmptyPackageJson();
|
|
298
|
+
if (!pkgJson.devDependencies) {
|
|
299
|
+
pkgJson.devDependencies = {};
|
|
300
|
+
}
|
|
301
|
+
upsertExistingDependencyVersion(pkgJson, "weapp-vite", version);
|
|
302
|
+
upsertExistingDependencyVersion(pkgJson, "wevu", version2);
|
|
303
|
+
await upsertTailwindcssVersion(pkgJson);
|
|
304
|
+
await writeJsonFile(packageJsonPath, pkgJson);
|
|
305
|
+
await updateGitIgnore({ root: targetDir, write: true });
|
|
306
|
+
import_logger2.default.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/cli.ts
|
|
41
310
|
var cwd = import_node_process.default.cwd();
|
|
42
311
|
async function run() {
|
|
43
312
|
const [argTarget, argTemplate] = import_node_process.default.argv.slice(2);
|
|
44
313
|
const isArgMode = Boolean(argTarget);
|
|
45
314
|
const targetDir = isArgMode ? argTarget : await (0, import_prompts.input)({ message: "\u521B\u5EFA\u5E94\u7528\u7684\u76EE\u5F55", default: "my-app" });
|
|
46
315
|
const dir = import_node_path.default.resolve(cwd, targetDir);
|
|
47
|
-
const existed = await
|
|
316
|
+
const existed = await import_fs_extra3.default.exists(dir);
|
|
48
317
|
if (existed) {
|
|
49
318
|
const isOverwrite = isArgMode ? true : await (0, import_prompts.confirm)({ message: "\u76EE\u5F55\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F", default: false });
|
|
50
319
|
if (!isOverwrite) {
|
|
51
320
|
return;
|
|
52
321
|
}
|
|
53
322
|
}
|
|
54
|
-
const templateName = isArgMode ? argTemplate ??
|
|
323
|
+
const templateName = isArgMode ? argTemplate ?? "default" /* default */ : await (0, import_prompts.select)({
|
|
55
324
|
message: "\u9009\u62E9\u6A21\u677F",
|
|
56
325
|
choices: [
|
|
57
326
|
{
|
|
58
327
|
name: "\u9ED8\u8BA4\u6A21\u677F",
|
|
59
|
-
value:
|
|
328
|
+
value: "default" /* default */
|
|
60
329
|
},
|
|
61
330
|
{
|
|
62
331
|
name: "Wevu \u6A21\u677F (Vue SFC)",
|
|
63
|
-
value:
|
|
332
|
+
value: "wevu" /* wevu */
|
|
64
333
|
},
|
|
65
334
|
{
|
|
66
335
|
name: "Wevu + TDesign \u6A21\u677F (wevu + tdesign + tailwindcss)",
|
|
67
|
-
value:
|
|
336
|
+
value: "wevu-tdesign" /* wevuTdesign */
|
|
68
337
|
},
|
|
69
338
|
{
|
|
70
339
|
name: "\u96C6\u6210 Tailwindcss",
|
|
71
|
-
value:
|
|
340
|
+
value: "tailwindcss" /* tailwindcss */
|
|
72
341
|
},
|
|
73
342
|
{
|
|
74
343
|
name: "Vant \u6A21\u677F (vant + tailwindcss)",
|
|
75
|
-
value:
|
|
344
|
+
value: "vant" /* vant */
|
|
76
345
|
},
|
|
77
346
|
{
|
|
78
347
|
name: "TDesign \u6A21\u677F (tdesign + tailwindcss)",
|
|
79
|
-
value:
|
|
348
|
+
value: "tdesign" /* tdesign */
|
|
80
349
|
}
|
|
81
350
|
],
|
|
82
|
-
default:
|
|
351
|
+
default: "default" /* default */
|
|
83
352
|
});
|
|
84
|
-
await
|
|
353
|
+
await createProject(targetDir, templateName);
|
|
85
354
|
}
|
|
86
355
|
run().catch(
|
|
87
356
|
(err) => {
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProject
|
|
3
|
+
} from "./chunk-CI2UMYKK.js";
|
|
4
|
+
|
|
1
5
|
// src/cli.ts
|
|
2
6
|
import path from "path";
|
|
3
7
|
import process from "process";
|
|
4
8
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
5
|
-
import { createProject, TemplateName } from "@weapp-core/init";
|
|
6
9
|
import fs from "fs-extra";
|
|
7
10
|
var cwd = process.cwd();
|
|
8
11
|
async function run() {
|
|
@@ -17,35 +20,35 @@ async function run() {
|
|
|
17
20
|
return;
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
|
-
const templateName = isArgMode ? argTemplate ??
|
|
23
|
+
const templateName = isArgMode ? argTemplate ?? "default" /* default */ : await select({
|
|
21
24
|
message: "\u9009\u62E9\u6A21\u677F",
|
|
22
25
|
choices: [
|
|
23
26
|
{
|
|
24
27
|
name: "\u9ED8\u8BA4\u6A21\u677F",
|
|
25
|
-
value:
|
|
28
|
+
value: "default" /* default */
|
|
26
29
|
},
|
|
27
30
|
{
|
|
28
31
|
name: "Wevu \u6A21\u677F (Vue SFC)",
|
|
29
|
-
value:
|
|
32
|
+
value: "wevu" /* wevu */
|
|
30
33
|
},
|
|
31
34
|
{
|
|
32
35
|
name: "Wevu + TDesign \u6A21\u677F (wevu + tdesign + tailwindcss)",
|
|
33
|
-
value:
|
|
36
|
+
value: "wevu-tdesign" /* wevuTdesign */
|
|
34
37
|
},
|
|
35
38
|
{
|
|
36
39
|
name: "\u96C6\u6210 Tailwindcss",
|
|
37
|
-
value:
|
|
40
|
+
value: "tailwindcss" /* tailwindcss */
|
|
38
41
|
},
|
|
39
42
|
{
|
|
40
43
|
name: "Vant \u6A21\u677F (vant + tailwindcss)",
|
|
41
|
-
value:
|
|
44
|
+
value: "vant" /* vant */
|
|
42
45
|
},
|
|
43
46
|
{
|
|
44
47
|
name: "TDesign \u6A21\u677F (tdesign + tailwindcss)",
|
|
45
|
-
value:
|
|
48
|
+
value: "tdesign" /* tdesign */
|
|
46
49
|
}
|
|
47
50
|
],
|
|
48
|
-
default:
|
|
51
|
+
default: "default" /* default */
|
|
49
52
|
});
|
|
50
53
|
await createProject(targetDir, templateName);
|
|
51
54
|
}
|