create-weapp-vite 2.0.47 → 2.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cli.d.ts +3 -2
  2. package/dist/cli.js +66 -69
  3. package/dist/index.d.ts +12 -10
  4. package/dist/index.js +2 -8
  5. package/dist/src-CSQ3j3_f.js +366 -0
  6. package/package.json +18 -9
  7. package/templates/default/gitignore +1 -0
  8. package/templates/default/package.json +1 -1
  9. package/templates/default/tsconfig.app.json +1 -9
  10. package/templates/lib/gitignore +1 -0
  11. package/templates/lib/package.json +1 -1
  12. package/templates/lib/tsconfig.app.json +1 -9
  13. package/templates/tailwindcss/gitignore +1 -0
  14. package/templates/tailwindcss/package.json +1 -1
  15. package/templates/tailwindcss/tsconfig.app.json +1 -9
  16. package/templates/tdesign/gitignore +1 -0
  17. package/templates/tdesign/package.json +1 -1
  18. package/templates/tdesign/tsconfig.app.json +1 -9
  19. package/templates/vant/gitignore +1 -0
  20. package/templates/vant/package.json +1 -1
  21. package/templates/vant/tsconfig.app.json +1 -9
  22. package/templates/wevu/README.md +1 -0
  23. package/templates/wevu/auto-import-components.json +2 -2
  24. package/templates/wevu/gitignore +1 -0
  25. package/templates/wevu/package.json +1 -1
  26. package/templates/wevu/src/app.vue +49 -7
  27. package/templates/wevu/src/components/InfoPanel/index.vue +52 -0
  28. package/templates/wevu/src/components/StatusPill/index.vue +42 -0
  29. package/templates/wevu/{components.d.ts → src/components.d.ts} +4 -4
  30. package/templates/wevu/src/packageA/pages/workspace/index.vue +137 -0
  31. package/templates/wevu/src/packageB/pages/settings/index.vue +131 -0
  32. package/templates/wevu/src/pages/index/index.vue +169 -304
  33. package/templates/wevu/src/pages/overview/index.vue +149 -0
  34. package/templates/wevu/{typed-components.d.ts → src/typed-components.d.ts} +6 -9
  35. package/templates/wevu/src/typed-router.d.ts +67 -0
  36. package/templates/wevu/tsconfig.app.json +2 -14
  37. package/templates/wevu/vite.config.ts +7 -5
  38. package/templates/wevu-tdesign/gitignore +1 -0
  39. package/templates/wevu-tdesign/package.json +1 -1
  40. package/templates/wevu-tdesign/src/typed-router.d.ts +75 -0
  41. package/templates/wevu-tdesign/src/vite-env.d.ts +0 -2
  42. package/templates/wevu-tdesign/tsconfig.app.json +2 -14
  43. package/templates/wevu-tdesign/vite.config.ts +7 -0
  44. package/dist/chunk-UECMRNKY.js +0 -411
  45. package/templates/wevu/src/components/HelloWorld/index.vue +0 -473
  46. package/templates/wevu/src/components/InfoBanner/index.vue +0 -79
  47. /package/templates/wevu-tdesign/{components.d.ts → src/components.d.ts} +0 -0
  48. /package/templates/wevu-tdesign/{typed-components.d.ts → src/typed-components.d.ts} +0 -0
@@ -6,18 +6,15 @@
6
6
  // 由 weapp-vite 自动生成,请勿编辑。
