create-weapp-vite 2.0.48 → 2.0.50
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/cli.d.ts +3 -2
- package/dist/cli.js +66 -69
- package/dist/index.d.ts +12 -10
- package/dist/index.js +2 -8
- package/dist/src-VWcsuvfM.js +366 -0
- package/package.json +18 -9
- package/dist/chunk-LIWR2QXJ.js +0 -412
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,73 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createProject
|
|
3
|
-
} from "./chunk-LIWR2QXJ.js";
|
|
4
|
-
|
|
5
|
-
// src/cli.ts
|
|
6
|
-
import path from "path";
|
|
7
|
-
import process from "process";
|
|
8
|
-
import { confirm, input, select } from "@inquirer/prompts";
|
|
1
|
+
import { n as TemplateName, t as createProject } from "./src-VWcsuvfM.js";
|
|
9
2
|
import logger from "@weapp-core/logger";
|
|
10
3
|
import fs from "fs-extra";
|
|
11
|
-
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { confirm, input, select } from "@inquirer/prompts";
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
const cwd = process.cwd();
|
|
12
9
|
async function run() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
10
|
+
const [argTarget, argTemplate] = process.argv.slice(2);
|
|
11
|
+
const isArgMode = Boolean(argTarget);
|
|
12
|
+
const targetDir = isArgMode ? argTarget : await input({
|
|
13
|
+
message: "创建应用的目录",
|
|
14
|
+
default: "my-app"
|
|
15
|
+
});
|
|
16
|
+
const dir = path.resolve(cwd, targetDir);
|
|
17
|
+
if (await fs.exists(dir)) {
|
|
18
|
+
if (!(isArgMode ? true : await confirm({
|
|
19
|
+
message: "目录已存在,是否覆盖?",
|
|
20
|
+
default: false
|
|
21
|
+
}))) return;
|
|
22
|
+
}
|
|
23
|
+
await createProject(targetDir, isArgMode ? argTemplate ?? TemplateName.default : await select({
|
|
24
|
+
message: "选择模板",
|
|
25
|
+
choices: [
|
|
26
|
+
{
|
|
27
|
+
name: "默认模板",
|
|
28
|
+
value: TemplateName.default
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "组件库模板 (lib 模式)",
|
|
32
|
+
value: TemplateName.lib
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "Wevu 模板 (Vue SFC)",
|
|
36
|
+
value: TemplateName.wevu
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "Wevu + TDesign 模板 (wevu + tdesign + tailwindcss)",
|
|
40
|
+
value: TemplateName.wevuTdesign
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "集成 Tailwindcss",
|
|
44
|
+
value: TemplateName.tailwindcss
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "Vant 模板 (vant + tailwindcss)",
|
|
48
|
+
value: TemplateName.vant
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "TDesign 模板 (tdesign + tailwindcss)",
|
|
52
|
+
value: TemplateName.tdesign
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
default: TemplateName.default
|
|
56
|
+
}));
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
58
|
+
/**
|
|
59
|
+
* @description CLI 主入口执行 Promise(便于测试或外部调用)
|
|
60
|
+
*/
|
|
61
|
+
const runPromise = run().catch((err) => {
|
|
62
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
63
|
+
if (message.toLowerCase().includes("cancel")) {
|
|
64
|
+
logger.warn("✗ 已取消创建");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
logger.error("✗ 创建失败:", message);
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
export { run, runPromise };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
//#region src/enums.d.ts
|
|
1
2
|
declare enum TemplateName {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
default = "default",
|
|
4
|
+
wevu = "wevu",
|
|
5
|
+
tailwindcss = "tailwindcss",
|
|
6
|
+
vant = "vant",
|
|
7
|
+
tdesign = "tdesign",
|
|
8
|
+
wevuTdesign = "wevu-tdesign",
|
|
9
|
+
lib = "lib"
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/createProject.d.ts
|
|
11
13
|
/**
|
|
12
14
|
* @description 根据模板创建项目
|
|
13
15
|
*/
|
|
14
16
|
declare function createProject(targetDir?: string, templateName?: TemplateName): Promise<void>;
|
|
15
|
-
|
|
16
|
-
export { TemplateName, createProject };
|
|
17
|
+
//#endregion
|
|
18
|
+
export { TemplateName, createProject };
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import logger from "@weapp-core/logger";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
import https from "node:https";
|
|
6
|
+
//#region ../weapp-vite/package.json
|
|
7
|
+
var version$1 = "6.9.1";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region ../wevu/package.json
|
|
10
|
+
var version = "6.9.1";
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/enums.ts
|
|
13
|
+
let TemplateName = /* @__PURE__ */ function(TemplateName) {
|
|
14
|
+
TemplateName["default"] = "default";
|
|
15
|
+
TemplateName["wevu"] = "wevu";
|
|
16
|
+
TemplateName["tailwindcss"] = "tailwindcss";
|
|
17
|
+
TemplateName["vant"] = "vant";
|
|
18
|
+
TemplateName["tdesign"] = "tdesign";
|
|
19
|
+
TemplateName["wevuTdesign"] = "wevu-tdesign";
|
|
20
|
+
TemplateName["lib"] = "lib";
|
|
21
|
+
return TemplateName;
|
|
22
|
+
}({});
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/generated/catalog.ts
|
|
25
|
+
const TEMPLATE_CATALOG = {
|
|
26
|
+
"@babel/core": "^7.29.0",
|
|
27
|
+
"@babel/generator": "^7.29.1",
|
|
28
|
+
"@babel/parser": "^7.29.0",
|
|
29
|
+
"@babel/traverse": "^7.29.0",
|
|
30
|
+
"@babel/types": "^7.29.0",
|
|
31
|
+
"@egoist/tailwindcss-icons": "^1.9.2",
|
|
32
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
33
|
+
"@mini-types/alipay": "^3.0.14",
|
|
34
|
+
"@tailwindcss/postcss": "^4.2.1",
|
|
35
|
+
"@tailwindcss/vite": "^4.2.1",
|
|
36
|
+
"@types/node": "^25.5.0",
|
|
37
|
+
"@types/semver": "^7.7.1",
|
|
38
|
+
"@vant/weapp": "^1.11.7",
|
|
39
|
+
"@vue/compiler-core": "^3.5.30",
|
|
40
|
+
"@vue/language-core": "^3.2.5",
|
|
41
|
+
"antd-mini": "^3.4.3",
|
|
42
|
+
"bundle-require": "^5.1.0",
|
|
43
|
+
"class-variance-authority": "^0.7.1",
|
|
44
|
+
"comment-json": "^4.6.2",
|
|
45
|
+
"estree-walker": "^3.0.3",
|
|
46
|
+
"fs-extra": "^11.3.4",
|
|
47
|
+
"gm-crypto": "^0.1.12",
|
|
48
|
+
"lru-cache": "^11.2.7",
|
|
49
|
+
"magic-string": "^0.30.21",
|
|
50
|
+
"miniprogram-api-typings": "^5.1.2",
|
|
51
|
+
"miniprogram-automator": "^0.12.1",
|
|
52
|
+
"object-hash": "^3.0.0",
|
|
53
|
+
"pkg-types": "^2.3.0",
|
|
54
|
+
"sass-embedded": "^1.98.0",
|
|
55
|
+
"tdesign-miniprogram": "^1.12.3",
|
|
56
|
+
"ts-morph": "^27.0.2",
|
|
57
|
+
"vite-plugin-inspect": "^11.3.3",
|
|
58
|
+
"vue-tsc": "^3.2.5",
|
|
59
|
+
"weapp-tailwindcss": "^4.10.3",
|
|
60
|
+
autoprefixer: "^10.4.27",
|
|
61
|
+
clsx: "^2.1.1",
|
|
62
|
+
dayjs: "^1.11.20",
|
|
63
|
+
debug: "^4.4.3",
|
|
64
|
+
echarts: "^6.0.0",
|
|
65
|
+
esbuild: "^0.27.4",
|
|
66
|
+
fdir: "^6.5.0",
|
|
67
|
+
htmlparser2: "^10.1.0",
|
|
68
|
+
lodash: "^4.17.23",
|
|
69
|
+
merge: "^2.1.1",
|
|
70
|
+
pathe: "^2.0.3",
|
|
71
|
+
postcss: "^8.5.8",
|
|
72
|
+
sass: "^1.98.0",
|
|
73
|
+
tailwindcss: "^3.4.19",
|
|
74
|
+
tslib: "^2.8.1",
|
|
75
|
+
typescript: "^5.9.3",
|
|
76
|
+
vite: "8.0.0",
|
|
77
|
+
vue: "^3.5.30",
|
|
78
|
+
zod: "^4.3.6"
|
|
79
|
+
};
|
|
80
|
+
const TEMPLATE_NAMED_CATALOG = {
|
|
81
|
+
"tdesign-miniprogram-fixed": { "tdesign-miniprogram": "1.12.3" },
|
|
82
|
+
"weapp-tailwindcss-fixed": { "weapp-tailwindcss": "4.10.3" },
|
|
83
|
+
latest: {
|
|
84
|
+
"miniprogram-api-typings": "^5.1.2",
|
|
85
|
+
typescript: "latest"
|
|
86
|
+
},
|
|
87
|
+
tailwind4: { tailwindcss: "^4.2.1" }
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/npm.ts
|
|
91
|
+
/**
|
|
92
|
+
* @description 从 npm registry 获取包的最新版本号
|
|
93
|
+
*/
|
|
94
|
+
function getLatestVersionFromNpm(packageName) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
97
|
+
https.get(url, (res) => {
|
|
98
|
+
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
99
|
+
res?.resume();
|
|
100
|
+
reject(/* @__PURE__ */ new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let data = "";
|
|
104
|
+
res.setEncoding("utf8");
|
|
105
|
+
res.on("data", (chunk) => data += chunk);
|
|
106
|
+
res.on("end", () => {
|
|
107
|
+
try {
|
|
108
|
+
const json = JSON.parse(data);
|
|
109
|
+
if (!json.version || typeof json.version !== "string") {
|
|
110
|
+
reject(/* @__PURE__ */ new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
resolve(json.version);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
reject(err);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
res.on("error", reject);
|
|
119
|
+
}).on("error", reject);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
123
|
+
try {
|
|
124
|
+
const resolved = await fetch(packageName);
|
|
125
|
+
if (!resolved) return null;
|
|
126
|
+
return `${prefix}${resolved}`;
|
|
127
|
+
} catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/gitignore.ts
|
|
133
|
+
const DEFAULT_GITIGNORE = `# dependencies
|
|
134
|
+
node_modules
|
|
135
|
+
.pnp
|
|
136
|
+
.pnp.js
|
|
137
|
+
|
|
138
|
+
# testing
|
|
139
|
+
coverage
|
|
140
|
+
|
|
141
|
+
# next.js
|
|
142
|
+
.next/
|
|
143
|
+
out/
|
|
144
|
+
build
|
|
145
|
+
|
|
146
|
+
# misc
|
|
147
|
+
.DS_Store
|
|
148
|
+
*.pem
|
|
149
|
+
|
|
150
|
+
# debug
|
|
151
|
+
npm-debug.log*
|
|
152
|
+
yarn-debug.log*
|
|
153
|
+
yarn-error.log*
|
|
154
|
+
.pnpm-debug.log*
|
|
155
|
+
|
|
156
|
+
# local env files
|
|
157
|
+
.env.local
|
|
158
|
+
.env.development.local
|
|
159
|
+
.env.test.local
|
|
160
|
+
.env.production.local
|
|
161
|
+
|
|
162
|
+
# turbo
|
|
163
|
+
.turbo
|
|
164
|
+
|
|
165
|
+
dist
|
|
166
|
+
dist-plugin
|
|
167
|
+
dist-web
|
|
168
|
+
dist/web
|
|
169
|
+
vite.config.ts.timestamp-*.mjs
|
|
170
|
+
.weapp-vite/`;
|
|
171
|
+
const CRLF_RE = /\r\n/g;
|
|
172
|
+
function normalizeLineEndings(value) {
|
|
173
|
+
return value.replace(CRLF_RE, "\n");
|
|
174
|
+
}
|
|
175
|
+
function trimTrailingBlankLines(lines) {
|
|
176
|
+
let end = lines.length;
|
|
177
|
+
while (end > 0 && lines[end - 1] === "") end -= 1;
|
|
178
|
+
return lines.slice(0, end);
|
|
179
|
+
}
|
|
180
|
+
function ensureTrailingNewline(value) {
|
|
181
|
+
return value.endsWith("\n") ? value : `${value}\n`;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @description 合并已有 gitignore 内容(保持去重)
|
|
185
|
+
*/
|
|
186
|
+
function mergeGitignore(existing) {
|
|
187
|
+
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
188
|
+
const merged = [...normalizedExisting.length ? normalizedExisting.split("\n") : []];
|
|
189
|
+
while (merged.length > 0 && merged.at(-1) === "") merged.pop();
|
|
190
|
+
const seen = new Set(merged);
|
|
191
|
+
let appendedNonBlank = false;
|
|
192
|
+
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
193
|
+
if (line.length === 0) {
|
|
194
|
+
if (merged.length === 0 || merged.at(-1) === "") continue;
|
|
195
|
+
merged.push("");
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (seen.has(line)) continue;
|
|
199
|
+
if (!appendedNonBlank && merged.length > 0 && merged.at(-1) !== "") merged.push("");
|
|
200
|
+
merged.push(line);
|
|
201
|
+
seen.add(line);
|
|
202
|
+
appendedNonBlank = true;
|
|
203
|
+
}
|
|
204
|
+
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/utils/fs.ts
|
|
208
|
+
/**
|
|
209
|
+
* @description 文件读取错误
|
|
210
|
+
*/
|
|
211
|
+
var FsReadError = class extends Error {
|
|
212
|
+
constructor(filepath, cause) {
|
|
213
|
+
super(`Failed to read ${filepath}`);
|
|
214
|
+
this.filepath = filepath;
|
|
215
|
+
this.cause = cause;
|
|
216
|
+
this.name = "FsReadError";
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* @description 文件写入错误
|
|
221
|
+
*/
|
|
222
|
+
var FsWriteError = class extends Error {
|
|
223
|
+
constructor(filepath, cause) {
|
|
224
|
+
super(`Failed to write ${filepath}`);
|
|
225
|
+
this.filepath = filepath;
|
|
226
|
+
this.cause = cause;
|
|
227
|
+
this.name = "FsWriteError";
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
async function readFileIfExists(filepath) {
|
|
231
|
+
try {
|
|
232
|
+
return await fs.readFile(filepath, "utf8");
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error?.code === "ENOENT") return null;
|
|
235
|
+
throw new FsReadError(filepath, error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
239
|
+
try {
|
|
240
|
+
await fs.outputJSON(filepath, data, { spaces });
|
|
241
|
+
} catch (error) {
|
|
242
|
+
throw new FsWriteError(filepath, error);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function writeFile(filepath, contents) {
|
|
246
|
+
try {
|
|
247
|
+
await fs.outputFile(filepath, contents, "utf8");
|
|
248
|
+
} catch (error) {
|
|
249
|
+
throw new FsWriteError(filepath, error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/updateGitignore.ts
|
|
254
|
+
async function updateGitIgnore(options) {
|
|
255
|
+
const { root, write = true } = options;
|
|
256
|
+
const gitignorePath = path.resolve(root, ".gitignore");
|
|
257
|
+
const existing = await readFileIfExists(gitignorePath);
|
|
258
|
+
const merged = mergeGitignore(existing);
|
|
259
|
+
if (write && merged !== (existing ?? "")) {
|
|
260
|
+
await writeFile(gitignorePath, merged);
|
|
261
|
+
logger.log(`✨ 更新 ${path.relative(root, gitignorePath)} 成功!`);
|
|
262
|
+
}
|
|
263
|
+
return merged;
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/createProject.ts
|
|
267
|
+
const DIGIT_RE = /\d/;
|
|
268
|
+
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
269
|
+
const templateCatalogMap = { ...TEMPLATE_CATALOG };
|
|
270
|
+
const templateNamedCatalogMap = Object.fromEntries(Object.entries(TEMPLATE_NAMED_CATALOG).map(([name, deps]) => [name, { ...deps }]));
|
|
271
|
+
async function ensureDotGitignore(root) {
|
|
272
|
+
const gitignorePath = path.resolve(root, "gitignore");
|
|
273
|
+
const dotGitignorePath = path.resolve(root, ".gitignore");
|
|
274
|
+
if (!await fs.pathExists(gitignorePath)) return;
|
|
275
|
+
if (await fs.pathExists(dotGitignorePath)) {
|
|
276
|
+
await fs.remove(gitignorePath);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
await fs.move(gitignorePath, dotGitignorePath);
|
|
280
|
+
}
|
|
281
|
+
function createEmptyPackageJson() {
|
|
282
|
+
return {
|
|
283
|
+
name: "weapp-vite-app",
|
|
284
|
+
homepage: "https://vite.icebreaker.top/",
|
|
285
|
+
type: "module",
|
|
286
|
+
scripts: {},
|
|
287
|
+
devDependencies: {}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async function upsertTailwindcssVersion(pkgJson) {
|
|
291
|
+
if (!pkgJson.devDependencies) return;
|
|
292
|
+
const resolved = await latestVersion("weapp-tailwindcss");
|
|
293
|
+
if (resolved) pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
294
|
+
else if (!pkgJson.devDependencies["weapp-tailwindcss"]) pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
295
|
+
}
|
|
296
|
+
function upsertExistingDependencyVersion(pkgJson, packageName, resolvedVersion) {
|
|
297
|
+
if (pkgJson.dependencies?.[packageName]) pkgJson.dependencies[packageName] = resolvedVersion;
|
|
298
|
+
if (pkgJson.devDependencies?.[packageName]) pkgJson.devDependencies[packageName] = resolvedVersion;
|
|
299
|
+
}
|
|
300
|
+
function toCaretVersion(version) {
|
|
301
|
+
return version.startsWith("^") ? version : `^${version}`;
|
|
302
|
+
}
|
|
303
|
+
function resolveCatalogSpec(packageName, spec) {
|
|
304
|
+
if (!spec.startsWith("catalog:")) return spec;
|
|
305
|
+
const catalogName = spec.slice(8);
|
|
306
|
+
if (!catalogName) return templateCatalogMap[packageName] ?? spec;
|
|
307
|
+
const fromNamedCatalog = templateNamedCatalogMap[catalogName]?.[packageName];
|
|
308
|
+
if (fromNamedCatalog) {
|
|
309
|
+
if (fromNamedCatalog === "latest") return templateCatalogMap[packageName] ?? fromNamedCatalog;
|
|
310
|
+
return fromNamedCatalog;
|
|
311
|
+
}
|
|
312
|
+
return templateCatalogMap[packageName] ?? spec;
|
|
313
|
+
}
|
|
314
|
+
function normalizeTemplateDependencySpecs(pkgJson) {
|
|
315
|
+
for (const field of [
|
|
316
|
+
"dependencies",
|
|
317
|
+
"devDependencies",
|
|
318
|
+
"peerDependencies",
|
|
319
|
+
"optionalDependencies"
|
|
320
|
+
]) {
|
|
321
|
+
const deps = pkgJson[field];
|
|
322
|
+
if (!deps) continue;
|
|
323
|
+
for (const [name, rawSpec] of Object.entries(deps)) {
|
|
324
|
+
if (typeof rawSpec !== "string" || !rawSpec) continue;
|
|
325
|
+
const spec = rawSpec;
|
|
326
|
+
if (spec.startsWith("catalog:")) deps[name] = resolveCatalogSpec(name, spec);
|
|
327
|
+
else if (spec.startsWith("workspace:")) {
|
|
328
|
+
const workspaceSpec = spec.slice(10);
|
|
329
|
+
if (workspaceSpec && DIGIT_RE.test(workspaceSpec)) {
|
|
330
|
+
deps[name] = workspaceSpec;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const fromCatalog = templateCatalogMap[name];
|
|
334
|
+
if (fromCatalog) deps[name] = fromCatalog;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @description 根据模板创建项目
|
|
341
|
+
*/
|
|
342
|
+
async function createProject(targetDir = "", templateName = TemplateName.default) {
|
|
343
|
+
const targetTemplateDir = path.resolve(moduleDir, "../templates", templateName);
|
|
344
|
+
if (!await fs.pathExists(targetTemplateDir)) {
|
|
345
|
+
logger.warn(`没有找到 ${templateName} 模板!`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
await fs.copy(targetTemplateDir, targetDir);
|
|
349
|
+
const templatePackagePath = path.resolve(targetTemplateDir, "package.json");
|
|
350
|
+
const packageJsonPath = path.resolve(targetDir, "package.json");
|
|
351
|
+
await ensureDotGitignore(targetDir);
|
|
352
|
+
const pkgJson = await fs.pathExists(templatePackagePath) ? await fs.readJSON(templatePackagePath) : createEmptyPackageJson();
|
|
353
|
+
normalizeTemplateDependencySpecs(pkgJson);
|
|
354
|
+
if (!pkgJson.devDependencies) pkgJson.devDependencies = {};
|
|
355
|
+
upsertExistingDependencyVersion(pkgJson, "weapp-vite", toCaretVersion(version$1));
|
|
356
|
+
upsertExistingDependencyVersion(pkgJson, "wevu", toCaretVersion(version));
|
|
357
|
+
await upsertTailwindcssVersion(pkgJson);
|
|
358
|
+
await writeJsonFile(packageJsonPath, pkgJson);
|
|
359
|
+
await updateGitIgnore({
|
|
360
|
+
root: targetDir,
|
|
361
|
+
write: true
|
|
362
|
+
});
|
|
363
|
+
logger.log("✨ 创建模板成功!");
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
export { TemplateName as n, createProject as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.50",
|
|
5
5
|
"description": "create-weapp-vite",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -19,12 +19,24 @@
|
|
|
19
19
|
"weapp"
|
|
20
20
|
],
|
|
21
21
|
"sideEffects": false,
|
|
22
|
+
"weapp-vite-dev": {
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./src/index.ts"
|
|
25
|
+
},
|
|
26
|
+
"main": "./src/index.ts",
|
|
27
|
+
"module": "./src/index.ts",
|
|
28
|
+
"types": "./src/index.ts",
|
|
29
|
+
"bin": "./dev/bin.ts"
|
|
30
|
+
},
|
|
22
31
|
"exports": {
|
|
23
32
|
".": {
|
|
24
33
|
"types": "./dist/index.d.ts",
|
|
25
34
|
"import": "./dist/index.js"
|
|
26
35
|
}
|
|
27
36
|
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
28
40
|
"bin": "./bin/create-weapp-vite.js",
|
|
29
41
|
"files": [
|
|
30
42
|
"bin",
|
|
@@ -35,24 +47,21 @@
|
|
|
35
47
|
"node": "^20.19.0 || >=22.12.0"
|
|
36
48
|
},
|
|
37
49
|
"dependencies": {
|
|
38
|
-
"@inquirer/prompts": "^8.3.
|
|
50
|
+
"@inquirer/prompts": "^8.3.2",
|
|
39
51
|
"fs-extra": "^11.3.4",
|
|
40
52
|
"pathe": "^2.0.3",
|
|
41
53
|
"pkg-types": "^2.3.0",
|
|
42
|
-
"@weapp-core/logger": "^3.1.
|
|
54
|
+
"@weapp-core/logger": "^3.1.1"
|
|
43
55
|
},
|
|
44
56
|
"scripts": {
|
|
45
57
|
"catalog:sync": "node --import tsx scripts/generate-template-catalog.ts",
|
|
46
|
-
"dev": "
|
|
47
|
-
"build": "
|
|
58
|
+
"dev": "tsdown -w --sourcemap",
|
|
59
|
+
"build": "tsdown",
|
|
48
60
|
"test": "vitest run",
|
|
49
61
|
"test:dev": "vitest",
|
|
50
62
|
"typecheck": "tsc --noEmit",
|
|
51
63
|
"release": "pnpm publish",
|
|
52
64
|
"lint": "eslint .",
|
|
53
65
|
"lint:fix": "eslint . --fix"
|
|
54
|
-
}
|
|
55
|
-
"main": "./dist/index.js",
|
|
56
|
-
"module": "./dist/index.js",
|
|
57
|
-
"types": "./dist/index.d.ts"
|
|
66
|
+
}
|
|
58
67
|
}
|
package/dist/chunk-LIWR2QXJ.js
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
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.8.0";
|
|
9
|
-
|
|
10
|
-
// ../wevu/package.json
|
|
11
|
-
var version2 = "6.8.0";
|
|
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
|
-
TemplateName2["lib"] = "lib";
|
|
22
|
-
return TemplateName2;
|
|
23
|
-
})(TemplateName || {});
|
|
24
|
-
|
|
25
|
-
// src/generated/catalog.ts
|
|
26
|
-
var TEMPLATE_CATALOG = {
|
|
27
|
-
"@babel/core": "^7.29.0",
|
|
28
|
-
"@babel/generator": "^7.29.1",
|
|
29
|
-
"@babel/parser": "^7.29.0",
|
|
30
|
-
"@babel/traverse": "^7.29.0",
|
|
31
|
-
"@babel/types": "^7.29.0",
|
|
32
|
-
"@egoist/tailwindcss-icons": "^1.9.2",
|
|
33
|
-
"@iconify-json/mdi": "^1.2.3",
|
|
34
|
-
"@mini-types/alipay": "^3.0.14",
|
|
35
|
-
"@tailwindcss/postcss": "^4.2.1",
|
|
36
|
-
"@tailwindcss/vite": "^4.2.1",
|
|
37
|
-
"@types/node": "^25.5.0",
|
|
38
|
-
"@types/semver": "^7.7.1",
|
|
39
|
-
"@vant/weapp": "^1.11.7",
|
|
40
|
-
"@vue/compiler-core": "^3.5.30",
|
|
41
|
-
"@vue/language-core": "^3.2.5",
|
|
42
|
-
"antd-mini": "^3.4.3",
|
|
43
|
-
"bundle-require": "^5.1.0",
|
|
44
|
-
"class-variance-authority": "^0.7.1",
|
|
45
|
-
"comment-json": "^4.6.2",
|
|
46
|
-
"estree-walker": "^3.0.3",
|
|
47
|
-
"fs-extra": "^11.3.4",
|
|
48
|
-
"gm-crypto": "^0.1.12",
|
|
49
|
-
"lru-cache": "^11.2.6",
|
|
50
|
-
"magic-string": "^0.30.21",
|
|
51
|
-
"miniprogram-api-typings": "^5.1.2",
|
|
52
|
-
"miniprogram-automator": "^0.12.1",
|
|
53
|
-
"object-hash": "^3.0.0",
|
|
54
|
-
"pkg-types": "^2.3.0",
|
|
55
|
-
"sass-embedded": "^1.98.0",
|
|
56
|
-
"tdesign-miniprogram": "^1.12.3",
|
|
57
|
-
"ts-morph": "^27.0.2",
|
|
58
|
-
"vite-plugin-inspect": "^11.3.3",
|
|
59
|
-
"vue-tsc": "^3.2.5",
|
|
60
|
-
"weapp-tailwindcss": "^4.10.3",
|
|
61
|
-
autoprefixer: "^10.4.27",
|
|
62
|
-
clsx: "^2.1.1",
|
|
63
|
-
dayjs: "^1.11.20",
|
|
64
|
-
debug: "^4.4.3",
|
|
65
|
-
echarts: "^6.0.0",
|
|
66
|
-
esbuild: "^0.27.4",
|
|
67
|
-
fdir: "^6.5.0",
|
|
68
|
-
htmlparser2: "^10.1.0",
|
|
69
|
-
lodash: "^4.17.23",
|
|
70
|
-
merge: "^2.1.1",
|
|
71
|
-
pathe: "^2.0.3",
|
|
72
|
-
postcss: "^8.5.8",
|
|
73
|
-
sass: "^1.98.0",
|
|
74
|
-
tailwindcss: "^3.4.19",
|
|
75
|
-
tslib: "^2.8.1",
|
|
76
|
-
typescript: "^5.9.3",
|
|
77
|
-
vite: "8.0.0",
|
|
78
|
-
vue: "^3.5.30",
|
|
79
|
-
zod: "^4.3.6"
|
|
80
|
-
};
|
|
81
|
-
var TEMPLATE_NAMED_CATALOG = {
|
|
82
|
-
"tdesign-miniprogram-fixed": {
|
|
83
|
-
"tdesign-miniprogram": "1.12.3"
|
|
84
|
-
},
|
|
85
|
-
"weapp-tailwindcss-fixed": {
|
|
86
|
-
"weapp-tailwindcss": "4.10.3"
|
|
87
|
-
},
|
|
88
|
-
latest: {
|
|
89
|
-
"miniprogram-api-typings": "^5.1.2",
|
|
90
|
-
typescript: "latest"
|
|
91
|
-
},
|
|
92
|
-
tailwind4: {
|
|
93
|
-
tailwindcss: "^4.2.1"
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/npm.ts
|
|
98
|
-
import https from "https";
|
|
99
|
-
function getLatestVersionFromNpm(packageName) {
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
102
|
-
https.get(url, (res) => {
|
|
103
|
-
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
104
|
-
res?.resume();
|
|
105
|
-
reject(new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
let data = "";
|
|
109
|
-
res.setEncoding("utf8");
|
|
110
|
-
res.on("data", (chunk) => data += chunk);
|
|
111
|
-
res.on("end", () => {
|
|
112
|
-
try {
|
|
113
|
-
const json = JSON.parse(data);
|
|
114
|
-
if (!json.version || typeof json.version !== "string") {
|
|
115
|
-
reject(new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
resolve(json.version);
|
|
119
|
-
} catch (err) {
|
|
120
|
-
reject(err);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
res.on("error", reject);
|
|
124
|
-
}).on("error", reject);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
128
|
-
try {
|
|
129
|
-
const resolved = await fetch(packageName);
|
|
130
|
-
if (!resolved) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
return `${prefix}${resolved}`;
|
|
134
|
-
} catch {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/updateGitignore.ts
|
|
140
|
-
import logger from "@weapp-core/logger";
|
|
141
|
-
import path from "pathe";
|
|
142
|
-
|
|
143
|
-
// src/gitignore.ts
|
|
144
|
-
var DEFAULT_GITIGNORE = `# dependencies
|
|
145
|
-
node_modules
|
|
146
|
-
.pnp
|
|
147
|
-
.pnp.js
|
|
148
|
-
|
|
149
|
-
# testing
|
|
150
|
-
coverage
|
|
151
|
-
|
|
152
|
-
# next.js
|
|
153
|
-
.next/
|
|
154
|
-
out/
|
|
155
|
-
build
|
|
156
|
-
|
|
157
|
-
# misc
|
|
158
|
-
.DS_Store
|
|
159
|
-
*.pem
|
|
160
|
-
|
|
161
|
-
# debug
|
|
162
|
-
npm-debug.log*
|
|
163
|
-
yarn-debug.log*
|
|
164
|
-
yarn-error.log*
|
|
165
|
-
.pnpm-debug.log*
|
|
166
|
-
|
|
167
|
-
# local env files
|
|
168
|
-
.env.local
|
|
169
|
-
.env.development.local
|
|
170
|
-
.env.test.local
|
|
171
|
-
.env.production.local
|
|
172
|
-
|
|
173
|
-
# turbo
|
|
174
|
-
.turbo
|
|
175
|
-
|
|
176
|
-
dist
|
|
177
|
-
dist-plugin
|
|
178
|
-
dist-web
|
|
179
|
-
dist/web
|
|
180
|
-
vite.config.ts.timestamp-*.mjs
|
|
181
|
-
.weapp-vite/`;
|
|
182
|
-
var CRLF_RE = /\r\n/g;
|
|
183
|
-
function normalizeLineEndings(value) {
|
|
184
|
-
return value.replace(CRLF_RE, "\n");
|
|
185
|
-
}
|
|
186
|
-
function trimTrailingBlankLines(lines) {
|
|
187
|
-
let end = lines.length;
|
|
188
|
-
while (end > 0 && lines[end - 1] === "") {
|
|
189
|
-
end -= 1;
|
|
190
|
-
}
|
|
191
|
-
return lines.slice(0, end);
|
|
192
|
-
}
|
|
193
|
-
function ensureTrailingNewline(value) {
|
|
194
|
-
return value.endsWith("\n") ? value : `${value}
|
|
195
|
-
`;
|
|
196
|
-
}
|
|
197
|
-
function mergeGitignore(existing) {
|
|
198
|
-
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
199
|
-
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
200
|
-
const merged = [...existingLines];
|
|
201
|
-
while (merged.length > 0 && merged.at(-1) === "") {
|
|
202
|
-
merged.pop();
|
|
203
|
-
}
|
|
204
|
-
const seen = new Set(merged);
|
|
205
|
-
let appendedNonBlank = false;
|
|
206
|
-
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
207
|
-
const isBlank = line.length === 0;
|
|
208
|
-
if (isBlank) {
|
|
209
|
-
if (merged.length === 0 || merged.at(-1) === "") {
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
merged.push("");
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (seen.has(line)) {
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if (!appendedNonBlank && merged.length > 0 && merged.at(-1) !== "") {
|
|
219
|
-
merged.push("");
|
|
220
|
-
}
|
|
221
|
-
merged.push(line);
|
|
222
|
-
seen.add(line);
|
|
223
|
-
appendedNonBlank = true;
|
|
224
|
-
}
|
|
225
|
-
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/utils/fs.ts
|
|
229
|
-
import fs from "fs-extra";
|
|
230
|
-
var FsReadError = class extends Error {
|
|
231
|
-
constructor(filepath, cause) {
|
|
232
|
-
super(`Failed to read ${filepath}`);
|
|
233
|
-
this.filepath = filepath;
|
|
234
|
-
this.cause = cause;
|
|
235
|
-
this.name = "FsReadError";
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
var FsWriteError = class extends Error {
|
|
239
|
-
constructor(filepath, cause) {
|
|
240
|
-
super(`Failed to write ${filepath}`);
|
|
241
|
-
this.filepath = filepath;
|
|
242
|
-
this.cause = cause;
|
|
243
|
-
this.name = "FsWriteError";
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
async function readFileIfExists(filepath) {
|
|
247
|
-
try {
|
|
248
|
-
return await fs.readFile(filepath, "utf8");
|
|
249
|
-
} catch (error) {
|
|
250
|
-
if (error?.code === "ENOENT") {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
throw new FsReadError(filepath, error);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
257
|
-
try {
|
|
258
|
-
await fs.outputJSON(filepath, data, {
|
|
259
|
-
spaces
|
|
260
|
-
});
|
|
261
|
-
} catch (error) {
|
|
262
|
-
throw new FsWriteError(filepath, error);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
async function writeFile(filepath, contents) {
|
|
266
|
-
try {
|
|
267
|
-
await fs.outputFile(filepath, contents, "utf8");
|
|
268
|
-
} catch (error) {
|
|
269
|
-
throw new FsWriteError(filepath, error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/updateGitignore.ts
|
|
274
|
-
async function updateGitIgnore(options) {
|
|
275
|
-
const { root, write = true } = options;
|
|
276
|
-
const gitignorePath = path.resolve(root, ".gitignore");
|
|
277
|
-
const existing = await readFileIfExists(gitignorePath);
|
|
278
|
-
const merged = mergeGitignore(existing);
|
|
279
|
-
if (write && merged !== (existing ?? "")) {
|
|
280
|
-
await writeFile(gitignorePath, merged);
|
|
281
|
-
logger.log(`\u2728 \u66F4\u65B0 ${path.relative(root, gitignorePath)} \u6210\u529F!`);
|
|
282
|
-
}
|
|
283
|
-
return merged;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// src/createProject.ts
|
|
287
|
-
var DIGIT_RE = /\d/;
|
|
288
|
-
var moduleDir = path2.dirname(fileURLToPath(import.meta.url));
|
|
289
|
-
var templateCatalogMap = { ...TEMPLATE_CATALOG };
|
|
290
|
-
var templateNamedCatalogMap = Object.fromEntries(
|
|
291
|
-
Object.entries(TEMPLATE_NAMED_CATALOG).map(([name, deps]) => [name, { ...deps }])
|
|
292
|
-
);
|
|
293
|
-
async function ensureDotGitignore(root) {
|
|
294
|
-
const gitignorePath = path2.resolve(root, "gitignore");
|
|
295
|
-
const dotGitignorePath = path2.resolve(root, ".gitignore");
|
|
296
|
-
if (!await fs2.pathExists(gitignorePath)) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (await fs2.pathExists(dotGitignorePath)) {
|
|
300
|
-
await fs2.remove(gitignorePath);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
await fs2.move(gitignorePath, dotGitignorePath);
|
|
304
|
-
}
|
|
305
|
-
function createEmptyPackageJson() {
|
|
306
|
-
return {
|
|
307
|
-
name: "weapp-vite-app",
|
|
308
|
-
homepage: "https://vite.icebreaker.top/",
|
|
309
|
-
type: "module",
|
|
310
|
-
scripts: {},
|
|
311
|
-
devDependencies: {}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
async function upsertTailwindcssVersion(pkgJson) {
|
|
315
|
-
if (!pkgJson.devDependencies) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const resolved = await latestVersion("weapp-tailwindcss");
|
|
319
|
-
if (resolved) {
|
|
320
|
-
pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
|
|
321
|
-
} else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
|
|
322
|
-
pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
function upsertExistingDependencyVersion(pkgJson, packageName, resolvedVersion) {
|
|
326
|
-
if (pkgJson.dependencies?.[packageName]) {
|
|
327
|
-
pkgJson.dependencies[packageName] = resolvedVersion;
|
|
328
|
-
}
|
|
329
|
-
if (pkgJson.devDependencies?.[packageName]) {
|
|
330
|
-
pkgJson.devDependencies[packageName] = resolvedVersion;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function toCaretVersion(version3) {
|
|
334
|
-
return version3.startsWith("^") ? version3 : `^${version3}`;
|
|
335
|
-
}
|
|
336
|
-
function resolveCatalogSpec(packageName, spec) {
|
|
337
|
-
if (!spec.startsWith("catalog:")) {
|
|
338
|
-
return spec;
|
|
339
|
-
}
|
|
340
|
-
const catalogName = spec.slice("catalog:".length);
|
|
341
|
-
if (!catalogName) {
|
|
342
|
-
return templateCatalogMap[packageName] ?? spec;
|
|
343
|
-
}
|
|
344
|
-
const fromNamedCatalog = templateNamedCatalogMap[catalogName]?.[packageName];
|
|
345
|
-
if (fromNamedCatalog) {
|
|
346
|
-
if (fromNamedCatalog === "latest") {
|
|
347
|
-
return templateCatalogMap[packageName] ?? fromNamedCatalog;
|
|
348
|
-
}
|
|
349
|
-
return fromNamedCatalog;
|
|
350
|
-
}
|
|
351
|
-
return templateCatalogMap[packageName] ?? spec;
|
|
352
|
-
}
|
|
353
|
-
function normalizeTemplateDependencySpecs(pkgJson) {
|
|
354
|
-
const fields = [
|
|
355
|
-
"dependencies",
|
|
356
|
-
"devDependencies",
|
|
357
|
-
"peerDependencies",
|
|
358
|
-
"optionalDependencies"
|
|
359
|
-
];
|
|
360
|
-
for (const field of fields) {
|
|
361
|
-
const deps = pkgJson[field];
|
|
362
|
-
if (!deps) {
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
for (const [name, rawSpec] of Object.entries(deps)) {
|
|
366
|
-
if (typeof rawSpec !== "string" || !rawSpec) {
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
const spec = rawSpec;
|
|
370
|
-
if (spec.startsWith("catalog:")) {
|
|
371
|
-
deps[name] = resolveCatalogSpec(name, spec);
|
|
372
|
-
} else if (spec.startsWith("workspace:")) {
|
|
373
|
-
const workspaceSpec = spec.slice("workspace:".length);
|
|
374
|
-
if (workspaceSpec && DIGIT_RE.test(workspaceSpec)) {
|
|
375
|
-
deps[name] = workspaceSpec;
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
const fromCatalog = templateCatalogMap[name];
|
|
379
|
-
if (fromCatalog) {
|
|
380
|
-
deps[name] = fromCatalog;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
async function createProject(targetDir = "", templateName = "default" /* default */) {
|
|
387
|
-
const targetTemplateDir = path2.resolve(moduleDir, "../templates", templateName);
|
|
388
|
-
if (!await fs2.pathExists(targetTemplateDir)) {
|
|
389
|
-
logger2.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
await fs2.copy(targetTemplateDir, targetDir);
|
|
393
|
-
const templatePackagePath = path2.resolve(targetTemplateDir, "package.json");
|
|
394
|
-
const packageJsonPath = path2.resolve(targetDir, "package.json");
|
|
395
|
-
await ensureDotGitignore(targetDir);
|
|
396
|
-
const pkgJson = await fs2.pathExists(templatePackagePath) ? await fs2.readJSON(templatePackagePath) : createEmptyPackageJson();
|
|
397
|
-
normalizeTemplateDependencySpecs(pkgJson);
|
|
398
|
-
if (!pkgJson.devDependencies) {
|
|
399
|
-
pkgJson.devDependencies = {};
|
|
400
|
-
}
|
|
401
|
-
upsertExistingDependencyVersion(pkgJson, "weapp-vite", toCaretVersion(version));
|
|
402
|
-
upsertExistingDependencyVersion(pkgJson, "wevu", toCaretVersion(version2));
|
|
403
|
-
await upsertTailwindcssVersion(pkgJson);
|
|
404
|
-
await writeJsonFile(packageJsonPath, pkgJson);
|
|
405
|
-
await updateGitIgnore({ root: targetDir, write: true });
|
|
406
|
-
logger2.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export {
|
|
410
|
-
TemplateName,
|
|
411
|
-
createProject
|
|
412
|
-
};
|