@weapp-core/init 1.0.8 → 1.0.9
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 +72 -33
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +69 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,12 +30,12 @@ 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,
|
|
33
35
|
initConfig: () => initConfig,
|
|
34
36
|
initTsDtsFile: () => initTsDtsFile,
|
|
35
37
|
initTsJsonFiles: () => initTsJsonFiles,
|
|
36
|
-
initViteConfigFile: () => initViteConfigFile
|
|
37
|
-
updatePackageJson: () => updatePackageJson,
|
|
38
|
-
updateProjectConfig: () => updateProjectConfig
|
|
38
|
+
initViteConfigFile: () => initViteConfigFile
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
41
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -82,7 +82,7 @@ function createContext() {
|
|
|
82
82
|
|
|
83
83
|
// src/index.ts
|
|
84
84
|
var ctx = createContext();
|
|
85
|
-
function
|
|
85
|
+
async function createOrUpdateProjectConfig(options) {
|
|
86
86
|
const { root, dest, cb, write, filename } = (0, import_shared.defu)(
|
|
87
87
|
options,
|
|
88
88
|
{
|
|
@@ -92,9 +92,9 @@ function updateProjectConfig(options) {
|
|
|
92
92
|
);
|
|
93
93
|
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
94
94
|
const projectConfigPath = ctx.projectConfig.path = import_node_path.default.resolve(root, projectConfigFilename);
|
|
95
|
-
if (import_fs_extra.default.
|
|
95
|
+
if (await import_fs_extra.default.exists(projectConfigPath)) {
|
|
96
96
|
try {
|
|
97
|
-
const projectConfig = import_fs_extra.default.
|
|
97
|
+
const projectConfig = await import_fs_extra.default.readJSON(projectConfigPath);
|
|
98
98
|
(0, import_shared.set)(projectConfig, "miniprogramRoot", "dist/");
|
|
99
99
|
(0, import_shared.set)(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
100
100
|
(0, import_shared.set)(projectConfig, "setting.packNpmManually", true);
|
|
@@ -122,7 +122,7 @@ function updateProjectConfig(options) {
|
|
|
122
122
|
]);
|
|
123
123
|
}
|
|
124
124
|
if (write) {
|
|
125
|
-
import_fs_extra.default.
|
|
125
|
+
await import_fs_extra.default.outputJSON(dest ?? projectConfigPath, projectConfig, {
|
|
126
126
|
spaces: 2
|
|
127
127
|
});
|
|
128
128
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -133,10 +133,47 @@ function updateProjectConfig(options) {
|
|
|
133
133
|
import_logger.default.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
134
134
|
}
|
|
135
135
|
} else {
|
|
136
|
-
import_logger.default.
|
|
136
|
+
import_logger.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6! \u6B63\u5728\u4E3A\u4F60\u521B\u5EFA\u4E2D...`);
|
|
137
|
+
await import_fs_extra.default.outputJson(projectConfigPath, {
|
|
138
|
+
compileType: "miniprogram",
|
|
139
|
+
libVersion: "trial",
|
|
140
|
+
packOptions: {
|
|
141
|
+
ignore: [],
|
|
142
|
+
include: []
|
|
143
|
+
},
|
|
144
|
+
setting: {
|
|
145
|
+
coverView: true,
|
|
146
|
+
es6: true,
|
|
147
|
+
postcss: true,
|
|
148
|
+
minified: true,
|
|
149
|
+
enhance: true,
|
|
150
|
+
showShadowRootInWxmlPanel: true,
|
|
151
|
+
packNpmRelationList: [
|
|
152
|
+
{
|
|
153
|
+
packageJsonPath: "./package.json",
|
|
154
|
+
miniprogramNpmDistDir: "./dist"
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
babelSetting: {
|
|
158
|
+
ignore: [],
|
|
159
|
+
disablePlugins: [],
|
|
160
|
+
outputPath: ""
|
|
161
|
+
},
|
|
162
|
+
packNpmManually: true
|
|
163
|
+
},
|
|
164
|
+
condition: {},
|
|
165
|
+
editorSetting: {
|
|
166
|
+
tabIndent: "auto",
|
|
167
|
+
tabSize: 2
|
|
168
|
+
},
|
|
169
|
+
appid: "",
|
|
170
|
+
miniprogramRoot: "dist/",
|
|
171
|
+
srcMiniprogramRoot: "dist/"
|
|
172
|
+
}, { spaces: 2 });
|
|
173
|
+
import_logger.default.success(`\u2728 \u521B\u5EFA\u5B8C\u6210! \u522B\u5FD8\u4E86\u5728\u91CC\u9762\u8BBE\u7F6E\u4F60\u7684 \`appid\` `);
|
|
137
174
|
}
|
|
138
175
|
}
|
|
139
|
-
function
|
|
176
|
+
async function createOrUpdatePackageJson(options) {
|
|
140
177
|
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
141
178
|
write: true,
|
|
142
179
|
filename: "package.json",
|
|
@@ -145,11 +182,13 @@ function updatePackageJson(options) {
|
|
|
145
182
|
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
146
183
|
const packageJsonPath = ctx.packageJson.path = import_node_path.default.resolve(root, packageJsonFilename);
|
|
147
184
|
let packageJson;
|
|
148
|
-
if (import_fs_extra.default.
|
|
149
|
-
packageJson = import_fs_extra.default.
|
|
185
|
+
if (await import_fs_extra.default.exists(packageJsonPath)) {
|
|
186
|
+
packageJson = await import_fs_extra.default.readJSON(packageJsonPath);
|
|
150
187
|
} else {
|
|
151
188
|
packageJson = {
|
|
152
|
-
name: "weapp-vite-app"
|
|
189
|
+
name: "weapp-vite-app",
|
|
190
|
+
homepage: "https://vite.icebreaker.top/",
|
|
191
|
+
type: "module"
|
|
153
192
|
};
|
|
154
193
|
}
|
|
155
194
|
try {
|
|
@@ -157,7 +196,7 @@ function updatePackageJson(options) {
|
|
|
157
196
|
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
158
197
|
if (command === "weapp-vite") {
|
|
159
198
|
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
160
|
-
(0, import_shared.set)(packageJson, "scripts.
|
|
199
|
+
(0, import_shared.set)(packageJson, "scripts.g", `${command} generate`);
|
|
161
200
|
(0, import_shared.set)(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
162
201
|
(0, import_shared.set)(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
163
202
|
(0, import_shared.set)(packageJson, "devDependencies.typescript", `latest`);
|
|
@@ -168,7 +207,7 @@ function updatePackageJson(options) {
|
|
|
168
207
|
}
|
|
169
208
|
);
|
|
170
209
|
if (write) {
|
|
171
|
-
import_fs_extra.default.
|
|
210
|
+
await import_fs_extra.default.outputJSON(dest ?? packageJsonPath, packageJson, {
|
|
172
211
|
spaces: 2
|
|
173
212
|
});
|
|
174
213
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -178,7 +217,7 @@ function updatePackageJson(options) {
|
|
|
178
217
|
} catch {
|
|
179
218
|
}
|
|
180
219
|
}
|
|
181
|
-
function initViteConfigFile(options) {
|
|
220
|
+
async function initViteConfigFile(options) {
|
|
182
221
|
const { root, write = true } = options;
|
|
183
222
|
const type = (0, import_shared.get)(ctx.packageJson.value, "type");
|
|
184
223
|
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
@@ -192,24 +231,24 @@ export default defineConfig({
|
|
|
192
231
|
})
|
|
193
232
|
`;
|
|
194
233
|
if (write) {
|
|
195
|
-
import_fs_extra.default.
|
|
234
|
+
await import_fs_extra.default.outputFile(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
196
235
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
197
236
|
}
|
|
198
237
|
return viteConfigFileCode;
|
|
199
238
|
}
|
|
200
|
-
function initTsDtsFile(options) {
|
|
239
|
+
async function initTsDtsFile(options) {
|
|
201
240
|
const { root, write = true } = options;
|
|
202
241
|
const targetFilename = "vite-env.d.ts";
|
|
203
242
|
const viteDtsFilePath = import_node_path.default.resolve(root, targetFilename);
|
|
204
243
|
const code = `/// <reference types="vite/client" />
|
|
205
244
|
`;
|
|
206
245
|
if (write) {
|
|
207
|
-
import_fs_extra.default.
|
|
246
|
+
await import_fs_extra.default.outputFile(viteDtsFilePath, code, "utf8");
|
|
208
247
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
209
248
|
}
|
|
210
249
|
return code;
|
|
211
250
|
}
|
|
212
|
-
function initTsJsonFiles(options) {
|
|
251
|
+
async function initTsJsonFiles(options) {
|
|
213
252
|
const { root, write = true } = options;
|
|
214
253
|
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
215
254
|
const tsJsonFilePath = ctx.tsconfig.path = import_node_path.default.resolve(root, tsJsonFilename);
|
|
@@ -263,7 +302,7 @@ function initTsJsonFiles(options) {
|
|
|
263
302
|
]
|
|
264
303
|
};
|
|
265
304
|
if (write) {
|
|
266
|
-
import_fs_extra.default.
|
|
305
|
+
await import_fs_extra.default.outputJSON(
|
|
267
306
|
tsJsonFilePath,
|
|
268
307
|
tsJsonValue,
|
|
269
308
|
{
|
|
@@ -288,7 +327,7 @@ function initTsJsonFiles(options) {
|
|
|
288
327
|
]
|
|
289
328
|
};
|
|
290
329
|
if (write) {
|
|
291
|
-
import_fs_extra.default.
|
|
330
|
+
await import_fs_extra.default.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
292
331
|
encoding: "utf8",
|
|
293
332
|
spaces: 2
|
|
294
333
|
});
|
|
@@ -297,7 +336,7 @@ function initTsJsonFiles(options) {
|
|
|
297
336
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
298
337
|
}
|
|
299
338
|
}
|
|
300
|
-
function updateGitIgnore(options) {
|
|
339
|
+
async function updateGitIgnore(options) {
|
|
301
340
|
const { root, write = true } = options;
|
|
302
341
|
const filepath = import_node_path.default.resolve(root, ".gitignore");
|
|
303
342
|
const data = `# dependencies
|
|
@@ -335,30 +374,30 @@ yarn-error.log*
|
|
|
335
374
|
dist
|
|
336
375
|
vite.config.ts.timestamp-*.mjs`;
|
|
337
376
|
if (write) {
|
|
338
|
-
import_fs_extra.default.
|
|
377
|
+
await import_fs_extra.default.outputFile(filepath, data, {
|
|
339
378
|
encoding: "utf8"
|
|
340
379
|
});
|
|
341
380
|
}
|
|
342
381
|
return data;
|
|
343
382
|
}
|
|
344
|
-
function initConfig(options) {
|
|
383
|
+
async function initConfig(options) {
|
|
345
384
|
const { root = import_node_process.default.cwd(), command } = options;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
updateGitIgnore({ root });
|
|
385
|
+
await createOrUpdateProjectConfig({ root });
|
|
386
|
+
await createOrUpdatePackageJson({ root, command });
|
|
387
|
+
await updateGitIgnore({ root });
|
|
349
388
|
if (command === "weapp-vite") {
|
|
350
|
-
initViteConfigFile({ root });
|
|
351
|
-
initTsDtsFile({ root });
|
|
352
|
-
initTsJsonFiles({ root });
|
|
389
|
+
await initViteConfigFile({ root });
|
|
390
|
+
await initTsDtsFile({ root });
|
|
391
|
+
await initTsJsonFiles({ root });
|
|
353
392
|
}
|
|
354
393
|
return ctx;
|
|
355
394
|
}
|
|
356
395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
357
396
|
0 && (module.exports = {
|
|
397
|
+
createOrUpdatePackageJson,
|
|
398
|
+
createOrUpdateProjectConfig,
|
|
358
399
|
initConfig,
|
|
359
400
|
initTsDtsFile,
|
|
360
401
|
initTsJsonFiles,
|
|
361
|
-
initViteConfigFile
|
|
362
|
-
updatePackageJson,
|
|
363
|
-
updateProjectConfig
|
|
402
|
+
initViteConfigFile
|
|
364
403
|
});
|
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,6 @@ declare function initConfig(options: {
|
|
|
69
69
|
path: string;
|
|
70
70
|
value: string;
|
|
71
71
|
};
|
|
72
|
-
}
|
|
72
|
+
}>;
|
|
73
73
|
|
|
74
|
-
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile
|
|
74
|
+
export { createOrUpdatePackageJson, createOrUpdateProjectConfig, 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,6 @@ declare function initConfig(options: {
|
|
|
69
69
|
path: string;
|
|
70
70
|
value: string;
|
|
71
71
|
};
|
|
72
|
-
}
|
|
72
|
+
}>;
|
|
73
73
|
|
|
74
|
-
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile
|
|
74
|
+
export { createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile };
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function createContext() {
|
|
|
43
43
|
|
|
44
44
|
// src/index.ts
|
|
45
45
|
var ctx = createContext();
|
|
46
|
-
function
|
|
46
|
+
async function createOrUpdateProjectConfig(options) {
|
|
47
47
|
const { root, dest, cb, write, filename } = defu(
|
|
48
48
|
options,
|
|
49
49
|
{
|
|
@@ -53,9 +53,9 @@ function updateProjectConfig(options) {
|
|
|
53
53
|
);
|
|
54
54
|
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
55
55
|
const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
|
|
56
|
-
if (fs.
|
|
56
|
+
if (await fs.exists(projectConfigPath)) {
|
|
57
57
|
try {
|
|
58
|
-
const projectConfig = fs.
|
|
58
|
+
const projectConfig = await fs.readJSON(projectConfigPath);
|
|
59
59
|
set(projectConfig, "miniprogramRoot", "dist/");
|
|
60
60
|
set(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
61
61
|
set(projectConfig, "setting.packNpmManually", true);
|
|
@@ -83,7 +83,7 @@ function updateProjectConfig(options) {
|
|
|
83
83
|
]);
|
|
84
84
|
}
|
|
85
85
|
if (write) {
|
|
86
|
-
fs.
|
|
86
|
+
await fs.outputJSON(dest ?? projectConfigPath, projectConfig, {
|
|
87
87
|
spaces: 2
|
|
88
88
|
});
|
|
89
89
|
logger.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -94,10 +94,47 @@ function updateProjectConfig(options) {
|
|
|
94
94
|
logger.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
95
95
|
}
|
|
96
96
|
} else {
|
|
97
|
-
logger.
|
|
97
|
+
logger.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6! \u6B63\u5728\u4E3A\u4F60\u521B\u5EFA\u4E2D...`);
|
|
98
|
+
await fs.outputJson(projectConfigPath, {
|
|
99
|
+
compileType: "miniprogram",
|
|
100
|
+
libVersion: "trial",
|
|
101
|
+
packOptions: {
|
|
102
|
+
ignore: [],
|
|
103
|
+
include: []
|
|
104
|
+
},
|
|
105
|
+
setting: {
|
|
106
|
+
coverView: true,
|
|
107
|
+
es6: true,
|
|
108
|
+
postcss: true,
|
|
109
|
+
minified: true,
|
|
110
|
+
enhance: true,
|
|
111
|
+
showShadowRootInWxmlPanel: true,
|
|
112
|
+
packNpmRelationList: [
|
|
113
|
+
{
|
|
114
|
+
packageJsonPath: "./package.json",
|
|
115
|
+
miniprogramNpmDistDir: "./dist"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
babelSetting: {
|
|
119
|
+
ignore: [],
|
|
120
|
+
disablePlugins: [],
|
|
121
|
+
outputPath: ""
|
|
122
|
+
},
|
|
123
|
+
packNpmManually: true
|
|
124
|
+
},
|
|
125
|
+
condition: {},
|
|
126
|
+
editorSetting: {
|
|
127
|
+
tabIndent: "auto",
|
|
128
|
+
tabSize: 2
|
|
129
|
+
},
|
|
130
|
+
appid: "",
|
|
131
|
+
miniprogramRoot: "dist/",
|
|
132
|
+
srcMiniprogramRoot: "dist/"
|
|
133
|
+
}, { spaces: 2 });
|
|
134
|
+
logger.success(`\u2728 \u521B\u5EFA\u5B8C\u6210! \u522B\u5FD8\u4E86\u5728\u91CC\u9762\u8BBE\u7F6E\u4F60\u7684 \`appid\` `);
|
|
98
135
|
}
|
|
99
136
|
}
|
|
100
|
-
function
|
|
137
|
+
async function createOrUpdatePackageJson(options) {
|
|
101
138
|
const { root, dest, command, cb, write, filename } = defu(options, {
|
|
102
139
|
write: true,
|
|
103
140
|
filename: "package.json",
|
|
@@ -106,11 +143,13 @@ function updatePackageJson(options) {
|
|
|
106
143
|
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
107
144
|
const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
|
|
108
145
|
let packageJson;
|
|
109
|
-
if (fs.
|
|
110
|
-
packageJson = fs.
|
|
146
|
+
if (await fs.exists(packageJsonPath)) {
|
|
147
|
+
packageJson = await fs.readJSON(packageJsonPath);
|
|
111
148
|
} else {
|
|
112
149
|
packageJson = {
|
|
113
|
-
name: "weapp-vite-app"
|
|
150
|
+
name: "weapp-vite-app",
|
|
151
|
+
homepage: "https://vite.icebreaker.top/",
|
|
152
|
+
type: "module"
|
|
114
153
|
};
|
|
115
154
|
}
|
|
116
155
|
try {
|
|
@@ -118,7 +157,7 @@ function updatePackageJson(options) {
|
|
|
118
157
|
set(packageJson, "scripts.build", `${command} build`);
|
|
119
158
|
if (command === "weapp-vite") {
|
|
120
159
|
set(packageJson, "scripts.open", `${command} open`);
|
|
121
|
-
set(packageJson, "scripts.
|
|
160
|
+
set(packageJson, "scripts.g", `${command} generate`);
|
|
122
161
|
set(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
123
162
|
set(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
124
163
|
set(packageJson, "devDependencies.typescript", `latest`);
|
|
@@ -129,7 +168,7 @@ function updatePackageJson(options) {
|
|
|
129
168
|
}
|
|
130
169
|
);
|
|
131
170
|
if (write) {
|
|
132
|
-
fs.
|
|
171
|
+
await fs.outputJSON(dest ?? packageJsonPath, packageJson, {
|
|
133
172
|
spaces: 2
|
|
134
173
|
});
|
|
135
174
|
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
@@ -139,7 +178,7 @@ function updatePackageJson(options) {
|
|
|
139
178
|
} catch {
|
|
140
179
|
}
|
|
141
180
|
}
|
|
142
|
-
function initViteConfigFile(options) {
|
|
181
|
+
async function initViteConfigFile(options) {
|
|
143
182
|
const { root, write = true } = options;
|
|
144
183
|
const type = get(ctx.packageJson.value, "type");
|
|
145
184
|
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
@@ -153,24 +192,24 @@ export default defineConfig({
|
|
|
153
192
|
})
|
|
154
193
|
`;
|
|
155
194
|
if (write) {
|
|
156
|
-
fs.
|
|
195
|
+
await fs.outputFile(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
157
196
|
logger.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
158
197
|
}
|
|
159
198
|
return viteConfigFileCode;
|
|
160
199
|
}
|
|
161
|
-
function initTsDtsFile(options) {
|
|
200
|
+
async function initTsDtsFile(options) {
|
|
162
201
|
const { root, write = true } = options;
|
|
163
202
|
const targetFilename = "vite-env.d.ts";
|
|
164
203
|
const viteDtsFilePath = path.resolve(root, targetFilename);
|
|
165
204
|
const code = `/// <reference types="vite/client" />
|
|
166
205
|
`;
|
|
167
206
|
if (write) {
|
|
168
|
-
fs.
|
|
207
|
+
await fs.outputFile(viteDtsFilePath, code, "utf8");
|
|
169
208
|
logger.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
170
209
|
}
|
|
171
210
|
return code;
|
|
172
211
|
}
|
|
173
|
-
function initTsJsonFiles(options) {
|
|
212
|
+
async function initTsJsonFiles(options) {
|
|
174
213
|
const { root, write = true } = options;
|
|
175
214
|
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
176
215
|
const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
|
|
@@ -224,7 +263,7 @@ function initTsJsonFiles(options) {
|
|
|
224
263
|
]
|
|
225
264
|
};
|
|
226
265
|
if (write) {
|
|
227
|
-
fs.
|
|
266
|
+
await fs.outputJSON(
|
|
228
267
|
tsJsonFilePath,
|
|
229
268
|
tsJsonValue,
|
|
230
269
|
{
|
|
@@ -249,7 +288,7 @@ function initTsJsonFiles(options) {
|
|
|
249
288
|
]
|
|
250
289
|
};
|
|
251
290
|
if (write) {
|
|
252
|
-
fs.
|
|
291
|
+
await fs.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
253
292
|
encoding: "utf8",
|
|
254
293
|
spaces: 2
|
|
255
294
|
});
|
|
@@ -258,7 +297,7 @@ function initTsJsonFiles(options) {
|
|
|
258
297
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
259
298
|
}
|
|
260
299
|
}
|
|
261
|
-
function updateGitIgnore(options) {
|
|
300
|
+
async function updateGitIgnore(options) {
|
|
262
301
|
const { root, write = true } = options;
|
|
263
302
|
const filepath = path.resolve(root, ".gitignore");
|
|
264
303
|
const data = `# dependencies
|
|
@@ -296,29 +335,29 @@ yarn-error.log*
|
|
|
296
335
|
dist
|
|
297
336
|
vite.config.ts.timestamp-*.mjs`;
|
|
298
337
|
if (write) {
|
|
299
|
-
fs.
|
|
338
|
+
await fs.outputFile(filepath, data, {
|
|
300
339
|
encoding: "utf8"
|
|
301
340
|
});
|
|
302
341
|
}
|
|
303
342
|
return data;
|
|
304
343
|
}
|
|
305
|
-
function initConfig(options) {
|
|
344
|
+
async function initConfig(options) {
|
|
306
345
|
const { root = process.cwd(), command } = options;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
updateGitIgnore({ root });
|
|
346
|
+
await createOrUpdateProjectConfig({ root });
|
|
347
|
+
await createOrUpdatePackageJson({ root, command });
|
|
348
|
+
await updateGitIgnore({ root });
|
|
310
349
|
if (command === "weapp-vite") {
|
|
311
|
-
initViteConfigFile({ root });
|
|
312
|
-
initTsDtsFile({ root });
|
|
313
|
-
initTsJsonFiles({ root });
|
|
350
|
+
await initViteConfigFile({ root });
|
|
351
|
+
await initTsDtsFile({ root });
|
|
352
|
+
await initTsJsonFiles({ root });
|
|
314
353
|
}
|
|
315
354
|
return ctx;
|
|
316
355
|
}
|
|
317
356
|
export {
|
|
357
|
+
createOrUpdatePackageJson,
|
|
358
|
+
createOrUpdateProjectConfig,
|
|
318
359
|
initConfig,
|
|
319
360
|
initTsDtsFile,
|
|
320
361
|
initTsJsonFiles,
|
|
321
|
-
initViteConfigFile
|
|
322
|
-
updatePackageJson,
|
|
323
|
-
updateProjectConfig
|
|
362
|
+
initViteConfigFile
|
|
324
363
|
};
|