@weapp-core/init 0.0.2-alpha.2 → 1.0.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 +97 -6
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +95 -6
- package/package.json +2 -2
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) {
|
|
@@ -76,8 +79,8 @@ function updateProjectConfig(options) {
|
|
|
76
79
|
import_fs_extra.default.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
|
|
77
80
|
spaces: 2
|
|
78
81
|
});
|
|
82
|
+
console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
79
83
|
}
|
|
80
|
-
console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
81
84
|
return projectConfig;
|
|
82
85
|
} catch {
|
|
83
86
|
console.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
@@ -96,7 +99,9 @@ function updatePackageJson(options) {
|
|
|
96
99
|
(0, import_shared.set)(packageJson, "scripts.dev", `${command} dev`);
|
|
97
100
|
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
98
101
|
if (command === "weapp-vite") {
|
|
102
|
+
(0, import_shared.set)(packageJson, "type", "module");
|
|
99
103
|
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
104
|
+
(0, import_shared.set)(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
100
105
|
}
|
|
101
106
|
cb?.(
|
|
102
107
|
(...args) => {
|
|
@@ -107,6 +112,7 @@ function updatePackageJson(options) {
|
|
|
107
112
|
import_fs_extra.default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
108
113
|
spaces: 2
|
|
109
114
|
});
|
|
115
|
+
console.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
110
116
|
}
|
|
111
117
|
return packageJson;
|
|
112
118
|
} catch {
|
|
@@ -115,27 +121,112 @@ function updatePackageJson(options) {
|
|
|
115
121
|
}
|
|
116
122
|
function initViteConfigFile(options) {
|
|
117
123
|
const { root, write = true } = options;
|
|
118
|
-
const
|
|
119
|
-
const
|
|
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'
|
|
120
127
|
|
|
121
|
-
export default defineConfig({
|
|
128
|
+
export default defineConfig({
|
|
129
|
+
weapp: {
|
|
130
|
+
// weapp-vite options
|
|
131
|
+
},
|
|
132
|
+
})
|
|
122
133
|
`;
|
|
123
134
|
if (write) {
|
|
124
|
-
import_fs_extra.default.outputFileSync(
|
|
135
|
+
import_fs_extra.default.outputFileSync(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
136
|
+
console.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
137
|
+
}
|
|
138
|
+
return viteConfigFileCode;
|
|
139
|
+
}
|
|
140
|
+
function initTsDtsFile(options) {
|
|
141
|
+
const { root, write = true } = options;
|
|
142
|
+
const targetFilename = "vite-env.d.ts";
|
|
143
|
+
const viteDtsFilePath = import_node_path.default.resolve(root, targetFilename);
|
|
144
|
+
const code = `/// <reference types="vite/client" />
|
|
145
|
+
`;
|
|
146
|
+
if (write) {
|
|
147
|
+
import_fs_extra.default.outputFileSync(viteDtsFilePath, code, "utf8");
|
|
148
|
+
console.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
125
149
|
}
|
|
126
150
|
return code;
|
|
127
151
|
}
|
|
152
|
+
function initTsJsonFiles(options) {
|
|
153
|
+
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);
|
|
158
|
+
if (write) {
|
|
159
|
+
import_fs_extra.default.outputJSONSync(tsJsonFilePath, {
|
|
160
|
+
compilerOptions: {
|
|
161
|
+
target: "ES2020",
|
|
162
|
+
jsx: "preserve",
|
|
163
|
+
lib: [
|
|
164
|
+
"ES2020",
|
|
165
|
+
"DOM",
|
|
166
|
+
"DOM.Iterable"
|
|
167
|
+
],
|
|
168
|
+
useDefineForClassFields: true,
|
|
169
|
+
module: "ESNext",
|
|
170
|
+
moduleResolution: "bundler",
|
|
171
|
+
resolveJsonModule: true,
|
|
172
|
+
allowImportingTsExtensions: true,
|
|
173
|
+
allowJs: true,
|
|
174
|
+
strict: true,
|
|
175
|
+
noFallthroughCasesInSwitch: true,
|
|
176
|
+
noUnusedLocals: true,
|
|
177
|
+
noUnusedParameters: true,
|
|
178
|
+
noEmit: true,
|
|
179
|
+
isolatedModules: true,
|
|
180
|
+
skipLibCheck: true
|
|
181
|
+
},
|
|
182
|
+
references: [
|
|
183
|
+
{
|
|
184
|
+
path: "./tsconfig.node.json"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
include: [
|
|
188
|
+
"src/**/*.ts",
|
|
189
|
+
"src/**/*.js"
|
|
190
|
+
]
|
|
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, {
|
|
197
|
+
compilerOptions: {
|
|
198
|
+
composite: true,
|
|
199
|
+
module: "ESNext",
|
|
200
|
+
moduleResolution: "bundler",
|
|
201
|
+
strict: true,
|
|
202
|
+
allowSyntheticDefaultImports: true,
|
|
203
|
+
skipLibCheck: true
|
|
204
|
+
},
|
|
205
|
+
include: [
|
|
206
|
+
"vite.config.ts"
|
|
207
|
+
]
|
|
208
|
+
}, {
|
|
209
|
+
encoding: "utf8",
|
|
210
|
+
spaces: 2
|
|
211
|
+
});
|
|
212
|
+
console.log(`\u2728 \u8BBE\u7F6E ${tsNodeJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
128
215
|
function initConfig(options) {
|
|
129
|
-
const { root, command } = options;
|
|
216
|
+
const { root = import_node_process.default.cwd(), command } = options;
|
|
130
217
|
updateProjectConfig({ root });
|
|
131
218
|
updatePackageJson({ root, command });
|
|
132
219
|
if (command === "weapp-vite") {
|
|
133
220
|
initViteConfigFile({ root });
|
|
221
|
+
initTsDtsFile({ root });
|
|
222
|
+
initTsJsonFiles({ root });
|
|
134
223
|
}
|
|
135
224
|
}
|
|
136
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
226
|
0 && (module.exports = {
|
|
138
227
|
initConfig,
|
|
228
|
+
initTsDtsFile,
|
|
229
|
+
initTsJsonFiles,
|
|
139
230
|
initViteConfigFile,
|
|
140
231
|
updatePackageJson,
|
|
141
232
|
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
|
|
19
|
-
srcMiniprogramRoot?: string
|
|
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
|
|
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
|
|
19
|
-
srcMiniprogramRoot?: string
|
|
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
|
|
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) {
|
|
@@ -39,8 +40,8 @@ function updateProjectConfig(options) {
|
|
|
39
40
|
fs.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
|
|
40
41
|
spaces: 2
|
|
41
42
|
});
|
|
43
|
+
console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
42
44
|
}
|
|
43
|
-
console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
44
45
|
return projectConfig;
|
|
45
46
|
} catch {
|
|
46
47
|
console.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
|
|
@@ -59,7 +60,9 @@ function updatePackageJson(options) {
|
|
|
59
60
|
set(packageJson, "scripts.dev", `${command} dev`);
|
|
60
61
|
set(packageJson, "scripts.build", `${command} build`);
|
|
61
62
|
if (command === "weapp-vite") {
|
|
63
|
+
set(packageJson, "type", "module");
|
|
62
64
|
set(packageJson, "scripts.open", `${command} open`);
|
|
65
|
+
set(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
63
66
|
}
|
|
64
67
|
cb?.(
|
|
65
68
|
(...args) => {
|
|
@@ -70,6 +73,7 @@ function updatePackageJson(options) {
|
|
|
70
73
|
fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
71
74
|
spaces: 2
|
|
72
75
|
});
|
|
76
|
+
console.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
73
77
|
}
|
|
74
78
|
return packageJson;
|
|
75
79
|
} catch {
|
|
@@ -78,26 +82,111 @@ function updatePackageJson(options) {
|
|
|
78
82
|
}
|
|
79
83
|
function initViteConfigFile(options) {
|
|
80
84
|
const { root, write = true } = options;
|
|
81
|
-
const
|
|
82
|
-
const
|
|
85
|
+
const targetFilename = "vite.config.ts";
|
|
86
|
+
const viteConfigFilePath = path.resolve(root, targetFilename);
|
|
87
|
+
const viteConfigFileCode = `import { defineConfig } from 'weapp-vite/config'
|
|
83
88
|
|
|
84
|
-
export default defineConfig({
|
|
89
|
+
export default defineConfig({
|
|
90
|
+
weapp: {
|
|
91
|
+
// weapp-vite options
|
|
92
|
+
},
|
|
93
|
+
})
|
|
85
94
|
`;
|
|
86
95
|
if (write) {
|
|
87
|
-
fs.outputFileSync(
|
|
96
|
+
fs.outputFileSync(viteConfigFilePath, viteConfigFileCode, "utf8");
|
|
97
|
+
console.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
98
|
+
}
|
|
99
|
+
return viteConfigFileCode;
|
|
100
|
+
}
|
|
101
|
+
function initTsDtsFile(options) {
|
|
102
|
+
const { root, write = true } = options;
|
|
103
|
+
const targetFilename = "vite-env.d.ts";
|
|
104
|
+
const viteDtsFilePath = path.resolve(root, targetFilename);
|
|
105
|
+
const code = `/// <reference types="vite/client" />
|
|
106
|
+
`;
|
|
107
|
+
if (write) {
|
|
108
|
+
fs.outputFileSync(viteDtsFilePath, code, "utf8");
|
|
109
|
+
console.log(`\u2728 \u8BBE\u7F6E ${targetFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
88
110
|
}
|
|
89
111
|
return code;
|
|
90
112
|
}
|
|
113
|
+
function initTsJsonFiles(options) {
|
|
114
|
+
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);
|
|
119
|
+
if (write) {
|
|
120
|
+
fs.outputJSONSync(tsJsonFilePath, {
|
|
121
|
+
compilerOptions: {
|
|
122
|
+
target: "ES2020",
|
|
123
|
+
jsx: "preserve",
|
|
124
|
+
lib: [
|
|
125
|
+
"ES2020",
|
|
126
|
+
"DOM",
|
|
127
|
+
"DOM.Iterable"
|
|
128
|
+
],
|
|
129
|
+
useDefineForClassFields: true,
|
|
130
|
+
module: "ESNext",
|
|
131
|
+
moduleResolution: "bundler",
|
|
132
|
+
resolveJsonModule: true,
|
|
133
|
+
allowImportingTsExtensions: true,
|
|
134
|
+
allowJs: true,
|
|
135
|
+
strict: true,
|
|
136
|
+
noFallthroughCasesInSwitch: true,
|
|
137
|
+
noUnusedLocals: true,
|
|
138
|
+
noUnusedParameters: true,
|
|
139
|
+
noEmit: true,
|
|
140
|
+
isolatedModules: true,
|
|
141
|
+
skipLibCheck: true
|
|
142
|
+
},
|
|
143
|
+
references: [
|
|
144
|
+
{
|
|
145
|
+
path: "./tsconfig.node.json"
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
include: [
|
|
149
|
+
"src/**/*.ts",
|
|
150
|
+
"src/**/*.js"
|
|
151
|
+
]
|
|
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, {
|
|
158
|
+
compilerOptions: {
|
|
159
|
+
composite: true,
|
|
160
|
+
module: "ESNext",
|
|
161
|
+
moduleResolution: "bundler",
|
|
162
|
+
strict: true,
|
|
163
|
+
allowSyntheticDefaultImports: true,
|
|
164
|
+
skipLibCheck: true
|
|
165
|
+
},
|
|
166
|
+
include: [
|
|
167
|
+
"vite.config.ts"
|
|
168
|
+
]
|
|
169
|
+
}, {
|
|
170
|
+
encoding: "utf8",
|
|
171
|
+
spaces: 2
|
|
172
|
+
});
|
|
173
|
+
console.log(`\u2728 \u8BBE\u7F6E ${tsNodeJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
91
176
|
function initConfig(options) {
|
|
92
|
-
const { root, command } = options;
|
|
177
|
+
const { root = process.cwd(), command } = options;
|
|
93
178
|
updateProjectConfig({ root });
|
|
94
179
|
updatePackageJson({ root, command });
|
|
95
180
|
if (command === "weapp-vite") {
|
|
96
181
|
initViteConfigFile({ root });
|
|
182
|
+
initTsDtsFile({ root });
|
|
183
|
+
initTsJsonFiles({ root });
|
|
97
184
|
}
|
|
98
185
|
}
|
|
99
186
|
export {
|
|
100
187
|
initConfig,
|
|
188
|
+
initTsDtsFile,
|
|
189
|
+
initTsJsonFiles,
|
|
101
190
|
initViteConfigFile,
|
|
102
191
|
updatePackageJson,
|
|
103
192
|
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
|
|
4
|
+
"version": "1.0.0",
|
|
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
|
|
25
|
+
"@weapp-core/shared": "^1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"dev": "tsup --watch --sourcemap",
|