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