@weapp-core/init 1.0.9 → 1.1.1

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 +352 -101
  2. package/dist/index.d.cts +2 -1
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +340 -96
  5. package/package.json +5 -3
  6. package/templates/default/package.json +37 -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 +12 -0
  11. package/templates/default/src/app.scss +3 -0
  12. package/templates/default/src/app.ts +6 -0
  13. package/templates/default/src/components/navigation-bar/navigation-bar.json +7 -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 +7 -0
  18. package/templates/default/src/pages/index/index.scss +0 -0
  19. package/templates/default/src/pages/index/index.ts +17 -0
  20. package/templates/default/src/pages/index/index.wxml +12 -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 +22 -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 {
@@ -80,7 +307,109 @@ function createContext() {
80
307
  };
81
308
  }
82
309
 
310
+ // src/gitignore.ts
311
+ function getDefaultGitignore() {
312
+ return `# dependencies
313
+ node_modules
314
+ .pnp
315
+ .pnp.js
316
+
317
+ # testing
318
+ coverage
319
+
320
+ # next.js
321
+ .next/
322
+ out/
323
+ build
324
+
325
+ # misc
326
+ .DS_Store
327
+ *.pem
328
+
329
+ # debug
330
+ npm-debug.log*
331
+ yarn-debug.log*
332
+ yarn-error.log*
333
+ .pnpm-debug.log*
334
+
335
+ # local env files
336
+ .env.local
337
+ .env.development.local
338
+ .env.test.local
339
+ .env.production.local
340
+
341
+ # turbo
342
+ .turbo
343
+
344
+ dist
345
+ vite.config.ts.timestamp-*.mjs`;
346
+ }
347
+
348
+ // src/tsconfigJson.ts
349
+ function getDefaultTsconfigJson() {
350
+ return {
351
+ compilerOptions: {
352
+ target: "ES2020",
353
+ jsx: "preserve",
354
+ lib: [
355
+ "ES2020",
356
+ "DOM",
357
+ "DOM.Iterable"
358
+ ],
359
+ useDefineForClassFields: true,
360
+ baseUrl: ".",
361
+ module: "ESNext",
362
+ moduleResolution: "bundler",
363
+ paths: {
364
+ "@/*": [
365
+ "./*"
366
+ ]
367
+ },
368
+ resolveJsonModule: true,
369
+ types: [
370
+ "miniprogram-api-typings"
371
+ ],
372
+ allowImportingTsExtensions: true,
373
+ allowJs: true,
374
+ strict: true,
375
+ noFallthroughCasesInSwitch: true,
376
+ noUnusedLocals: true,
377
+ noUnusedParameters: true,
378
+ noEmit: true,
379
+ isolatedModules: true,
380
+ skipLibCheck: true
381
+ },
382
+ references: [
383
+ {
384
+ path: "./tsconfig.node.json"
385
+ }
386
+ ],
387
+ include: [
388
+ "**/*.ts",
389
+ "**/*.js"
390
+ ],
391
+ exclude: [
392
+ "node_modules",
393
+ "dist"
394
+ ]
395
+ };
396
+ }
397
+ function getDefaultTsconfigNodeJson(include) {
398
+ return {
399
+ compilerOptions: {
400
+ composite: true,
401
+ module: "ESNext",
402
+ moduleResolution: "bundler",
403
+ strict: true,
404
+ allowSyntheticDefaultImports: true,
405
+ skipLibCheck: true
406
+ },
407
+ include
408
+ };
409
+ }
410
+
83
411
  // src/index.ts
412
+ var __dirname = path.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
84
413
  var ctx = createContext();
