@weapp-core/init 1.0.9 → 1.1.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.
Files changed (32) hide show
  1. package/dist/index.cjs +246 -8
  2. package/dist/index.d.cts +2 -1
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +234 -3
  5. package/package.json +5 -3
  6. package/templates/default/package.json +34 -0
  7. package/templates/default/postcss.config.js +6 -0
  8. package/templates/default/project.config.json +42 -0
  9. package/templates/default/project.private.config.json +7 -0
  10. package/templates/default/src/app.json +20 -0
  11. package/templates/default/src/app.scss +3 -0
  12. package/templates/default/src/app.ts +18 -0
  13. package/templates/default/src/components/navigation-bar/navigation-bar.json +6 -0
  14. package/templates/default/src/components/navigation-bar/navigation-bar.scss +0 -0
  15. package/templates/default/src/components/navigation-bar/navigation-bar.ts +3 -0
  16. package/templates/default/src/components/navigation-bar/navigation-bar.wxml +0 -0
  17. package/templates/default/src/pages/index/index.json +6 -0
  18. package/templates/default/src/pages/index/index.scss +0 -0
  19. package/templates/default/src/pages/index/index.ts +3 -0
  20. package/templates/default/src/pages/index/index.wxml +1 -0
  21. package/templates/default/src/pages/logs/logs.json +6 -0
  22. package/templates/default/src/pages/logs/logs.scss +0 -0
  23. package/templates/default/src/pages/logs/logs.ts +3 -0
  24. package/templates/default/src/pages/logs/logs.wxml +0 -0
  25. package/templates/default/src/sitemap.json +10 -0
  26. package/templates/default/src/theme.json +5 -0
  27. package/templates/default/src/utils/util.ts +0 -0
  28. package/templates/default/tailwind.config.ts +17 -0
  29. package/templates/default/tsconfig.json +46 -0
  30. package/templates/default/tsconfig.node.json +13 -0
  31. package/templates/default/vite-env.d.ts +1 -0
  32. package/templates/default/vite.config.ts +28 -0
package/dist/index.cjs CHANGED
@@ -32,18 +32,245 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  createOrUpdatePackageJson: () => createOrUpdatePackageJson,
34
34
  createOrUpdateProjectConfig: () => createOrUpdateProjectConfig,
35
+ createProject: () => createProject,
35
36
  initConfig: () => initConfig,
36
37
  initTsDtsFile: () => initTsDtsFile,
37
38
  initTsJsonFiles: () => initTsJsonFiles,
38
39
  initViteConfigFile: () => initViteConfigFile
39
40
  });
40
41
  module.exports = __toCommonJS(src_exports);
41
- var import_node_path = __toESM(require("path"), 1);
42
+
43
+ // ../../node_modules/.pnpm/tsup@8.3.0_jiti@2.3.1_postcss@8.4.47_tsx@4.19.1_typescript@5.6.3_yaml@2.5.1/node_modules/tsup/assets/cjs_shims.js
44
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
45
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
46
+
47
+ // src/index.ts
42
48
  var import_node_process = __toESM(require("process"), 1);
49
+ var import_node_url = require("url");
43
50
  var import_logger = __toESM(require("@weapp-core/logger"), 1);
44
51
  var import_shared = require("@weapp-core/shared");
45
52
  var import_fs_extra = __toESM(require("fs-extra"), 1);
46
53
 
