@simplysm/sd-cli 10.0.35 → 10.0.37

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.
@@ -1,122 +0,0 @@
1
- import path from "path";
2
- import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
3
- import { SdCliConfigUtil } from "../utils/SdCliConfigUtil";
4
-
5
- export class SdCliLocalUpdate {
6
- public static async runAsync(opt: { rootPath: string; confFileRelPath: string; }): Promise<void> {
7
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliLocalUpdate", "runAsync"]);
8
-
9
- logger.debug("프로젝트 설정 가져오기...");
10
- const conf = await SdCliConfigUtil.loadConfigAsync(path.resolve(opt.rootPath, opt.confFileRelPath), false);
11
- if (!conf.localUpdates) return;
12
-
13
- logger.debug("로컬 업데이트 구성...");
14
- const updatePathInfos = await this._getUpdatePathInfosAsync(opt.rootPath, conf.localUpdates);
15
- logger.debug("로컬 업데이트 구성 완료", updatePathInfos);
16
-
17
- logger.log("로컬 라이브러리 업데이트 시작...");
18
- for (const updatePathInfo of updatePathInfos) {
19
- if (!FsUtil.exists(updatePathInfo.source)) {
20
- logger.warn(`소스경로를 찾을 수 없어 무시됩니다(${updatePathInfo.source})`);
21
- return;
22
- }
23
-
24
- // 소스경로에서 대상경로로 파일 복사
25
- await FsUtil.copyAsync(updatePathInfo.source, updatePathInfo.target, (src) => {
26
- return !src.includes("node_modules") && !src.endsWith("package.json");
27
- });
28
- }
29
- logger.info("로컬 라이브러리 업데이트 완료");
30
- }
31
-
32
- public static async watchAsync(opt: { rootPath: string; confFileRelPath: string; }): Promise<void> {
33
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliLocalUpdate", "watchAsync"]);
34
-
35
- logger.debug("프로젝트 설정 가져오기...");
36
- const conf = await SdCliConfigUtil.loadConfigAsync(path.resolve(opt.rootPath, opt.confFileRelPath), false);
37
- if (!conf.localUpdates) return;
38
-
39
- logger.debug("로컬 업데이트 구성...");
40
- const updatePathInfos = await this._getUpdatePathInfosAsync(opt.rootPath, conf.localUpdates);
41
- logger.debug("로컬 업데이트 구성 완료", updatePathInfos);
42
-
43
- const watchPaths = (await updatePathInfos.mapManyAsync(async (item) => await this._getWatchPathsAsync(item.source))).distinct();
44
-
45
- const watcher = SdFsWatcher.watch(watchPaths);
46
- watcher.onChange({ delay: 1000 }, async (changedInfos) => {
47
- const changeFilePaths = changedInfos.filter((item) => ["add", "change", "unlink"].includes(item.event)).map((item) => item.path);
48
- if (changeFilePaths.length === 0) return;
49
-
50
- logger.log("로컬 라이브러리 변경감지...");
51
- for (const changedFilePath of changeFilePaths) {
52
- if (!FsUtil.exists(changedFilePath)) continue;
53
-
54
- for (const updatePathInfo of updatePathInfos) {
55
- if (!PathUtil.isChildPath(changedFilePath, updatePathInfo.source)) continue;
56
-
57
- const sourceRelPath = path.relative(updatePathInfo.source, changedFilePath);
58
- if (sourceRelPath.includes("node_modules")) continue;
59
- if (sourceRelPath.includes("package.json")) continue;
60
-
61
- const targetFilePath = path.resolve(updatePathInfo.target, sourceRelPath);
62
-
63
- logger.debug(`변경파일감지(복사): ${changedFilePath} => ${targetFilePath}`);
64
- await FsUtil.copyAsync(changedFilePath, targetFilePath);
65
- }
66
- }
67
-
68
- const watchWatchPaths = (await updatePathInfos.mapManyAsync(async (item) => await this._getWatchPathsAsync(item.source))).distinct();
69
- watcher.add(watchWatchPaths);
70
-
71
- logger.info("로컬 라이브러리 복사 완료");
72
- });
73
- }
74
-
75
- private static async _getWatchPathsAsync(sourcePath: string): Promise<string[]> {
76
- return await FsUtil.globAsync(path.resolve(sourcePath, "**"), {
77
- ignore: [
78
- "**/node_modules/**",
79
- "**/package.json"
80
- ]
81
- });
82
- }
83
-
84
- private static async _getUpdatePathInfosAsync(rootPath: string, record: Record<string, string>): Promise<IUpdatePathInfo[]> {
85
- const result: IUpdatePathInfo[] = [];
86
- for (const pkgGlobPath of Object.keys(record)) {
87
- // "node_modules'에서 로컬업데이트 설정에 맞는 패키지를 "glob"하여 대상 패키지경로 목록 가져오기
88
- const targetPaths = [
89
- ...await FsUtil.globAsync(path.resolve(rootPath, "node_modules", pkgGlobPath)),
90
- ...await FsUtil.globAsync(path.resolve(rootPath, "**", "node_modules", pkgGlobPath))
91
- ];
92
-
93
- result.push(
94
- ...targetPaths
95
- .map((targetPath) => {
96
- // 대상의 명칭 추출
97
- const regexpText = pkgGlobPath.replace(/[\\/.*]/g, (item) => (
98
- item === "/" ? "[\\\\\\/]"
99
- : item === "." ? "\\."
100
- : item === "*" ? "(.*)"
101
- : item
102
- ));
103
- const targetNameMatch = new RegExp(regexpText).exec(targetPath);
104
- if (!targetNameMatch || typeof targetNameMatch[1] === "undefined") return undefined;
105
- const targetName = targetNameMatch[1];
106
-
107
- // 가져올 소스 경로 추출
108
- const sourcePath = path.resolve(record[pkgGlobPath].replace(/\*/g, targetName));
109
- return { source: sourcePath, target: targetPath };
110
- })
111
- .filterExists()
112
- );
113
- }
114
-
115
- return result;
116
- }
117
- }
118
-
119
- interface IUpdatePathInfo {
120
- source: string;
121
- target: string;
122
- }