7
7
  declare module 'weapp-vite/typed-components' {
8
8
  export interface ComponentProps {
9
- HelloWorld: {
10
- readonly compact?: boolean;
11
- readonly features?: any[];
12
- readonly highlights?: any[];
13
- readonly subtitle?: string;
14
- readonly title?: string;
15
- };
16
- InfoBanner: {
17
- readonly badge?: string;
9
+ InfoPanel: {
18
10
  readonly description?: string;
11
+ readonly eyebrow?: string;
19
12
  readonly title?: string;
20
13
  };
14
+ StatusPill: {
15
+ readonly label?: string;
16
+ readonly tone?: string;
17
+ };
21
18
  }
22
19
  export type ComponentPropName = keyof ComponentProps;
23
20
  export type ComponentProp<Name extends string> = Name extends ComponentPropName ? ComponentProps[Name] : Record<string, any>;
@@ -0,0 +1,67 @@
1
+ /* eslint-disable */
2
+ // biome-ignore lint: disable
3
+ // oxlint-disable
4
+ // ------
5
+ // 由 weapp-vite 自动生成,请勿编辑。
6
+ import 'wevu/router';
7
+
8
+ declare module 'weapp-vite/auto-routes' {
9
+ export type AutoRoutesPages = [
10
+ "pages/index/index",
11
+ "pages/overview/index"
12
+ ];
13
+ export type AutoRoutesEntries = [
14
+ "pages/index/index",
15
+ "packageA/pages/workspace/index",
16
+ "packageB/pages/settings/index",
17
+ "pages/overview/index"
18
+ ];
19
+ export type AutoRoutesSubPackages = [
20
+ {
21
+ readonly root: "packageA";
22
+ readonly pages: [
23
+ "pages/workspace/index"
24
+ ];
25
+ [k: string]: unknown;
26
+ },
27
+ {
28
+ readonly root: "packageB";
29
+ readonly pages: [
30
+ "pages/settings/index"
31
+ ];
32
+ [k: string]: unknown;
33
+ }
34
+ ];
35
+ export type AutoRoutesSubPackage = AutoRoutesSubPackages[number];
36
+ export interface AutoRoutes {
37
+ readonly pages: AutoRoutesPages;
38
+ readonly entries: AutoRoutesEntries;
39
+ readonly subPackages: AutoRoutesSubPackages;
40
+ }
41
+ export type AutoRouteEntry = AutoRoutesEntries[number];
42
+ export type AutoRoutesRelativeUrl = `./${string}` | `../${string}`;
43
+ export type AutoRoutesAbsoluteUrl<Path extends string> = Path | `/${Path}` | `${Path}?${string}` | `/${Path}?${string}`;
44
+ export type AutoRoutesUrl = AutoRoutesAbsoluteUrl<AutoRouteEntry> | AutoRoutesRelativeUrl;
45
+ export type AutoRouteNavigateOption = {
46
+ readonly url: AutoRoutesUrl;
47
+ } & Record<string, any>;
48
+ export interface AutoRoutesWxRouter {
49
+ switchTab: (option: AutoRouteNavigateOption) => unknown;
50
+ reLaunch: (option: AutoRouteNavigateOption) => unknown;
51
+ redirectTo: (option: AutoRouteNavigateOption) => unknown;
52
+ navigateTo: (option: AutoRouteNavigateOption) => unknown;
53
+ navigateBack: (option?: Record<string, any>) => unknown;
54
+ }
55
+ export const routes: AutoRoutes;
56
+ export const pages: AutoRoutesPages;
57
+ export const entries: AutoRoutesEntries;
58
+ export const subPackages: AutoRoutesSubPackages;
59
+ export const wxRouter: AutoRoutesWxRouter;
60
+ export default routes;
61
+ }
62
+
63
+ declare module 'wevu/router' {
64
+ interface WevuTypedRouterRouteMap {
65
+ entries: import('weapp-vite/auto-routes').AutoRoutesEntries[number];
66
+ }
67
+ }
@@ -17,7 +17,7 @@
17
17
  "./src/*"
18
18
  ],
19
19
  "weapp-vite/typed-components": [
20
- "./typed-components.d.ts"
20
+ "./src/typed-components.d.ts"
21
21
  ]
22
22
  },
23
23
  "resolveJsonModule": true,
@@ -46,18 +46,6 @@
46
46
  "lib": "wevu"
47
47
  },
48
48
  "include": [
49
- "src/**/*.ts",
50
- "src/**/*.tsx",
51
- "src/**/*.js",
52
- "src/**/*.jsx",
53
- "src/**/*.mts",
54
- "src/**/*.cts",
55
- "src/**/*.vue",
56
- "src/**/*.json",
57
- "src/**/*.d.ts",
58
- "types/**/*.d.ts",
59
- "env.d.ts",
60
- "components.d.ts",
61
- "typed-components.d.ts"
49
+ "src/**/*"
62
50
  ]
