@lark-apaas/fullstack-cli 1.1.2 → 1.1.4
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/commands/sync.d.ts
CHANGED
package/dist/commands/sync.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import {
|
|
4
|
+
import { genSyncConfig } from '../config/sync.js';
|
|
5
5
|
/**
|
|
6
6
|
* 同步模板文件到用户项目
|
|
7
7
|
*/
|
|
8
|
-
export async function run() {
|
|
8
|
+
export async function run(options) {
|
|
9
9
|
// 检测是否在用户项目中(通过 INIT_CWD 判断)
|
|
10
10
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
11
11
|
// 获取插件根目录
|
|
@@ -26,7 +26,9 @@ export async function run() {
|
|
|
26
26
|
try {
|
|
27
27
|
console.log('[fullstack-cli] Starting sync...');
|
|
28
28
|
// 使用配置
|
|
29
|
-
const config =
|
|
29
|
+
const config = genSyncConfig({
|
|
30
|
+
disableGenOpenapi: options.disableGenOpenapi ?? false,
|
|
31
|
+
});
|
|
30
32
|
if (!config || !config.sync) {
|
|
31
33
|
console.warn('[fullstack-cli] No sync configuration found');
|
|
32
34
|
process.exit(0);
|
|
@@ -51,6 +53,22 @@ export async function run() {
|
|
|
51
53
|
* 执行单个同步规则
|
|
52
54
|
*/
|
|
53
55
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
56
|
+
// 处理删除操作(只需要 to 路径)
|
|
57
|
+
if (rule.type === 'delete-file' || rule.type === 'delete-directory') {
|
|
58
|
+
const destPath = path.join(userProjectRoot, rule.to);
|
|
59
|
+
if (rule.type === 'delete-file') {
|
|
60
|
+
deleteFile(destPath);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
deleteDirectory(destPath);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// TypeScript 类型窄化:使用 'from' in rule 确保类型安全
|
|
68
|
+
if (!('from' in rule)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// 处理需要源文件的操作(CopyRule 和 AppendRule)
|
|
54
72
|
const srcPath = path.join(pluginRoot, rule.from);
|
|
55
73
|
const destPath = path.join(userProjectRoot, rule.to);
|
|
56
74
|
if (!fs.existsSync(srcPath)) {
|
|
@@ -67,8 +85,6 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
67
85
|
case 'append':
|
|
68
86
|
appendToFile(srcPath, destPath);
|
|
69
87
|
break;
|
|
70
|
-
default:
|
|
71
|
-
console.warn(`[fullstack-cli] Unknown sync type: ${rule.type}`);
|
|
72
88
|
}
|
|
73
89
|
}
|
|
74
90
|
/**
|
|
@@ -160,3 +176,29 @@ function setPermissions(permissions, projectRoot) {
|
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* 删除单个文件
|
|
181
|
+
* @param filePath 要删除的文件路径
|
|
182
|
+
*/
|
|
183
|
+
function deleteFile(filePath) {
|
|
184
|
+
if (fs.existsSync(filePath)) {
|
|
185
|
+
fs.unlinkSync(filePath);
|
|
186
|
+
console.log(`[fullstack-cli] ✓ ${path.basename(filePath)} (deleted)`);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log(`[fullstack-cli] ○ ${path.basename(filePath)} (not found)`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 删除整个目录
|
|
194
|
+
* @param dirPath 要删除的目录路径
|
|
195
|
+
*/
|
|
196
|
+
function deleteDirectory(dirPath) {
|
|
197
|
+
if (fs.existsSync(dirPath)) {
|
|
198
|
+
fs.rmSync(dirPath, { recursive: true });
|
|
199
|
+
console.log(`[fullstack-cli] ✓ ${path.basename(dirPath)} (deleted)`);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.log(`[fullstack-cli] ○ ${path.basename(dirPath)} (not found)`);
|
|
203
|
+
}
|
|
204
|
+
}
|
package/dist/config/sync.d.ts
CHANGED
|
@@ -2,20 +2,42 @@
|
|
|
2
2
|
* fullstack-cli 派生配置
|
|
3
3
|
* 定义哪些文件/目录需要同步到用户项目
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
/** 复制目录或文件规则 */
|
|
6
|
+
type CopyRule = {
|
|
6
7
|
/** 源文件/目录路径(相对于插件根目录) */
|
|
7
8
|
from: string;
|
|
8
9
|
/** 目标文件/目录路径(相对于用户项目根目录) */
|
|
9
10
|
to: string;
|
|
10
11
|
/** 同步类型 */
|
|
11
|
-
type: 'directory' | 'file'
|
|
12
|
-
/**
|
|
12
|
+
type: 'directory' | 'file';
|
|
13
|
+
/** 是否覆盖已存在的文件 */
|
|
13
14
|
overwrite?: boolean;
|
|
14
|
-
}
|
|
15
|
+
};
|
|
16
|
+
/** 追加内容规则 */
|
|
17
|
+
type AppendRule = {
|
|
18
|
+
/** 源文件路径(相对于插件根目录) */
|
|
19
|
+
from: string;
|
|
20
|
+
/** 目标文件路径(相对于用户项目根目录) */
|
|
21
|
+
to: string;
|
|
22
|
+
/** 同步类型 */
|
|
23
|
+
type: 'append';
|
|
24
|
+
};
|
|
25
|
+
/** 删除文件或目录规则 */
|
|
26
|
+
type DeleteRule = {
|
|
27
|
+
/** 目标文件/目录路径(相对于用户项目根目录) */
|
|
28
|
+
to: string;
|
|
29
|
+
/** 同步类型 */
|
|
30
|
+
type: 'delete-file' | 'delete-directory';
|
|
31
|
+
};
|
|
32
|
+
/** 同步规则联合类型 */
|
|
33
|
+
export type SyncRule = CopyRule | AppendRule | DeleteRule;
|
|
15
34
|
export interface SyncConfig {
|
|
16
35
|
/** 派生规则 */
|
|
17
36
|
sync: SyncRule[];
|
|
18
37
|
/** 文件权限设置 */
|
|
19
38
|
permissions?: Record<string, number>;
|
|
20
39
|
}
|
|
21
|
-
export declare
|
|
40
|
+
export declare function genSyncConfig(perms?: {
|
|
41
|
+
disableGenOpenapi?: boolean;
|
|
42
|
+
}): SyncConfig;
|
|
43
|
+
export {};
|
package/dist/config/sync.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* fullstack-cli 派生配置
|
|
3
3
|
* 定义哪些文件/目录需要同步到用户项目
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
const syncConfig = {
|
|
6
6
|
// 派生规则
|
|
7
7
|
sync: [
|
|
8
8
|
// 1. 派生 scripts 目录(总是覆盖)
|
|
@@ -24,6 +24,10 @@ export const syncConfig = {
|
|
|
24
24
|
// to: 'server/types/global.d.ts',
|
|
25
25
|
// type: 'file',
|
|
26
26
|
// },
|
|
27
|
+
{
|
|
28
|
+
type: 'delete-directory',
|
|
29
|
+
to: '.swc', // 删除 .swc 目录(如果存在)
|
|
30
|
+
},
|
|
27
31
|
],
|
|
28
32
|
// 文件权限设置
|
|
29
33
|
permissions: {
|
|
@@ -31,3 +35,14 @@ export const syncConfig = {
|
|
|
31
35
|
// '**/*.sh': 0o755,
|
|
32
36
|
},
|
|
33
37
|
};
|
|
38
|
+
export function genSyncConfig(perms = {}) {
|
|
39
|
+
if (!perms.disableGenOpenapi) {
|
|
40
|
+
syncConfig.sync.push({
|
|
41
|
+
from: 'templates/helper/gen-openapi.ts',
|
|
42
|
+
to: 'scripts/gen-openapi.ts',
|
|
43
|
+
type: 'file',
|
|
44
|
+
overwrite: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return syncConfig;
|
|
48
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -38,10 +38,11 @@ cli
|
|
|
38
38
|
// sync 命令
|
|
39
39
|
cli
|
|
40
40
|
.command('sync', 'Sync template files (scripts, configs) to user project')
|
|
41
|
+
.option('--disable-gen-openapi', 'Disable generating openapi.ts')
|
|
41
42
|
.example('fullstack-cli sync')
|
|
42
|
-
.action(async () => {
|
|
43
|
+
.action(async (options) => {
|
|
43
44
|
try {
|
|
44
|
-
await runSync();
|
|
45
|
+
await runSync(options);
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
47
48
|
console.error(`Failed to execute command:`, error.message);
|
package/package.json
CHANGED