@weapp-core/init 1.0.2 → 1.0.4
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 +89 -28
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +89 -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,44 @@ 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
|
-
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
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
|
+
}
|
|
164
|
+
cb?.(
|
|
165
|
+
(...args) => {
|
|
166
|
+
(0, import_shared.set)(packageJson, ...args);
|
|
157
167
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
);
|
|
169
|
+
if (write) {
|
|
170
|
+
import_fs_extra.default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
171
|
+
spaces: 2
|
|
172
|
+
});
|
|
173
|
+
import_logger.default.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
161
174
|
}
|
|
175
|
+
ctx.packageJson.value = packageJson;
|
|
176
|
+
return packageJson;
|
|
177
|
+
} catch {
|
|
162
178
|
}
|
|
163
179
|
}
|
|
164
180
|
function initViteConfigFile(options) {
|
|
@@ -279,10 +295,55 @@ function initTsJsonFiles(options) {
|
|
|
279
295
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
280
296
|
}
|
|
281
297
|
}
|
|
298
|
+
function updateGitIgnore(options) {
|
|
299
|
+
const { root, write = true } = options;
|
|
300
|
+
const filepath = import_node_path.default.resolve(root, ".gitignore");
|
|
301
|
+
const data = `# dependencies
|
|
302
|
+
node_modules
|
|
303
|
+
.pnp
|
|
304
|
+
.pnp.js
|
|
305
|
+
|
|
306
|
+
# testing
|
|
307
|
+
coverage
|
|
308
|
+
|
|
309
|
+
# next.js
|
|
310
|
+
.next/
|
|
311
|
+
out/
|
|
312
|
+
build
|
|
313
|
+
|
|
314
|
+
# misc
|
|
315
|
+
.DS_Store
|
|
316
|
+
*.pem
|
|
317
|
+
|
|
318
|
+
# debug
|
|
319
|
+
npm-debug.log*
|
|
320
|
+
yarn-debug.log*
|
|
321
|
+
yarn-error.log*
|
|
322
|
+
.pnpm-debug.log*
|
|
323
|
+
|
|
324
|
+
# local env files
|
|
325
|
+
.env.local
|
|
326
|
+
.env.development.local
|
|
327
|
+
.env.test.local
|
|
328
|
+
.env.production.local
|
|
329
|
+
|
|
330
|
+
# turbo
|
|
331
|
+
.turbo
|
|
332
|
+
|
|
333
|
+
dist
|
|
334
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
335
|
+
if (write) {
|
|
336
|
+
import_fs_extra.default.outputFileSync(filepath, data, {
|
|
337
|
+
encoding: "utf8"
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return data;
|
|
341
|
+
}
|
|
282
342
|
function initConfig(options) {
|
|
283
343
|
const { root = import_node_process.default.cwd(), command } = options;
|
|
284
344
|
updateProjectConfig({ root });
|
|
285
345
|
updatePackageJson({ root, command });
|
|
346
|
+
updateGitIgnore({ root });
|
|
286
347
|
if (command === "weapp-vite") {
|
|
287
348
|
initViteConfigFile({ root });
|
|
288
349
|
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,44 @@ 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
|
-
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
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
|
+
}
|
|
125
|
+
cb?.(
|
|
126
|
+
(...args) => {
|
|
127
|
+
set(packageJson, ...args);
|
|
118
128
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
129
|
+
);
|
|
130
|
+
if (write) {
|
|
131
|
+
fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
|
|
132
|
+
spaces: 2
|
|
133
|
+
});
|
|
134
|
+
logger.log(`\u2728 \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
|
|
122
135
|
}
|
|
136
|
+
ctx.packageJson.value = packageJson;
|
|
137
|
+
return packageJson;
|
|
138
|
+
} catch {
|
|
123
139
|
}
|
|
124
140
|
}
|
|
125
141
|
function initViteConfigFile(options) {
|
|
@@ -240,10 +256,55 @@ function initTsJsonFiles(options) {
|
|
|
240
256
|
ctx.tsconfigNode.value = tsJsonNodeValue;
|
|
241
257
|
}
|
|
242
258
|
}
|
|
259
|
+
function updateGitIgnore(options) {
|
|
260
|
+
const { root, write = true } = options;
|
|
261
|
+
const filepath = path.resolve(root, ".gitignore");
|
|
262
|
+
const data = `# dependencies
|
|
263
|
+
node_modules
|
|
264
|
+
.pnp
|
|
265
|
+
.pnp.js
|
|
266
|
+
|
|
267
|
+
# testing
|
|
268
|
+
coverage
|
|
269
|
+
|
|
270
|
+
# next.js
|
|
271
|
+
.next/
|
|
272
|
+
out/
|
|
273
|
+
build
|
|
274
|
+
|
|
275
|
+
# misc
|
|
276
|
+
.DS_Store
|
|
277
|
+
*.pem
|
|
278
|
+
|
|
279
|
+
# debug
|
|
280
|
+
npm-debug.log*
|
|
281
|
+
yarn-debug.log*
|
|
282
|
+
yarn-error.log*
|
|
283
|
+
.pnpm-debug.log*
|
|
284
|
+
|
|
285
|
+
# local env files
|
|
286
|
+
.env.local
|
|
287
|
+
.env.development.local
|
|
288
|
+
.env.test.local
|
|
289
|
+
.env.production.local
|
|
290
|
+
|
|
291
|
+
# turbo
|
|
292
|
+
.turbo
|
|
293
|
+
|
|
294
|
+
dist
|
|
295
|
+
vite.config.ts.timestamp-*.mjs`;
|
|
296
|
+
if (write) {
|
|
297
|
+
fs.outputFileSync(filepath, data, {
|
|
298
|
+
encoding: "utf8"
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return data;
|
|
302
|
+
}
|
|
243
303
|
function initConfig(options) {
|
|
244
304
|
const { root = process.cwd(), command } = options;
|
|
245
305
|
updateProjectConfig({ root });
|
|
246
306
|
updatePackageJson({ root, command });
|
|
307
|
+
updateGitIgnore({ root });
|
|
247
308
|
if (command === "weapp-vite") {
|
|
248
309
|
initViteConfigFile({ root });
|
|
249
310
|
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.4",
|
|
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": {
|