63
51
  }
@@ -3,11 +3,13 @@ import { defineConfig } from 'weapp-vite/config'
3
3
  export default defineConfig(() => ({
4
4
  weapp: {
5
5
  srcRoot: 'src',
6
- autoImportComponents: {
7
- globs: ['components/**/*.vue', 'components/**/*.wxml'],
8
- typedComponents: true,
9
- vueComponents: true,
10
- vueComponentsModule: 'wevu',
6
+ autoRoutes: true,
7
+ autoImportComponents: true,
8
+ subPackages: {
9
+ packageA: {},
10
+ packageB: {
11
+ independent: true,
12
+ },
11
13
  },
12
14
  },
13
15
  // weapp-vite 内置的 Vue 支持会自动处理 .vue 文件,不需要额外插件
@@ -33,3 +33,4 @@ yarn-error.log*
33
33
  dist
34
34
  vite.config.ts.timestamp-*.mjs
35
35
  dist-web
36
+ .weapp-vite/
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite-wevu-tailwindcss-tdesign-template",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "private": true,
6
6
  "description": "weapp-vite + wevu (Vue SFC) 模板",
7
7
  "author": "ice breaker <1324318532@qq.com>",
@@ -0,0 +1,75 @@
1
+ /* eslint-disable */
2
+ // biome-ignore lint: disable
3
+ // oxlint-disable
4
+ // ------
5
+ // 由 weapp-vite 自动生成,请勿编辑。
6
+ import 'wevu/router';
7
+
8
+ declare module 'weapp-vite/auto-routes' {
9
+ export type AutoRoutesPages = [
10
+ "pages/index/index",
11
+ "pages/ability/index",
12
+ "pages/data/index",
13
+ "pages/form/index",
14
+ "pages/list/index"
15
+ ];
16
+ export type AutoRoutesEntries = [
17
+ "pages/index/index",
18
+ "pages/ability/index",
19
+ "pages/data/index",
20
+ "pages/form/index",
21
+ "pages/list/index",
22
+ "subpackages/ability/index",
23
+ "subpackages/lab/class-binding/index",
24
+ "subpackages/lab/index"
25
+ ];
26
+ export type AutoRoutesSubPackages = [
27
+ {
28
+ readonly root: "subpackages/ability";
29
+ readonly pages: [
30
+ "index"
31
+ ];
32
+ [k: string]: unknown;
33
+ },
34
+ {
35
+ readonly root: "subpackages/lab";
36
+ readonly pages: [
37
+ "class-binding/index",
38
+ "index"
39
+ ];
40
+ [k: string]: unknown;
41
+ }
42
+ ];
43
+ export type AutoRoutesSubPackage = AutoRoutesSubPackages[number];
44
+ export interface AutoRoutes {
45
+ readonly pages: AutoRoutesPages;
46
+ readonly entries: AutoRoutesEntries;
47
+ readonly subPackages: AutoRoutesSubPackages;
48
+ }
49
+ export type AutoRouteEntry = AutoRoutesEntries[number];
50
+ export type AutoRoutesRelativeUrl = `./${string}` | `../${string}`;
51
+ export type AutoRoutesAbsoluteUrl<Path extends string> = Path | `/${Path}` | `${Path}?${string}` | `/${Path}?${string}`;
52
+ export type AutoRoutesUrl = AutoRoutesAbsoluteUrl<AutoRouteEntry> | AutoRoutesRelativeUrl;
53
+ export type AutoRouteNavigateOption = {
54
+ readonly url: AutoRoutesUrl;
55
+ } & Record<string, any>;
56
+ export interface AutoRoutesWxRouter {
57
+ switchTab: (option: AutoRouteNavigateOption) => unknown;
58
+ reLaunch: (option: AutoRouteNavigateOption) => unknown;
59
+ redirectTo: (option: AutoRouteNavigateOption) => unknown;
60
+ navigateTo: (option: AutoRouteNavigateOption) => unknown;
61
+ navigateBack: (option?: Record<string, any>) => unknown;
62
+ }
63
+ export const routes: AutoRoutes;
64
+ export const pages: AutoRoutesPages;
65
+ export const entries: AutoRoutesEntries;
66
+ export const subPackages: AutoRoutesSubPackages;
67
+ export const wxRouter: AutoRoutesWxRouter;
68
+ export default routes;
69
+ }
70
+
71
+ declare module 'wevu/router' {
72
+ interface WevuTypedRouterRouteMap {
73
+ entries: import('weapp-vite/auto-routes').AutoRoutesEntries[number];
74
+ }
75
+ }
@@ -1,3 +1 @@
1
1
  /// <reference types="weapp-vite/client" />
2
- /// <reference path="../components.d.ts" />
3
- /// <reference path="../typed-components.d.ts" />
@@ -17,7 +17,7 @@
17
17
  "./src/*"
18
18
  ],
19
19
  "weapp-vite/typed-components": [
20
- "./typed-components.d.ts"
20
+ "./src/typed-components.d.ts"
21
21
  ],
22
22
  "tdesign-miniprogram/*": [
23
23
  "./node_modules/tdesign-miniprogram/miniprogram_dist/*"
@@ -49,18 +49,6 @@
49
49
  "lib": "wevu"
50
50
  },
51
51
  "include": [
52
- "src/**/*.ts",
53
- "src/**/*.tsx",
54
- "src/**/*.js",
55
- "src/**/*.jsx",
56
- "src/**/*.mts",
57
- "src/**/*.cts",
58
- "src/**/*.vue",
59
- "src/**/*.json",
60
- "src/**/*.d.ts",
61
- "types/**/*.d.ts",
62
- "env.d.ts",
63
- "components.d.ts",
64
- "typed-components.d.ts"
52
+ "src/**/*"
65
53
  ]
66
54
  }
@@ -1,10 +1,17 @@
1
+ import path from 'node:path'
1
2
  import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite'
2
3
  import { TDesignResolver } from 'weapp-vite/auto-import-components/resolvers'
3
4
  import { defineConfig } from 'weapp-vite/config'
4
5
 
5
6
  export default defineConfig({
7
+ resolve: {
8
+ alias: {
9
+ '@': path.resolve(import.meta.dirname, 'src'),
10
+ },
11
+ },
6
12
  weapp: {
7
13
  srcRoot: 'src',
14
+ autoRoutes: true,
8
15
  autoImportComponents: {
9
16
  resolvers: [TDesignResolver()],
10
17
  htmlCustomData: true,
@@ -1,411 +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.7.7";
9
-
10
- // ../wevu/package.json
11
- var version2 = "6.7.7";
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.4.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.1",
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.3",
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": "latest",
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
- var CRLF_RE = /\r\n/g;
182
- function normalizeLineEndings(value) {
183
- return value.replace(CRLF_RE, "\n");
184
- }
185
- function trimTrailingBlankLines(lines) {
186
- let end = lines.length;
187
- while (end > 0 && lines[end - 1] === "") {
188
- end -= 1;
189
- }
190
- return lines.slice(0, end);
191
- }
192
- function ensureTrailingNewline(value) {
193
- return value.endsWith("\n") ? value : `${value}
194
- `;
195
- }
196
- function mergeGitignore(existing) {
197
- const normalizedExisting = normalizeLineEndings(existing ?? "");
198
- const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
199
- const merged = [...existingLines];
200
- while (merged.length > 0 && merged.at(-1) === "") {
201
- merged.pop();
202
- }
203
- const seen = new Set(merged);
204
- let appendedNonBlank = false;
205
- for (const line of DEFAULT_GITIGNORE.split("\n")) {
206
- const isBlank = line.length === 0;
207
- if (isBlank) {
208
- if (merged.length === 0 || merged.at(-1) === "") {
209
- continue;
210
- }
211
- merged.push("");
212
- continue;
213
- }
214
- if (seen.has(line)) {
215
- continue;
216
- }
217
- if (!appendedNonBlank && merged.length > 0 && merged.at(-1) !== "") {
218
- merged.push("");
219
- }
220
- merged.push(line);
221
- seen.add(line);
222
- appendedNonBlank = true;
223
- }
224
- return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
225
- }
226
-
227
- // src/utils/fs.ts
228
- import fs from "fs-extra";
229
- var FsReadError = class extends Error {
230
- constructor(filepath, cause) {
231
- super(`Failed to read ${filepath}`);
232
- this.filepath = filepath;
233
- this.cause = cause;
234
- this.name = "FsReadError";
235
- }
236
- };
237
- var FsWriteError = class extends Error {
238
- constructor(filepath, cause) {
239
- super(`Failed to write ${filepath}`);
240
- this.filepath = filepath;
241
- this.cause = cause;
242
- this.name = "FsWriteError";
243
- }
244
- };
245
- async function readFileIfExists(filepath) {
246
- try {
247
- return await fs.readFile(filepath, "utf8");
248
- } catch (error) {
249
- if (error?.code === "ENOENT") {
250
- return null;
251
- }
252
- throw new FsReadError(filepath, error);
253
- }
254
- }
255
- async function writeJsonFile(filepath, data, spaces = 2) {
256
- try {
257
- await fs.outputJSON(filepath, data, {
258
- spaces
259
- });
260
- } catch (error) {
261
- throw new FsWriteError(filepath, error);
262
- }
263
- }
264
- async function writeFile(filepath, contents) {
265
- try {
266
- await fs.outputFile(filepath, contents, "utf8");
267
- } catch (error) {
268
- throw new FsWriteError(filepath, error);
269
- }
270
- }
271
-
272
- // src/updateGitignore.ts
273
- async function updateGitIgnore(options) {
274
- const { root, write = true } = options;
275
- const gitignorePath = path.resolve(root, ".gitignore");
276
- const existing = await readFileIfExists(gitignorePath);
277
- const merged = mergeGitignore(existing);
278
- if (write && merged !== (existing ?? "")) {
279
- await writeFile(gitignorePath, merged);
280
- logger.log(`\u2728 \u66F4\u65B0 ${path.relative(root, gitignorePath)} \u6210\u529F!`);
281
- }
282
- return merged;
283
- }
284
-
285
- // src/createProject.ts
286
- var DIGIT_RE = /\d/;
287
- var moduleDir = path2.dirname(fileURLToPath(import.meta.url));
288
- var templateCatalogMap = { ...TEMPLATE_CATALOG };
289
- var templateNamedCatalogMap = Object.fromEntries(
290
- Object.entries(TEMPLATE_NAMED_CATALOG).map(([name, deps]) => [name, { ...deps }])
291
- );
292
- async function ensureDotGitignore(root) {
293
- const gitignorePath = path2.resolve(root, "gitignore");
294
- const dotGitignorePath = path2.resolve(root, ".gitignore");
295
- if (!await fs2.pathExists(gitignorePath)) {
296
- return;
297
- }
298
- if (await fs2.pathExists(dotGitignorePath)) {
299
- await fs2.remove(gitignorePath);
300
- return;
301
- }
302
- await fs2.move(gitignorePath, dotGitignorePath);
303
- }
304
- function createEmptyPackageJson() {
305
- return {
306
- name: "weapp-vite-app",
307
- homepage: "https://vite.icebreaker.top/",
308
- type: "module",
309
- scripts: {},
310
- devDependencies: {}
311
- };
312
- }
313
- async function upsertTailwindcssVersion(pkgJson) {
314
- if (!pkgJson.devDependencies) {
315
- return;
316
- }
317
- const resolved = await latestVersion("weapp-tailwindcss");
318
- if (resolved) {
319
- pkgJson.devDependencies["weapp-tailwindcss"] = resolved;
320
- } else if (!pkgJson.devDependencies["weapp-tailwindcss"]) {
321
- pkgJson.devDependencies["weapp-tailwindcss"] = "^4.3.3";
322
- }
323
- }
324
- function upsertExistingDependencyVersion(pkgJson, packageName, resolvedVersion) {
325
- if (pkgJson.dependencies?.[packageName]) {
326
- pkgJson.dependencies[packageName] = resolvedVersion;
327
- }
328
- if (pkgJson.devDependencies?.[packageName]) {
329
- pkgJson.devDependencies[packageName] = resolvedVersion;
330
- }
331
- }
332
- function toCaretVersion(version3) {
333
- return version3.startsWith("^") ? version3 : `^${version3}`;
334
- }
335
- function resolveCatalogSpec(packageName, spec) {
336
- if (!spec.startsWith("catalog:")) {
337
- return spec;
338
- }
339
- const catalogName = spec.slice("catalog:".length);
340
- if (!catalogName) {
341
- return templateCatalogMap[packageName] ?? spec;
342
- }
343
- const fromNamedCatalog = templateNamedCatalogMap[catalogName]?.[packageName];
344
- if (fromNamedCatalog) {
345
- if (fromNamedCatalog === "latest") {
346
- return templateCatalogMap[packageName] ?? fromNamedCatalog;
347
- }
348
- return fromNamedCatalog;
349
- }
350
- return templateCatalogMap[packageName] ?? spec;
351
- }
352
- function normalizeTemplateDependencySpecs(pkgJson) {
353
- const fields = [
354
- "dependencies",
355
- "devDependencies",
356
- "peerDependencies",
357
- "optionalDependencies"
358
- ];
359
- for (const field of fields) {
360
- const deps = pkgJson[field];
361
- if (!deps) {
362
- continue;
363
- }
364
- for (const [name, rawSpec] of Object.entries(deps)) {
365
- if (typeof rawSpec !== "string" || !rawSpec) {
366
- continue;
367
- }
368
- const spec = rawSpec;
369
- if (spec.startsWith("catalog:")) {
370
- deps[name] = resolveCatalogSpec(name, spec);
371
- } else if (spec.startsWith("workspace:")) {
372
- const workspaceSpec = spec.slice("workspace:".length);
373
- if (workspaceSpec && DIGIT_RE.test(workspaceSpec)) {
374
- deps[name] = workspaceSpec;
375
- continue;
376
- }
377
- const fromCatalog = templateCatalogMap[name];
378
- if (fromCatalog) {
379
- deps[name] = fromCatalog;
380
- }
381
- }
382
- }
383
- }
384
- }
385
- async function createProject(targetDir = "", templateName = "default" /* default */) {
386
- const targetTemplateDir = path2.resolve(moduleDir, "../templates", templateName);
387
- if (!await fs2.pathExists(targetTemplateDir)) {
388
- logger2.warn(`\u6CA1\u6709\u627E\u5230 ${templateName} \u6A21\u677F!`);
389
- return;
390
- }
391
- await fs2.copy(targetTemplateDir, targetDir);
392
- const templatePackagePath = path2.resolve(targetTemplateDir, "package.json");
393
- const packageJsonPath = path2.resolve(targetDir, "package.json");
394
- await ensureDotGitignore(targetDir);
395
- const pkgJson = await fs2.pathExists(templatePackagePath) ? await fs2.readJSON(templatePackagePath) : createEmptyPackageJson();
396
- normalizeTemplateDependencySpecs(pkgJson);
397
- if (!pkgJson.devDependencies) {
398
- pkgJson.devDependencies = {};
399
- }
400
- upsertExistingDependencyVersion(pkgJson, "weapp-vite", toCaretVersion(version));
401
- upsertExistingDependencyVersion(pkgJson, "wevu", toCaretVersion(version2));
402
- await upsertTailwindcssVersion(pkgJson);
403
- await writeJsonFile(packageJsonPath, pkgJson);
404
- await updateGitIgnore({ root: targetDir, write: true });
405
- logger2.log("\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!");
406
- }
407
-
408
- export {
409
- TemplateName,
410
- createProject
411
- };