@weapp-core/init 1.0.1 → 1.0.2
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 +94 -30
- package/dist/index.d.cts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.js +94 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43,10 +43,49 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
43
43
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
44
44
|
var import_shared = require("@weapp-core/shared");
|
|
45
45
|
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
46
|
+
|
|
47
|
+
// src/context.ts
|
|
48
|
+
function createContext() {
|
|
49
|
+
return {
|
|
50
|
+
projectConfig: {
|
|
51
|
+
name: "",
|
|
52
|
+
path: "",
|
|
53
|
+
value: {}
|
|
54
|
+
},
|
|
55
|
+
packageJson: {
|
|
56
|
+
name: "",
|
|
57
|
+
path: "",
|
|
58
|
+
value: {}
|
|
59
|
+
},
|
|
60
|
+
viteConfig: {
|
|
61
|
+
name: "",
|
|
62
|
+
path: "",
|
|
63
|
+
value: ""
|
|
64
|
+
},
|
|
65
|
+
tsconfig: {
|
|
66
|
+
name: "",
|
|
67
|
+
path: "",
|
|
68
|
+
value: {}
|
|
69
|
+
},
|
|
70
|
+
tsconfigNode: {
|
|
71
|
+
name: "",
|
|
72
|
+
path: "",
|
|
73
|
+
value: {}
|
|
74
|
+
},
|
|
75
|
+
dts: {
|
|
76
|
+
name: "",
|
|
77
|
+
path: "",
|
|
78
|
+
value: ""
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/index.ts
|
|
84
|
+
var ctx = createContext();
|
|
46
85
|
function updateProjectConfig(options) {
|
|
47
86
|
const { root, dest, cb, write = true } = options;
|
|
48
|
-
const projectConfigFilename = "project.config.json";
|
|
49
|
-
const projectConfigPath = import_node_path.default.resolve(root, projectConfigFilename);
|
|
87
|
+
const projectConfigFilename = ctx.projectConfig.name = "project.config.json";
|
|
88
|
+
const projectConfigPath = ctx.projectConfig.path = import_node_path.default.resolve(root, projectConfigFilename);
|
|
50
89
|
if (import_fs_extra.default.existsSync(projectConfigPath)) {
|
|
51
90
|
try {
|
|
52
91
|
const projectConfig = import_fs_extra.default.readJSONSync(projectConfigPath);
|
|
@@ -82,6 +121,7 @@ function updateProjectConfig(options) {
|
|
|
82
121
|
});
|
|
83
122
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
84
123
|
}
|
|
124
|
+
ctx.projectConfig.value = projectConfig;
|
|
85
125
|
return projectConfig;
|
|
86
126
|
} catch {
|
|
87
127
|
import_logger.default.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
@@ -92,8 +132,8 @@ function updateProjectConfig(options) {
|
|
|
92
132
|
}
|
|
93
133
|
function updatePackageJson(options) {
|
|
94
134
|
const { root, dest, command, cb, write = true } = options;
|
|
95
|
-
const packageJsonFilename = "package.json";
|
|
96
|
-
const packageJsonPath = import_node_path.default.resolve(root, packageJsonFilename);
|
|
135
|
+
const packageJsonFilename = ctx.packageJson.name = "package.json";
|
|
136
|
+
const packageJsonPath = ctx.packageJson.path = import_node_path.default.resolve(root, packageJsonFilename);
|
|
97
137
|
if (import_fs_extra.default.existsSync(packageJsonPath)) {
|
|
98
138
|
try {
|
|
99
139
|
const packageJson = import_fs_extra.default.readJSONSync(packageJsonPath);
|
|
@@ -102,6 +142,7 @@ function updatePackageJson(options) {
|
|
|
102
142
|
if (command === "weapp-vite") {
|
|
103
143
|
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
104
144
|
(0, import_shared.set)(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
145
|
+
(0, import_shared.set)(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
105
146
|
}
|
|
106
147
|
cb?.(
|
|
107
148
|
(...args) => {
|
|
@@ -114,6 +155,7 @@ function updatePackageJson(options) {
|
|
|
114
155
|
});
|
|
115
156
|
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
116
157
|
}
|
|
158
|
+
ctx.packageJson.value = packageJson;
|
|
117
159
|
return packageJson;
|
|
118
160
|
} catch {
|
|
119
161
|
}
|
|
@@ -121,13 +163,10 @@ function updatePackageJson(options) {
|
|
|
121
163
|
}
|
|
122
164
|
function initViteConfigFile(options) {
|
|
123
165
|
const { root, write = true } = options;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const targetFilename = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
129
|
-
const viteConfigFilePath = import_node_path.default.resolve(root, targetFilename);
|
|
130
|
-
const viteConfigFileCode = `import { defineConfig } from 'weapp-vite/config'
|
|
166
|
+
const type = (0, import_shared.get)(ctx.packageJson.value, "type");
|
|
167
|
+
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
168
|
+
const viteConfigFilePath = ctx.viteConfig.path = import_node_path.default.resolve(root, targetFilename);
|
|
169
|
+
const viteConfigFileCode = ctx.viteConfig.value = `import { defineConfig } from 'weapp-vite/config'
|
|
131
170
|
|
|
132
171
|
export default defineConfig({
|
|
133
172
|
weapp: {
|
|
@@ -155,12 +194,12 @@ function initTsDtsFile(options) {
|
|
|
155
194
|
}
|
|
156
195
|
function initTsJsonFiles(options) {
|
|
157
196
|
const { root, write = true } = options;
|
|
158
|
-
const tsJsonFilename = "tsconfig.json";
|
|
159
|
-
const tsJsonFilePath = import_node_path.default.resolve(root, tsJsonFilename);
|
|
160
|
-
const tsNodeJsonFilename = "tsconfig.node.json";
|
|
161
|
-
const tsNodeJsonFilePath = import_node_path.default.resolve(root, tsNodeJsonFilename);
|
|
197
|
+
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
198
|
+
const tsJsonFilePath = ctx.tsconfig.path = import_node_path.default.resolve(root, tsJsonFilename);
|
|
199
|
+
const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
|
|
200
|
+
const tsNodeJsonFilePath = ctx.tsconfigNode.path = import_node_path.default.resolve(root, tsNodeJsonFilename);
|
|
162
201
|
if (write) {
|
|
163
|
-
|
|
202
|
+
const tsJsonValue = {
|
|
164
203
|
compilerOptions: {
|
|
165
204
|
target: "ES2020",
|
|
166
205
|
jsx: "preserve",
|
|
@@ -170,9 +209,18 @@ function initTsJsonFiles(options) {
|
|
|
170
209
|
"DOM.Iterable"
|
|
171
210
|
],
|
|
172
211
|
useDefineForClassFields: true,
|
|
212
|
+
baseUrl: ".",
|
|
173
213
|
module: "ESNext",
|
|
174
214
|
moduleResolution: "bundler",
|
|
215
|
+
paths: {
|
|
216
|
+
"@/*": [
|
|
217
|
+
"./*"
|
|
218
|
+
]
|
|
219
|
+
},
|
|
175
220
|
resolveJsonModule: true,
|
|
221
|
+
types: [
|
|
222
|
+
"miniprogram-api-typings"
|
|
223
|
+
],
|
|
176
224
|
allowImportingTsExtensions: true,
|
|
177
225
|
allowJs: true,
|
|
178
226
|
strict: true,
|
|
@@ -189,15 +237,26 @@ function initTsJsonFiles(options) {
|
|
|
189
237
|
}
|
|
190
238
|
],
|
|
191
239
|
include: [
|
|
192
|
-
"
|
|
193
|
-
"
|
|
240
|
+
"**/*.ts",
|
|
241
|
+
"**/*.js"
|
|
242
|
+
],
|
|
243
|
+
exclude: [
|
|
244
|
+
"node_modules"
|
|
194
245
|
]
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
246
|
+
};
|
|
247
|
+
if (write) {
|
|
248
|
+
import_fs_extra.default.outputJSONSync(
|
|
249
|
+
tsJsonFilePath,
|
|
250
|
+
tsJsonValue,
|
|
251
|
+
{
|
|
252
|
+
encoding: "utf8",
|
|
253
|
+
spaces: 2
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${tsJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
257
|
+
}
|
|
258
|
+
ctx.tsconfig.value = tsJsonValue;
|
|
259
|
+
const tsJsonNodeValue = {
|
|
201
260
|
compilerOptions: {
|
|
202
261
|
composite: true,
|
|
203
262
|
module: "ESNext",
|
|
@@ -207,13 +266,17 @@ function initTsJsonFiles(options) {
|
|
|
207
266
|
skipLibCheck: true
|
|
208
267
|
},
|
|
209
268
|
include: [
|
|
210
|
-
|
|
269
|
+
ctx.viteConfig.name
|
|
211
270
|
]
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
271
|
+
};
|
|
272
|
+
if (write) {
|
|
273
|
+
import_fs_extra.default.outputJSONSync(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
274
|
+
encoding: "utf8",
|
|
275
|
+
spaces: 2
|
|
276
|
+
});
|
|
277
|
+
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${tsNodeJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
278
|
+
}
|
|
279
|
+
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
217
280
|
}
|
|
218
281
|
}
|
|
219
282
|
function initConfig(options) {
|
|
@@ -225,6 +288,7 @@ function initConfig(options) {
|
|
|
225
288
|
initTsDtsFile({ root });
|
|
226
289
|
initTsJsonFiles({ root });
|
|
227
290
|
}
|
|
291
|
+
return ctx;
|
|
228
292
|
}
|
|
229
293
|
// Annotate the CommonJS export names for ESM import in node:
|
|
230
294
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as pkg_types from 'pkg-types';
|
|
2
|
+
import { PackageJson } from 'pkg-types';
|
|
1
3
|
import { set } from '@weapp-core/shared';
|
|
2
4
|
|
|
3
5
|
interface SetMethod {
|
|
@@ -14,8 +16,7 @@ interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
|
14
16
|
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
15
17
|
command?: 'weapp-vite';
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
|
|
19
|
+
interface ProjectConfig {
|
|
19
20
|
miniprogramRoot?: string;
|
|
20
21
|
srcMiniprogramRoot?: string;
|
|
21
22
|
setting: {
|
|
@@ -25,16 +26,47 @@ declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
|
|
|
25
26
|
miniprogramNpmDistDir: string;
|
|
26
27
|
}[];
|
|
27
28
|
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare function updateProjectConfig(options: UpdateProjectConfigOptions): ProjectConfig | undefined;
|
|
32
|
+
declare function updatePackageJson(options: UpdatePackageJsonOptions): PackageJson | undefined;
|
|
32
33
|
declare function initViteConfigFile(options: SharedUpdateOptions): string;
|
|
33
34
|
declare function initTsDtsFile(options: SharedUpdateOptions): string;
|
|
34
35
|
declare function initTsJsonFiles(options: SharedUpdateOptions): void;
|
|
35
36
|
declare function initConfig(options: {
|
|
36
37
|
root?: string;
|
|
37
38
|
command?: 'weapp-vite';
|
|
38
|
-
}):
|
|
39
|
+
}): {
|
|
40
|
+
projectConfig: {
|
|
41
|
+
name: string;
|
|
42
|
+
path: string;
|
|
43
|
+
value: ProjectConfig;
|
|
44
|
+
};
|
|
45
|
+
packageJson: {
|
|
46
|
+
name: string;
|
|
47
|
+
path: string;
|
|
48
|
+
value: PackageJson;
|
|
49
|
+
};
|
|
50
|
+
viteConfig: {
|
|
51
|
+
name: string;
|
|
52
|
+
path: string;
|
|
53
|
+
value: string;
|
|
54
|
+
};
|
|
55
|
+
tsconfig: {
|
|
56
|
+
name: string;
|
|
57
|
+
path: string;
|
|
58
|
+
value: pkg_types.TSConfig;
|
|
59
|
+
};
|
|
60
|
+
tsconfigNode: {
|
|
61
|
+
name: string;
|
|
62
|
+
path: string;
|
|
63
|
+
value: pkg_types.TSConfig;
|
|
64
|
+
};
|
|
65
|
+
dts: {
|
|
66
|
+
name: string;
|
|
67
|
+
path: string;
|
|
68
|
+
value: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
39
71
|
|
|
40
72
|
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, updatePackageJson, updateProjectConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as pkg_types from 'pkg-types';
|
|
2
|
+
import { PackageJson } from 'pkg-types';
|
|
1
3
|
import { set } from '@weapp-core/shared';
|
|
2
4
|
|
|
3
5
|
interface SetMethod {
|
|
@@ -14,8 +16,7 @@ interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
|
14
16
|
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
15
17
|
command?: 'weapp-vite';
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
|
|
19
|
+
interface ProjectConfig {
|
|
19
20
|
miniprogramRoot?: string;
|
|
20
21
|
srcMiniprogramRoot?: string;
|
|
21
22
|
setting: {
|
|
@@ -25,16 +26,47 @@ declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
|
|
|
25
26
|
miniprogramNpmDistDir: string;
|
|
26
27
|
}[];
|
|
27
28
|
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare function updateProjectConfig(options: UpdateProjectConfigOptions): ProjectConfig | undefined;
|
|
32
|
+
declare function updatePackageJson(options: UpdatePackageJsonOptions): PackageJson | undefined;
|
|
32
33
|
declare function initViteConfigFile(options: SharedUpdateOptions): string;
|
|
33
34
|
declare function initTsDtsFile(options: SharedUpdateOptions): string;
|
|
34
35
|
declare function initTsJsonFiles(options: SharedUpdateOptions): void;
|
|
35
36
|
declare function initConfig(options: {
|
|
36
37
|
root?: string;
|
|
37
38
|
command?: 'weapp-vite';
|
|
38
|
-
}):
|
|
39
|
+
}): {
|
|
40
|
+
projectConfig: {
|
|
41
|
+
name: string;
|
|
42
|
+
path: string;
|
|
43
|
+
value: ProjectConfig;
|
|
44
|
+
};
|
|
45
|
+
packageJson: {
|
|
46
|
+
name: string;
|
|
47
|
+
path: string;
|
|
48
|
+
value: PackageJson;
|
|
49
|
+
};
|
|
50
|
+
viteConfig: {
|
|
51
|
+
name: string;
|
|
52
|
+
path: string;
|
|
53
|
+
value: string;
|
|
54
|
+
};
|
|
55
|
+
tsconfig: {
|
|
56
|
+
name: string;
|
|
57
|
+
path: string;
|
|
58
|
+
value: pkg_types.TSConfig;
|
|
59
|
+
};
|
|
60
|
+
tsconfigNode: {
|
|
61
|
+
name: string;
|
|
62
|
+
path: string;
|
|
63
|
+
value: pkg_types.TSConfig;
|
|
64
|
+
};
|
|
65
|
+
dts: {
|
|
66
|
+
name: string;
|
|
67
|
+
path: string;
|
|
68
|
+
value: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
39
71
|
|
|
40
72
|
export { initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, updatePackageJson, updateProjectConfig };
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,49 @@ import process from "node:process";
|
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
import { get, set } from "@weapp-core/shared";
|
|
6
6
|
import logger from "@weapp-core/logger";
|
|
7
|
+
|
|
8
|
+
// src/context.ts
|
|
9
|
+
function createContext() {
|
|
10
|
+
return {
|
|
11
|
+
projectConfig: {
|
|
12
|
+
name: "",
|
|
13
|
+
path: "",
|
|
14
|
+
value: {}
|
|
15
|
+
},
|
|
16
|
+
packageJson: {
|
|
17
|
+
name: "",
|
|
18
|
+
path: "",
|
|
19
|
+
value: {}
|
|
20
|
+
},
|
|
21
|
+
viteConfig: {
|
|
22
|
+
name: "",
|
|
23
|
+
path: "",
|
|
24
|
+
value: ""
|
|
25
|
+
},
|
|
26
|
+
tsconfig: {
|
|
27
|
+
name: "",
|
|
28
|
+
path: "",
|
|
29
|
+
value: {}
|
|
30
|
+
},
|
|
31
|
+
tsconfigNode: {
|
|
32
|
+
name: "",
|
|
33
|
+
path: "",
|
|
34
|
+
value: {}
|
|
35
|
+
},
|
|
36
|
+
dts: {
|
|
37
|
+
name: "",
|
|
38
|
+
path: "",
|
|
39
|
+
value: ""
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/index.ts
|
|
45
|
+
var ctx = createContext();
|
|
7
46
|
function updateProjectConfig(options) {
|
|
8
47
|
const { root, dest, cb, write = true } = options;
|
|
9
|
-
const projectConfigFilename = "project.config.json";
|
|
10
|
-
const projectConfigPath = path.resolve(root, projectConfigFilename);
|
|
48
|
+
const projectConfigFilename = ctx.projectConfig.name = "project.config.json";
|
|
49
|
+
const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
|
|
11
50
|
if (fs.existsSync(projectConfigPath)) {
|
|
12
51
|
try {
|
|
13
52
|
const projectConfig = fs.readJSONSync(projectConfigPath);
|
|
@@ -43,6 +82,7 @@ function updateProjectConfig(options) {
|
|
|
43
82
|
});
|
|
44
83
|
logger.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
45
84
|
}
|
|
85
|
+
ctx.projectConfig.value = projectConfig;
|
|
46
86
|
return projectConfig;
|
|
47
87
|
} catch {
|
|
48
88
|
logger.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
@@ -53,8 +93,8 @@ function updateProjectConfig(options) {
|
|
|
53
93
|
}
|
|
54
94
|
function updatePackageJson(options) {
|
|
55
95
|
const { root, dest, command, cb, write = true } = options;
|
|
56
|
-
const packageJsonFilename = "package.json";
|
|
57
|
-
const packageJsonPath = path.resolve(root, packageJsonFilename);
|
|
96
|
+
const packageJsonFilename = ctx.packageJson.name = "package.json";
|
|
97
|
+
const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
|
|
58
98
|
if (fs.existsSync(packageJsonPath)) {
|
|
59
99
|
try {
|
|
60
100
|
const packageJson = fs.readJSONSync(packageJsonPath);
|
|
@@ -63,6 +103,7 @@ function updatePackageJson(options) {
|
|
|
63
103
|
if (command === "weapp-vite") {
|
|
64
104
|
set(packageJson, "scripts.open", `${command} open`);
|
|
65
105
|
set(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
106
|
+
set(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
66
107
|
}
|
|
67
108
|
cb?.(
|
|
68
109
|
(...args) => {
|
|
@@ -75,6 +116,7 @@ function updatePackageJson(options) {
|
|
|
75
116
|
});
|
|
76
117
|
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
77
118
|
}
|
|
119
|
+
ctx.packageJson.value = packageJson;
|
|
78
120
|
return packageJson;
|
|
79
121
|
} catch {
|
|
80
122
|
}
|
|
@@ -82,13 +124,10 @@ function updatePackageJson(options) {
|
|
|
82
124
|
}
|
|
83
125
|
function initViteConfigFile(options) {
|
|
84
126
|
const { root, write = true } = options;
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const targetFilename = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
90
|
-
const viteConfigFilePath = path.resolve(root, targetFilename);
|
|
91
|
-
const viteConfigFileCode = `import { defineConfig } from 'weapp-vite/config'
|
|
127
|
+
const type = get(ctx.packageJson.value, "type");
|
|
128
|
+
const targetFilename = ctx.viteConfig.name = type === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
129
|
+
const viteConfigFilePath = ctx.viteConfig.path = path.resolve(root, targetFilename);
|
|
130
|
+
const viteConfigFileCode = ctx.viteConfig.value = `import { defineConfig } from 'weapp-vite/config'
|
|
92
131
|
|
|
93
132
|
export default defineConfig({
|
|
94
133
|
weapp: {
|
|
@@ -116,12 +155,12 @@ function initTsDtsFile(options) {
|
|
|
116
155
|
}
|
|
117
156
|
function initTsJsonFiles(options) {
|
|
118
157
|
const { root, write = true } = options;
|
|
119
|
-
const tsJsonFilename = "tsconfig.json";
|
|
120
|
-
const tsJsonFilePath = path.resolve(root, tsJsonFilename);
|
|
121
|
-
const tsNodeJsonFilename = "tsconfig.node.json";
|
|
122
|
-
const tsNodeJsonFilePath = path.resolve(root, tsNodeJsonFilename);
|
|
158
|
+
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
159
|
+
const tsJsonFilePath = ctx.tsconfig.path = path.resolve(root, tsJsonFilename);
|
|
160
|
+
const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
|
|
161
|
+
const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
|
|
123
162
|
if (write) {
|
|
124
|
-
|
|
163
|
+
const tsJsonValue = {
|
|
125
164
|
compilerOptions: {
|
|
126
165
|
target: "ES2020",
|
|
127
166
|
jsx: "preserve",
|
|
@@ -131,9 +170,18 @@ function initTsJsonFiles(options) {
|
|
|
131
170
|
"DOM.Iterable"
|
|
132
171
|
],
|
|
133
172
|
useDefineForClassFields: true,
|
|
173
|
+
baseUrl: ".",
|
|
134
174
|
module: "ESNext",
|
|
135
175
|
moduleResolution: "bundler",
|
|
176
|
+
paths: {
|
|
177
|
+
"@/*": [
|
|
178
|
+
"./*"
|
|
179
|
+
]
|
|
180
|
+
},
|
|
136
181
|
resolveJsonModule: true,
|
|
182
|
+
types: [
|
|
183
|
+
"miniprogram-api-typings"
|
|
184
|
+
],
|
|
137
185
|
allowImportingTsExtensions: true,
|
|
138
186
|
allowJs: true,
|
|
139
187
|
strict: true,
|
|
@@ -150,15 +198,26 @@ function initTsJsonFiles(options) {
|
|
|
150
198
|
}
|
|
151
199
|
],
|
|
152
200
|
include: [
|
|
153
|
-
"
|
|
154
|
-
"
|
|
201
|
+
"**/*.ts",
|
|
202
|
+
"**/*.js"
|
|
203
|
+
],
|
|
204
|
+
exclude: [
|
|
205
|
+
"node_modules"
|
|
155
206
|
]
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
207
|
+
};
|
|
208
|
+
if (write) {
|
|
209
|
+
fs.outputJSONSync(
|
|
210
|
+
tsJsonFilePath,
|
|
211
|
+
tsJsonValue,
|
|
212
|
+
{
|
|
213
|
+
encoding: "utf8",
|
|
214
|
+
spaces: 2
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
logger.log(`\u2728 \u8BBE\u7F6E ${tsJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
218
|
+
}
|
|
219
|
+
ctx.tsconfig.value = tsJsonValue;
|
|
220
|
+
const tsJsonNodeValue = {
|
|
162
221
|
compilerOptions: {
|
|
163
222
|
composite: true,
|
|
164
223
|
module: "ESNext",
|
|
@@ -168,13 +227,17 @@ function initTsJsonFiles(options) {
|
|
|
168
227
|
skipLibCheck: true
|
|
169
228
|
},
|
|
170
229
|
include: [
|
|
171
|
-
|
|
230
|
+
ctx.viteConfig.name
|
|
172
231
|
]
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
232
|
+
};
|
|
233
|
+
if (write) {
|
|
234
|
+
fs.outputJSONSync(tsNodeJsonFilePath, tsJsonNodeValue, {
|
|
235
|
+
encoding: "utf8",
|
|
236
|
+
spaces: 2
|
|
237
|
+
});
|
|
238
|
+
logger.log(`\u2728 \u8BBE\u7F6E ${tsNodeJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
239
|
+
}
|
|
240
|
+
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
178
241
|
}
|
|
179
242
|
}
|
|
180
243
|
function initConfig(options) {
|
|
@@ -186,6 +249,7 @@ function initConfig(options) {
|
|
|
186
249
|
initTsDtsFile({ root });
|
|
187
250
|
initTsJsonFiles({ root });
|
|
188
251
|
}
|
|
252
|
+
return ctx;
|
|
189
253
|
}
|
|
190
254
|
export {
|
|
191
255
|
initConfig,
|