@weapp-core/init 1.0.3 → 1.0.5
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/LICENSE +1 -1
- package/dist/index.cjs +90 -28
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +90 -28
- package/package.json +10 -2
package/LICENSE
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -40,9 +40,9 @@ __export(src_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
41
|
var import_node_path = __toESM(require("path"), 1);
|
|
42
42
|
var import_node_process = __toESM(require("process"), 1);
|
|
43
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
44
|
-
var import_shared = require("@weapp-core/shared");
|
|
45
43
|
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
44
|
+
var import_shared = require("@weapp-core/shared");
|
|
45
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
46
46
|
|
|
47
47
|
// src/context.ts
|
|
48
48
|
function createContext() {
|
|
@@ -83,8 +83,14 @@ function createContext() {
|
|
|
83
83
|
// src/index.ts
|
|
84
84
|
var ctx = createContext();
|
|
85
85
|
function updateProjectConfig(options) {
|
|
86
|
-
const { root, dest, cb, write
|
|
87
|
-
|
|
86
|
+
const { root, dest, cb, write, filename } = (0, import_shared.defu)(
|
|
87
|
+
options,
|
|
88
|
+
{
|
|
89
|
+
write: true,
|
|
90
|
+
filename: "project.config.json"
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
88
94
|
const projectConfigPath = ctx.projectConfig.path = import_node_path.default.resolve(root, projectConfigFilename);
|
|
89
95
|
if (import_fs_extra.default.existsSync(projectConfigPath)) {
|
|
90
96
|
try {
|
|
@@ -131,34 +137,45 @@ function updateProjectConfig(options) {
|
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
function updatePackageJson(options) {
|
|
134
|
-
const { root, dest, command, cb, write
|
|
135
|
-
|
|
140
|
+
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
141
|
+
write: true,
|
|
142
|
+
filename: "package.json",
|
|
143
|
+
command: "weapp-vite"
|
|
144
|
+
});
|
|
145
|
+
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
136
146
|
const packageJsonPath = ctx.packageJson.path = import_node_path.default.resolve(root, packageJsonFilename);
|
|
147
|
+
let packageJson;
|
|
137
148
|
if (import_fs_extra.default.existsSync(packageJsonPath)) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
packageJson = import_fs_extra.default.readJSONSync(packageJsonPath);
|
|
150
|
+
} else {
|
|
151
|
+
packageJson = {
|
|
152
|
+
name: "weapp-vite-app"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
(0, import_shared.set)(packageJson, "scripts.dev", `${command} dev`);
|
|
157
|
+
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
158
|
+
if (command === "weapp-vite") {
|
|
159
|
+
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
160
|
+
(0, import_shared.set)(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
161
|
+
(0, import_shared.set)(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
162
|
+
(0, import_shared.set)(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
163
|
+
(0, import_shared.set)(packageJson, "devDependencies.typescript", `latest`);
|
|
164
|
+
}
|
|
165
|
+
cb?.(
|
|
166
|
+
(...args) => {
|
|
167
|
+
(0, import_shared.set)(packageJson, ...args);
|
|
157
168
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
);
|
|
170
|
+
if (write) {
|
|
171
|
+
import_fs_extra.default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
172
|
+
spaces: 2
|
|
173
|
+
});
|
|
174
|
+
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
161
175
|
}
|
|
176
|
+
ctx.packageJson.value = packageJson;
|
|
177
|
+
return packageJson;
|
|
178
|
+
} catch {
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
function initViteConfigFile(options) {
|
|
@@ -279,10 +296,55 @@ function initTsJsonFiles(options) {
|
|
|
279
296
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
280
297
|
}
|
|
281
298
|
}
|
|
299
|
+
function updateGitIgnore(options) {
|
|
300
|
+
const { root, write = true } = options;
|
|
301
|
+
const filepath = import_node_path.default.resolve(root, ".gitignore");
|
|
302
|
+
const data = `# dependencies
|
|
303
|
+
node_modules
|
|
304
|
+
.pnp
|
|
305
|
+
.pnp.js
|
|
306
|
+
|
|
307
|
+
# testing
|
|
308
|
+
coverage
|
|
309
|
+
|
|
310
|
+
# next.js
|
|
311
|
+
.next/
|
|
312
|
+
out/
|
|
313
|
+
build
|
|
314
|
+
|
|
315
|
+
# misc
|
|
316
|
+
.DS_Store
|
|
317
|
+
*.pem
|
|
318
|
+
|
|
319
|
+
# debug
|
|
320
|
+
npm-debug.log*
|
|
321
|
+
yarn-debug.log*
|
|
322
|
+
yarn-error.log*
|
|
323
|
+
.pnpm-debug.log*
|
|
324
|
+
|
|
325
|
+
# local env files
|
|
326
|
+
.env.local
|
|
327
|
+
.env.development.local
|
|
328
|
+
.env.test.local
|
|
329
|
+
.env.production.local
|
|
330
|
+
|
|
331
|
+
# turbo
|
|
332
|
+
.turbo
|
|
333
|
+
|
|
334
|
+
dist
|
|
335
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
336
|
+
if (write) {
|
|
337
|
+
import_fs_extra.default.outputFileSync(filepath, data, {
|
|
338
|
+
encoding: "utf8"
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return data;
|
|
342
|
+
}
|
|
282
343
|
function initConfig(options) {
|
|
283
344
|
const { root = import_node_process.default.cwd(), command } = options;
|
|
284
345
|
updateProjectConfig({ root });
|
|
285
346
|
updatePackageJson({ root, command });
|
|
347
|
+
updateGitIgnore({ root });
|
|
286
348
|
if (command === "weapp-vite") {
|
|
287
349
|
initViteConfigFile({ root });
|
|
288
350
|
initTsDtsFile({ root });
|
package/dist/index.d.cts
CHANGED
|
@@ -12,9 +12,11 @@ interface SharedUpdateOptions {
|
|
|
12
12
|
cb?: (set: SetMethod) => void;
|
|
13
13
|
}
|
|
14
14
|
interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
15
|
+
filename?: string;
|
|
15
16
|
}
|
|
16
17
|
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
17
18
|
command?: 'weapp-vite';
|
|
19
|
+
filename?: string;
|
|
18
20
|
}
|
|
19
21
|
interface ProjectConfig {
|
|
20
22
|
miniprogramRoot?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ interface SharedUpdateOptions {
|
|
|
12
12
|
cb?: (set: SetMethod) => void;
|
|
13
13
|
}
|
|
14
14
|
interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
15
|
+
filename?: string;
|
|
15
16
|
}
|
|
16
17
|
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
17
18
|
command?: 'weapp-vite';
|
|
19
|
+
filename?: string;
|
|
18
20
|
}
|
|
19
21
|
interface ProjectConfig {
|
|
20
22
|
miniprogramRoot?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import { get, set } from "@weapp-core/shared";
|
|
6
4
|
import logger from "@weapp-core/logger";
|
|
5
|
+
import { defu, get, set } from "@weapp-core/shared";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
7
|
|
|
8
8
|
// src/context.ts
|
|
9
9
|
function createContext() {
|
|
@@ -44,8 +44,14 @@ function createContext() {
|
|
|
44
44
|
// src/index.ts
|
|
45
45
|
var ctx = createContext();
|
|
46
46
|
function updateProjectConfig(options) {
|
|
47
|
-
const { root, dest, cb, write
|
|
48
|
-
|
|
47
|
+
const { root, dest, cb, write, filename } = defu(
|
|
48
|
+
options,
|
|
49
|
+
{
|
|
50
|
+
write: true,
|
|
51
|
+
filename: "project.config.json"
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
49
55
|
const projectConfigPath = ctx.projectConfig.path = path.resolve(root, projectConfigFilename);
|
|
50
56
|
if (fs.existsSync(projectConfigPath)) {
|
|
51
57
|
try {
|
|
@@ -92,34 +98,45 @@ function updateProjectConfig(options) {
|
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
function updatePackageJson(options) {
|
|
95
|
-
const { root, dest, command, cb, write
|
|
96
|
-
|
|
101
|
+
const { root, dest, command, cb, write, filename } = defu(options, {
|
|
102
|
+
write: true,
|
|
103
|
+
filename: "package.json",
|
|
104
|
+
command: "weapp-vite"
|
|
105
|
+
});
|
|
106
|
+
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
97
107
|
const packageJsonPath = ctx.packageJson.path = path.resolve(root, packageJsonFilename);
|
|
108
|
+
let packageJson;
|
|
98
109
|
if (fs.existsSync(packageJsonPath)) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
packageJson = fs.readJSONSync(packageJsonPath);
|
|
111
|
+
} else {
|
|
112
|
+
packageJson = {
|
|
113
|
+
name: "weapp-vite-app"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
set(packageJson, "scripts.dev", `${command} dev`);
|
|
118
|
+
set(packageJson, "scripts.build", `${command} build`);
|
|
119
|
+
if (command === "weapp-vite") {
|
|
120
|
+
set(packageJson, "scripts.open", `${command} open`);
|
|
121
|
+
set(packageJson, "scripts.build-npm", `${command} build-npm`);
|
|
122
|
+
set(packageJson, "devDependencies.miniprogram-api-typings", `latest`);
|
|
123
|
+
set(packageJson, "devDependencies.weapp-vite", `latest`);
|
|
124
|
+
set(packageJson, "devDependencies.typescript", `latest`);
|
|
125
|
+
}
|
|
126
|
+
cb?.(
|
|
127
|
+
(...args) => {
|
|
128
|
+
set(packageJson, ...args);
|
|
118
129
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
);
|
|
131
|
+
if (write) {
|
|
132
|
+
fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
133
|
+
spaces: 2
|
|
134
|
+
});
|
|
135
|
+
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
122
136
|
}
|
|
137
|
+
ctx.packageJson.value = packageJson;
|
|
138
|
+
return packageJson;
|
|
139
|
+
} catch {
|
|
123
140
|
}
|
|
124
141
|
}
|
|
125
142
|
function initViteConfigFile(options) {
|
|
@@ -240,10 +257,55 @@ function initTsJsonFiles(options) {
|
|
|
240
257
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
241
258
|
}
|
|
242
259
|
}
|
|
260
|
+
function updateGitIgnore(options) {
|
|
261
|
+
const { root, write = true } = options;
|
|
262
|
+
const filepath = path.resolve(root, ".gitignore");
|
|
263
|
+
const data = `# dependencies
|
|
264
|
+
node_modules
|
|
265
|
+
.pnp
|
|
266
|
+
.pnp.js
|
|
267
|
+
|
|
268
|
+
# testing
|
|
269
|
+
coverage
|
|
270
|
+
|
|
271
|
+
# next.js
|
|
272
|
+
.next/
|
|
273
|
+
out/
|
|
274
|
+
build
|
|
275
|
+
|
|
276
|
+
# misc
|
|
277
|
+
.DS_Store
|
|
278
|
+
*.pem
|
|
279
|
+
|
|
280
|
+
# debug
|
|
281
|
+
npm-debug.log*
|
|
282
|
+
yarn-debug.log*
|
|
283
|
+
yarn-error.log*
|
|
284
|
+
.pnpm-debug.log*
|
|
285
|
+
|
|
286
|
+
# local env files
|
|
287
|
+
.env.local
|
|
288
|
+
.env.development.local
|
|
289
|
+
.env.test.local
|
|
290
|
+
.env.production.local
|
|
291
|
+
|
|
292
|
+
# turbo
|
|
293
|
+
.turbo
|
|
294
|
+
|
|
295
|
+
dist
|
|
296
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
297
|
+
if (write) {
|
|
298
|
+
fs.outputFileSync(filepath, data, {
|
|
299
|
+
encoding: "utf8"
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return data;
|
|
303
|
+
}
|
|
243
304
|
function initConfig(options) {
|
|
244
305
|
const { root = process.cwd(), command } = options;
|
|
245
306
|
updateProjectConfig({ root });
|
|
246
307
|
updatePackageJson({ root, command });
|
|
308
|
+
updateGitIgnore({ root });
|
|
247
309
|
if (command === "weapp-vite") {
|
|
248
310
|
initViteConfigFile({ root });
|
|
249
311
|
initTsDtsFile({ root });
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/init",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"description": "@weapp-core/init",
|
|
6
|
-
"author": "
|
|
6
|
+
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/weapp-vite/weapp-vite.git",
|
|
11
|
+
"directory": "@weapp-core/init"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/weapp-vite/weapp-vite/issues"
|
|
15
|
+
},
|
|
8
16
|
"keywords": [],
|
|
9
17
|
"sideEffects": false,
|
|
10
18
|
"exports": {
|