@weapp-core/init 1.0.8 → 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.
- package/dist/index.cjs +318 -41
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +303 -33
- package/package.json +5 -3
- package/templates/default/package.json +34 -0
- package/templates/default/postcss.config.js +6 -0
- package/templates/default/project.config.json +42 -0
- package/templates/default/project.private.config.json +7 -0
- package/templates/default/src/app.json +20 -0
- package/templates/default/src/app.scss +3 -0
- package/templates/default/src/app.ts +18 -0
- package/templates/default/src/components/navigation-bar/navigation-bar.json +6 -0
- package/templates/default/src/components/navigation-bar/navigation-bar.scss +0 -0
- package/templates/default/src/components/navigation-bar/navigation-bar.ts +3 -0
- package/templates/default/src/components/navigation-bar/navigation-bar.wxml +0 -0
- package/templates/default/src/pages/index/index.json +6 -0
- package/templates/default/src/pages/index/index.scss +0 -0
- package/templates/default/src/pages/index/index.ts +3 -0
- package/templates/default/src/pages/index/index.wxml +1 -0
- package/templates/default/src/pages/logs/logs.json +6 -0
- package/templates/default/src/pages/logs/logs.scss +0 -0
- package/templates/default/src/pages/logs/logs.ts +3 -0
- package/templates/default/src/pages/logs/logs.wxml +0 -0
- package/templates/default/src/sitemap.json +10 -0
- package/templates/default/src/theme.json +5 -0
- package/templates/default/src/utils/util.ts +0 -0
- package/templates/default/tailwind.config.ts +17 -0
- package/templates/default/tsconfig.json +46 -0
- package/templates/default/tsconfig.node.json +13 -0
- package/templates/default/vite-env.d.ts +1 -0
- package/templates/default/vite.config.ts +28 -0
package/dist/index.cjs
CHANGED
|
@@ -30,20 +30,247 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
createOrUpdatePackageJson: () => createOrUpdatePackageJson,
|
|
34
|
+
createOrUpdateProjectConfig: () => createOrUpdateProjectConfig,
|
|
35
|
+
createProject: () => createProject,
|
|
33
36
|
initConfig: () => initConfig,
|
|
34
37
|
initTsDtsFile: () => initTsDtsFile,
|
|
35
38
|
initTsJsonFiles: () => initTsJsonFiles,
|
|
36
|
-
initViteConfigFile: () => initViteConfigFile
|
|
37
|
-
updatePackageJson: () => updatePackageJson,
|
|
38
|
-
updateProjectConfig: () => updateProjectConfig
|
|
39
|
+
initViteConfigFile: () => initViteConfigFile
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(src_exports);
|
|
41
|
-
|
|
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,8 +308,9 @@ 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
|
-
function
|
|
313
|
+
async function createOrUpdateProjectConfig(options) {
|
|
86
314
|
const { root, dest, cb, write, filename } = (0, import_shared.defu)(
|
|
87
315
|
options,
|
|
88
316
|
{
|
|
@@ -91,10 +319,10 @@ function updateProjectConfig(options) {
|
|
|
91
319
|
}
|
|
92
320
|
);
|
|
93
321
|
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
94
|
-
const projectConfigPath = ctx.projectConfig.path =
|
|
95
|
-
if (import_fs_extra.default.
|
|
322
|
+
const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
|
|
323
|
+
if (await import_fs_extra.default.exists(projectConfigPath)) {
|
|
96
324
|
try {
|
|
97
|
-
const projectConfig = import_fs_extra.default.
|
|
325
|
+
const projectConfig = await import_fs_extra.default.readJSON(projectConfigPath);
|
|
98
326
|
(0, import_shared.set)(projectConfig, "miniprogramRoot", "dist/");
|
|
99
327
|
(0, import_shared.set)(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
100
328
|
(0, import_shared.set)(projectConfig, "setting.packNpmManually", true);
|
|
@@ -122,7 +350,7 @@ function updateProjectConfig(options) {
|
|
|
122
350
|
]);
|
|
123
351
|
}
|
|
124
352
|
if (write) {
|
|
125
|
-
import_fs_extra.default.
|
|
353
|
+
await import_fs_extra.default.outputJSON(dest ?? projectConfigPath, projectConfig, {
|
|
126
354
|
spaces: 2
|
|
127
355
|
});
|
|
128
356
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -133,23 +361,62 @@ function updateProjectConfig(options) {
|
|
|
133
361
|
import_logger.default.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
134
362
|
}
|
|
135
363
|
} else {
|
|
136
|
-
import_logger.default.
|
|
364
|
+
import_logger.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6! \u6B63\u5728\u4E3A\u4F60\u521B\u5EFA\u4E2D...`);
|
|
365
|
+
await import_fs_extra.default.outputJson(projectConfigPath, {
|
|
366
|
+
compileType: "miniprogram",
|
|
367
|
+
libVersion: "trial",
|
|
368
|
+
packOptions: {
|
|
369
|
+
ignore: [],
|
|
370
|
+
include: []
|
|
371
|
+
},
|
|
372
|
+
setting: {
|
|
373
|
+
coverView: true,
|
|
374
|
+
es6: true,
|
|
375
|
+
postcss: true,
|
|
376
|
+
minified: true,
|
|
377
|
+
enhance: true,
|
|
378
|
+
showShadowRootInWxmlPanel: true,
|
|
379
|
+
packNpmRelationList: [
|
|
380
|
+
{
|
|
381
|
+
packageJsonPath: "./package.json",
|
|
382
|
+
miniprogramNpmDistDir: "./dist"
|
|
383
|
+
}
|
|
384
|
+
],
|
|
385
|
+
babelSetting: {
|
|
386
|
+
ignore: [],
|
|
387
|
+
disablePlugins: [],
|
|
388
|
+
outputPath: ""
|
|
389
|
+
},
|
|
390
|
+
packNpmManually: true
|
|
391
|
+
},
|
|
392
|
+
condition: {},
|
|
393
|
+
editorSetting: {
|
|
394
|
+
tabIndent: "auto",
|
|
395
|
+
tabSize: 2
|
|
396
|
+
},
|
|
397
|
+
appid: "",
|
|
398
|
+
miniprogramRoot: "dist/",
|
|
399
|
+
srcMiniprogramRoot: "dist/"
|
|
400
|
+
}, { spaces: 2 });
|
|
401
|
+
import_logger.default.success(`\u2728 \u521B\u5EFA\u5B8C\u6210! \u522B\u5FD8\u4E86\u5728\u91CC\u9762\u8BBE\u7F6E\u4F60\u7684 \`appid\` `);
|
|
137
402
|
}
|
|
138
403
|
}
|
|
139
|
-
function
|
|
404
|
+
async function createOrUpdatePackageJson(options) {
|
|
140
405
|
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
141
406
|
write: true,
|
|
142
407
|
filename: "package.json",
|
|
143
408
|
command: "weapp-vite"
|
|
144
409
|
});
|
|
145
410
|
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
146
|
-
const packageJsonPath = ctx.packageJson.path =
|
|
411
|
+
const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
|
|
147
412
|
let packageJson;
|
|
148
|
-
if (import_fs_extra.default.
|
|
149
|
-
packageJson = import_fs_extra.default.
|
|
413
|
+
if (await import_fs_extra.default.exists(packageJsonPath)) {
|
|
414
|
+
packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
|
|
150
415
|
} else {
|
|
151
416
|
packageJson = {
|
|
152
|
-
name: "weapp-vite-app"
|
|
417
|
+
name: "weapp-vite-app",
|
|
418
|
+
homepage: "https://vite.icebreaker.top/",
|
|
419
|
+
type: "module"
|
|
153
420
|
};
|
|
154
421
|
}
|
|
155
422
|
try {
|
|
@@ -157,7 +424,7 @@ function updatePackageJson(options) {
|
|
|
157
424
|
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
158
425
|
if (command === "weapp-vite") {
|
|
159
426
|
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
160
|
-
(0, import_shared.set)(packageJson, "scripts.
|
|
427
|
+
(0, import_shared.set)(packageJson, "scripts.g", `${command} generate`);
|
|
161
428
|
(0, import_shared.set)(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
162
429
|
(0, import_shared.set)(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
163
430
|
(0, import_shared.set)(packageJson, "devDependencies.typescript", `latest`);
|
|
@@ -168,7 +435,7 @@ function updatePackageJson(options) {
|
|
|
168
435
|
}
|
|
169
436
|
);
|
|
170
437
|
if (write) {
|
|
171
|
-
import_fs_extra.default.
|
|
438
|
+
await import_fs_extra.default.outputJSON(dest ?? packageJsonPath, packageJson, {
|
|
172
439
|
spaces: 2
|
|
173
440
|
});
|
|
174
441
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -178,11 +445,11 @@ function updatePackageJson(options) {
|
|
|
178
445
|
} catch {
|
|
179
446
|
}
|
|
180
447
|
}
|
|
181
|
-
function initViteConfigFile(options) {
|
|
448
|
+
async function initViteConfigFile(options) {
|
|
182
449
|
const { root, write = true } = options;
|
|
183
450
|
const type = (0, import_shared.get)(ctx.packageJson.value, "type");
|
|
184
451
|
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
185
|
-
const viteConfigFilePath = ctx.viteConfig.path =
|
|
452
|
+
const viteConfigFilePath = ctx.viteConfig.path = path.resolve(root, targetFilename);
|
|
186
453
|
const viteConfigFileCode = ctx.viteConfig.value = `import { defineConfig } from 'weapp-vite/config'
|
|
187
454
|
|
|
188
455
|
export default defineConfig({
|
|
@@ -192,29 +459,29 @@ export default defineConfig({
|
|
|
192
459
|
})
|
|
193
460
|
`;
|
|
194
461
|
if (write) {
|
|
195
|
-
import_fs_extra.default.
|
|
462
|
+
await import_fs_extra.default.outputFile(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
196
463
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
197
464
|
}
|
|
198
465
|
return viteConfigFileCode;
|
|
199
466
|
}
|
|
200
|
-
function initTsDtsFile(options) {
|
|
467
|
+
async function initTsDtsFile(options) {
|
|
201
468
|
const { root, write = true } = options;
|
|
202
469
|
const targetFilename = "vite-env.d.ts";
|
|
203
|
-
const viteDtsFilePath =
|
|
470
|
+
const viteDtsFilePath = path.resolve(root, targetFilename);
|
|
204
471
|
const code = `/// <reference types="vite/client" />
|
|
205
472
|
`;
|
|
206
473
|
if (write) {
|
|
207
|
-
import_fs_extra.default.
|
|
474
|
+
await import_fs_extra.default.outputFile(viteDtsFilePath, code, "utf8");
|
|
208
475
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
209
476
|
}
|
|
210
477
|
return code;
|
|
211
478
|
}
|
|
212
|
-
function initTsJsonFiles(options) {
|
|
479
|
+
async function initTsJsonFiles(options) {
|
|
213
480
|
const { root, write = true } = options;
|
|
214
481
|
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
215
|
-
const tsJsonFilePath = ctx.tsconfig.path =
|
|
482
|
+
const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
|
|
216
483
|
const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
|
|
217
|
-
const tsNodeJsonFilePath = ctx.tsconfigNode.path =
|
|
484
|
+
const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
|
|
218
485
|
if (write) {
|
|
219
486
|
const tsJsonValue = {
|
|
220
487
|
compilerOptions: {
|
|
@@ -263,7 +530,7 @@ function initTsJsonFiles(options) {
|
|
|
263
530
|
]
|
|
264
531
|
};
|
|
265
532
|
if (write) {
|
|
266
|
-
import_fs_extra.default.
|
|
533
|
+
await import_fs_extra.default.outputJSON(
|
|
267
534
|
tsJsonFilePath,
|
|
268
535
|
tsJsonValue,
|
|
269
536
|
{
|
|
@@ -288,7 +555,7 @@ function initTsJsonFiles(options) {
|
|
|
288
555
|
]
|
|
289
556
|
};
|
|
290
557
|
if (write) {
|
|
291
|
-
import_fs_extra.default.
|
|
558
|
+
await import_fs_extra.default.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
292
559
|
encoding: "utf8",
|
|
293
560
|
spaces: 2
|
|
294
561
|
});
|
|
@@ -297,9 +564,9 @@ function initTsJsonFiles(options) {
|
|
|
297
564
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
298
565
|
}
|
|
299
566
|
}
|
|
300
|
-
function updateGitIgnore(options) {
|
|
567
|
+
async function updateGitIgnore(options) {
|
|
301
568
|
const { root, write = true } = options;
|
|
302
|
-
const filepath =
|
|
569
|
+
const filepath = path.resolve(root, ".gitignore");
|
|
303
570
|
const data = `# dependencies
|
|
304
571
|
node_modules
|
|
305
572
|
.pnp
|
|
@@ -335,30 +602,40 @@ yarn-error.log*
|
|
|
335
602
|
dist
|
|
336
603
|
vite.config.ts.timestamp-*.mjs`;
|
|
337
604
|
if (write) {
|
|
338
|
-
import_fs_extra.default.
|
|
605
|
+
await import_fs_extra.default.outputFile(filepath, data, {
|
|
339
606
|
encoding: "utf8"
|
|
340
607
|
});
|
|
341
608
|
}
|
|
342
609
|
return data;
|
|
343
610
|
}
|
|
344
|
-
function initConfig(options) {
|
|
611
|
+
async function initConfig(options) {
|
|
345
612
|
const { root = import_node_process.default.cwd(), command } = options;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
updateGitIgnore({ root });
|
|
613
|
+
await createOrUpdateProjectConfig({ root });
|
|
614
|
+
await createOrUpdatePackageJson({ root, command });
|
|
615
|
+
await updateGitIgnore({ root });
|
|
349
616
|
if (command === "weapp-vite") {
|
|
350
|
-
initViteConfigFile({ root });
|
|
351
|
-
initTsDtsFile({ root });
|
|
352
|
-
initTsJsonFiles({ root });
|
|
617
|
+
await initViteConfigFile({ root });
|
|
618
|
+
await initTsDtsFile({ root });
|
|
619
|
+
await initTsJsonFiles({ root });
|
|
353
620
|
}
|
|
354
621
|
return ctx;
|
|
355
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
|
+
}
|
|
356
632
|
// Annotate the CommonJS export names for ESM import in node:
|
|
357
633
|
0 && (module.exports = {
|
|
634
|
+
createOrUpdatePackageJson,
|
|
635
|
+
createOrUpdateProjectConfig,
|
|
636
|
+
createProject,
|
|
358
637
|
initConfig,
|
|
359
638
|
initTsDtsFile,
|
|
360
639
|
initTsJsonFiles,
|
|
361
|
-
initViteConfigFile
|
|
362
|
-
updatePackageJson,
|
|
363
|
-
updateProjectConfig
|
|
640
|
+
initViteConfigFile
|
|
364
641
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -30,15 +30,15 @@ interface ProjectConfig {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
declare function
|
|
34
|
-
declare function
|
|
35
|
-
declare function initViteConfigFile(options: SharedUpdateOptions): string
|
|
36
|
-
declare function initTsDtsFile(options: SharedUpdateOptions): string
|
|
37
|
-
declare function initTsJsonFiles(options: SharedUpdateOptions): void
|
|
33
|
+
declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig | undefined>;
|
|
34
|
+
declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJson | undefined>;
|
|
35
|
+
declare function initViteConfigFile(options: SharedUpdateOptions): Promise<string>;
|
|
36
|
+
declare function initTsDtsFile(options: SharedUpdateOptions): Promise<string>;
|
|
37
|
+
declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<void>;
|
|
38
38
|
declare function initConfig(options: {
|
|
39
39
|
root?: string;
|
|
40
40
|
command?: 'weapp-vite';
|
|
41
|
-
}): {
|
|
41
|
+
}): Promise<{
|
|
42
42
|
projectConfig: {
|
|
43
43
|
name: string;
|
|
44
44
|
path: string;
|
|
@@ -69,6 +69,7 @@ declare function initConfig(options: {
|
|
|
69
69
|
path: string;
|
|
70
70
|
value: string;
|
|
71
71
|
};
|
|
72
|
-
}
|
|
72
|
+
}>;
|
|
73
|
+
declare function createProject(targetDir?: string, templateDirName?: string): Promise<void>;
|
|
73
74
|
|
|
74
|
-
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile
|
|
75
|
+
export { createOrUpdatePackageJson, createOrUpdateProjectConfig, createProject, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -30,15 +30,15 @@ interface ProjectConfig {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
declare function
|
|
34
|
-
declare function
|
|
35
|
-
declare function initViteConfigFile(options: SharedUpdateOptions): string
|
|
36
|
-
declare function initTsDtsFile(options: SharedUpdateOptions): string
|
|
37
|
-
declare function initTsJsonFiles(options: SharedUpdateOptions): void
|
|
33
|
+
declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig | undefined>;
|
|
34
|
+
declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJson | undefined>;
|
|
35
|
+
declare function initViteConfigFile(options: SharedUpdateOptions): Promise<string>;
|
|
36
|
+
declare function initTsDtsFile(options: SharedUpdateOptions): Promise<string>;
|
|
37
|
+
declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<void>;
|
|
38
38
|
declare function initConfig(options: {
|
|
39
39
|
root?: string;
|
|
40
40
|
command?: 'weapp-vite';
|
|
41
|
-
}): {
|
|
41
|
+
}): Promise<{
|
|
42
42
|
projectConfig: {
|
|
43
43
|
name: string;
|
|
44
44
|
path: string;
|
|
@@ -69,6 +69,7 @@ declare function initConfig(options: {
|
|
|
69
69
|
path: string;
|
|
70
70
|
value: string;
|
|
71
71
|
};
|
|
72
|
-
}
|
|
72
|
+
}>;
|
|
73
|
+
declare function createProject(targetDir?: string, templateDirName?: string): Promise<void>;
|
|
73
74
|
|
|
74
|
-
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile
|
|
75
|
+
export { createOrUpdatePackageJson, createOrUpdateProjectConfig, createProject, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
|