85
414
  async function createOrUpdateProjectConfig(options) {
86
415
  const { root, dest, cb, write, filename } = (0, import_shared.defu)(
@@ -91,7 +420,7 @@ async function createOrUpdateProjectConfig(options) {
91
420
  }
92
421
  );
93
422
  const projectConfigFilename = ctx.projectConfig.name = filename;
94
- const projectConfigPath = ctx.projectConfig.path = import_node_path.default.resolve(root, projectConfigFilename);
423
+ const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
95
424
  if (await import_fs_extra.default.exists(projectConfigPath)) {
96
425
  try {
97
426
  const projectConfig = await import_fs_extra.default.readJSON(projectConfigPath);
@@ -180,7 +509,7 @@ async function createOrUpdatePackageJson(options) {
180
509
  command: "weapp-vite"
181
510
  });
182
511
  const packageJsonFilename = ctx.packageJson.name = filename;
183
- const packageJsonPath = ctx.packageJson.path = import_node_path.default.resolve(root, packageJsonFilename);
512
+ const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
184
513
  let packageJson;
185
514
  if (await import_fs_extra.default.exists(packageJsonPath)) {
186
515
  packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
@@ -221,7 +550,7 @@ async function initViteConfigFile(options) {
221
550
  const { root, write = true } = options;
222
551
  const type = (0, import_shared.get)(ctx.packageJson.value, "type");
223
552
  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);
553
+ const viteConfigFilePath = ctx.viteConfig.path = path.resolve(root, targetFilename);
225
554
  const viteConfigFileCode = ctx.viteConfig.value = `import { defineConfig } from 'weapp-vite/config'
226
555
 
227
556
  export default defineConfig({
@@ -239,7 +568,7 @@ export default defineConfig({
239
568
  async function initTsDtsFile(options) {
240
569
  const { root, write = true } = options;
241
570
  const targetFilename = "vite-env.d.ts";
242
- const viteDtsFilePath = import_node_path.default.resolve(root, targetFilename);
571
+ const viteDtsFilePath = path.resolve(root, targetFilename);
243
572
  const code = `/// <reference types="vite/client" />
244
573
  `;
245
574
  if (write) {
@@ -251,56 +580,11 @@ async function initTsDtsFile(options) {
251
580
  async function initTsJsonFiles(options) {
252
581
  const { root, write = true } = options;
253
582
  const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
254
- const tsJsonFilePath = ctx.tsconfig.path = import_node_path.default.resolve(root, tsJsonFilename);
583
+ const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
255
584
  const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
256
- const tsNodeJsonFilePath = ctx.tsconfigNode.path = import_node_path.default.resolve(root, tsNodeJsonFilename);
585
+ const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
257
586
  if (write) {
258
- const tsJsonValue = {
259
- compilerOptions: {
260
- target: "ES2020",
261
- jsx: "preserve",
262
- lib: [
263
- "ES2020",
264
- "DOM",
265
- "DOM.Iterable"
266
- ],
267
- useDefineForClassFields: true,
268
- baseUrl: ".",
269
- module: "ESNext",
270
- moduleResolution: "bundler",
271
- paths: {
272
- "@/*": [
273
- "./*"
274
- ]
275
- },
276
- resolveJsonModule: true,
277
- types: [
278
- "miniprogram-api-typings"
279
- ],
280
- allowImportingTsExtensions: true,
281
- allowJs: true,
282
- strict: true,
283
- noFallthroughCasesInSwitch: true,
284
- noUnusedLocals: true,
285
- noUnusedParameters: true,
286
- noEmit: true,
287
- isolatedModules: true,
288
- skipLibCheck: true
289
- },
290
- references: [
291
- {
292
- path: "./tsconfig.node.json"
293
- }
294
- ],
295
- include: [
296
- "**/*.ts",
297
- "**/*.js"
298
- ],
299
- exclude: [
300
- "node_modules",
301
- "dist"
302
- ]
303
- };
587
+ const tsJsonValue = getDefaultTsconfigJson();
304
588
  if (write) {
305
589
  await import_fs_extra.default.outputJSON(
306
590
  tsJsonFilePath,
@@ -313,19 +597,9 @@ async function initTsJsonFiles(options) {
313
597
  import_logger.default.log(`\u2728 \u8BBE\u7F6E ${tsJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
314
598
  }
315
599
  ctx.tsconfig.value = tsJsonValue;
316
- const tsJsonNodeValue = {
317
- compilerOptions: {
318
- composite: true,
319
- module: "ESNext",
320
- moduleResolution: "bundler",
321
- strict: true,
322
- allowSyntheticDefaultImports: true,
323
- skipLibCheck: true
324
- },
325
- include: [
326
- ctx.viteConfig.name
327
- ]
328
- };
600
+ const tsJsonNodeValue = getDefaultTsconfigNodeJson([
601
+ ctx.viteConfig.name
602
+ ]);
329
603
  if (write) {
330
604
  await import_fs_extra.default.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
331
605
  encoding: "utf8",
@@ -338,41 +612,8 @@ async function initTsJsonFiles(options) {
338
612
  }
339
613
  async function updateGitIgnore(options) {
340
614
  const { root, write = true } = options;
341
- const filepath = import_node_path.default.resolve(root, ".gitignore");
342
- const data = `# dependencies
343
- node_modules
344
- .pnp
345
- .pnp.js
346
-
347
- # testing
348
- coverage
349
-
350
- # next.js
351
- .next/
352
- out/
353
- build
354
-
355
- # misc
356
- .DS_Store
357
- *.pem
358
-
359
- # debug
360
- npm-debug.log*
361
- yarn-debug.log*
362
- yarn-error.log*
363
- .pnpm-debug.log*
364
-
365
- # local env files
366
- .env.local
367
- .env.development.local
368
- .env.test.local
369
- .env.production.local
370
-
371
- # turbo
372
- .turbo
373
-
374
- dist
375
- vite.config.ts.timestamp-*.mjs`;
615
+ const filepath = path.resolve(root, ".gitignore");
616
+ const data = getDefaultGitignore();
376
617
  if (write) {
377
618
  await import_fs_extra.default.outputFile(filepath, data, {
378
619
  encoding: "utf8"
@@ -392,10 +633,20 @@ async function initConfig(options) {
392
633
  }
393
634
  return ctx;
394
635
  }
636
+ async function createProject(targetDir = "", templateDirName = "default") {
637
+ const targetTemplateDir = path.resolve(__dirname, "../templates", templateDirName);
638
+ if (await import_fs_extra.default.exists(targetTemplateDir)) {
639
+ await import_fs_extra.default.copy(targetTemplateDir, targetDir);
640
+ import_logger.default.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
641
+ } else {
642
+ import_logger.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateDirName} \u6A21\u677F!`);
643
+ }
644
+ }
395
645
  // Annotate the CommonJS export names for ESM import in node:
396
646
  0 && (module.exports = {
397
647
  createOrUpdatePackageJson,
398
648
  createOrUpdateProjectConfig,
649
+ createProject,
399
650
  initConfig,
400
651
  initTsDtsFile,
401
652
  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 };