@seayoo-web/scripts 2.5.4 → 2.5.6
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.js +58 -21
- package/package.json +1 -1
- package/types/src/env.d.ts +2 -0
- package/types/src/vite.page.d.ts +3 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import vue from "@vitejs/plugin-vue";
|
|
3
3
|
import { visualizer } from "rollup-plugin-visualizer";
|
|
4
|
-
import { viteDeployPlugin } from "@seayoo-web/finder";
|
|
4
|
+
import { finderDeploy, viteDeployPlugin } from "@seayoo-web/finder";
|
|
5
5
|
import { sentryVitePlugin } from "@sentry/vite-plugin";
|
|
6
6
|
import legacy from "@vitejs/plugin-legacy";
|
|
7
7
|
import vueDevTools from "vite-plugin-vue-devtools";
|
|
8
|
-
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import { existsSync, readFileSync, statSync, readdirSync } from "fs";
|
|
9
9
|
import { loadEnv } from "vite";
|
|
10
|
-
import "colors";
|
|
11
10
|
import { g as getNowTime, a as getCommitInfo, c as createPageDeployTag } from "./git-9UtzsH83.js";
|
|
11
|
+
import "colors";
|
|
12
12
|
import skipFormatting from "@vue/eslint-config-prettier/skip-formatting";
|
|
13
13
|
import { vueTsConfigs, defineConfigWithVueTs } from "@vue/eslint-config-typescript";
|
|
14
14
|
import { flatConfigs } from "eslint-plugin-import";
|
|
@@ -90,18 +90,37 @@ function getBuildEnv(command, mode, onlyBuild, requireSentryToken, ignoreSentryT
|
|
|
90
90
|
envConfig.page = execDirWithPackage;
|
|
91
91
|
const port = +envs[p];
|
|
92
92
|
if (port) envConfig.port = port;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
envConfig.deployTo = (envs[t] || "").replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/^(.)/, "https://$1");
|
|
94
|
+
envConfig.deployUser = envs[u];
|
|
95
|
+
envConfig.deployKey = envs[k];
|
|
96
|
+
envConfig.deployDebug = envs[d] === "1" || envs[d] === "y" || envs[d] === "true";
|
|
97
|
+
if (mode === "wellknown") {
|
|
98
|
+
const wellknownDir = join(process.cwd(), ".well-known");
|
|
99
|
+
if (!existsSync(wellknownDir)) {
|
|
100
|
+
console.error(`没有找到 .well-known 目录,它应该跟项目 package.json 文件在一个目录下`.red);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
if (!statSync(wellknownDir).isDirectory()) {
|
|
104
|
+
console.error(`.well-known 应该是一个目录`.red);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
const files = readdirSync(wellknownDir);
|
|
108
|
+
if (files.length === 0) {
|
|
109
|
+
console.error(`.well-known 不能是一个空目录`.red);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
if (!envConfig.deployTo) {
|
|
113
|
+
console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
if (!envConfig.deployUser || !envConfig.deployKey) {
|
|
117
|
+
console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
|
|
99
118
|
process.exit(1);
|
|
100
119
|
}
|
|
101
|
-
envConfig.
|
|
102
|
-
envConfig
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
envConfig.wellKnownDir = wellknownDir;
|
|
121
|
+
return envConfig;
|
|
122
|
+
}
|
|
123
|
+
if (!onlyBuild && envConfig.command === "build") {
|
|
105
124
|
if (!envConfig.deployTo) {
|
|
106
125
|
console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
|
|
107
126
|
process.exit(1);
|
|
@@ -152,16 +171,16 @@ function definePageBuildConfig(option) {
|
|
|
152
171
|
manualChunks,
|
|
153
172
|
badPackages = [],
|
|
154
173
|
plugins = [],
|
|
155
|
-
define = {},
|
|
156
174
|
build = {},
|
|
157
175
|
resolve = {},
|
|
158
176
|
server = {},
|
|
159
177
|
sentry = {},
|
|
178
|
+
base,
|
|
160
179
|
...optionReset
|
|
161
180
|
} = option || {};
|
|
162
181
|
const { alias, ...resolveReset } = resolve;
|
|
163
182
|
if (server.port) {
|
|
164
|
-
console.warn(`ServerPort 不允许直接修改,请使用环境变量 ${EnvPrefix}
|
|
183
|
+
console.warn(`ServerPort 不允许直接修改,请使用环境变量 ${EnvPrefix}SERVER_PORT 设置`);
|
|
165
184
|
delete server.port;
|
|
166
185
|
}
|
|
167
186
|
return async function({ command, mode }) {
|
|
@@ -169,7 +188,22 @@ function definePageBuildConfig(option) {
|
|
|
169
188
|
const justBuild = mode === "build";
|
|
170
189
|
const envs = getBuildEnv(command, mode, justBuild, requireSentryToken, ignoreSentryToken);
|
|
171
190
|
const gitInfo = justBuild ? null : await getCommitInfo(command, mode, envs.page, envs.deployTo || "");
|
|
172
|
-
const isProductMode = mode === "production" || mode === "prod";
|
|
191
|
+
const isProductMode = mode === "production" || mode === "prod" || mode === "prd";
|
|
192
|
+
if (mode === "wellknown" && envs.wellKnownDir && envs.deployTo) {
|
|
193
|
+
const result = await finderDeploy({
|
|
194
|
+
preview: false,
|
|
195
|
+
deployTo: envs.deployTo,
|
|
196
|
+
dist: envs.wellKnownDir,
|
|
197
|
+
user: envs.deployUser,
|
|
198
|
+
key: envs.deployKey
|
|
199
|
+
}).catch((e) => e instanceof Error ? e : typeof e === "string" ? new Error(e) : new Error(e + ""));
|
|
200
|
+
if (result instanceof Error) {
|
|
201
|
+
console.log("部署 .well-known 失败".bgRed, result.message);
|
|
202
|
+
} else {
|
|
203
|
+
console.log("部署 .well-known 成功".bgGreen, (result || "").green);
|
|
204
|
+
}
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
173
207
|
const trunkMap = {
|
|
174
208
|
"naive-ui": "naive-ui",
|
|
175
209
|
html2canvas: "html2canvas",
|
|
@@ -182,8 +216,13 @@ function definePageBuildConfig(option) {
|
|
|
182
216
|
if (k) return trunkMap[k];
|
|
183
217
|
};
|
|
184
218
|
const ignoreSideEffects = ["thinkingdata", "@esotericsoftware/spine", ...badPackages];
|
|
219
|
+
const baseValue = typeof base === "object" && base ? base[mode] : typeof base === "string" ? base : "./";
|
|
220
|
+
if (baseValue === void 0 && mode !== "development") {
|
|
221
|
+
console.warn(`base 参数在模式(${mode})下未设置内容`.red);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
185
224
|
return {
|
|
186
|
-
base: "./",
|
|
225
|
+
base: baseValue || "./",
|
|
187
226
|
build: {
|
|
188
227
|
emptyOutDir: true,
|
|
189
228
|
outDir: join(process.cwd(), "./dist"),
|
|
@@ -232,8 +271,7 @@ function definePageBuildConfig(option) {
|
|
|
232
271
|
BUILD_TIME: envs.stamp,
|
|
233
272
|
BUILD_MODE: envs.mode,
|
|
234
273
|
BUILD_VERSION: (gitInfo == null ? void 0 : gitInfo.hash) || "",
|
|
235
|
-
...envs.viteEnvs
|
|
236
|
-
...define
|
|
274
|
+
...envs.viteEnvs
|
|
237
275
|
}),
|
|
238
276
|
...plugins,
|
|
239
277
|
command === "build" && envs.deployTo && !justBuild && gitInfo ? viteDeployPlugin({
|
|
@@ -262,8 +300,7 @@ function definePageBuildConfig(option) {
|
|
|
262
300
|
define: transformEnvs({
|
|
263
301
|
BUILD_TIME: envs.stamp,
|
|
264
302
|
BUILD_MODE: envs.mode,
|
|
265
|
-
...envs.viteEnvs
|
|
266
|
-
...define
|
|
303
|
+
...envs.viteEnvs
|
|
267
304
|
}),
|
|
268
305
|
resolve: {
|
|
269
306
|
alias: {
|
package/package.json
CHANGED
package/types/src/env.d.ts
CHANGED
package/types/src/vite.page.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { UserConfig, UserConfigFnPromise } from "vite";
|
|
2
2
|
interface ExternalConfig {
|
|
3
|
+
/** 设置base路径,支持配置多组 base,以 mode 为key */
|
|
4
|
+
base?: string | Record<string, string>;
|
|
3
5
|
/** 是否不使用 vue */
|
|
4
6
|
notVuePage?: boolean;
|
|
5
7
|
/** 是否不加载 polyfill */
|
|
@@ -47,5 +49,5 @@ interface ExternalConfig {
|
|
|
47
49
|
/**
|
|
48
50
|
* 导出一个动态的配置工厂函数
|
|
49
51
|
*/
|
|
50
|
-
export declare function definePageBuildConfig(option?: UserConfig & ExternalConfig): UserConfigFnPromise;
|
|
52
|
+
export declare function definePageBuildConfig(option?: Omit<UserConfig, "base" | "define"> & ExternalConfig): UserConfigFnPromise;
|
|
51
53
|
export {};
|