@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.js
CHANGED
|
@@ -1,10 +1,230 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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,8 +262,9 @@ 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
|
-
function
|
|
267
|
+
async function createOrUpdateProjectConfig(options) {
|
|
47
268
|
const { root, dest, cb, write, filename } = defu(
|
|
48
269
|
options,
|
|
49
270
|
{
|
|
@@ -53,9 +274,9 @@ function updateProjectConfig(options) {
|
|
|
53
274
|
);
|
|
54
275
|
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
55
276
|
const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
|
|
56
|
-
if (fs.
|
|
277
|
+
if (await fs.exists(projectConfigPath)) {
|
|
57
278
|
try {
|
|
58
|
-
const projectConfig = fs.
|
|
279
|
+
const projectConfig = await fs.readJSON(projectConfigPath);
|
|
59
280
|
set(projectConfig, "miniprogramRoot", "dist/");
|
|
60
281
|
set(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
61
282
|
set(projectConfig, "setting.packNpmManually", true);
|
|
@@ -83,7 +304,7 @@ function updateProjectConfig(options) {
|
|
|
83
304
|
]);
|
|
84
305
|
}
|
|
85
306
|
if (write) {
|
|
86
|
-
fs.
|
|
307
|
+
await fs.outputJSON(dest ?? projectConfigPath, projectConfig, {
|
|
87
308
|
spaces: 2
|
|
88
309
|
});
|
|
89
310
|
logger.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -94,10 +315,47 @@ function updateProjectConfig(options) {
|
|
|
94
315
|
logger.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
95
316
|
}
|
|
96
317
|
} else {
|
|
97
|
-
logger.
|
|
318
|
+
logger.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6! \u6B63\u5728\u4E3A\u4F60\u521B\u5EFA\u4E2D...`);
|
|
319
|
+
await fs.outputJson(projectConfigPath, {
|
|
320
|
+
compileType: "miniprogram",
|
|
321
|
+
libVersion: "trial",
|
|
322
|
+
packOptions: {
|
|
323
|
+
ignore: [],
|
|
324
|
+
include: []
|
|
325
|
+
},
|
|
326
|
+
setting: {
|
|
327
|
+
coverView: true,
|
|
328
|
+
es6: true,
|
|
329
|
+
postcss: true,
|
|
330
|
+
minified: true,
|
|
331
|
+
enhance: true,
|
|
332
|
+
showShadowRootInWxmlPanel: true,
|
|
333
|
+
packNpmRelationList: [
|
|
334
|
+
{
|
|
335
|
+
packageJsonPath: "./package.json",
|
|
336
|
+
miniprogramNpmDistDir: "./dist"
|
|
337
|
+
}
|
|
338
|
+
],
|
|
339
|
+
babelSetting: {
|
|
340
|
+
ignore: [],
|
|
341
|
+
disablePlugins: [],
|
|
342
|
+
outputPath: ""
|
|
343
|
+
},
|
|
344
|
+
packNpmManually: true
|
|
345
|
+
},
|
|
346
|
+
condition: {},
|
|
347
|
+
editorSetting: {
|
|
348
|
+
tabIndent: "auto",
|
|
349
|
+
tabSize: 2
|
|
350
|
+
},
|
|
351
|
+
appid: "",
|
|
352
|
+
miniprogramRoot: "dist/",
|
|
353
|
+
srcMiniprogramRoot: "dist/"
|
|
354
|
+
}, { spaces: 2 });
|
|
355
|
+
logger.success(`\u2728 \u521B\u5EFA\u5B8C\u6210! \u522B\u5FD8\u4E86\u5728\u91CC\u9762\u8BBE\u7F6E\u4F60\u7684 \`appid\` `);
|
|
98
356
|
}
|
|
99
357
|
}
|
|
100
|
-
function
|
|
358
|
+
async function createOrUpdatePackageJson(options) {
|
|
101
359
|
const { root, dest, command, cb, write, filename } = defu(options, {
|
|
102
360
|
write: true,
|
|
103
361
|
filename: "package.json",
|
|
@@ -106,11 +364,13 @@ function updatePackageJson(options) {
|
|
|
106
364
|
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
107
365
|
const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
|
|
108
366
|
let packageJson;
|
|
109
|
-
if (fs.
|
|
110
|
-
packageJson = fs.
|
|
367
|
+
if (await fs.exists(packageJsonPath)) {
|
|
368
|
+
packageJson = await fs.readJSON(packageJsonPath);
|
|
111
369
|
} else {
|
|
112
370
|
packageJson = {
|
|
113
|
-
name: "weapp-vite-app"
|
|
371
|
+
name: "weapp-vite-app",
|
|
372
|
+
homepage: "https://vite.icebreaker.top/",
|
|
373
|
+
type: "module"
|
|
114
374
|
};
|
|
115
375
|
}
|
|
116
376
|
try {
|
|
@@ -118,7 +378,7 @@ function updatePackageJson(options) {
|
|
|
118
378
|
set(packageJson, "scripts.build", `${command} build`);
|
|
119
379
|
if (command === "weapp-vite") {
|
|
120
380
|
set(packageJson, "scripts.open", `${command} open`);
|
|
121
|
-
set(packageJson, "scripts.
|
|
381
|
+
set(packageJson, "scripts.g", `${command} generate`);
|
|
122
382
|
set(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
123
383
|
set(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
124
384
|
set(packageJson, "devDependencies.typescript", `latest`);
|
|
@@ -129,7 +389,7 @@ function updatePackageJson(options) {
|
|
|
129
389
|
}
|
|
130
390
|
);
|
|
131
391
|
if (write) {
|
|
132
|
-
fs.
|
|
392
|
+
await fs.outputJSON(dest ?? packageJsonPath, packageJson, {
|
|
133
393
|
spaces: 2
|
|
134
394
|
});
|
|
135
395
|
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -139,7 +399,7 @@ function updatePackageJson(options) {
|
|
|
139
399
|
} catch {
|
|
140
400
|
}
|
|
141
401
|
}
|
|
142
|
-
function initViteConfigFile(options) {
|
|
402
|
+
async function initViteConfigFile(options) {
|
|
143
403
|
const { root, write = true } = options;
|
|
144
404
|
const type = get(ctx.packageJson.value, "type");
|
|
145
405
|
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
@@ -153,24 +413,24 @@ export default defineConfig({
|
|
|
153
413
|
})
|
|
154
414
|
`;
|
|
155
415
|
if (write) {
|
|
156
|
-
fs.
|
|
416
|
+
await fs.outputFile(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
157
417
|
logger.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
158
418
|
}
|
|
159
419
|
return viteConfigFileCode;
|
|
160
420
|
}
|
|
161
|
-
function initTsDtsFile(options) {
|
|
421
|
+
async function initTsDtsFile(options) {
|
|
162
422
|
const { root, write = true } = options;
|
|
163
423
|
const targetFilename = "vite-env.d.ts";
|
|
164
424
|
const viteDtsFilePath = path.resolve(root, targetFilename);
|
|
165
425
|
const code = `/// <reference types="vite/client" />
|
|
166
426
|
`;
|
|
167
427
|
if (write) {
|
|
168
|
-
fs.
|
|
428
|
+
await fs.outputFile(viteDtsFilePath, code, "utf8");
|
|
169
429
|
logger.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
170
430
|
}
|
|
171
431
|
return code;
|
|
172
432
|
}
|
|
173
|
-
function initTsJsonFiles(options) {
|
|
433
|
+
async function initTsJsonFiles(options) {
|
|
174
434
|
const { root, write = true } = options;
|
|
175
435
|
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
176
436
|
const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
|
|
@@ -224,7 +484,7 @@ function initTsJsonFiles(options) {
|
|
|
224
484
|
]
|
|
225
485
|
};
|
|
226
486
|
if (write) {
|
|
227
|
-
fs.
|
|
487
|
+
await fs.outputJSON(
|
|
228
488
|
tsJsonFilePath,
|
|
229
489
|
tsJsonValue,
|
|
230
490
|
{
|
|
@@ -249,7 +509,7 @@ function initTsJsonFiles(options) {
|
|
|
249
509
|
]
|
|
250
510
|
};
|
|
251
511
|
if (write) {
|
|
252
|
-
fs.
|
|
512
|
+
await fs.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
253
513
|
encoding: "utf8",
|
|
254
514
|
spaces: 2
|
|
255
515
|
});
|
|
@@ -258,7 +518,7 @@ function initTsJsonFiles(options) {
|
|
|
258
518
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
259
519
|
}
|
|
260
520
|
}
|
|
261
|
-
function updateGitIgnore(options) {
|
|
521
|
+
async function updateGitIgnore(options) {
|
|
262
522
|
const { root, write = true } = options;
|
|
263
523
|
const filepath = path.resolve(root, ".gitignore");
|
|
264
524
|
const data = `# dependencies
|
|
@@ -296,29 +556,39 @@ yarn-error.log*
|
|
|
296
556
|
dist
|
|
297
557
|
vite.config.ts.timestamp-*.mjs`;
|
|
298
558
|
if (write) {
|
|
299
|
-
fs.
|
|
559
|
+
await fs.outputFile(filepath, data, {
|
|
300
560
|
encoding: "utf8"
|
|
301
561
|
});
|
|
302
562
|
}
|
|
303
563
|
return data;
|
|
304
564
|
}
|
|
305
|
-
function initConfig(options) {
|
|
306
|
-
const { root =
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
updateGitIgnore({ root });
|
|
565
|
+
async function initConfig(options) {
|
|
566
|
+
const { root = process2.cwd(), command } = options;
|
|
567
|
+
await createOrUpdateProjectConfig({ root });
|
|
568
|
+
await createOrUpdatePackageJson({ root, command });
|
|
569
|
+
await updateGitIgnore({ root });
|
|
310
570
|
if (command === "weapp-vite") {
|
|
311
|
-
initViteConfigFile({ root });
|
|
312
|
-
initTsDtsFile({ root });
|
|
313
|
-
initTsJsonFiles({ root });
|
|
571
|
+
await initViteConfigFile({ root });
|
|
572
|
+
await initTsDtsFile({ root });
|
|
573
|
+
await initTsJsonFiles({ root });
|
|
314
574
|
}
|
|
315
575
|
return ctx;
|
|
316
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
|
+
}
|
|
317
586
|
export {
|
|
587
|
+
createOrUpdatePackageJson,
|
|
588
|
+
createOrUpdateProjectConfig,
|
|
589
|
+
createProject,
|
|
318
590
|
initConfig,
|
|
319
591
|
initTsDtsFile,
|
|
320
592
|
initTsJsonFiles,
|
|
321
|
-
initViteConfigFile
|
|
322
|
-
updatePackageJson,
|
|
323
|
-
updateProjectConfig
|
|
593
|
+
initViteConfigFile
|
|
324
594
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/init",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
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,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,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,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
|
+
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<view class="bg-slate-800 text-white">weapp-vite + weapp-tailwindcss</view>
|
|
File without changes
|
|
File without changes
|