54
+ // ../../node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs
55
+ var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
56
+ function normalizeWindowsPath(input = "") {
57
+ if (!input) {
58
+ return input;
59
+ }
60
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
61
+ }
62
+ var _UNC_REGEX = /^[/\\]{2}/;
63
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
64
+ var _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
65
+ var _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
66
+ var sep = "/";
67
+ var delimiter = ":";
68
+ var normalize = function(path2) {
69
+ if (path2.length === 0) {
70
+ return ".";
71
+ }
72
+ path2 = normalizeWindowsPath(path2);
73
+ const isUNCPath = path2.match(_UNC_REGEX);
74
+ const isPathAbsolute = isAbsolute(path2);
75
+ const trailingSeparator = path2[path2.length - 1] === "/";
76
+ path2 = normalizeString(path2, !isPathAbsolute);
77
+ if (path2.length === 0) {
78
+ if (isPathAbsolute) {
79
+ return "/";
80
+ }
81
+ return trailingSeparator ? "./" : ".";
82
+ }
83
+ if (trailingSeparator) {
84
+ path2 += "/";
85
+ }
86
+ if (_DRIVE_LETTER_RE.test(path2)) {
87
+ path2 += "/";
88
+ }
89
+ if (isUNCPath) {
90
+ if (!isPathAbsolute) {
91
+ return `//./${path2}`;
92
+ }
93
+ return `//${path2}`;
94
+ }
95
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
96
+ };
97
+ var join = function(...arguments_) {
98
+ if (arguments_.length === 0) {
99
+ return ".";
100
+ }
101
+ let joined;
102
+ for (const argument of arguments_) {
103
+ if (argument && argument.length > 0) {
104
+ if (joined === void 0) {
105
+ joined = argument;
106
+ } else {
107
+ joined += `/${argument}`;
108
+ }
109
+ }
110
+ }
111
+ if (joined === void 0) {
112
+ return ".";
113
+ }
114
+ return normalize(joined.replace(/\/\/+/g, "/"));
115
+ };
116
+ function cwd() {
117
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
118
+ return process.cwd().replace(/\\/g, "/");
119
+ }
120
+ return "/";
121
+ }
122
+ var resolve = function(...arguments_) {
123
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
124
+ let resolvedPath = "";
125
+ let resolvedAbsolute = false;
126
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
127
+ const path2 = index >= 0 ? arguments_[index] : cwd();
128
+ if (!path2 || path2.length === 0) {
129
+ continue;
130
+ }
131
+ resolvedPath = `${path2}/${resolvedPath}`;
132
+ resolvedAbsolute = isAbsolute(path2);
133
+ }
134
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
135
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
136
+ return `/${resolvedPath}`;
137
+ }
138
+ return resolvedPath.length > 0 ? resolvedPath : ".";
139
+ };
140
+ function normalizeString(path2, allowAboveRoot) {
141
+ let res = "";
142
+ let lastSegmentLength = 0;
143
+ let lastSlash = -1;
144
+ let dots = 0;
145
+ let char = null;
146
+ for (let index = 0; index <= path2.length; ++index) {
147
+ if (index < path2.length) {
148
+ char = path2[index];
149
+ } else if (char === "/") {
150
+ break;
151
+ } else {
152
+ char = "/";
153
+ }
154
+ if (char === "/") {
155
+ if (lastSlash === index - 1 || dots === 1) ;
156
+ else if (dots === 2) {
157
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
158
+ if (res.length > 2) {
159
+ const lastSlashIndex = res.lastIndexOf("/");
160
+ if (lastSlashIndex === -1) {
161
+ res = "";
162
+ lastSegmentLength = 0;
163
+ } else {
164
+ res = res.slice(0, lastSlashIndex);
165
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
166
+ }
167
+ lastSlash = index;
168
+ dots = 0;
169
+ continue;
170
+ } else if (res.length > 0) {
171
+ res = "";
172
+ lastSegmentLength = 0;
173
+ lastSlash = index;
174
+ dots = 0;
175
+ continue;
176
+ }
177
+ }
178
+ if (allowAboveRoot) {
179
+ res += res.length > 0 ? "/.." : "..";
180
+ lastSegmentLength = 2;
181
+ }
182
+ } else {
183
+ if (res.length > 0) {
184
+ res += `/${path2.slice(lastSlash + 1, index)}`;
185
+ } else {
186
+ res = path2.slice(lastSlash + 1, index);
187
+ }
188
+ lastSegmentLength = index - lastSlash - 1;
189
+ }
190
+ lastSlash = index;
191
+ dots = 0;
192
+ } else if (char === "." && dots !== -1) {
193
+ ++dots;
194
+ } else {
195
+ dots = -1;
196
+ }
197
+ }
198
+ return res;
199
+ }
200
+ var isAbsolute = function(p) {
201
+ return _IS_ABSOLUTE_RE.test(p);
202
+ };
203
+ var toNamespacedPath = function(p) {
204
+ return normalizeWindowsPath(p);
205
+ };
206
+ var _EXTNAME_RE = /.(\.[^./]+)$/;
207
+ var extname = function(p) {
208
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
209
+ return match && match[1] || "";
210
+ };
211
+ var relative = function(from, to) {
212
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
213
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
214
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
215
+ return _to.join("/");
216
+ }
217
+ const _fromCopy = [..._from];
218
+ for (const segment of _fromCopy) {
219
+ if (_to[0] !== segment) {
220
+ break;
221
+ }
222
+ _from.shift();
223
+ _to.shift();
224
+ }
225
+ return [..._from.map(() => ".."), ..._to].join("/");
226
+ };
227
+ var dirname = function(p) {
228
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
229
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
230
+ segments[0] += "/";
231
+ }
232
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
233
+ };
234
+ var format = function(p) {
235
+ const segments = [p.root, p.dir, p.base ?? p.name + p.ext].filter(Boolean);
236
+ return normalizeWindowsPath(
237
+ p.root ? resolve(...segments) : segments.join("/")
238
+ );
239
+ };
240
+ var basename = function(p, extension) {
241
+ const lastSegment = normalizeWindowsPath(p).split("/").pop();
242
+ return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
243
+ };
244
+ var parse = function(p) {
245
+ const root = normalizeWindowsPath(p).split("/").shift() || "/";
246
+ const base = basename(p);
247
+ const extension = extname(base);
248
+ return {
249
+ root,
250
+ dir: dirname(p),
251
+ base,
252
+ ext: extension,
253
+ name: base.slice(0, base.length - extension.length)
254
+ };
255
+ };
256
+ var path = {
257
+ __proto__: null,
258
+ basename,
259
+ delimiter,
260
+ dirname,
261
+ extname,
262
+ format,
263
+ isAbsolute,
264
+ join,
265
+ normalize,
266
+ normalizeString,
267
+ parse,
268
+ relative,
269
+ resolve,
270
+ sep,
271
+ toNamespacedPath
272
+ };
273
+
47
274
  // src/context.ts
