@weapp-core/init 5.0.1 → 6.0.1
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/README.md +39 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +2 -1
- package/package.json +8 -6
- package/dist/index.cjs +0 -1099
- package/dist/index.d.cts +0 -124
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @weapp-core/init
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@weapp-core/init` 用于初始化 weapp-vite 项目的基础配置文件,包含 `project.config`、`package.json`、`.gitignore`,并在需要时生成 `vite.config` 与 TypeScript 相关文件。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 初始化/更新小程序项目配置
|
|
10
|
+
- 自动写入 `package.json` 与 `.gitignore`
|
|
11
|
+
- 可根据命令类型生成 `vite.config` 与 `tsconfig` 系列文件
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @weapp-core/init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { initConfig } from '@weapp-core/init'
|
|
23
|
+
|
|
24
|
+
await initConfig({
|
|
25
|
+
root: process.cwd(),
|
|
26
|
+
command: 'weapp-vite',
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 配置
|
|
31
|
+
|
|
32
|
+
`initConfig(options)` 选项:
|
|
33
|
+
|
|
34
|
+
- `root`:项目根目录(默认 `process.cwd()`)
|
|
35
|
+
- `command`:当为 `weapp-vite` 时会额外生成 `vite.config` 与 TS 配置文件
|
|
36
|
+
|
|
37
|
+
## 相关链接
|
|
38
|
+
|
|
39
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import { PackageJson, TSConfig } from 'pkg-types';
|
|
2
2
|
import { set } from '@weapp-core/shared';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @description set-value 的写入方法签名
|
|
6
|
+
*/
|
|
4
7
|
interface SetMethod {
|
|
5
8
|
(path: set.InputType, value: any, options?: set.Options): void;
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @description 共享更新参数
|
|
12
|
+
*/
|
|
7
13
|
interface SharedUpdateOptions {
|
|
8
14
|
root: string;
|
|
9
15
|
dest?: string;
|
|
10
16
|
write?: boolean;
|
|
11
17
|
cb?: (set: SetMethod) => void;
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @description project.config 更新参数
|
|
21
|
+
*/
|
|
13
22
|
interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
14
23
|
filename?: string;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @description package.json 更新参数
|
|
27
|
+
*/
|
|
16
28
|
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
17
29
|
command?: 'weapp-vite';
|
|
18
30
|
filename?: string;
|
|
19
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* @description project.config.json 的核心字段类型
|
|
34
|
+
*/
|
|
20
35
|
interface ProjectConfig {
|
|
21
36
|
miniprogramRoot?: string;
|
|
22
37
|
srcMiniprogramRoot?: string;
|
|
@@ -29,11 +44,17 @@ interface ProjectConfig {
|
|
|
29
44
|
};
|
|
30
45
|
}
|
|
31
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @description init 过程中单个文件的上下文结构
|
|
49
|
+
*/
|
|
32
50
|
interface ContextDocument<T> {
|
|
33
51
|
name: string;
|
|
34
52
|
path: string;
|
|
35
53
|
value: T | null;
|
|
36
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* @description init 过程的上下文容器
|
|
57
|
+
*/
|
|
37
58
|
interface Context {
|
|
38
59
|
projectConfig: ContextDocument<ProjectConfig>;
|
|
39
60
|
packageJson: ContextDocument<PackageJson>;
|
|
@@ -110,12 +131,24 @@ declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<{
|
|
|
110
131
|
};
|
|
111
132
|
}>;
|
|
112
133
|
|
|
134
|
+
/**
|
|
135
|
+
* @description 创建或更新 package.json
|
|
136
|
+
*/
|
|
113
137
|
declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJson>;
|
|
114
138
|
|
|
139
|
+
/**
|
|
140
|
+
* @description 创建或更新 project.config.json
|
|
141
|
+
*/
|
|
115
142
|
declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig>;
|
|
116
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @description 重置全局上下文
|
|
146
|
+
*/
|
|
117
147
|
declare function resetContext(): void;
|
|
118
148
|
|
|
149
|
+
/**
|
|
150
|
+
* @description 初始化项目配置(project.config、package.json、tsconfig、vite.config 等)
|
|
151
|
+
*/
|
|
119
152
|
declare function initConfig(options: {
|
|
120
153
|
root?: string;
|
|
121
154
|
command?: 'weapp-vite';
|
package/dist/index.js
CHANGED
|
@@ -716,7 +716,7 @@ import logger2 from "@weapp-core/logger";
|
|
|
716
716
|
import { defu, get, set } from "@weapp-core/shared";
|
|
717
717
|
|
|
718
718
|
// ../../packages/weapp-vite/package.json
|
|
719
|
-
var version = "6.1
|
|
719
|
+
var version = "6.5.1";
|
|
720
720
|
|
|
721
721
|
// src/npm.ts
|
|
722
722
|
import https from "https";
|
|
@@ -974,6 +974,7 @@ yarn-error.log*
|
|
|
974
974
|
dist
|
|
975
975
|
dist-plugin
|
|
976
976
|
dist-web
|
|
977
|
+
dist/web
|
|
977
978
|
vite.config.ts.timestamp-*.mjs`;
|
|
978
979
|
function normalizeLineEndings(value) {
|
|
979
980
|
return value.replace(/\r\n/g, "\n");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/init",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.1",
|
|
5
5
|
"description": "@weapp-core/init",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,11 +18,10 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.js"
|
|
22
|
-
"require": "./dist/index.cjs"
|
|
21
|
+
"import": "./dist/index.js"
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
|
-
"main": "./dist/index.
|
|
24
|
+
"main": "./dist/index.js",
|
|
26
25
|
"module": "./dist/index.js",
|
|
27
26
|
"types": "./dist/index.d.ts",
|
|
28
27
|
"weapp-vite-dev": {
|
|
@@ -36,10 +35,13 @@
|
|
|
36
35
|
"files": [
|
|
37
36
|
"dist"
|
|
38
37
|
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
40
|
+
},
|
|
39
41
|
"dependencies": {
|
|
40
42
|
"fs-extra": "^11.3.3",
|
|
41
|
-
"@weapp-core/
|
|
42
|
-
"@weapp-core/
|
|
43
|
+
"@weapp-core/logger": "^3.0.3",
|
|
44
|
+
"@weapp-core/shared": "^3.0.1"
|
|
43
45
|
},
|
|
44
46
|
"scripts": {
|
|
45
47
|
"dev": "tsup --watch --sourcemap",
|
package/dist/index.cjs
DELETED
|
@@ -1,1099 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
createOrUpdatePackageJson: () => createOrUpdatePackageJson,
|
|
34
|
-
createOrUpdateProjectConfig: () => createOrUpdateProjectConfig,
|
|
35
|
-
initConfig: () => initConfig,
|
|
36
|
-
initTsDtsFile: () => initTsDtsFile,
|
|
37
|
-
initTsJsonFiles: () => initTsJsonFiles,
|
|
38
|
-
initViteConfigFile: () => initViteConfigFile,
|
|
39
|
-
resetContext: () => resetContext
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(index_exports);
|
|
42
|
-
var import_node_process = __toESM(require("process"), 1);
|
|
43
|
-
|
|
44
|
-
// src/configFiles.ts
|
|
45
|
-
var import_logger = __toESM(require("@weapp-core/logger"), 1);
|
|
46
|
-
|
|
47
|
-
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
48
|
-
var _lazyMatch = () => {
|
|
49
|
-
var __lib__ = (() => {
|
|
50
|
-
var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
|
|
51
|
-
for (var n in e) m(r, n, { get: e[n], enumerable: true });
|
|
52
|
-
}, H = (r, e, n, a) => {
|
|
53
|
-
if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, { get: () => e[t], enumerable: !(a = V(e, t)) || a.enumerable });
|
|
54
|
-
return r;
|
|
55
|
-
}, J = (r) => H(m({}, "__esModule", { value: true }), r), w = {};
|
|
56
|
-
q(w, { default: () => re });
|
|
57
|
-
var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => {
|
|
58
|
-
const e = /* @__PURE__ */ new Map();
|
|
59
|
-
return (n) => {
|
|
60
|
-
const a = e.get(n);
|
|
61
|
-
if (a) return a;
|
|
62
|
-
const t = r(n);
|
|
63
|
-
return e.set(n, t), t;
|
|
64
|
-
};
|
|
65
|
-
}, rr = (r, e, n = {}) => {
|
|
66
|
-
const a = { cache: {}, input: r, index: 0, indexMax: 0, options: n, output: [] };
|
|
67
|
-
if (v(e)(a) && a.index === r.length) return a.output;
|
|
68
|
-
throw new Error(`Failed to parse at index ${a.indexMax}`);
|
|
69
|
-
}, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => {
|
|
70
|
-
const n = {};
|
|
71
|
-
for (const a of r) {
|
|
72
|
-
if (a.length !== 1) throw new Error(`Invalid character: "${a}"`);
|
|
73
|
-
const t = a.charCodeAt(0);
|
|
74
|
-
n[t] = true;
|
|
75
|
-
}
|
|
76
|
-
return (a) => {
|
|
77
|
-
const t = a.index, o = a.input;
|
|
78
|
-
for (; a.index < o.length && o.charCodeAt(a.index) in n; ) a.index += 1;
|
|
79
|
-
const u = a.index;
|
|
80
|
-
if (u > t) {
|
|
81
|
-
if (!h(e) && !a.options.silent) {
|
|
82
|
-
const s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e;
|
|
83
|
-
h(c) || a.output.push(c);
|
|
84
|
-
}
|
|
85
|
-
a.indexMax = Math.max(a.indexMax, a.index);
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
};
|
|
89
|
-
}, nr = (r, e) => {
|
|
90
|
-
const n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a);
|
|
91
|
-
return g((o) => {
|
|
92
|
-
t.lastIndex = o.index;
|
|
93
|
-
const u = t.exec(o.input);
|
|
94
|
-
if (u) {
|
|
95
|
-
if (!h(e) && !o.options.silent) {
|
|
96
|
-
const s = d(e) ? e(...u, o.input, String(o.index)) : e;
|
|
97
|
-
h(s) || o.output.push(s);
|
|
98
|
-
}
|
|
99
|
-
return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), true;
|
|
100
|
-
} else return false;
|
|
101
|
-
});
|
|
102
|
-
}, ar = (r, e) => (n) => {
|
|
103
|
-
if (n.input.startsWith(r, n.index)) {
|
|
104
|
-
if (!h(e) && !n.options.silent) {
|
|
105
|
-
const t = d(e) ? e(r, n.input, String(n.index)) : e;
|
|
106
|
-
h(t) || n.output.push(t);
|
|
107
|
-
}
|
|
108
|
-
return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), true;
|
|
109
|
-
} else return false;
|
|
110
|
-
}, C = (r, e, n, a) => {
|
|
111
|
-
const t = v(r);
|
|
112
|
-
return g(_(M((o) => {
|
|
113
|
-
let u = 0;
|
|
114
|
-
for (; u < n; ) {
|
|
115
|
-
const s = o.index;
|
|
116
|
-
if (!t(o) || (u += 1, o.index === s)) break;
|
|
117
|
-
}
|
|
118
|
-
return u >= e;
|
|
119
|
-
})));
|
|
120
|
-
}, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, 1 / 0), x = (r, e) => {
|
|
121
|
-
const n = r.map(v);
|
|
122
|
-
return g(_(M((a) => {
|
|
123
|
-
for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return false;
|
|
124
|
-
return true;
|
|
125
|
-
})));
|
|
126
|
-
}, l = (r, e) => {
|
|
127
|
-
const n = r.map(v);
|
|
128
|
-
return g(_((a) => {
|
|
129
|
-
for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return true;
|
|
130
|
-
return false;
|
|
131
|
-
}));
|
|
132
|
-
}, M = (r, e = false) => {
|
|
133
|
-
const n = v(r);
|
|
134
|
-
return (a) => {
|
|
135
|
-
const t = a.index, o = a.output.length, u = n(a);
|
|
136
|
-
return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u;
|
|
137
|
-
};
|
|
138
|
-
}, _ = (r, e) => {
|
|
139
|
-
const n = v(r);
|
|
140
|
-
return n;
|
|
141
|
-
}, g = /* @__PURE__ */ (() => {
|
|
142
|
-
let r = 0;
|
|
143
|
-
return (e) => {
|
|
144
|
-
const n = v(e), a = r += 1;
|
|
145
|
-
return (t) => {
|
|
146
|
-
var o;
|
|
147
|
-
if (t.options.memoization === false) return n(t);
|
|
148
|
-
const u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u);
|
|
149
|
-
if (c === false) return false;
|
|
150
|
-
if (W(c)) return t.index = c, true;
|
|
151
|
-
if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), true;
|
|
152
|
-
{
|
|
153
|
-
const Z = t.output.length;
|
|
154
|
-
if (n(t)) {
|
|
155
|
-
const D = t.index, U = t.output.length;
|
|
156
|
-
if (U > Z) {
|
|
157
|
-
const ee = t.output.slice(Z, U);
|
|
158
|
-
s.set(u, { index: D, output: ee });
|
|
159
|
-
} else s.set(u, D);
|
|
160
|
-
return true;
|
|
161
|
-
} else return s.set(u, false), false;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
})(), E = (r) => {
|
|
166
|
-
let e;
|
|
167
|
-
return (n) => (e || (e = v(r())), e(n));
|
|
168
|
-
}, v = Y((r) => {
|
|
169
|
-
if (d(r)) return Q(r) ? E(r) : r;
|
|
170
|
-
if (b(r) || X(r)) return i(r);
|
|
171
|
-
if (A(r)) return x(r);
|
|
172
|
-
if (K(r)) return l(Object.values(r));
|
|
173
|
-
throw new Error("Invalid rule");
|
|
174
|
-
}), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => {
|
|
175
|
-
let e = "";
|
|
176
|
-
for (; r > 0; ) {
|
|
177
|
-
const n = (r - 1) % 26;
|
|
178
|
-
e = P[n] + e, r = Math.floor((r - 1) / 26);
|
|
179
|
-
}
|
|
180
|
-
return e;
|
|
181
|
-
}, O = (r) => {
|
|
182
|
-
let e = 0;
|
|
183
|
-
for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1;
|
|
184
|
-
return e;
|
|
185
|
-
}, S = (r, e) => {
|
|
186
|
-
if (e < r) return S(e, r);
|
|
187
|
-
const n = [];
|
|
188
|
-
for (; r <= e; ) n.push(r++);
|
|
189
|
-
return n;
|
|
190
|
-
}, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: false }).join("")), ur = (r) => {
|
|
191
|
-
const e = {};
|
|
192
|
-
return (n) => e[n] ?? (e[n] = r(n));
|
|
193
|
-
}, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), hr = i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), dr = i(/^(!!)+/, ""), fr = l([hr, dr]), xr = i(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = i(/^(\*\*\/)+/, "(?:^|.*/)"), mr = i(/\/(\*\*)$/, "(?:/.*|$)"), _r = i(/\*\*/, ".*"), j = l([xr, gr, mr, _r]), Sr = i(/\*\/(?!\*\*\/)/, "[^/]*/"), yr = i(/\*/, "[^/]*"), N = l([Sr, yr]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Cr = i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`), Mr = i(/[^\]]/, p), Er = l([y, Cr, br, Mr]), B = x([$r, tr(Ar), f(Er), wr]), Pr = i("{", "(?:"), Or = i("}", ")"), Rr = i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")), zr = i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")), jr = i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase()), Nr = l([Rr, zr, jr]), I = x([Pr, Nr, Or]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), Zr = E(() => F), Dr = l([j, N, k, B, I, Zr, y, Fr, Ir, Lr]), F = x([kr, f(Dr), Br]), Ur = f(l([sr, cr, lr, fr, j, N, k, B, I, F, y, pr, vr])), Vr = Ur, Gr = z(Vr), L = Gr, Tr = i(/\\./, p), qr = i(/./, p), Hr = i(/\*\*\*+/, "*"), Jr = i(/([^/{[(!])\*\*/, (r, e) => `${e}*`), Qr = i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`), Wr = f(l([Tr, Hr, Jr, Qr, qr])), Kr = Wr, Xr = z(Kr), Yr = Xr, $ = (r, e) => {
|
|
194
|
-
const n = Array.isArray(r) ? r : [r];
|
|
195
|
-
if (!n.length) return false;
|
|
196
|
-
const a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : "");
|
|
197
|
-
return a.some((s) => s.test(o));
|
|
198
|
-
};
|
|
199
|
-
$.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s");
|
|
200
|
-
var re = $;
|
|
201
|
-
return J(w);
|
|
202
|
-
})();
|
|
203
|
-
return __lib__.default || __lib__;
|
|
204
|
-
};
|
|
205
|
-
var _match;
|
|
206
|
-
var zeptomatch = (path, pattern) => {
|
|
207
|
-
if (!_match) {
|
|
208
|
-
_match = _lazyMatch();
|
|
209
|
-
_lazyMatch = null;
|
|
210
|
-
}
|
|
211
|
-
return _match(path, pattern);
|
|
212
|
-
};
|
|
213
|
-
var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
214
|
-
function normalizeWindowsPath(input = "") {
|
|
215
|
-
if (!input) {
|
|
216
|
-
return input;
|
|
217
|
-
}
|
|
218
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
219
|
-
}
|
|
220
|
-
var _UNC_REGEX = /^[/\\]{2}/;
|
|
221
|
-
var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
222
|
-
var _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
223
|
-
var _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
224
|
-
var _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
225
|
-
var _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
226
|
-
var sep = "/";
|
|
227
|
-
var normalize = function(path) {
|
|
228
|
-
if (path.length === 0) {
|
|
229
|
-
return ".";
|
|
230
|
-
}
|
|
231
|
-
path = normalizeWindowsPath(path);
|
|
232
|
-
const isUNCPath = path.match(_UNC_REGEX);
|
|
233
|
-
const isPathAbsolute = isAbsolute(path);
|
|
234
|
-
const trailingSeparator = path[path.length - 1] === "/";
|
|
235
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
236
|
-
if (path.length === 0) {
|
|
237
|
-
if (isPathAbsolute) {
|
|
238
|
-
return "/";
|
|
239
|
-
}
|
|
240
|
-
return trailingSeparator ? "./" : ".";
|
|
241
|
-
}
|
|
242
|
-
if (trailingSeparator) {
|
|
243
|
-
path += "/";
|
|
244
|
-
}
|
|
245
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
246
|
-
path += "/";
|
|
247
|
-
}
|
|
248
|
-
if (isUNCPath) {
|
|
249
|
-
if (!isPathAbsolute) {
|
|
250
|
-
return `//./${path}`;
|
|
251
|
-
}
|
|
252
|
-
return `//${path}`;
|
|
253
|
-
}
|
|
254
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
255
|
-
};
|
|
256
|
-
var join = function(...segments) {
|
|
257
|
-
let path = "";
|
|
258
|
-
for (const seg of segments) {
|
|
259
|
-
if (!seg) {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (path.length > 0) {
|
|
263
|
-
const pathTrailing = path[path.length - 1] === "/";
|
|
264
|
-
const segLeading = seg[0] === "/";
|
|
265
|
-
const both = pathTrailing && segLeading;
|
|
266
|
-
if (both) {
|
|
267
|
-
path += seg.slice(1);
|
|
268
|
-
} else {
|
|
269
|
-
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
270
|
-
}
|
|
271
|
-
} else {
|
|
272
|
-
path += seg;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return normalize(path);
|
|
276
|
-
};
|
|
277
|
-
function cwd() {
|
|
278
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
279
|
-
return process.cwd().replace(/\\/g, "/");
|
|
280
|
-
}
|
|
281
|
-
return "/";
|
|
282
|
-
}
|
|
283
|
-
var resolve = function(...arguments_) {
|
|
284
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
285
|
-
let resolvedPath = "";
|
|
286
|
-
let resolvedAbsolute = false;
|
|
287
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
288
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
289
|
-
if (!path || path.length === 0) {
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
293
|
-
resolvedAbsolute = isAbsolute(path);
|
|
294
|
-
}
|
|
295
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
296
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
297
|
-
return `/${resolvedPath}`;
|
|
298
|
-
}
|
|
299
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
300
|
-
};
|
|
301
|
-
function normalizeString(path, allowAboveRoot) {
|
|
302
|
-
let res = "";
|
|
303
|
-
let lastSegmentLength = 0;
|
|
304
|
-
let lastSlash = -1;
|
|
305
|
-
let dots = 0;
|
|
306
|
-
let char = null;
|
|
307
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
308
|
-
if (index < path.length) {
|
|
309
|
-
char = path[index];
|
|
310
|
-
} else if (char === "/") {
|
|
311
|
-
break;
|
|
312
|
-
} else {
|
|
313
|
-
char = "/";
|
|
314
|
-
}
|
|
315
|
-
if (char === "/") {
|
|
316
|
-
if (lastSlash === index - 1 || dots === 1) ;
|
|
317
|
-
else if (dots === 2) {
|
|
318
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
319
|
-
if (res.length > 2) {
|
|
320
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
321
|
-
if (lastSlashIndex === -1) {
|
|
322
|
-
res = "";
|
|
323
|
-
lastSegmentLength = 0;
|
|
324
|
-
} else {
|
|
325
|
-
res = res.slice(0, lastSlashIndex);
|
|
326
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
327
|
-
}
|
|
328
|
-
lastSlash = index;
|
|
329
|
-
dots = 0;
|
|
330
|
-
continue;
|
|
331
|
-
} else if (res.length > 0) {
|
|
332
|
-
res = "";
|
|
333
|
-
lastSegmentLength = 0;
|
|
334
|
-
lastSlash = index;
|
|
335
|
-
dots = 0;
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (allowAboveRoot) {
|
|
340
|
-
res += res.length > 0 ? "/.." : "..";
|
|
341
|
-
lastSegmentLength = 2;
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
if (res.length > 0) {
|
|
345
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
346
|
-
} else {
|
|
347
|
-
res = path.slice(lastSlash + 1, index);
|
|
348
|
-
}
|
|
349
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
350
|
-
}
|
|
351
|
-
lastSlash = index;
|
|
352
|
-
dots = 0;
|
|
353
|
-
} else if (char === "." && dots !== -1) {
|
|
354
|
-
++dots;
|
|
355
|
-
} else {
|
|
356
|
-
dots = -1;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return res;
|
|
360
|
-
}
|
|
361
|
-
var isAbsolute = function(p) {
|
|
362
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
363
|
-
};
|
|
364
|
-
var toNamespacedPath = function(p) {
|
|
365
|
-
return normalizeWindowsPath(p);
|
|
366
|
-
};
|
|
367
|
-
var extname = function(p) {
|
|
368
|
-
if (p === "..") return "";
|
|
369
|
-
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
370
|
-
return match && match[1] || "";
|
|
371
|
-
};
|
|
372
|
-
var relative = function(from, to) {
|
|
373
|
-
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
374
|
-
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
375
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
376
|
-
return _to.join("/");
|
|
377
|
-
}
|
|
378
|
-
const _fromCopy = [..._from];
|
|
379
|
-
for (const segment of _fromCopy) {
|
|
380
|
-
if (_to[0] !== segment) {
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
_from.shift();
|
|
384
|
-
_to.shift();
|
|
385
|
-
}
|
|
386
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
387
|
-
};
|
|
388
|
-
var dirname = function(p) {
|
|
389
|
-
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
390
|
-
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
|
|
391
|
-
segments[0] += "/";
|
|
392
|
-
}
|
|
393
|
-
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
394
|
-
};
|
|
395
|
-
var format = function(p) {
|
|
396
|
-
const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
|
|
397
|
-
const segments = [p.root, p.dir, p.base ?? (p.name ?? "") + ext].filter(
|
|
398
|
-
Boolean
|
|
399
|
-
);
|
|
400
|
-
return normalizeWindowsPath(
|
|
401
|
-
p.root ? resolve(...segments) : segments.join("/")
|
|
402
|
-
);
|
|
403
|
-
};
|
|
404
|
-
var basename = function(p, extension) {
|
|
405
|
-
const segments = normalizeWindowsPath(p).split("/");
|
|
406
|
-
let lastSegment = "";
|
|
407
|
-
for (let i = segments.length - 1; i >= 0; i--) {
|
|
408
|
-
const val = segments[i];
|
|
409
|
-
if (val) {
|
|
410
|
-
lastSegment = val;
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
415
|
-
};
|
|
416
|
-
var parse = function(p) {
|
|
417
|
-
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
418
|
-
const base = basename(p);
|
|
419
|
-
const extension = extname(base);
|
|
420
|
-
return {
|
|
421
|
-
root,
|
|
422
|
-
dir: dirname(p),
|
|
423
|
-
base,
|
|
424
|
-
ext: extension,
|
|
425
|
-
name: base.slice(0, base.length - extension.length)
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
var matchesGlob = (path, pattern) => {
|
|
429
|
-
return zeptomatch(pattern, normalize(path));
|
|
430
|
-
};
|
|
431
|
-
var _path = {
|
|
432
|
-
__proto__: null,
|
|
433
|
-
basename,
|
|
434
|
-
dirname,
|
|
435
|
-
extname,
|
|
436
|
-
format,
|
|
437
|
-
isAbsolute,
|
|
438
|
-
join,
|
|
439
|
-
matchesGlob,
|
|
440
|
-
normalize,
|
|
441
|
-
normalizeString,
|
|
442
|
-
parse,
|
|
443
|
-
relative,
|
|
444
|
-
resolve,
|
|
445
|
-
sep,
|
|
446
|
-
toNamespacedPath
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
|
|
450
|
-
var delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
|
451
|
-
var _platforms = { posix: void 0, win32: void 0 };
|
|
452
|
-
var mix = (del = delimiter) => {
|
|
453
|
-
return new Proxy(_path, {
|
|
454
|
-
get(_, prop) {
|
|
455
|
-
if (prop === "delimiter") return del;
|
|
456
|
-
if (prop === "posix") return posix;
|
|
457
|
-
if (prop === "win32") return win32;
|
|
458
|
-
return _platforms[prop] || _path[prop];
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
};
|
|
462
|
-
var posix = /* @__PURE__ */ mix(":");
|
|
463
|
-
var win32 = /* @__PURE__ */ mix(";");
|
|
464
|
-
|
|
465
|
-
// src/context.ts
|
|
466
|
-
function createDocument() {
|
|
467
|
-
return {
|
|
468
|
-
name: "",
|
|
469
|
-
path: "",
|
|
470
|
-
value: null
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
function createContext() {
|
|
474
|
-
return {
|
|
475
|
-
projectConfig: createDocument(),
|
|
476
|
-
packageJson: createDocument(),
|
|
477
|
-
viteConfig: createDocument(),
|
|
478
|
-
tsconfig: createDocument(),
|
|
479
|
-
tsconfigApp: createDocument(),
|
|
480
|
-
tsconfigNode: createDocument(),
|
|
481
|
-
dts: createDocument()
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// src/state.ts
|
|
486
|
-
var ctx = createContext();
|
|
487
|
-
function resetContext() {
|
|
488
|
-
const next = createContext();
|
|
489
|
-
Object.assign(ctx.projectConfig, next.projectConfig);
|
|
490
|
-
Object.assign(ctx.packageJson, next.packageJson);
|
|
491
|
-
Object.assign(ctx.viteConfig, next.viteConfig);
|
|
492
|
-
Object.assign(ctx.tsconfig, next.tsconfig);
|
|
493
|
-
Object.assign(ctx.tsconfigApp, next.tsconfigApp);
|
|
494
|
-
Object.assign(ctx.tsconfigNode, next.tsconfigNode);
|
|
495
|
-
Object.assign(ctx.dts, next.dts);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
// src/tsconfigJson.ts
|
|
499
|
-
var srcIncludeGlobs = [
|
|
500
|
-
"src/**/*.ts",
|
|
501
|
-
"src/**/*.tsx",
|
|
502
|
-
"src/**/*.js",
|
|
503
|
-
"src/**/*.jsx",
|
|
504
|
-
"src/**/*.mts",
|
|
505
|
-
"src/**/*.cts",
|
|
506
|
-
"src/**/*.vue",
|
|
507
|
-
"src/**/*.json",
|
|
508
|
-
"src/**/*.d.ts",
|
|
509
|
-
"types/**/*.d.ts",
|
|
510
|
-
"env.d.ts"
|
|
511
|
-
];
|
|
512
|
-
function getDefaultTsconfigJson() {
|
|
513
|
-
return {
|
|
514
|
-
references: [
|
|
515
|
-
{
|
|
516
|
-
path: "./tsconfig.app.json"
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
path: "./tsconfig.node.json"
|
|
520
|
-
}
|
|
521
|
-
],
|
|
522
|
-
files: []
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
function getDefaultTsconfigAppJson() {
|
|
526
|
-
return {
|
|
527
|
-
compilerOptions: {
|
|
528
|
-
tsBuildInfoFile: "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
529
|
-
target: "ES2023",
|
|
530
|
-
lib: [
|
|
531
|
-
"ES2023",
|
|
532
|
-
"DOM",
|
|
533
|
-
"DOM.Iterable"
|
|
534
|
-
],
|
|
535
|
-
jsx: "preserve",
|
|
536
|
-
module: "ESNext",
|
|
537
|
-
moduleResolution: "bundler",
|
|
538
|
-
moduleDetection: "force",
|
|
539
|
-
baseUrl: ".",
|
|
540
|
-
paths: {
|
|
541
|
-
"@/*": [
|
|
542
|
-
"./src/*"
|
|
543
|
-
]
|
|
544
|
-
},
|
|
545
|
-
resolveJsonModule: true,
|
|
546
|
-
types: [
|
|
547
|
-
"miniprogram-api-typings"
|
|
548
|
-
],
|
|
549
|
-
allowImportingTsExtensions: true,
|
|
550
|
-
allowJs: true,
|
|
551
|
-
allowSyntheticDefaultImports: true,
|
|
552
|
-
esModuleInterop: true,
|
|
553
|
-
isolatedModules: true,
|
|
554
|
-
strict: true,
|
|
555
|
-
noFallthroughCasesInSwitch: true,
|
|
556
|
-
noUnusedLocals: true,
|
|
557
|
-
noUnusedParameters: true,
|
|
558
|
-
noEmit: true,
|
|
559
|
-
verbatimModuleSyntax: true,
|
|
560
|
-
noUncheckedSideEffectImports: true,
|
|
561
|
-
erasableSyntaxOnly: true,
|
|
562
|
-
skipLibCheck: true
|
|
563
|
-
},
|
|
564
|
-
include: srcIncludeGlobs
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function getDefaultTsconfigNodeJson(include = []) {
|
|
568
|
-
const baseInclude = [
|
|
569
|
-
"vite.config.ts",
|
|
570
|
-
"vite.config.*.ts",
|
|
571
|
-
"*.config.ts",
|
|
572
|
-
"config/**/*.ts",
|
|
573
|
-
"scripts/**/*.ts"
|
|
574
|
-
];
|
|
575
|
-
const mergedInclude = Array.from(/* @__PURE__ */ new Set([
|
|
576
|
-
...baseInclude,
|
|
577
|
-
...include
|
|
578
|
-
]));
|
|
579
|
-
return {
|
|
580
|
-
compilerOptions: {
|
|
581
|
-
tsBuildInfoFile: "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
582
|
-
target: "ES2023",
|
|
583
|
-
lib: [
|
|
584
|
-
"ES2023"
|
|
585
|
-
],
|
|
586
|
-
module: "ESNext",
|
|
587
|
-
moduleResolution: "bundler",
|
|
588
|
-
moduleDetection: "force",
|
|
589
|
-
types: [
|
|
590
|
-
"node"
|
|
591
|
-
],
|
|
592
|
-
allowImportingTsExtensions: true,
|
|
593
|
-
resolveJsonModule: true,
|
|
594
|
-
verbatimModuleSyntax: true,
|
|
595
|
-
strict: true,
|
|
596
|
-
noFallthroughCasesInSwitch: true,
|
|
597
|
-
noUnusedLocals: true,
|
|
598
|
-
noUnusedParameters: true,
|
|
599
|
-
noEmit: true,
|
|
600
|
-
noUncheckedSideEffectImports: true,
|
|
601
|
-
erasableSyntaxOnly: true,
|
|
602
|
-
skipLibCheck: true
|
|
603
|
-
},
|
|
604
|
-
include: mergedInclude
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// src/tsDts.ts
|
|
609
|
-
function getDefaultTsDts() {
|
|
610
|
-
return `/// <reference types="weapp-vite/client" />
|
|
611
|
-
`;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// src/utils/fs.ts
|
|
615
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
616
|
-
var FsReadError = class extends Error {
|
|
617
|
-
constructor(filepath, cause) {
|
|
618
|
-
super(`Failed to read ${filepath}`);
|
|
619
|
-
this.filepath = filepath;
|
|
620
|
-
this.cause = cause;
|
|
621
|
-
this.name = "FsReadError";
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
var FsWriteError = class extends Error {
|
|
625
|
-
constructor(filepath, cause) {
|
|
626
|
-
super(`Failed to write ${filepath}`);
|
|
627
|
-
this.filepath = filepath;
|
|
628
|
-
this.cause = cause;
|
|
629
|
-
this.name = "FsWriteError";
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
async function readJsonIfExists(filepath) {
|
|
633
|
-
try {
|
|
634
|
-
return await import_fs_extra.default.readJSON(filepath);
|
|
635
|
-
} catch (error) {
|
|
636
|
-
if (error?.code === "ENOENT") {
|
|
637
|
-
return null;
|
|
638
|
-
}
|
|
639
|
-
throw new FsReadError(filepath, error);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
async function readFileIfExists(filepath) {
|
|
643
|
-
try {
|
|
644
|
-
return await import_fs_extra.default.readFile(filepath, "utf8");
|
|
645
|
-
} catch (error) {
|
|
646
|
-
if (error?.code === "ENOENT") {
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
throw new FsReadError(filepath, error);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
async function writeJsonFile(filepath, data, spaces = 2) {
|
|
653
|
-
try {
|
|
654
|
-
await import_fs_extra.default.outputJSON(filepath, data, {
|
|
655
|
-
spaces
|
|
656
|
-
});
|
|
657
|
-
} catch (error) {
|
|
658
|
-
throw new FsWriteError(filepath, error);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
async function writeFile(filepath, contents) {
|
|
662
|
-
try {
|
|
663
|
-
await import_fs_extra.default.outputFile(filepath, contents, "utf8");
|
|
664
|
-
} catch (error) {
|
|
665
|
-
throw new FsWriteError(filepath, error);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// src/utils/path.ts
|
|
670
|
-
function resolveOutputPath(root, dest, fallback) {
|
|
671
|
-
if (!dest) {
|
|
672
|
-
return fallback;
|
|
673
|
-
}
|
|
674
|
-
return posix.isAbsolute(dest) ? dest : posix.resolve(root, dest);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// src/viteConfig.ts
|
|
678
|
-
function getDefaultViteConfig() {
|
|
679
|
-
return `import { defineConfig } from 'weapp-vite/config'
|
|
680
|
-
|
|
681
|
-
export default defineConfig({
|
|
682
|
-
weapp: {
|
|
683
|
-
// weapp-vite options
|
|
684
|
-
},
|
|
685
|
-
})
|
|
686
|
-
`;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// src/configFiles.ts
|
|
690
|
-
async function initViteConfigFile(options) {
|
|
691
|
-
const { root, dest, write = true } = options;
|
|
692
|
-
const packageType = ctx.packageJson.value?.type ?? "module";
|
|
693
|
-
const targetFilename = ctx.viteConfig.name = packageType === "module" ? "vite.config.ts" : "vite.config.mts";
|
|
694
|
-
const viteConfigFilePath = ctx.viteConfig.path = posix.resolve(root, targetFilename);
|
|
695
|
-
const outputPath = resolveOutputPath(root, dest, viteConfigFilePath);
|
|
696
|
-
const code = getDefaultViteConfig();
|
|
697
|
-
ctx.viteConfig.value = code;
|
|
698
|
-
if (write) {
|
|
699
|
-
await writeFile(outputPath, code);
|
|
700
|
-
import_logger.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
701
|
-
}
|
|
702
|
-
return code;
|
|
703
|
-
}
|
|
704
|
-
async function initTsDtsFile(options) {
|
|
705
|
-
const { root, dest, write = true } = options;
|
|
706
|
-
const targetFilename = ctx.dts.name = "vite-env.d.ts";
|
|
707
|
-
const viteDtsFilePath = ctx.dts.path = posix.resolve(root, targetFilename);
|
|
708
|
-
const outputPath = resolveOutputPath(root, dest, viteDtsFilePath);
|
|
709
|
-
const code = getDefaultTsDts();
|
|
710
|
-
ctx.dts.value = code;
|
|
711
|
-
if (write) {
|
|
712
|
-
await writeFile(outputPath, code);
|
|
713
|
-
import_logger.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
714
|
-
}
|
|
715
|
-
return code;
|
|
716
|
-
}
|
|
717
|
-
async function initTsJsonFiles(options) {
|
|
718
|
-
const { root, dest, write = true } = options;
|
|
719
|
-
const tsJsonFilename = ctx.tsconfig.name = "tsconfig.json";
|
|
720
|
-
const tsJsonFilePath = ctx.tsconfig.path = posix.resolve(root, tsJsonFilename);
|
|
721
|
-
const tsAppJsonFilename = ctx.tsconfigApp.name = "tsconfig.app.json";
|
|
722
|
-
const tsAppJsonFilePath = ctx.tsconfigApp.path = posix.resolve(root, tsAppJsonFilename);
|
|
723
|
-
const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
|
|
724
|
-
const tsNodeJsonFilePath = ctx.tsconfigNode.path = posix.resolve(root, tsNodeJsonFilename);
|
|
725
|
-
const tsconfig = getDefaultTsconfigJson();
|
|
726
|
-
const tsconfigApp = getDefaultTsconfigAppJson();
|
|
727
|
-
const includeFiles = ctx.viteConfig.name ? [ctx.viteConfig.name] : [];
|
|
728
|
-
const tsconfigNode = getDefaultTsconfigNodeJson(includeFiles);
|
|
729
|
-
ctx.tsconfig.value = tsconfig;
|
|
730
|
-
ctx.tsconfigApp.value = tsconfigApp;
|
|
731
|
-
ctx.tsconfigNode.value = tsconfigNode;
|
|
732
|
-
if (write) {
|
|
733
|
-
const tsconfigOutputPath = resolveOutputPath(root, dest, tsJsonFilePath);
|
|
734
|
-
const tsconfigAppOutputPath = resolveOutputPath(root, dest, tsAppJsonFilePath);
|
|
735
|
-
const tsconfigNodeOutputPath = resolveOutputPath(root, dest, tsNodeJsonFilePath);
|
|
736
|
-
await writeJsonFile(tsconfigOutputPath, tsconfig);
|
|
737
|
-
await writeJsonFile(tsconfigAppOutputPath, tsconfigApp);
|
|
738
|
-
await writeJsonFile(tsconfigNodeOutputPath, tsconfigNode);
|
|
739
|
-
import_logger.default.log(
|
|
740
|
-
`\u2728 \u5199\u5165 ${[
|
|
741
|
-
posix.relative(root, tsconfigOutputPath),
|
|
742
|
-
posix.relative(root, tsconfigAppOutputPath),
|
|
743
|
-
posix.relative(root, tsconfigNodeOutputPath)
|
|
744
|
-
].join(", ")} \u6210\u529F!`
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
return {
|
|
748
|
-
tsconfig,
|
|
749
|
-
tsconfigApp,
|
|
750
|
-
tsconfigNode
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// src/packageJson.ts
|
|
755
|
-
var import_logger2 = __toESM(require("@weapp-core/logger"), 1);
|
|
756
|
-
var import_shared = require("@weapp-core/shared");
|
|
757
|
-
|
|
758
|
-
// ../../packages/weapp-vite/package.json
|
|
759
|
-
var version = "6.1.5";
|
|
760
|
-
|
|
761
|
-
// src/npm.ts
|
|
762
|
-
var import_node_https = __toESM(require("https"), 1);
|
|
763
|
-
function getLatestVersionFromNpm(packageName) {
|
|
764
|
-
return new Promise((resolve2, reject) => {
|
|
765
|
-
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
766
|
-
import_node_https.default.get(url, (res) => {
|
|
767
|
-
if (!res || res.statusCode && res.statusCode >= 400) {
|
|
768
|
-
res?.resume();
|
|
769
|
-
reject(new Error(`Request to ${url} failed with status ${res?.statusCode ?? "unknown"}`));
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
let data = "";
|
|
773
|
-
res.setEncoding("utf8");
|
|
774
|
-
res.on("data", (chunk) => data += chunk);
|
|
775
|
-
res.on("end", () => {
|
|
776
|
-
try {
|
|
777
|
-
const json = JSON.parse(data);
|
|
778
|
-
if (!json.version || typeof json.version !== "string") {
|
|
779
|
-
reject(new Error(`Unexpected response when fetching ${packageName}: missing version`));
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
resolve2(json.version);
|
|
783
|
-
} catch (err) {
|
|
784
|
-
reject(err);
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
res.on("error", reject);
|
|
788
|
-
}).on("error", reject);
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
async function latestVersion(packageName, prefix = "^", fetch = getLatestVersionFromNpm) {
|
|
792
|
-
try {
|
|
793
|
-
const resolved = await fetch(packageName);
|
|
794
|
-
if (!resolved) {
|
|
795
|
-
return null;
|
|
796
|
-
}
|
|
797
|
-
return `${prefix}${resolved}`;
|
|
798
|
-
} catch {
|
|
799
|
-
return null;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// src/packageJson.ts
|
|
804
|
-
var FALLBACK_DEP_VERSIONS = {
|
|
805
|
-
"miniprogram-api-typings": "^4.1.0",
|
|
806
|
-
"typescript": "^5.9.2",
|
|
807
|
-
"weapp-tailwindcss": "^4.3.3"
|
|
808
|
-
};
|
|
809
|
-
function createDefaultPackageJson() {
|
|
810
|
-
return {
|
|
811
|
-
name: "weapp-vite-app",
|
|
812
|
-
homepage: "https://vite.icebreaker.top/",
|
|
813
|
-
type: "module",
|
|
814
|
-
scripts: {},
|
|
815
|
-
devDependencies: {}
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
async function upsertDependencyVersion(packageJson, keyPath, packageName, options = {}) {
|
|
819
|
-
const currentValue = (0, import_shared.get)(packageJson, keyPath);
|
|
820
|
-
const resolved = options.skipNetwork ? null : await latestVersion(packageName);
|
|
821
|
-
if (resolved) {
|
|
822
|
-
(0, import_shared.set)(packageJson, keyPath, resolved);
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
if (currentValue === void 0) {
|
|
826
|
-
const fallback = FALLBACK_DEP_VERSIONS[packageName] ?? "latest";
|
|
827
|
-
(0, import_shared.set)(packageJson, keyPath, fallback);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
async function createOrUpdatePackageJson(options) {
|
|
831
|
-
const { root, dest, command, cb, write, filename } = (0, import_shared.defu)(options, {
|
|
832
|
-
write: true,
|
|
833
|
-
filename: "package.json",
|
|
834
|
-
command: "weapp-vite"
|
|
835
|
-
});
|
|
836
|
-
const packageJsonFilename = ctx.packageJson.name = filename;
|
|
837
|
-
const packageJsonPath = ctx.packageJson.path = posix.resolve(root, packageJsonFilename);
|
|
838
|
-
const outputPath = resolveOutputPath(root, dest, packageJsonPath);
|
|
839
|
-
try {
|
|
840
|
-
let packageJson = await readJsonIfExists(packageJsonPath);
|
|
841
|
-
if (!packageJson) {
|
|
842
|
-
packageJson = createDefaultPackageJson();
|
|
843
|
-
import_logger2.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${packageJsonFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u521B\u5EFA\u9ED8\u8BA4 package.json ...`);
|
|
844
|
-
}
|
|
845
|
-
(0, import_shared.set)(packageJson, "scripts.dev", `${command} dev`);
|
|
846
|
-
(0, import_shared.set)(packageJson, "scripts.dev:open", `${command} dev -o`);
|
|
847
|
-
(0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
|
|
848
|
-
if (command === "weapp-vite") {
|
|
849
|
-
(0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
|
|
850
|
-
(0, import_shared.set)(packageJson, "scripts.g", `${command} generate`);
|
|
851
|
-
(0, import_shared.set)(packageJson, "devDependencies.weapp-vite", `^${version}`);
|
|
852
|
-
await Promise.all([
|
|
853
|
-
upsertDependencyVersion(packageJson, "devDependencies.miniprogram-api-typings", "miniprogram-api-typings", { skipNetwork: !write }),
|
|
854
|
-
upsertDependencyVersion(packageJson, "devDependencies.typescript", "typescript", { skipNetwork: !write })
|
|
855
|
-
]);
|
|
856
|
-
}
|
|
857
|
-
cb?.(
|
|
858
|
-
(...args) => {
|
|
859
|
-
(0, import_shared.set)(packageJson, ...args);
|
|
860
|
-
}
|
|
861
|
-
);
|
|
862
|
-
ctx.packageJson.value = packageJson;
|
|
863
|
-
if (write) {
|
|
864
|
-
await writeJsonFile(outputPath, packageJson);
|
|
865
|
-
import_logger2.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
866
|
-
}
|
|
867
|
-
return packageJson;
|
|
868
|
-
} catch (error) {
|
|
869
|
-
import_logger2.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${packageJsonFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
870
|
-
throw error;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
// src/projectConfig.ts
|
|
875
|
-
var import_logger3 = __toESM(require("@weapp-core/logger"), 1);
|
|
876
|
-
var import_shared2 = require("@weapp-core/shared");
|
|
877
|
-
function applyProjectConfigDefaults(projectConfig) {
|
|
878
|
-
(0, import_shared2.set)(projectConfig, "miniprogramRoot", "dist/");
|
|
879
|
-
(0, import_shared2.set)(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
880
|
-
(0, import_shared2.set)(projectConfig, "setting.packNpmManually", true);
|
|
881
|
-
const compileType = (0, import_shared2.get)(projectConfig, "compileType");
|
|
882
|
-
if (compileType === "plugin") {
|
|
883
|
-
(0, import_shared2.set)(projectConfig, "pluginRoot", "dist-plugin");
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
function ensurePackNpmRelationList(projectConfig) {
|
|
887
|
-
const relations = (0, import_shared2.get)(projectConfig, "setting.packNpmRelationList");
|
|
888
|
-
const defaultRelation = {
|
|
889
|
-
packageJsonPath: "./package.json",
|
|
890
|
-
miniprogramNpmDistDir: "./dist"
|
|
891
|
-
};
|
|
892
|
-
if (Array.isArray(relations)) {
|
|
893
|
-
const exists = relations.some(
|
|
894
|
-
(relation) => relation.packageJsonPath === defaultRelation.packageJsonPath && relation.miniprogramNpmDistDir === defaultRelation.miniprogramNpmDistDir
|
|
895
|
-
);
|
|
896
|
-
if (!exists) {
|
|
897
|
-
relations.push(defaultRelation);
|
|
898
|
-
}
|
|
899
|
-
} else {
|
|
900
|
-
(0, import_shared2.set)(projectConfig, "setting.packNpmRelationList", [defaultRelation]);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
function createDefaultProjectConfig() {
|
|
904
|
-
return {
|
|
905
|
-
compileType: "miniprogram",
|
|
906
|
-
libVersion: "trial",
|
|
907
|
-
packOptions: {
|
|
908
|
-
ignore: [],
|
|
909
|
-
include: []
|
|
910
|
-
},
|
|
911
|
-
setting: {
|
|
912
|
-
coverView: true,
|
|
913
|
-
es6: true,
|
|
914
|
-
postcss: true,
|
|
915
|
-
minified: true,
|
|
916
|
-
enhance: true,
|
|
917
|
-
showShadowRootInWxmlPanel: true,
|
|
918
|
-
packNpmRelationList: [
|
|
919
|
-
{
|
|
920
|
-
packageJsonPath: "./package.json",
|
|
921
|
-
miniprogramNpmDistDir: "./dist"
|
|
922
|
-
}
|
|
923
|
-
],
|
|
924
|
-
babelSetting: {
|
|
925
|
-
ignore: [],
|
|
926
|
-
disablePlugins: [],
|
|
927
|
-
outputPath: ""
|
|
928
|
-
},
|
|
929
|
-
packNpmManually: true
|
|
930
|
-
},
|
|
931
|
-
condition: {},
|
|
932
|
-
editorSetting: {
|
|
933
|
-
tabIndent: "auto",
|
|
934
|
-
tabSize: 2
|
|
935
|
-
},
|
|
936
|
-
appid: "",
|
|
937
|
-
miniprogramRoot: "dist/",
|
|
938
|
-
srcMiniprogramRoot: "dist/"
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
async function createOrUpdateProjectConfig(options) {
|
|
942
|
-
const { root, dest, cb, write, filename } = (0, import_shared2.defu)(
|
|
943
|
-
options,
|
|
944
|
-
{
|
|
945
|
-
write: true,
|
|
946
|
-
filename: "project.config.json"
|
|
947
|
-
}
|
|
948
|
-
);
|
|
949
|
-
const projectConfigFilename = ctx.projectConfig.name = filename;
|
|
950
|
-
const projectConfigPath = ctx.projectConfig.path = posix.resolve(root, projectConfigFilename);
|
|
951
|
-
const outputPath = resolveOutputPath(root, dest, projectConfigPath);
|
|
952
|
-
try {
|
|
953
|
-
let projectConfig = await readJsonIfExists(projectConfigPath);
|
|
954
|
-
if (projectConfig) {
|
|
955
|
-
applyProjectConfigDefaults(projectConfig);
|
|
956
|
-
} else {
|
|
957
|
-
projectConfig = createDefaultProjectConfig();
|
|
958
|
-
import_logger3.default.info(`\u2728 \u6CA1\u6709\u627E\u5230 ${projectConfigFilename} \u6587\u4EF6\uFF0C\u6B63\u5728\u4F7F\u7528\u9ED8\u8BA4\u6A21\u677F\u521B\u5EFA...`);
|
|
959
|
-
}
|
|
960
|
-
cb?.(
|
|
961
|
-
(...args) => {
|
|
962
|
-
(0, import_shared2.set)(projectConfig, ...args);
|
|
963
|
-
}
|
|
964
|
-
);
|
|
965
|
-
ensurePackNpmRelationList(projectConfig);
|
|
966
|
-
ctx.projectConfig.value = projectConfig;
|
|
967
|
-
if (write) {
|
|
968
|
-
await writeJsonFile(outputPath, projectConfig);
|
|
969
|
-
import_logger3.default.log(`\u2728 \u5199\u5165 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
970
|
-
}
|
|
971
|
-
return projectConfig;
|
|
972
|
-
} catch (error) {
|
|
973
|
-
import_logger3.default.error(`\u26A0\uFE0F \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25`, error);
|
|
974
|
-
throw error;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// src/updateGitignore.ts
|
|
979
|
-
var import_logger4 = __toESM(require("@weapp-core/logger"), 1);
|
|
980
|
-
|
|
981
|
-
// src/gitignore.ts
|
|
982
|
-
var DEFAULT_GITIGNORE = `# dependencies
|
|
983
|
-
node_modules
|
|
984
|
-
.pnp
|
|
985
|
-
.pnp.js
|
|
986
|
-
|
|
987
|
-
# testing
|
|
988
|
-
coverage
|
|
989
|
-
|
|
990
|
-
# next.js
|
|
991
|
-
.next/
|
|
992
|
-
out/
|
|
993
|
-
build
|
|
994
|
-
|
|
995
|
-
# misc
|
|
996
|
-
.DS_Store
|
|
997
|
-
*.pem
|
|
998
|
-
|
|
999
|
-
# debug
|
|
1000
|
-
npm-debug.log*
|
|
1001
|
-
yarn-debug.log*
|
|
1002
|
-
yarn-error.log*
|
|
1003
|
-
.pnpm-debug.log*
|
|
1004
|
-
|
|
1005
|
-
# local env files
|
|
1006
|
-
.env.local
|
|
1007
|
-
.env.development.local
|
|
1008
|
-
.env.test.local
|
|
1009
|
-
.env.production.local
|
|
1010
|
-
|
|
1011
|
-
# turbo
|
|
1012
|
-
.turbo
|
|
1013
|
-
|
|
1014
|
-
dist
|
|
1015
|
-
dist-plugin
|
|
1016
|
-
dist-web
|
|
1017
|
-
vite.config.ts.timestamp-*.mjs`;
|
|
1018
|
-
function normalizeLineEndings(value) {
|
|
1019
|
-
return value.replace(/\r\n/g, "\n");
|
|
1020
|
-
}
|
|
1021
|
-
function trimTrailingBlankLines(lines) {
|
|
1022
|
-
let end = lines.length;
|
|
1023
|
-
while (end > 0 && lines[end - 1] === "") {
|
|
1024
|
-
end -= 1;
|
|
1025
|
-
}
|
|
1026
|
-
return lines.slice(0, end);
|
|
1027
|
-
}
|
|
1028
|
-
function ensureTrailingNewline(value) {
|
|
1029
|
-
return value.endsWith("\n") ? value : `${value}
|
|
1030
|
-
`;
|
|
1031
|
-
}
|
|
1032
|
-
function mergeGitignore(existing) {
|
|
1033
|
-
const normalizedExisting = normalizeLineEndings(existing ?? "");
|
|
1034
|
-
const existingLines = normalizedExisting.length ? normalizedExisting.split("\n") : [];
|
|
1035
|
-
const merged = [...existingLines];
|
|
1036
|
-
while (merged.length > 0 && merged[merged.length - 1] === "") {
|
|
1037
|
-
merged.pop();
|
|
1038
|
-
}
|
|
1039
|
-
const seen = new Set(merged);
|
|
1040
|
-
let appendedNonBlank = false;
|
|
1041
|
-
for (const line of DEFAULT_GITIGNORE.split("\n")) {
|
|
1042
|
-
const isBlank = line.length === 0;
|
|
1043
|
-
if (isBlank) {
|
|
1044
|
-
if (merged.length === 0 || merged[merged.length - 1] === "") {
|
|
1045
|
-
continue;
|
|
1046
|
-
}
|
|
1047
|
-
merged.push("");
|
|
1048
|
-
continue;
|
|
1049
|
-
}
|
|
1050
|
-
if (seen.has(line)) {
|
|
1051
|
-
continue;
|
|
1052
|
-
}
|
|
1053
|
-
if (!appendedNonBlank && merged.length > 0 && merged[merged.length - 1] !== "") {
|
|
1054
|
-
merged.push("");
|
|
1055
|
-
}
|
|
1056
|
-
merged.push(line);
|
|
1057
|
-
seen.add(line);
|
|
1058
|
-
appendedNonBlank = true;
|
|
1059
|
-
}
|
|
1060
|
-
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
// src/updateGitignore.ts
|
|
1064
|
-
async function updateGitIgnore(options) {
|
|
1065
|
-
const { root, dest, write = true } = options;
|
|
1066
|
-
const gitignorePath = posix.resolve(root, ".gitignore");
|
|
1067
|
-
const outputPath = resolveOutputPath(root, dest, gitignorePath);
|
|
1068
|
-
const existing = await readFileIfExists(outputPath);
|
|
1069
|
-
const merged = mergeGitignore(existing);
|
|
1070
|
-
if (write && merged !== (existing ?? "")) {
|
|
1071
|
-
await writeFile(outputPath, merged);
|
|
1072
|
-
import_logger4.default.log(`\u2728 \u66F4\u65B0 ${posix.relative(root, outputPath)} \u6210\u529F!`);
|
|
1073
|
-
}
|
|
1074
|
-
return merged;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// src/index.ts
|
|
1078
|
-
async function initConfig(options) {
|
|
1079
|
-
const { root = import_node_process.default.cwd(), command } = options;
|
|
1080
|
-
await createOrUpdateProjectConfig({ root });
|
|
1081
|
-
await createOrUpdatePackageJson({ root, command });
|
|
1082
|
-
await updateGitIgnore({ root });
|
|
1083
|
-
if (command === "weapp-vite") {
|
|
1084
|
-
await initViteConfigFile({ root });
|
|
1085
|
-
await initTsDtsFile({ root });
|
|
1086
|
-
await initTsJsonFiles({ root });
|
|
1087
|
-
}
|
|
1088
|
-
return ctx;
|
|
1089
|
-
}
|
|
1090
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1091
|
-
0 && (module.exports = {
|
|
1092
|
-
createOrUpdatePackageJson,
|
|
1093
|
-
createOrUpdateProjectConfig,
|
|
1094
|
-
initConfig,
|
|
1095
|
-
initTsDtsFile,
|
|
1096
|
-
initTsJsonFiles,
|
|
1097
|
-
initViteConfigFile,
|
|
1098
|
-
resetContext
|
|
1099
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { PackageJson, TSConfig } from 'pkg-types';
|
|
2
|
-
import { set } from '@weapp-core/shared';
|
|
3
|
-
|
|
4
|
-
interface SetMethod {
|
|
5
|
-
(path: set.InputType, value: any, options?: set.Options): void;
|
|
6
|
-
}
|
|
7
|
-
interface SharedUpdateOptions {
|
|
8
|
-
root: string;
|
|
9
|
-
dest?: string;
|
|
10
|
-
write?: boolean;
|
|
11
|
-
cb?: (set: SetMethod) => void;
|
|
12
|
-
}
|
|
13
|
-
interface UpdateProjectConfigOptions extends SharedUpdateOptions {
|
|
14
|
-
filename?: string;
|
|
15
|
-
}
|
|
16
|
-
interface UpdatePackageJsonOptions extends SharedUpdateOptions {
|
|
17
|
-
command?: 'weapp-vite';
|
|
18
|
-
filename?: string;
|
|
19
|
-
}
|
|
20
|
-
interface ProjectConfig {
|
|
21
|
-
miniprogramRoot?: string;
|
|
22
|
-
srcMiniprogramRoot?: string;
|
|
23
|
-
setting: {
|
|
24
|
-
packNpmManually: boolean;
|
|
25
|
-
packNpmRelationList: {
|
|
26
|
-
packageJsonPath: string;
|
|
27
|
-
miniprogramNpmDistDir: string;
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ContextDocument<T> {
|
|
33
|
-
name: string;
|
|
34
|
-
path: string;
|
|
35
|
-
value: T | null;
|
|
36
|
-
}
|
|
37
|
-
interface Context {
|
|
38
|
-
projectConfig: ContextDocument<ProjectConfig>;
|
|
39
|
-
packageJson: ContextDocument<PackageJson>;
|
|
40
|
-
viteConfig: ContextDocument<string>;
|
|
41
|
-
tsconfig: ContextDocument<TSConfig>;
|
|
42
|
-
tsconfigApp: ContextDocument<TSConfig>;
|
|
43
|
-
tsconfigNode: ContextDocument<TSConfig>;
|
|
44
|
-
dts: ContextDocument<string>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare function initViteConfigFile(options: SharedUpdateOptions): Promise<string>;
|
|
48
|
-
declare function initTsDtsFile(options: SharedUpdateOptions): Promise<string>;
|
|
49
|
-
declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<{
|
|
50
|
-
tsconfig: {
|
|
51
|
-
references: {
|
|
52
|
-
path: string;
|
|
53
|
-
}[];
|
|
54
|
-
files: never[];
|
|
55
|
-
};
|
|
56
|
-
tsconfigApp: {
|
|
57
|
-
compilerOptions: {
|
|
58
|
-
tsBuildInfoFile: string;
|
|
59
|
-
target: string;
|
|
60
|
-
lib: string[];
|
|
61
|
-
jsx: string;
|
|
62
|
-
module: string;
|
|
63
|
-
moduleResolution: string;
|
|
64
|
-
moduleDetection: string;
|
|
65
|
-
baseUrl: string;
|
|
66
|
-
paths: {
|
|
67
|
-
'@/*': string[];
|
|
68
|
-
};
|
|
69
|
-
resolveJsonModule: boolean;
|
|
70
|
-
types: string[];
|
|
71
|
-
allowImportingTsExtensions: boolean;
|
|
72
|
-
allowJs: boolean;
|
|
73
|
-
allowSyntheticDefaultImports: boolean;
|
|
74
|
-
esModuleInterop: boolean;
|
|
75
|
-
isolatedModules: boolean;
|
|
76
|
-
strict: boolean;
|
|
77
|
-
noFallthroughCasesInSwitch: boolean;
|
|
78
|
-
noUnusedLocals: boolean;
|
|
79
|
-
noUnusedParameters: boolean;
|
|
80
|
-
noEmit: boolean;
|
|
81
|
-
verbatimModuleSyntax: boolean;
|
|
82
|
-
noUncheckedSideEffectImports: boolean;
|
|
83
|
-
erasableSyntaxOnly: boolean;
|
|
84
|
-
skipLibCheck: boolean;
|
|
85
|
-
};
|
|
86
|
-
include: string[];
|
|
87
|
-
};
|
|
88
|
-
tsconfigNode: {
|
|
89
|
-
compilerOptions: {
|
|
90
|
-
tsBuildInfoFile: string;
|
|
91
|
-
target: string;
|
|
92
|
-
lib: string[];
|
|
93
|
-
module: string;
|
|
94
|
-
moduleResolution: string;
|
|
95
|
-
moduleDetection: string;
|
|
96
|
-
types: string[];
|
|
97
|
-
allowImportingTsExtensions: boolean;
|
|
98
|
-
resolveJsonModule: boolean;
|
|
99
|
-
verbatimModuleSyntax: boolean;
|
|
100
|
-
strict: boolean;
|
|
101
|
-
noFallthroughCasesInSwitch: boolean;
|
|
102
|
-
noUnusedLocals: boolean;
|
|
103
|
-
noUnusedParameters: boolean;
|
|
104
|
-
noEmit: boolean;
|
|
105
|
-
noUncheckedSideEffectImports: boolean;
|
|
106
|
-
erasableSyntaxOnly: boolean;
|
|
107
|
-
skipLibCheck: boolean;
|
|
108
|
-
};
|
|
109
|
-
include: string[];
|
|
110
|
-
};
|
|
111
|
-
}>;
|
|
112
|
-
|
|
113
|
-
declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJson>;
|
|
114
|
-
|
|
115
|
-
declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig>;
|
|
116
|
-
|
|
117
|
-
declare function resetContext(): void;
|
|
118
|
-
|
|
119
|
-
declare function initConfig(options: {
|
|
120
|
-
root?: string;
|
|
121
|
-
command?: 'weapp-vite';
|
|
122
|
-
}): Promise<Context>;
|
|
123
|
-
|
|
124
|
-
export { type Context, createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, resetContext };
|