@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 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
- if (onlyBuild) {
94
- return envConfig;
95
- }
96
- if (envConfig.command === "build") {
97
- if (process.env.NODE_ENV !== "production") {
98
- console.error("部署时需要设置 NODE_ENV 为 production,请检查环境变量设置".red);
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.deployTo = (envs[t] || "").replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/^(.)/, "https://$1");
102
- envConfig.deployUser = envs[u];
103
- envConfig.deployKey = envs[k];
104
- envConfig.deployDebug = envs[d] === "1" || envs[d] === "y" || envs[d] === "true";
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}_SERVER_PORT 设置`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -13,6 +13,8 @@ interface IBuildEnvs {
13
13
  deployTo?: string;
14
14
  /** 打印部署详细日志 */
15
15
  deployDebug?: boolean;
16
+ /** 当部署 well-known 目录时有效 */
17
+ wellKnownDir?: string;
16
18
  /** 部署 sentry sourcemap 用的 token */
17
19
  sentryAuthToken?: string;
18
20
  /** 部署的 user */
@@ -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 {};