48
275
  function createContext() {
49
276
  return {
@@ -81,6 +308,7 @@ function createContext() {
81
308
  }
82
309
 
83
310
  // src/index.ts
311
+ var __dirname = path.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
84
312
  var ctx = createContext();
85
313
  async function createOrUpdateProjectConfig(options) {
86
314
  const { root, dest, cb, write, filename } = (0, import_shared.defu)(
@@ -91,7 +319,7 @@ async function createOrUpdateProjectConfig(options) {
91
319
  }
92
320
  );
93
321
  const projectConfigFilename = ctx.projectConfig.name = filename;
94
- const projectConfigPath = ctx.projectConfig.path = import_node_path.default.resolve(root, projectConfigFilename);
322
+ const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
95
323
  if (await import_fs_extra.default.exists(projectConfigPath)) {
96
324
  try {
97
325
  const projectConfig = await import_fs_extra.default.readJSON(projectConfigPath);
@@ -180,7 +408,7 @@ async function createOrUpdatePackageJson(options) {
180
408
  command: "weapp-vite"
181
409
  });
182
410
  const packageJsonFilename = ctx.packageJson.name = filename;
183
- const packageJsonPath = ctx.packageJson.path = import_node_path.default.resolve(root, packageJsonFilename);
411
+ const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
184
412
  let packageJson;
185
413
  if (await import_fs_extra.default.exists(packageJsonPath)) {
186
414
  packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
@@ -221,7 +449,7 @@ async function initViteConfigFile(options) {
221
449
  const { root, write = true } = options;
222
450
  const type = (0, import_shared.get)(ctx.packageJson.value, "type");
223
451
  const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
224
- const viteConfigFilePath = ctx.viteConfig.path = import_node_path.default.resolve(root, targetFilename);
452
+ const viteConfigFilePath = ctx.viteConfig.path = path.resolve(root, targetFilename);
225
453
  const viteConfigFileCode = ctx.viteConfig.value = `import { defineConfig } from 'weapp-vite/config'
226
454
 
227
455
  export default defineConfig({
@@ -239,7 +467,7 @@ export default defineConfig({
239
467
  async function initTsDtsFile(options) {
240
468
  const { root, write = true } = options;
241
469
  const targetFilename = "vite-env.d.ts";
242
- const viteDtsFilePath = import_node_path.default.resolve(root, targetFilename);
470
+ const viteDtsFilePath = path.resolve(root, targetFilename);
243
471
  const code = `/// <reference types="vite/client" />
244
472
  `;
245
473
  if (write) {
@@ -251,9 +479,9 @@ async function initTsDtsFile(options) {
251
479
  async function initTsJsonFiles(options) {
252
480
  const { root, write = true } = options;
253
481
  const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
254
- const tsJsonFilePath = ctx.tsconfig.path = import_node_path.default.resolve(root, tsJsonFilename);
482
+ const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
255
483
  const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
256
- const tsNodeJsonFilePath = ctx.tsconfigNode.path = import_node_path.default.resolve(root, tsNodeJsonFilename);
484
+ const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
257
485
  if (write) {
258
486
  const tsJsonValue = {
259
487
  compilerOptions: {
@@ -338,7 +566,7 @@ async function initTsJsonFiles(options) {
338
566
  }
339
567
  async function updateGitIgnore(options) {
340
568
  const { root, write = true } = options;
341
- const filepath = import_node_path.default.resolve(root, ".gitignore");
569
+ const filepath = path.resolve(root, ".gitignore");
342
570
  const data = `# dependencies
343
571
  node_modules
344
572
  .pnp
@@ -392,10 +620,20 @@ async function initConfig(options) {
392
620
  }
393
621
  return ctx;
394
622
  }
623
+ async function createProject(targetDir = "", templateDirName = "default") {
624
+ const targetTemplateDir = path.resolve(__dirname, "../templates", templateDirName);
625
+ if (await import_fs_extra.default.exists(targetTemplateDir)) {
626
+ await import_fs_extra.default.copy(targetTemplateDir, targetDir);
627
+ import_logger.default.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
628
+ } else {
629
+ import_logger.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateDirName} \u6A21\u677F!`);
630
+ }
631
+ }
395
632
  // Annotate the CommonJS export names for ESM import in node:
396
633
  0 && (module.exports = {
397
634
  createOrUpdatePackageJson,
398
635
  createOrUpdateProjectConfig,
636
+ createProject,
399
637
  initConfig,
400
638
  initTsDtsFile,
401
639
  initTsJsonFiles,
package/dist/index.d.cts CHANGED
@@ -70,5 +70,6 @@ declare function initConfig(options: {
70
70
  value: string;
71
71
  };
72
72
  }>;
73
+ declare function createProject(targetDir?: string, templateDirName?: string): Promise<void>;
73
74
 
74
- export { createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
75
+ export { createOrUpdatePackageJson, createOrUpdateProjectConfig, createProject, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
package/dist/index.d.ts CHANGED
@@ -70,5 +70,6 @@ declare function initConfig(options: {
70
70
  value: string;
71
71
  };
72
72
  }>;
73
+ declare function createProject(targetDir?: string, templateDirName?: string): Promise<void>;
73
74
 
74
- export { createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
75
+ export { createOrUpdatePackageJson, createOrUpdateProjectConfig, createProject, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
package/dist/index.js CHANGED
@@ -1,10 +1,230 @@
1
1
  // src/index.ts
2
- import path from "node:path";
3
- import process from "node:process";
2
+ import process2 from "node:process";
3
+ import { fileURLToPath } from "node:url";
4
4
  import logger from "@weapp-core/logger";
5
5
  import { defu, get, set } from "@weapp-core/shared";
6
6
  import fs from "fs-extra";
7
7
 
8
+ // ../../node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs
9
+ var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
10
+ function normalizeWindowsPath(input = "") {
11
+ if (!input) {
12
+ return input;
13
+ }
14
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
15
+ }
16
+ var _UNC_REGEX = /^[/\\]{2}/;
17
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
18
+ var _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
19
+ var _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
20
+ var sep = "/";
21
+ var delimiter = ":";
22
+ var normalize = function(path2) {
23
+ if (path2.length === 0) {
24
+ return ".";
25
+ }
26
+ path2 = normalizeWindowsPath(path2);
27
+ const isUNCPath = path2.match(_UNC_REGEX);
28
+ const isPathAbsolute = isAbsolute(path2);
29
+ const trailingSeparator = path2[path2.length - 1] === "/";
30
+ path2 = normalizeString(path2, !isPathAbsolute);
31
+ if (path2.length === 0) {
32
+ if (isPathAbsolute) {
33
+ return "/";
34
+ }
35
+ return trailingSeparator ? "./" : ".";
36
+ }
37
+ if (trailingSeparator) {
38
+ path2 += "/";
39
+ }
40
+ if (_DRIVE_LETTER_RE.test(path2)) {
41
+ path2 += "/";
42
+ }
43
+ if (isUNCPath) {
44
+ if (!isPathAbsolute) {
45
+ return `//./${path2}`;
46
+ }
47
+ return `//${path2}`;
48
+ }
49
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
50
+ };
51
+ var join = function(...arguments_) {
52
+ if (arguments_.length === 0) {
53
+ return ".";
54
+ }
55
+ let joined;
56
+ for (const argument of arguments_) {
57
+ if (argument && argument.length > 0) {
58
+ if (joined === void 0) {
59
+ joined = argument;
60
+ } else {
61
+ joined += `/${argument}`;
62
+ }
63
+ }
64
+ }
65
+ if (joined === void 0) {
66
+ return ".";
67
+ }
68
+ return normalize(joined.replace(/\/\/+/g, "/"));
69
+ };
70
+ function cwd() {
71
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
72
+ return process.cwd().replace(/\\/g, "/");
73
+ }
74
+ return "/";
75
+ }
76
+ var resolve = function(...arguments_) {
77
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
78
+ let resolvedPath = "";
79
+ let resolvedAbsolute = false;
80
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
81
+ const path2 = index >= 0 ? arguments_[index] : cwd();
82
+ if (!path2 || path2.length === 0) {
83
+ continue;
84
+ }
85
+ resolvedPath = `${path2}/${resolvedPath}`;
86
+ resolvedAbsolute = isAbsolute(path2);
87
+ }
88
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
89
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
90
+ return `/${resolvedPath}`;
91
+ }
92
+ return resolvedPath.length > 0 ? resolvedPath : ".";
93
+ };
94
+ function normalizeString(path2, allowAboveRoot) {
95
+ let res = "";
96
+ let lastSegmentLength = 0;
97
+ let lastSlash = -1;
98
+ let dots = 0;
99
+ let char = null;
100
+ for (let index = 0; index <= path2.length; ++index) {
101
+ if (index < path2.length) {
102
+ char = path2[index];
103
+ } else if (char === "/") {
104
+ break;
105
+ } else {
106
+ char = "/";
107
+ }
108
+ if (char === "/") {
109
+ if (lastSlash === index - 1 || dots === 1) ;
110
+ else if (dots === 2) {
111
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
112
+ if (res.length > 2) {
113
+ const lastSlashIndex = res.lastIndexOf("/");
114
+ if (lastSlashIndex === -1) {
115
+ res = "";
116
+ lastSegmentLength = 0;
117
+ } else {
118
+ res = res.slice(0, lastSlashIndex);
119
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
120
+ }
121
+ lastSlash = index;
122
+ dots = 0;
123
+ continue;
124
+ } else if (res.length > 0) {
125
+ res = "";
126
+ lastSegmentLength = 0;
127
+ lastSlash = index;
128
+ dots = 0;
129
+ continue;
130
+ }
131
+ }
132
+ if (allowAboveRoot) {
133
+ res += res.length > 0 ? "/.." : "..";
134
+ lastSegmentLength = 2;
135
+ }
136
+ } else {
137
+ if (res.length > 0) {
138
+ res += `/${path2.slice(lastSlash + 1, index)}`;
139
+ } else {
140
+ res = path2.slice(lastSlash + 1, index);
141
+ }
142
+ lastSegmentLength = index - lastSlash - 1;
143
+ }
144
+ lastSlash = index;
145
+ dots = 0;
146
+ } else if (char === "." && dots !== -1) {
147
+ ++dots;
148
+ } else {
149
+ dots = -1;
150
+ }
151
+ }
152
+ return res;
153
+ }
154
+ var isAbsolute = function(p) {
155
+ return _IS_ABSOLUTE_RE.test(p);
156
+ };
157
+ var toNamespacedPath = function(p) {
158
+ return normalizeWindowsPath(p);
159
+ };
160
+ var _EXTNAME_RE = /.(\.[^./]+)$/;
161
+ var extname = function(p) {
162
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
163
+ return match && match[1] || "";
164
+ };
165
+ var relative = function(from, to) {
166
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
167
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
168
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
169
+ return _to.join("/");
170
+ }
171
+ const _fromCopy = [..._from];
172
+ for (const segment of _fromCopy) {
173
+ if (_to[0] !== segment) {
174
+ break;
175
+ }
176
+ _from.shift();
177
+ _to.shift();
178
+ }
179
+ return [..._from.map(() => ".."), ..._to].join("/");
180
+ };
181
+ var dirname = function(p) {
182
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
183
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
184
+ segments[0] += "/";
185
+ }
186
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
187
+ };
188
+ var format = function(p) {
189
+ const segments = [p.root, p.dir, p.base ?? p.name + p.ext].filter(Boolean);
190
+ return normalizeWindowsPath(
191
+ p.root ? resolve(...segments) : segments.join("/")
192
+ );
193
+ };
194
+ var basename = function(p, extension) {
195
+ const lastSegment = normalizeWindowsPath(p).split("/").pop();
196
+ return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
197
+ };
198
+ var parse = function(p) {
199
+ const root = normalizeWindowsPath(p).split("/").shift() || "/";
200
+ const base = basename(p);
201
+ const extension = extname(base);
202
+ return {
203
+ root,
204
+ dir: dirname(p),
205
+ base,
206
+ ext: extension,
207
+ name: base.slice(0, base.length - extension.length)
208
+ };
209
+ };
210
+ var path = {
211
+ __proto__: null,
212
+ basename,
213
+ delimiter,
214
+ dirname,
215
+ extname,
216
+ format,
217
+ isAbsolute,
218
+ join,
219
+ normalize,
220
+ normalizeString,
221
+ parse,
222
+ relative,
223
+ resolve,
224
+ sep,
225
+ toNamespacedPath
226
+ };
227
+
8
228
  // src/context.ts
