@seayoo-web/scripts 1.0.6 → 1.1.0
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/git-6CgysH-T.cjs +223 -0
- package/dist/git-DqZLg6mx.js +224 -0
- package/dist/index.cjs.js +257 -0
- package/dist/index.js +19 -481
- package/dist/node.cjs +278 -0
- package/dist/node.es.js +278 -0
- package/package.json +24 -1
- package/types/index.d.ts +3 -4
- package/types/node.d.ts +3 -0
- package/types/src/postcss.d.ts +7 -0
- package/types/src/stylelint.d.ts +11 -0
- package/types/src/vite.lab.d.ts +2 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_path = require("node:path");
|
|
4
|
+
const vite = require("vite");
|
|
5
|
+
const finder = require("@seayoo-web/finder");
|
|
6
|
+
const vitePlugin = require("@sentry/vite-plugin");
|
|
7
|
+
const legacy = require("@vitejs/plugin-legacy");
|
|
8
|
+
const vue = require("@vitejs/plugin-vue");
|
|
9
|
+
const vueDevTools = require("vite-plugin-vue-devtools");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
require("colors");
|
|
12
|
+
const git = require("./git-6CgysH-T.cjs");
|
|
13
|
+
const skipFormatting = require("@vue/eslint-config-prettier/skip-formatting");
|
|
14
|
+
const eslintConfigTypescript = require("@vue/eslint-config-typescript");
|
|
15
|
+
const eslintPluginImport = require("eslint-plugin-import");
|
|
16
|
+
const pluginVue = require("eslint-plugin-vue");
|
|
17
|
+
const nestingPlugin = require("postcss-nesting");
|
|
18
|
+
function defineLibBuildConfig(option) {
|
|
19
|
+
return vite.defineConfig({
|
|
20
|
+
build: {
|
|
21
|
+
outDir: (option == null ? void 0 : option.outDir) || "dist",
|
|
22
|
+
lib: {
|
|
23
|
+
entry: node_path.join(process.cwd(), (option == null ? void 0 : option.rootEntry) || "index.ts"),
|
|
24
|
+
formats: ["es"],
|
|
25
|
+
fileName: (format, entryName) => {
|
|
26
|
+
return format === "es" ? `${entryName}.js` : `${entryName}.${format}.js`;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
rollupOptions: {
|
|
30
|
+
external: (option == null ? void 0 : option.external) || [/^@seayoo-web\/(?:request|utils)/]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const EnvPrefix = "SY_";
|
|
36
|
+
function getBuildEnv(command, mode) {
|
|
37
|
+
const envs = vite.loadEnv(mode, process.cwd(), EnvPrefix);
|
|
38
|
+
const envConfig = {
|
|
39
|
+
command,
|
|
40
|
+
stamp: git.getNowTime(),
|
|
41
|
+
page: "",
|
|
42
|
+
mode: "",
|
|
43
|
+
deployUser: "",
|
|
44
|
+
deployKey: ""
|
|
45
|
+
};
|
|
46
|
+
envConfig.mode = mode || "preview";
|
|
47
|
+
const d = `${EnvPrefix}DEPLOY_DEBUG`;
|
|
48
|
+
const t = `${EnvPrefix}DEPLOY_TO`;
|
|
49
|
+
const s = `${EnvPrefix}SENTRY_AUTH_TOKEN`;
|
|
50
|
+
const u = `${EnvPrefix}DEPLOY_USER`;
|
|
51
|
+
const k = `${EnvPrefix}DEPLOY_KEY`;
|
|
52
|
+
const execDir = process.cwd().replace(/\\/g, "/").split("/").slice(-2).join("/");
|
|
53
|
+
const packageFile = node_path.join(process.cwd(), "./package.json");
|
|
54
|
+
if (!fs.existsSync(packageFile)) {
|
|
55
|
+
console.error("执行代码有误,没有找到 package.json".red);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
const packageJson = JSON.parse(fs.readFileSync(packageFile, { encoding: "utf-8" }).toString());
|
|
59
|
+
if (!packageJson || !packageJson.name || packageJson.name !== `@${execDir}`) {
|
|
60
|
+
console.error(`工程 package.json/name 属性设置错误,应该跟目录保持一致(@${execDir}),请先调整`.red);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
envConfig.page = execDir;
|
|
64
|
+
if (envConfig.command === "build") {
|
|
65
|
+
if (process.env.NODE_ENV !== "production") {
|
|
66
|
+
console.error("部署时需要设置 NODE_ENV 为 production,请检查环境变量设置".red);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
envConfig.deployTo = (envs[t] || "").replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/^(.)/, "https://$1");
|
|
70
|
+
envConfig.deployUser = envs[u];
|
|
71
|
+
envConfig.deployKey = envs[k];
|
|
72
|
+
envConfig.deployDebug = envs[d] === "1" || envs[d] === "y" || envs[d] === "true";
|
|
73
|
+
if (!envConfig.deployTo) {
|
|
74
|
+
console.error(`缺少 ${t.bgRed} 设置,请在 .env.${mode} 中配置`.red);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
if (!envConfig.deployUser || !envConfig.deployKey) {
|
|
78
|
+
console.error(`缺少 ${u.bgRed} / ${k.bgRed} 设置,请在 .env.local 配置`.red);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
envConfig.sentryAuthToken = envs[s];
|
|
82
|
+
if (!envConfig.sentryAuthToken) {
|
|
83
|
+
console.warn(`尚未设置 ${s.red},推送 sourcemap 到 sentry 的功能将无效`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return envConfig;
|
|
87
|
+
}
|
|
88
|
+
function transformEnvs(envs) {
|
|
89
|
+
return Object.entries(envs).reduce(
|
|
90
|
+
function(result, [key, value]) {
|
|
91
|
+
result[key] = JSON.stringify(value);
|
|
92
|
+
return result;
|
|
93
|
+
},
|
|
94
|
+
{}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
function htmlInjectPlugin(data) {
|
|
98
|
+
return {
|
|
99
|
+
name: "html-inject-plugin",
|
|
100
|
+
transformIndexHtml: {
|
|
101
|
+
order: "pre",
|
|
102
|
+
handler: (html) => html.replace(/%\s*(.*?)\s*%/g, (match, p1) => data[p1] ?? match).replace(/[\r\n]{2,}/g, "\n").replace(/(?:^[\s\r\n]*|[\s\r\n]*$)/g, "")
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function definePageBuildConfig(option) {
|
|
107
|
+
return vite.defineConfig(async function(viteEnvs) {
|
|
108
|
+
const { command, mode } = viteEnvs;
|
|
109
|
+
const envs = getBuildEnv(command, mode);
|
|
110
|
+
const gitInfo = await git.getCommitInfo(command, mode, envs.deployTo || "");
|
|
111
|
+
const isProductMode = mode === "production" || mode === "prod";
|
|
112
|
+
const {
|
|
113
|
+
plugins = [],
|
|
114
|
+
define = {},
|
|
115
|
+
build = {},
|
|
116
|
+
resolve = {},
|
|
117
|
+
server = {},
|
|
118
|
+
sentry = {},
|
|
119
|
+
...optionReset
|
|
120
|
+
} = option || {};
|
|
121
|
+
const { alias, ...resolveReset } = resolve || {};
|
|
122
|
+
return {
|
|
123
|
+
base: "./",
|
|
124
|
+
build: {
|
|
125
|
+
emptyOutDir: true,
|
|
126
|
+
outDir: node_path.join(process.cwd(), "./dist"),
|
|
127
|
+
assetsDir: "assets",
|
|
128
|
+
reportCompressedSize: false,
|
|
129
|
+
sourcemap: command === "build" && !!envs.sentryAuthToken,
|
|
130
|
+
...build
|
|
131
|
+
},
|
|
132
|
+
plugins: [
|
|
133
|
+
vue(),
|
|
134
|
+
vueDevTools(),
|
|
135
|
+
legacy({
|
|
136
|
+
targets: ["defaults", "ie >= 10", "chrome 52"],
|
|
137
|
+
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
|
|
138
|
+
renderLegacyChunks: true
|
|
139
|
+
}),
|
|
140
|
+
htmlInjectPlugin({
|
|
141
|
+
BUILD_TIME: envs.stamp,
|
|
142
|
+
BUILD_MODE: envs.mode,
|
|
143
|
+
BUILD_VERSION: gitInfo.hash
|
|
144
|
+
}),
|
|
145
|
+
...plugins,
|
|
146
|
+
command === "build" && envs.deployTo ? finder.viteDeployPlugin({
|
|
147
|
+
deployTo: envs.deployTo,
|
|
148
|
+
user: envs.deployUser,
|
|
149
|
+
key: envs.deployKey,
|
|
150
|
+
debug: envs.deployDebug,
|
|
151
|
+
commitLogs: isProductMode && gitInfo.logs.length > 0 ? "\n" + gitInfo.logs.join("\n") : void 0,
|
|
152
|
+
onFinished() {
|
|
153
|
+
if (isProductMode) {
|
|
154
|
+
git.createPageDeployTag(envs.page, envs.deployTo || "", envs.deployUser);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}) : null,
|
|
158
|
+
command === "build" && envs.sentryAuthToken ? vitePlugin.sentryVitePlugin({
|
|
159
|
+
authToken: envs.sentryAuthToken,
|
|
160
|
+
org: "sentry",
|
|
161
|
+
url: sentry.url || "https://sentry.seayoo.com/",
|
|
162
|
+
project: sentry.project || "gamer-fe"
|
|
163
|
+
}) : null
|
|
164
|
+
],
|
|
165
|
+
define: transformEnvs({
|
|
166
|
+
BUILD_TIME: envs.stamp,
|
|
167
|
+
BUILD_MODE: envs.mode,
|
|
168
|
+
...envs,
|
|
169
|
+
...define
|
|
170
|
+
}),
|
|
171
|
+
resolve: {
|
|
172
|
+
alias: {
|
|
173
|
+
"@": node_path.join(process.cwd(), "./src"),
|
|
174
|
+
...alias
|
|
175
|
+
},
|
|
176
|
+
extensions: [".mts", ".mjs", ".ts", ".js"],
|
|
177
|
+
// allowImportingTsExtensions: true,
|
|
178
|
+
...resolveReset
|
|
179
|
+
},
|
|
180
|
+
server: {
|
|
181
|
+
open: true,
|
|
182
|
+
...server
|
|
183
|
+
},
|
|
184
|
+
...optionReset,
|
|
185
|
+
// envPrefix 不允许覆盖
|
|
186
|
+
envPrefix: EnvPrefix
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
const vueEslintConfig = [
|
|
191
|
+
pluginVue.configs["flat/essential"],
|
|
192
|
+
eslintConfigTypescript.vueTsConfigs.recommended,
|
|
193
|
+
skipFormatting,
|
|
194
|
+
{
|
|
195
|
+
files: ["**/*.vue"],
|
|
196
|
+
rules: {
|
|
197
|
+
"vue/multi-word-component-names": "off"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
];
|
|
201
|
+
const importEslintConfig = [
|
|
202
|
+
eslintPluginImport.flatConfigs.recommended,
|
|
203
|
+
{
|
|
204
|
+
rules: {
|
|
205
|
+
"import/no-unresolved": "off",
|
|
206
|
+
"import/named": "off",
|
|
207
|
+
"import/namespace": "off",
|
|
208
|
+
"import/no-named-as-default": "off",
|
|
209
|
+
"import/no-named-as-default-member": "off",
|
|
210
|
+
"import/export": ["error"],
|
|
211
|
+
"import/order": [
|
|
212
|
+
"error",
|
|
213
|
+
{
|
|
214
|
+
groups: ["builtin", "external", "internal", "parent", "sibling", "index", "type"],
|
|
215
|
+
pathGroups: [
|
|
216
|
+
{
|
|
217
|
+
pattern: "@/**",
|
|
218
|
+
group: "internal"
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
"newlines-between": "always",
|
|
222
|
+
alphabetize: {
|
|
223
|
+
order: "asc",
|
|
224
|
+
caseInsensitive: true
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
];
|
|
231
|
+
const stylelintConfig = {
|
|
232
|
+
extends: ["stylelint-config-standard", "stylelint-config-recess-order"],
|
|
233
|
+
overrides: [
|
|
234
|
+
{
|
|
235
|
+
files: ["**/*.vue", "**/*.html"],
|
|
236
|
+
customSyntax: "postcss-html"
|
|
237
|
+
}
|
|
238
|
+
],
|
|
239
|
+
rules: {}
|
|
240
|
+
};
|
|
241
|
+
const postcssConfig = {
|
|
242
|
+
plugins: [nestingPlugin]
|
|
243
|
+
};
|
|
244
|
+
Object.defineProperty(exports, "defineConfigWithVueTs", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
get: () => eslintConfigTypescript.defineConfigWithVueTs
|
|
247
|
+
});
|
|
248
|
+
exports.EnvPrefix = EnvPrefix;
|
|
249
|
+
exports.defineLibBuildConfig = defineLibBuildConfig;
|
|
250
|
+
exports.definePageBuildConfig = definePageBuildConfig;
|
|
251
|
+
exports.getBuildEnv = getBuildEnv;
|
|
252
|
+
exports.htmlInjectPlugin = htmlInjectPlugin;
|
|
253
|
+
exports.importEslintConfig = importEslintConfig;
|
|
254
|
+
exports.postcssConfig = postcssConfig;
|
|
255
|
+
exports.stylelintConfig = stylelintConfig;
|
|
256
|
+
exports.transformEnvs = transformEnvs;
|
|
257
|
+
exports.vueEslintConfig = vueEslintConfig;
|