ylyx-cli 1.0.12 → 1.0.14
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 +4 -0
- package/lib/deploy.js +60 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
公司内部使用的项目脚手架工具:支持交互式/命令式生成项目与代码模板,并提供 `.ylyxrc.json` 项目配置、环境配置切换(`isDev`)、以及一键部署(测试服上传/正式服打包压缩)等能力。
|
|
4
4
|
|
|
5
|
+
> 说明:当前部署/配置切换能力**暂时只针对 Vue2 项目约定**(如 `.env.production` 的 `VUE_APP_PUBLIC_URL` 等)。其它技术栈/项目结构可能需要你根据实际情况调整 `.ylyxrc.json` 与相关路径配置。
|
|
6
|
+
|
|
5
7
|
## 功能特性
|
|
6
8
|
|
|
7
9
|
- 🚀 **快速生成项目代码**:内置多种模板,一键生成项目/组件/模块代码
|
|
@@ -159,6 +161,8 @@ prod 输出目录规则:
|
|
|
159
161
|
|
|
160
162
|
压缩产物命名规则(正式服或 `--zip`):`buildDir(最后一级)-YYYYMMDDHHmmss-哈希(纯字母).zip`,且 zip 内顶层目录名为 `buildDir` 的最后一级目录名。
|
|
161
163
|
|
|
164
|
+
`localDir` 默认推导优先级:`deploy.localDir` → `.env.production` 的 `VUE_APP_PUBLIC_URL` → `.ylyxrc.json` 的 `buildDir`。
|
|
165
|
+
|
|
162
166
|
### 命令
|
|
163
167
|
|
|
164
168
|
```bash
|
package/lib/deploy.js
CHANGED
|
@@ -210,6 +210,61 @@ function resolveDeployConfig(overrides = {}) {
|
|
|
210
210
|
const projectConfig = readProjectConfig();
|
|
211
211
|
const deploy = (projectConfig && projectConfig.deploy) || {};
|
|
212
212
|
|
|
213
|
+
function parseDotEnvFile(envPath) {
|
|
214
|
+
if (!fs.existsSync(envPath)) return {};
|
|
215
|
+
const content = fs.readFileSync(envPath, 'utf-8');
|
|
216
|
+
const lines = content.split(/\r?\n/);
|
|
217
|
+
const out = {};
|
|
218
|
+
for (const raw of lines) {
|
|
219
|
+
const line = raw.trim();
|
|
220
|
+
if (!line || line.startsWith('#')) continue;
|
|
221
|
+
const idx = line.indexOf('=');
|
|
222
|
+
if (idx < 0) continue;
|
|
223
|
+
const key = line.slice(0, idx).trim();
|
|
224
|
+
let value = line.slice(idx + 1).trim();
|
|
225
|
+
if (
|
|
226
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
227
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
228
|
+
) {
|
|
229
|
+
value = value.slice(1, -1);
|
|
230
|
+
}
|
|
231
|
+
out[key] = value;
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function normalizePublicUrlToDir(publicUrl) {
|
|
237
|
+
// 与 config.js 规则保持一致:忽略完整 URL;去掉首尾 /;把 \ 转 /
|
|
238
|
+
if (!publicUrl || typeof publicUrl !== 'string') return '';
|
|
239
|
+
let v = publicUrl.trim();
|
|
240
|
+
v = v.replace(/\\/g, '/');
|
|
241
|
+
if (/^https?:\/\//i.test(v)) return '';
|
|
242
|
+
v = v.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
243
|
+
return v;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// localDir 默认优先从项目 .env.production 推导(VUE_APP_PUBLIC_URL -> 目录名)
|
|
247
|
+
const envProdPath = path.join(process.cwd(), '.env.production');
|
|
248
|
+
const envProd = parseDotEnvFile(envProdPath);
|
|
249
|
+
const publicUrlDir = normalizePublicUrlToDir(envProd.VUE_APP_PUBLIC_URL);
|
|
250
|
+
const inferredFromEnvProd = publicUrlDir ? path.resolve(process.cwd(), publicUrlDir) : null;
|
|
251
|
+
|
|
252
|
+
// localDir 默认使用项目 buildDir(打包输出目录)
|
|
253
|
+
// 规则:优先 deploy.localDir;否则使用 .env.production 的 VUE_APP_PUBLIC_URL;否则使用 .ylyxrc.json 的 buildDir;最后才回退 ./EXTERNAL_DIGIC
|
|
254
|
+
const inferredLocalDir =
|
|
255
|
+
deploy.localDir ||
|
|
256
|
+
inferredFromEnvProd ||
|
|
257
|
+
(projectConfig && projectConfig.buildDir ? path.resolve(process.cwd(), projectConfig.buildDir) : null);
|
|
258
|
+
|
|
259
|
+
if (!inferredLocalDir) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
'无法确定 deploy.localDir(本地打包目录)。请设置以下任意一种:\n' +
|
|
262
|
+
'- 在 .ylyxrc.json 配置 deploy.localDir\n' +
|
|
263
|
+
'- 在项目 .env.production 配置 VUE_APP_PUBLIC_URL(相对路径,如 /dist/app/)\n' +
|
|
264
|
+
'- 在 .ylyxrc.json 配置 buildDir(可相对/绝对路径)'
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
213
268
|
const cfg = {
|
|
214
269
|
env: overrides.env ?? deploy.env,
|
|
215
270
|
buildDir: overrides.buildDir ?? deploy.buildDir ?? projectConfig.buildDir,
|
|
@@ -217,8 +272,8 @@ function resolveDeployConfig(overrides = {}) {
|
|
|
217
272
|
port: String(overrides.port ?? deploy.port ?? '22'),
|
|
218
273
|
username: overrides.username ?? deploy.username,
|
|
219
274
|
password: overrides.password ?? deploy.password,
|
|
220
|
-
localDir: overrides.localDir ??
|
|
221
|
-
remoteDir: overrides.remoteDir ?? deploy.remoteDir
|
|
275
|
+
localDir: overrides.localDir ?? inferredLocalDir,
|
|
276
|
+
remoteDir: overrides.remoteDir ?? deploy.remoteDir,
|
|
222
277
|
zipAfter: overrides.zipAfter ?? deploy.zipAfter ?? false,
|
|
223
278
|
zipOutDir: overrides.zipOutDir ?? deploy.zipOutDir ?? path.join(process.cwd(), '.ylyx-deploy'),
|
|
224
279
|
};
|
|
@@ -269,7 +324,9 @@ async function deploy(overrides = {}) {
|
|
|
269
324
|
if (!cfg.host) throw new Error('缺少 deploy.host(测试服上传需要)');
|
|
270
325
|
if (!cfg.username) throw new Error('缺少 deploy.username(测试服上传需要)');
|
|
271
326
|
if (!cfg.password) throw new Error('缺少 deploy.password(测试服上传需要)');
|
|
272
|
-
if (!remoteFolderPath)
|
|
327
|
+
if (!remoteFolderPath) {
|
|
328
|
+
throw new Error('缺少 deploy.remoteDir(测试服上传需要):请在 .ylyxrc.json 的 deploy.remoteDir 配置远端部署目录');
|
|
329
|
+
}
|
|
273
330
|
|
|
274
331
|
let Client;
|
|
275
332
|
try {
|