9
229
  function createContext() {
10
230
  return {
@@ -42,6 +262,7 @@ function createContext() {
42
262
  }
43
263
 
44
264
  // src/index.ts
265
+ var __dirname2 = path.dirname(fileURLToPath(import.meta.url));
45
266
  var ctx = createContext();
46
267
  async function createOrUpdateProjectConfig(options) {
47
268
  const { root, dest, cb, write, filename } = defu(
@@ -342,7 +563,7 @@ vite.config.ts.timestamp-*.mjs`;
342
563
  return data;
343
564
  }
344
565
  async function initConfig(options) {
345
- const { root = process.cwd(), command } = options;
566
+ const { root = process2.cwd(), command } = options;
346
567
  await createOrUpdateProjectConfig({ root });
347
568
  await createOrUpdatePackageJson({ root, command });
348
569
  await updateGitIgnore({ root });
@@ -353,9 +574,19 @@ async function initConfig(options) {
353
574
  }
354
575
  return ctx;
355
576
  }
577
+ async function createProject(targetDir = "", templateDirName = "default") {
578
+ const targetTemplateDir = path.resolve(__dirname2, "../templates", templateDirName);
579
+ if (await fs.exists(targetTemplateDir)) {
580
+ await fs.copy(targetTemplateDir, targetDir);
581
+ logger.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
582
+ } else {
583
+ logger.warn(`\u6CA1\u6709\u627E\u5230 ${templateDirName} \u6A21\u677F!`);
584
+ }
585
+ }
356
586
  export {
357
587
  createOrUpdatePackageJson,
358
588
  createOrUpdateProjectConfig,
589
+ createProject,
359
590
  initConfig,
360
591
  initTsDtsFile,
361
592
  initTsJsonFiles,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/init",
3
3
  "type": "module",
4
- "version": "1.0.9",
4
+ "version": "1.1.0",
5
5
  "description": "@weapp-core/init",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -26,7 +26,8 @@
26
26
  "module": "./dist/index.js",
27
27
  "types": "./dist/index.d.ts",
28
28
  "files": [
29
- "dist"
29
+ "dist",
30
+ "templates"
30
31
  ],
31
32
  "dependencies": {
32
33
  "fs-extra": "^11.2.0",
@@ -41,6 +42,7 @@
41
42
  "release": "pnpm publish",
42
43
  "lint": "eslint .",
43
44
  "lint:fix": "eslint . --fix",
44
- "sync": "cnpm sync @weapp-core/init"
45
+ "sync": "cnpm sync @weapp-core/init",
46
+ "prepublish": "tsx scripts/prepublish.ts"
45
47
  }
46
48
  }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "weapp-vite-tailwindcss-template",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "原生微信小程序 weapp-vite + tailwindcss 模板",
6
+ "author": "ice breaker <1324318532@qq.com>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/weapp-vite/weapp-vite.git",
11
+ "directory": "apps/weapp-vite-tailwindcss-template"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/weapp-vite/weapp-vite/issues"
15
+ },
16
+ "keywords": [],
17
+ "scripts": {
18
+ "dev": "weapp-vite dev",
19
+ "build": "weapp-vite build",
20
+ "open": "weapp-vite open",
21
+ "g": "weapp-vite generate",
22
+ "postinstall": "weapp-tw patch"
23
+ },
24
+ "devDependencies": {
25
+ "autoprefixer": "^10.4.20",
26
+ "miniprogram-api-typings": "latest",
27
+ "postcss": "^8.4.47",
28
+ "sass": "^1.79.5",
29
+ "tailwindcss": "^3.4.13",
30
+ "typescript": "latest",
31
+ "weapp-tailwindcss": "^3.5.3",
32
+ "weapp-vite": "workspace:*"
33
+ }
34
+ }
@@ -0,0 +1,6 @@
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "description": "项目配置文件",
3
+ "miniprogramRoot": "dist/",
4
+ "compileType": "miniprogram",
5
+ "setting": {
6
+ "babelSetting": {
7
+ "ignore": [],
8
+ "disablePlugins": [],
9
+ "outputPath": ""
10
+ },
11
+ "coverView": false,
12
+ "postcss": false,
13
+ "minified": false,
14
+ "enhance": true,
15
+ "showShadowRootInWxmlPanel": false,
16
+ "packNpmRelationList": [
17
+ {
18
+ "packageJsonPath": "./package.json",
19
+ "miniprogramNpmDistDir": "./dist"
20
+ }
21
+ ],
22
+ "ignoreUploadUnusedFiles": true,
23
+ "compileHotReLoad": false,
24
+ "skylineRenderEnable": true,
25
+ "packNpmManually": true,
26
+ "es6": true
27
+ },
28
+ "simulatorType": "wechat",
29
+ "simulatorPluginLibVersion": {},
30
+ "condition": {},
31
+ "srcMiniprogramRoot": "dist/",
32
+ "editorSetting": {
33
+ "tabIndent": "insertSpaces",
34
+ "tabSize": 2
35
+ },
36
+ "libVersion": "2.32.3",
37
+ "packOptions": {
38
+ "ignore": [],
39
+ "include": []
40
+ },
41
+ "appid": "wx6ffee4673b257014"
42
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
3
+ "projectname": "weapp-vite-tailwindcss-template",
4
+ "setting": {
5
+ "compileHotReLoad": true
6
+ }
7
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/app.json",
3
+ "pages": [
4
+ "pages/index/index",
5
+ "pages/logs/logs"
6
+ ],
7
+ "window": {},
8
+ "style": "v2",
9
+ "rendererOptions": {
10
+ "skyline": {
11
+ "defaultDisplayBlock": true,
12
+ "disableABTest": true,
13
+ "sdkVersionBegin": "3.0.0",
14
+ "sdkVersionEnd": "15.255.255"
15
+ }
16
+ },
17
+ "componentFramework": "glass-easel",
18
+ "sitemapLocation": "sitemap.json",
19
+ "lazyCodeLoading": "requiredComponents"
20
+ }
@@ -0,0 +1,3 @@
1
+ @import 'tailwindcss/base';
2
+ @import 'tailwindcss/components';
3
+ @import 'tailwindcss/utilities';
@@ -0,0 +1,18 @@
1
+ // app.ts
2
+ App({
3
+ globalData: {},
4
+ onLaunch() {
5
+ // 展示本地存储能力
6
+ const logs = wx.getStorageSync('logs') || []
7
+ logs.unshift(Date.now())
8
+ wx.setStorageSync('logs', logs)
9
+
10
+ // 登录
11
+ wx.login({
12
+ success: (res) => {
13
+ console.log(res.code)
14
+ // 发送 res.code 到后台换取 openId, sessionKey, unionId
15
+ },
16
+ })
17
+ },
18
+ })
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/component.json",
3
+ "component": true,
4
+ "styleIsolation": "apply-shared",
5
+ "usingComponents": {}
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/page.json",
3
+ "usingComponents": {
4
+ "navigation-bar": "/components/navigation-bar/navigation-bar"
5
+ }
6
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ Component({
2
+
3
+ })
@@ -0,0 +1 @@
1
+ <view class="bg-slate-800 text-white">weapp-vite + weapp-tailwindcss</view>
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/page.json",
3
+ "usingComponents": {
4
+ "navigation-bar": "/components/navigation-bar/navigation-bar"
5
+ }
6
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ Component({
2
+
3
+ })
File without changes
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/sitemap.json",
3
+ "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
4
+ "rules": [
5
+ {
6
+ "action": "allow",
7
+ "page": "*"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://vite.icebreaker.top/theme.json",
3
+ "light": {},
4
+ "dark": {}
5
+ }
File without changes
@@ -0,0 +1,17 @@
1
+ import type { Config } from 'tailwindcss'
2
+
3
+ export default <Config>{
4
+ content: [
5
+ // 添加你需要提取的文件目录
6
+ 'src/**/*.{wxml,js,ts}',
7
+ ],
8
+ theme: {
9
+ extend: {},
10
+ },
11
+ plugins: [],
12
+ corePlugins: {
13
+ // 小程序不需要 preflight 和 container,因为这主要是给 h5 的,如果你要同时开发小程序和 h5 端,你应该使用环境变量来控制它
14
+ preflight: false,
15
+ container: false,
16
+ },
17
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "jsx": "preserve",
5
+ "lib": [
6
+ "ES2020",
7
+ "DOM",
8
+ "DOM.Iterable"
9
+ ],
10
+ "useDefineForClassFields": true,
11
+ "baseUrl": ".",
12
+ "module": "ESNext",
13
+ "moduleResolution": "bundler",
14
+ "paths": {
15
+ "@/*": [
16
+ "./*"
17
+ ]
18
+ },
19
+ "resolveJsonModule": true,
20
+ "types": [
21
+ "miniprogram-api-typings"
22
+ ],
23
+ "allowImportingTsExtensions": true,
24
+ "allowJs": true,
25
+ "strict": true,
26
+ "noFallthroughCasesInSwitch": true,
27
+ "noUnusedLocals": true,
28
+ "noUnusedParameters": true,
29
+ "noEmit": true,
30
+ "isolatedModules": true,
31
+ "skipLibCheck": true
32
+ },
33
+ "references": [
34
+ {
35
+ "path": "./tsconfig.node.json"
36
+ }
37
+ ],
38
+ "include": [
39
+ "src/**/*.ts",
40
+ "src/**/*.js"
41
+ ],
42
+ "exclude": [
43
+ "node_modules",
44
+ "dist"
45
+ ]
46
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "allowSyntheticDefaultImports": true,
8
+ "skipLibCheck": true
9
+ },
10
+ "include": [
11
+ "vite.config.ts"
12
+ ]
13
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,28 @@
1
+ import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite'
2
+ import { defineConfig } from 'weapp-vite/config'
3
+
4
+ export default defineConfig({
5
+ weapp: {
6
+ srcRoot: 'src',
7
+ // pnpm g 生成的格式
8
+ // https://vite.icebreaker.top/guide/generate.html
9
+ generate: {
10
+ extensions: {
11
+ js: 'ts',
12
+ wxss: 'scss',
13
+ },
14
+ },
15
+ },
16
+ css: {
17
+ preprocessorOptions: {
18
+ scss: {
19
+ silenceDeprecations: ['legacy-js-api'],
20
+ },
21
+ },
22
+ },
23
+ plugins: [
24
+ UnifiedViteWeappTailwindcssPlugin({
25
+ rem2rpx: true,
26
+ }),
27
+ ],
28
+ })