@weapp-core/init 0.0.2-alpha.2 → 0.0.2-alpha.3

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
@@ -31,12 +31,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  initConfig: () => initConfig,
34
+ initTsDtsFile: () => initTsDtsFile,
35
+ initTsJsonFiles: () => initTsJsonFiles,
34
36
  initViteConfigFile: () => initViteConfigFile,
35
37
  updatePackageJson: () => updatePackageJson,
36
38
  updateProjectConfig: () => updateProjectConfig
37
39
  });
38
40
  module.exports = __toCommonJS(src_exports);
39
41
  var import_node_path = __toESM(require("path"), 1);
42
+ var import_node_process = __toESM(require("process"), 1);
40
43
  var import_fs_extra = __toESM(require("fs-extra"), 1);
41
44
  var import_shared = require("@weapp-core/shared");
42
45
  function updateProjectConfig(options) {
@@ -115,27 +118,100 @@ function updatePackageJson(options) {
115
118
  }
116
119
  function initViteConfigFile(options) {
117
120
  const { root, write = true } = options;
118
- const viteConfigFile = import_node_path.default.resolve(root, "vite.config.ts");
119
- const code = `import { defineConfig } from 'weapp-vite/config'
121
+ const viteConfigFilePath = import_node_path.default.resolve(root, "vite.config.ts");
122
+ const viteConfigFileCode = `import { defineConfig } from 'weapp-vite/config'
120
123
 
121
124
  export default defineConfig({})
122
125
  `;
123
126
  if (write) {
124
- import_fs_extra.default.outputFileSync(viteConfigFile, code, "utf8");
127
+ import_fs_extra.default.outputFileSync(viteConfigFilePath, viteConfigFileCode, "utf8");
128
+ }
129
+ return viteConfigFileCode;
130
+ }
131
+ function initTsDtsFile(options) {
132
+ const { root, write = true } = options;
133
+ const viteDtsFilePath = import_node_path.default.resolve(root, "vite-env.d.ts");
134
+ const code = `/// <reference types="vite/client" />
135
+ `;
136
+ if (write) {
137
+ import_fs_extra.default.outputFileSync(viteDtsFilePath, code, "utf8");
125
138
  }
126
139
  return code;
127
140
  }
141
+ function initTsJsonFiles(options) {
142
+ const { root, write = true } = options;
143
+ const tsJsonFilePath = import_node_path.default.resolve(root, "tsconfig.json");
144
+ const tsNodeJsonFilePath = import_node_path.default.resolve(root, "tsconfig.node.json");
145
+ if (write) {
146
+ import_fs_extra.default.outputJSONSync(tsJsonFilePath, {
147
+ compilerOptions: {
148
+ target: "ES2020",
149
+ jsx: "preserve",
150
+ lib: [
151
+ "ES2020",
152
+ "DOM",
153
+ "DOM.Iterable"
154
+ ],
155
+ useDefineForClassFields: true,
156
+ module: "ESNext",
157
+ moduleResolution: "bundler",
158
+ resolveJsonModule: true,
159
+ allowImportingTsExtensions: true,
160
+ allowJs: true,
161
+ strict: true,
162
+ noFallthroughCasesInSwitch: true,
163
+ noUnusedLocals: true,
164
+ noUnusedParameters: true,
165
+ noEmit: true,
166
+ isolatedModules: true,
167
+ skipLibCheck: true
168
+ },
169
+ references: [
170
+ {
171
+ path: "./tsconfig.node.json"
172
+ }
173
+ ],
174
+ include: [
175
+ "src/**/*.ts",
176
+ "src/**/*.js"
177
+ ]
178
+ }, {
179
+ encoding: "utf8",
180
+ spaces: 2
181
+ });
182
+ import_fs_extra.default.outputJSONSync(tsNodeJsonFilePath, {
183
+ compilerOptions: {
184
+ composite: true,
185
+ module: "ESNext",
186
+ moduleResolution: "bundler",
187
+ strict: true,
188
+ allowSyntheticDefaultImports: true,
189
+ skipLibCheck: true
190
+ },
191
+ include: [
192
+ "vite.config.ts"
193
+ ]
194
+ }, {
195
+ encoding: "utf8",
196
+ spaces: 2
197
+ });
198
+ }
199
+ }
128
200
  function initConfig(options) {
129
- const { root, command } = options;
201
+ const { root = import_node_process.default.cwd(), command } = options;
130
202
  updateProjectConfig({ root });
131
203
  updatePackageJson({ root, command });
132
204
  if (command === "weapp-vite") {
133
205
  initViteConfigFile({ root });
206
+ initTsDtsFile({ root });
207
+ initTsJsonFiles({ root });
134
208
  }
135
209
  }
136
210
  // Annotate the CommonJS export names for ESM import in node:
137
211
  0 && (module.exports = {
138
212
  initConfig,
213
+ initTsDtsFile,
214
+ initTsJsonFiles,
139
215
  initViteConfigFile,
140
216
  updatePackageJson,
141
217
  updateProjectConfig
package/dist/index.d.cts CHANGED
@@ -15,8 +15,8 @@ interface UpdatePackageJsonOptions extends SharedUpdateOptions {
15
15
  command?: 'weapp-vite';
16
16
  }
17
17
  declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
18
- miniprogramRoot?: string | undefined;
19
- srcMiniprogramRoot?: string | undefined;
18
+ miniprogramRoot?: string;
19
+ srcMiniprogramRoot?: string;
20
20
  setting: {
21
21
  packNpmManually: boolean;
22
22
  packNpmRelationList: {
@@ -29,9 +29,11 @@ declare function updatePackageJson(options: UpdatePackageJsonOptions): {
29
29
  scripts: Record<string, string>;
30
30
  } | undefined;
31
31
  declare function initViteConfigFile(options: SharedUpdateOptions): string;
32
+ declare function initTsDtsFile(options: SharedUpdateOptions): string;
33
+ declare function initTsJsonFiles(options: SharedUpdateOptions): void;
32
34
  declare function initConfig(options: {
33
- root: string;
35
+ root?: string;
34
36
  command?: 'weapp-vite';
35
37
  }): void;
36
38
 
37
- export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initViteConfigFile, updatePackageJson, updateProjectConfig };
39
+ export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, updatePackageJson, updateProjectConfig };
package/dist/index.d.ts CHANGED
@@ -15,8 +15,8 @@ interface UpdatePackageJsonOptions extends SharedUpdateOptions {
15
15
  command?: 'weapp-vite';
16
16
  }
17
17
  declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
18
- miniprogramRoot?: string | undefined;
19
- srcMiniprogramRoot?: string | undefined;
18
+ miniprogramRoot?: string;
19
+ srcMiniprogramRoot?: string;
20
20
  setting: {
21
21
  packNpmManually: boolean;
22
22
  packNpmRelationList: {
@@ -29,9 +29,11 @@ declare function updatePackageJson(options: UpdatePackageJsonOptions): {
29
29
  scripts: Record<string, string>;
30
30
  } | undefined;
31
31
  declare function initViteConfigFile(options: SharedUpdateOptions): string;
32
+ declare function initTsDtsFile(options: SharedUpdateOptions): string;
33
+ declare function initTsJsonFiles(options: SharedUpdateOptions): void;
32
34
  declare function initConfig(options: {
33
- root: string;
35
+ root?: string;
34
36
  command?: 'weapp-vite';
35
37
  }): void;
36
38
 
37
- export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initViteConfigFile, updatePackageJson, updateProjectConfig };
39
+ export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, updatePackageJson, updateProjectConfig };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/index.ts
2
2
  import path from "node:path";
3
+ import process from "node:process";
3
4
  import fs from "fs-extra";
4
5
  import { get, set } from "@weapp-core/shared";
5
6
  function updateProjectConfig(options) {
@@ -78,26 +79,99 @@ function updatePackageJson(options) {
78
79
  }
79
80
  function initViteConfigFile(options) {
80
81
  const { root, write = true } = options;
81
- const viteConfigFile = path.resolve(root, "vite.config.ts");
82
- const code = `import { defineConfig } from 'weapp-vite/config'
82
+ const viteConfigFilePath = path.resolve(root, "vite.config.ts");
83
+ const viteConfigFileCode = `import { defineConfig } from 'weapp-vite/config'
83
84
 
84
85
  export default defineConfig({})
85
86
  `;
86
87
  if (write) {
87
- fs.outputFileSync(viteConfigFile, code, "utf8");
88
+ fs.outputFileSync(viteConfigFilePath, viteConfigFileCode, "utf8");
89
+ }
90
+ return viteConfigFileCode;
91
+ }
92
+ function initTsDtsFile(options) {
93
+ const { root, write = true } = options;
94
+ const viteDtsFilePath = path.resolve(root, "vite-env.d.ts");
95
+ const code = `/// <reference types="vite/client" />
96
+ `;
97
+ if (write) {
98
+ fs.outputFileSync(viteDtsFilePath, code, "utf8");
88
99
  }
89
100
  return code;
90
101
  }
102
+ function initTsJsonFiles(options) {
103
+ const { root, write = true } = options;
104
+ const tsJsonFilePath = path.resolve(root, "tsconfig.json");
105
+ const tsNodeJsonFilePath = path.resolve(root, "tsconfig.node.json");
106
+ if (write) {
107
+ fs.outputJSONSync(tsJsonFilePath, {
108
+ compilerOptions: {
109
+ target: "ES2020",
110
+ jsx: "preserve",
111
+ lib: [
112
+ "ES2020",
113
+ "DOM",
114
+ "DOM.Iterable"
115
+ ],
116
+ useDefineForClassFields: true,
117
+ module: "ESNext",
118
+ moduleResolution: "bundler",
119
+ resolveJsonModule: true,
120
+ allowImportingTsExtensions: true,
121
+ allowJs: true,
122
+ strict: true,
123
+ noFallthroughCasesInSwitch: true,
124
+ noUnusedLocals: true,
125
+ noUnusedParameters: true,
126
+ noEmit: true,
127
+ isolatedModules: true,
128
+ skipLibCheck: true
129
+ },
130
+ references: [
131
+ {
132
+ path: "./tsconfig.node.json"
133
+ }
134
+ ],
135
+ include: [
136
+ "src/**/*.ts",
137
+ "src/**/*.js"
138
+ ]
139
+ }, {
140
+ encoding: "utf8",
141
+ spaces: 2
142
+ });
143
+ fs.outputJSONSync(tsNodeJsonFilePath, {
144
+ compilerOptions: {
145
+ composite: true,
146
+ module: "ESNext",
147
+ moduleResolution: "bundler",
148
+ strict: true,
149
+ allowSyntheticDefaultImports: true,
150
+ skipLibCheck: true
151
+ },
152
+ include: [
153
+ "vite.config.ts"
154
+ ]
155
+ }, {
156
+ encoding: "utf8",
157
+ spaces: 2
158
+ });
159
+ }
160
+ }
91
161
  function initConfig(options) {
92
- const { root, command } = options;
162
+ const { root = process.cwd(), command } = options;
93
163
  updateProjectConfig({ root });
94
164
  updatePackageJson({ root, command });
95
165
  if (command === "weapp-vite") {
96
166
  initViteConfigFile({ root });
167
+ initTsDtsFile({ root });
168
+ initTsJsonFiles({ root });
97
169
  }
98
170
  }
99
171
  export {
100
172
  initConfig,
173
+ initTsDtsFile,
174
+ initTsJsonFiles,
101
175
  initViteConfigFile,
102
176
  updatePackageJson,
103
177
  updateProjectConfig
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/init",
3
3
  "type": "module",
4
- "version": "0.0.2-alpha.2",
4
+ "version": "0.0.2-alpha.3",
5
5
  "description": "@weapp-core/init",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "fs-extra": "^11.2.0",
25
- "@weapp-core/shared": "^0.0.2-alpha.2"
25
+ "@weapp-core/shared": "^0.0.2-alpha.3"
26
26
  },
27
27
  "scripts": {
28
28
  "dev": "tsup --watch --sourcemap",