@codefast/cli 0.2.46-canary.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/.turbo/turbo-build.log +12 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/dist/cjs/commands/update-exports/analyze-imports.cjs +92 -0
- package/dist/cjs/commands/update-exports/analyze-imports.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/command.cjs +58 -0
- package/dist/cjs/commands/update-exports/command.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/config.cjs +113 -0
- package/dist/cjs/commands/update-exports/config.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/file-utils.cjs +144 -0
- package/dist/cjs/commands/update-exports/file-utils.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/generate-exports.cjs +76 -0
- package/dist/cjs/commands/update-exports/generate-exports.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/index.cjs +36 -0
- package/dist/cjs/commands/update-exports/process-package.cjs +143 -0
- package/dist/cjs/commands/update-exports/process-package.cjs.map +1 -0
- package/dist/cjs/commands/update-exports/types.cjs +55 -0
- package/dist/cjs/commands/update-exports/types.cjs.map +1 -0
- package/dist/cjs/index.cjs +46 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lib/logger.cjs +72 -0
- package/dist/cjs/lib/logger.cjs.map +1 -0
- package/dist/esm/commands/update-exports/analyze-imports.js +58 -0
- package/dist/esm/commands/update-exports/analyze-imports.js.map +1 -0
- package/dist/esm/commands/update-exports/command.js +24 -0
- package/dist/esm/commands/update-exports/command.js.map +1 -0
- package/dist/esm/commands/update-exports/config.js +62 -0
- package/dist/esm/commands/update-exports/config.js.map +1 -0
- package/dist/esm/commands/update-exports/file-utils.js +81 -0
- package/dist/esm/commands/update-exports/file-utils.js.map +1 -0
- package/dist/esm/commands/update-exports/generate-exports.js +42 -0
- package/dist/esm/commands/update-exports/generate-exports.js.map +1 -0
- package/dist/esm/commands/update-exports/index.js +3 -0
- package/dist/esm/commands/update-exports/process-package.js +93 -0
- package/dist/esm/commands/update-exports/process-package.js.map +1 -0
- package/dist/esm/commands/update-exports/types.js +18 -0
- package/dist/esm/commands/update-exports/types.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/logger.js +28 -0
- package/dist/esm/lib/logger.js.map +1 -0
- package/dist/types/src/commands/update-exports/analyze-imports.d.ts +9 -0
- package/dist/types/src/commands/update-exports/analyze-imports.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/command.d.ts +7 -0
- package/dist/types/src/commands/update-exports/command.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/config.d.ts +16 -0
- package/dist/types/src/commands/update-exports/config.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/file-utils.d.ts +47 -0
- package/dist/types/src/commands/update-exports/file-utils.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/generate-exports.d.ts +11 -0
- package/dist/types/src/commands/update-exports/generate-exports.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/index.d.ts +2 -0
- package/dist/types/src/commands/update-exports/index.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/process-package.d.ts +23 -0
- package/dist/types/src/commands/update-exports/process-package.d.ts.map +1 -0
- package/dist/types/src/commands/update-exports/types.d.ts +83 -0
- package/dist/types/src/commands/update-exports/types.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/lib/logger.d.ts +15 -0
- package/dist/types/src/lib/logger.d.ts.map +1 -0
- package/eslint.config.js +18 -0
- package/package.json +49 -0
- package/rslib.config.ts +40 -0
- package/src/commands/update-exports/analyze-imports.ts +112 -0
- package/src/commands/update-exports/command.ts +38 -0
- package/src/commands/update-exports/config.ts +99 -0
- package/src/commands/update-exports/file-utils.ts +178 -0
- package/src/commands/update-exports/generate-exports.ts +74 -0
- package/src/commands/update-exports/index.ts +1 -0
- package/src/commands/update-exports/process-package.ts +164 -0
- package/src/commands/update-exports/types.ts +94 -0
- package/src/index.ts +28 -0
- package/src/lib/logger.ts +39 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> @codefast/cli@0.2.46-canary.6 build /home/runner/work/codefast/codefast/packages/cli
|
|
3
|
+
> rslib build
|
|
4
|
+
|
|
5
|
+
Rslib v0.6.3
|
|
6
|
+
|
|
7
|
+
info Rspack persistent cache enabled [2m(experimental)[22m
|
|
8
|
+
ready built in [1m0.41[22m s[90m (esm)[39m
|
|
9
|
+
ready built in [1m0.41[22m s[90m (cjs)[39m
|
|
10
|
+
start generating declaration files... [90m(esm)[39m
|
|
11
|
+
ready declaration files generated in [1m8.28[22m s [90m(esm)[39m
|
|
12
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# update-exports
|
|
2
|
+
|
|
3
|
+
## 0.2.46-canary.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`873e3c8`](https://github.com/codefastlabs/codefast/commit/873e3c886fa7a92a3087f6719b1ffa99f3c12cde) Thanks [@thevuong](https://github.com/thevuong)! - refactor(cli): update configs and optimize import handling
|
|
8
|
+
|
|
9
|
+
- [`32e6d0e`](https://github.com/codefastlabs/codefast/commit/32e6d0e89d87bfa2ebff900cd162f579ff6f4df2) Thanks [@thevuong](https://github.com/thevuong)! - feat: enhance configs with build cache and simplified tsconfigs
|
|
10
|
+
|
|
11
|
+
## 0.2.46-canary.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`62e3ba5`](https://github.com/codefastlabs/codefast/commit/62e3ba580feb521d335ad1da2c82c7a434f8851b) Thanks [@thevuong](https://github.com/thevuong)! - feat: add new component exports and consolidate paths
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CodeFast Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Command `update-exports`
|
|
2
|
+
|
|
3
|
+
## Tổng Quan
|
|
4
|
+
|
|
5
|
+
Command `update-exports` là một công cụ tự động hóa việc cập nhật cấu hình `exports` trong file `package.json` của các package trong dự án. Nó phân tích mã nguồn để xác định các module được export và tạo cấu trúc exports phù hợp.
|
|
6
|
+
|
|
7
|
+
## Cách Sử Dụng
|
|
8
|
+
|
|
9
|
+
```shell script
|
|
10
|
+
codefast update-exports [options]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Tùy Chọn
|
|
14
|
+
|
|
15
|
+
| Tùy chọn | Mô tả |
|
|
16
|
+
| ------------------------- | ------------------------------------------------ |
|
|
17
|
+
| `-p, --package <package>` | Lọc theo tên package cụ thể |
|
|
18
|
+
| `-d, --dry-run` | Chạy mà không thực hiện thay đổi (chỉ xem trước) |
|
|
19
|
+
| `-v, --verbose` | Hiển thị đầu ra chi tiết |
|
|
20
|
+
| `-c, --config <path>` | Đường dẫn đến file cấu hình tùy chỉnh |
|
|
21
|
+
|
|
22
|
+
## Luồng Hoạt Động
|
|
23
|
+
|
|
24
|
+
```mermaid
|
|
25
|
+
flowchart TD
|
|
26
|
+
A[Bắt đầu update-exports] --> B[processAllPackages]
|
|
27
|
+
B --> C[Tìm kiếm packages với findAllPackages]
|
|
28
|
+
C --> D[Lấy cấu hình với getConfig]
|
|
29
|
+
D --> E[Tìm tất cả package.json với glob]
|
|
30
|
+
E --> F{Đã tìm thấy packages?}
|
|
31
|
+
F -- Không --> G[Hiển thị cảnh báo]
|
|
32
|
+
G --> Z[Kết thúc]
|
|
33
|
+
F -- Có --> H[Xử lý từng package]
|
|
34
|
+
H --> I[processPackage cho từng package]
|
|
35
|
+
I --> J[Đọc package.json]
|
|
36
|
+
J --> K{Match với package filter?}
|
|
37
|
+
K -- Không --> L[Bỏ qua package]
|
|
38
|
+
K -- Có --> M[Phân tích imports với analyzeImports]
|
|
39
|
+
M --> N[Lưu kết quả phân tích]
|
|
40
|
+
N --> O[Tạo exports mới với generateExports]
|
|
41
|
+
O --> P{Dry run mode?}
|
|
42
|
+
P -- Có --> Q[Tạo preview exports]
|
|
43
|
+
Q --> Z
|
|
44
|
+
P -- Không --> R[Sao lưu package.json]
|
|
45
|
+
R --> S[Cập nhật package.json với exports mới]
|
|
46
|
+
S --> Z
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
1. **Khởi tạo và Tìm Kiếm Package**
|
|
50
|
+
|
|
51
|
+
- Command đọc các tùy chọn từ người dùng
|
|
52
|
+
- Tìm kiếm tất cả các file `package.json` trong workspace theo mẫu glob được cấu hình
|
|
53
|
+
|
|
54
|
+
2. **Xử Lý Từng Package**
|
|
55
|
+
|
|
56
|
+
- Kiểm tra xem package có khớp với filter hay không (nếu có)
|
|
57
|
+
- Đọc cấu hình cụ thể cho package
|
|
58
|
+
- Xác định đường dẫn đến file index
|
|
59
|
+
|
|
60
|
+
3. **Phân Tích Imports**
|
|
61
|
+
|
|
62
|
+
- Sử dụng ts-morph để phân tích cú pháp của file index
|
|
63
|
+
- Tìm tất cả các khai báo export
|
|
64
|
+
- Chuẩn hóa đường dẫn (ví dụ: @/ thành ./)
|
|
65
|
+
- Bỏ qua các import từ modules bên ngoài
|
|
66
|
+
- Xử lý đường dẫn export theo cấu hình
|
|
67
|
+
|
|
68
|
+
4. **Tạo Exports Mới**
|
|
69
|
+
|
|
70
|
+
- Dựa trên imports đã phân tích, tạo cấu trúc exports mới
|
|
71
|
+
- So sánh với exports hiện tại
|
|
72
|
+
|
|
73
|
+
5. **Lưu Thay Đổi**
|
|
74
|
+
|
|
75
|
+
- Nếu ở chế độ dry-run:
|
|
76
|
+
- Tạo preview của exports mới mà không thực hiện thay đổi
|
|
77
|
+
- Nếu không ở chế độ dry-run:
|
|
78
|
+
- Tạo bản sao lưu của package.json
|
|
79
|
+
- Cập nhật package.json với exports mới
|
|
80
|
+
|
|
81
|
+
6. **Báo Cáo Kết Quả**
|
|
82
|
+
|
|
83
|
+
- Hiển thị thống kê về số lượng package đã xử lý thành công, bỏ qua, thất bại
|
|
84
|
+
|
|
85
|
+
## Cấu Hình
|
|
86
|
+
|
|
87
|
+
Command `update-exports` sử dụng file cấu hình để xác định:
|
|
88
|
+
|
|
89
|
+
- Mẫu glob để tìm packages
|
|
90
|
+
- Các prefix đường dẫn cần loại bỏ
|
|
91
|
+
- Cấu hình cụ thể cho từng package
|
|
92
|
+
|
|
93
|
+
Bạn có thể chỉ định file cấu hình tùy chỉnh bằng tùy chọn `-c, --config`.
|
|
94
|
+
|
|
95
|
+
## Ví Dụ
|
|
96
|
+
|
|
97
|
+
Cập nhật exports cho tất cả các package:
|
|
98
|
+
|
|
99
|
+
```shell script
|
|
100
|
+
codefast update-exports
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Chạy ở chế độ verbose để xem thông tin chi tiết:
|
|
104
|
+
|
|
105
|
+
```shell script
|
|
106
|
+
codefast update-exports --verbose
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Chỉ xử lý một package cụ thể:
|
|
110
|
+
|
|
111
|
+
```shell script
|
|
112
|
+
codefast update-exports --package @codefast/ui
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Xem trước thay đổi mà không thực sự cập nhật:
|
|
116
|
+
|
|
117
|
+
```shell script
|
|
118
|
+
codefast update-exports --dry-run
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Lưu Ý
|
|
122
|
+
|
|
123
|
+
- Command sẽ tạo bản sao lưu của các file package.json trước khi thực hiện thay đổi
|
|
124
|
+
- Các exports được tạo dựa trên việc phân tích mã nguồn, đảm bảo tính nhất quán
|
|
125
|
+
- Sử dụng tùy chọn `--dry-run` để kiểm tra các thay đổi trước khi áp dụng
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
analyzeImports: ()=>analyzeImports
|
|
28
|
+
});
|
|
29
|
+
const external_ts_morph_namespaceObject = require("ts-morph");
|
|
30
|
+
function makeRegexPrefixesToRemove(prefixes) {
|
|
31
|
+
const prefixPattern = prefixes.join("|");
|
|
32
|
+
return new RegExp(`^.?\\/?(?:${prefixPattern})\\/(.*)$`);
|
|
33
|
+
}
|
|
34
|
+
function processExportPath(modulePath, regexPattern) {
|
|
35
|
+
let processedPath = modulePath;
|
|
36
|
+
const match = processedPath.match(regexPattern);
|
|
37
|
+
if (match) {
|
|
38
|
+
const remainingPath = match[1];
|
|
39
|
+
processedPath = remainingPath.startsWith("./") ? remainingPath : `./${remainingPath}`;
|
|
40
|
+
}
|
|
41
|
+
return processedPath;
|
|
42
|
+
}
|
|
43
|
+
function analyzeImports(indexFilePath, packageConfig) {
|
|
44
|
+
const project = new external_ts_morph_namespaceObject.Project();
|
|
45
|
+
let sourceFile;
|
|
46
|
+
try {
|
|
47
|
+
sourceFile = project.addSourceFileAtPath(indexFilePath);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`Error loading source file at ${indexFilePath}:`, error);
|
|
50
|
+
return {
|
|
51
|
+
imports: []
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const imports = [];
|
|
55
|
+
const prefixesToRemove = packageConfig.exportPathPrefixesToRemove ?? [];
|
|
56
|
+
const regexPattern = makeRegexPrefixesToRemove(prefixesToRemove);
|
|
57
|
+
for (const exportDecl of sourceFile.getExportDeclarations()){
|
|
58
|
+
let moduleSpecifier = exportDecl.getModuleSpecifierValue();
|
|
59
|
+
if (!moduleSpecifier) continue;
|
|
60
|
+
if (moduleSpecifier.startsWith("@/")) moduleSpecifier = `./${moduleSpecifier.slice(2)}`;
|
|
61
|
+
const isExternal = !moduleSpecifier.startsWith(".");
|
|
62
|
+
if (isExternal) continue;
|
|
63
|
+
const parts = moduleSpecifier.split("/").filter(Boolean);
|
|
64
|
+
if (parts.length < 2) continue;
|
|
65
|
+
let directory;
|
|
66
|
+
if (parts.length <= 1) directory = ".";
|
|
67
|
+
else {
|
|
68
|
+
directory = parts.slice(0, -1).join("/");
|
|
69
|
+
if (directory.startsWith("./")) directory = directory.slice(2);
|
|
70
|
+
}
|
|
71
|
+
const name = parts.at(-1) ?? "";
|
|
72
|
+
const importPath = {
|
|
73
|
+
originalPath: moduleSpecifier,
|
|
74
|
+
directory,
|
|
75
|
+
name,
|
|
76
|
+
exportPath: processExportPath(moduleSpecifier, regexPattern)
|
|
77
|
+
};
|
|
78
|
+
imports.push(importPath);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
imports
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.analyzeImports = __webpack_exports__.analyzeImports;
|
|
85
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
86
|
+
"analyzeImports"
|
|
87
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
88
|
+
Object.defineProperty(exports, '__esModule', {
|
|
89
|
+
value: true
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=analyze-imports.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands/update-exports/analyze-imports.cjs","sources":["webpack://@codefast/cli/./src/commands/update-exports/analyze-imports.ts"],"sourcesContent":["import type { SourceFile } from \"ts-morph\";\n\nimport { Project } from \"ts-morph\";\n\nimport type { AnalysisResult, ImportPath, PackageConfig } from \"@/commands/update-exports/types\";\n\n/**\n * Creates a regex to remove specified prefixes from paths\n * @param prefixes - Array of prefixes to remove\n * @returns RegExp matching any prefix\n */\nfunction makeRegexPrefixesToRemove(prefixes: string[]): RegExp {\n // Matches: ^\\.?\\/?(prefix1|prefix2)\\/(.*)\n // - ^\\.?\\/? : Optional ./ or /\n // - (prefix1|prefix2): Any prefix from the list\n // - \\/(.*) : Remaining path after prefix\n const prefixPattern = prefixes.join(\"|\");\n\n return new RegExp(`^.?\\\\/?(?:${prefixPattern})\\\\/(.*)$`);\n}\n\n/**\n * Processes an export path by removing specified prefixes\n * @param modulePath - Path to process\n * @param regexPattern - Regex for prefix removal\n * @returns Processed path starting with ./\n */\nfunction processExportPath(modulePath: string, regexPattern: RegExp): string {\n let processedPath = modulePath;\n const match = processedPath.match(regexPattern);\n\n if (match) {\n const remainingPath = match[1];\n\n processedPath = remainingPath.startsWith(\"./\") ? remainingPath : `./${remainingPath}`;\n }\n\n return processedPath;\n}\n\n/**\n * Analyzes imports from an index.ts file\n * @param indexFilePath - Path to index.ts\n * @param packageConfig - Package configuration\n * @returns AnalysisResult containing import paths\n */\nexport function analyzeImports(indexFilePath: string, packageConfig: PackageConfig): AnalysisResult {\n const project = new Project();\n let sourceFile: SourceFile;\n\n try {\n sourceFile = project.addSourceFileAtPath(indexFilePath);\n } catch (error) {\n console.error(`Error loading source file at ${indexFilePath}:`, error);\n\n return { imports: [] };\n }\n\n const imports: ImportPath[] = [];\n const prefixesToRemove = packageConfig.exportPathPrefixesToRemove ?? [];\n const regexPattern = makeRegexPrefixesToRemove(prefixesToRemove);\n\n for (const exportDecl of sourceFile.getExportDeclarations()) {\n let moduleSpecifier = exportDecl.getModuleSpecifierValue();\n\n if (!moduleSpecifier) {\n continue;\n }\n\n // Normalize @/ to ./\n if (moduleSpecifier.startsWith(\"@/\")) {\n moduleSpecifier = `./${moduleSpecifier.slice(2)}`;\n }\n\n const isExternal = !moduleSpecifier.startsWith(\".\");\n\n if (isExternal) {\n continue;\n }\n\n const parts = moduleSpecifier.split(\"/\").filter(Boolean);\n\n if (parts.length < 2) {\n continue;\n }\n\n let directory;\n\n if (parts.length <= 1) {\n directory = \".\";\n } else {\n directory = parts.slice(0, -1).join(\"/\");\n\n if (directory.startsWith(\"./\")) {\n directory = directory.slice(2);\n }\n }\n\n const name = parts.at(-1) ?? \"\";\n\n const importPath: ImportPath = {\n originalPath: moduleSpecifier,\n directory,\n name,\n exportPath: processExportPath(moduleSpecifier, regexPattern),\n };\n\n imports.push(importPath);\n }\n\n return { imports };\n}\n"],"names":["makeRegexPrefixesToRemove","prefixes","prefixPattern","RegExp","processExportPath","modulePath","regexPattern","processedPath","match","remainingPath","analyzeImports","indexFilePath","packageConfig","project","Project","sourceFile","error","console","imports","prefixesToRemove","exportDecl","moduleSpecifier","isExternal","parts","Boolean","directory","name","importPath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,SAASA,0BAA0BC,QAAkB;IAKnD,MAAMC,gBAAgBD,SAAS,IAAI,CAAC;IAEpC,OAAO,IAAIE,OAAO,CAAC,UAAU,EAAED,cAAc,SAAS,CAAC;AACzD;AAQA,SAASE,kBAAkBC,UAAkB,EAAEC,YAAoB;IACjE,IAAIC,gBAAgBF;IACpB,MAAMG,QAAQD,cAAc,KAAK,CAACD;IAElC,IAAIE,OAAO;QACT,MAAMC,gBAAgBD,KAAK,CAAC,EAAE;QAE9BD,gBAAgBE,cAAc,UAAU,CAAC,QAAQA,gBAAgB,CAAC,EAAE,EAAEA,eAAe;IACvF;IAEA,OAAOF;AACT;AAQO,SAASG,eAAeC,aAAqB,EAAEC,aAA4B;IAChF,MAAMC,UAAU,IAAIC,kCAAAA,OAAOA;IAC3B,IAAIC;IAEJ,IAAI;QACFA,aAAaF,QAAQ,mBAAmB,CAACF;IAC3C,EAAE,OAAOK,OAAO;QACdC,QAAQ,KAAK,CAAC,CAAC,6BAA6B,EAAEN,cAAc,CAAC,CAAC,EAAEK;QAEhE,OAAO;YAAE,SAAS,EAAE;QAAC;IACvB;IAEA,MAAME,UAAwB,EAAE;IAChC,MAAMC,mBAAmBP,cAAc,0BAA0B,IAAI,EAAE;IACvE,MAAMN,eAAeN,0BAA0BmB;IAE/C,KAAK,MAAMC,cAAcL,WAAW,qBAAqB,GAAI;QAC3D,IAAIM,kBAAkBD,WAAW,uBAAuB;QAExD,IAAI,CAACC,iBACH;QAIF,IAAIA,gBAAgB,UAAU,CAAC,OAC7BA,kBAAkB,CAAC,EAAE,EAAEA,gBAAgB,KAAK,CAAC,IAAI;QAGnD,MAAMC,aAAa,CAACD,gBAAgB,UAAU,CAAC;QAE/C,IAAIC,YACF;QAGF,MAAMC,QAAQF,gBAAgB,KAAK,CAAC,KAAK,MAAM,CAACG;QAEhD,IAAID,MAAM,MAAM,GAAG,GACjB;QAGF,IAAIE;QAEJ,IAAIF,MAAM,MAAM,IAAI,GAClBE,YAAY;aACP;YACLA,YAAYF,MAAM,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;YAEpC,IAAIE,UAAU,UAAU,CAAC,OACvBA,YAAYA,UAAU,KAAK,CAAC;QAEhC;QAEA,MAAMC,OAAOH,MAAM,EAAE,CAAC,OAAO;QAE7B,MAAMI,aAAyB;YAC7B,cAAcN;YACdI;YACAC;YACA,YAAYtB,kBAAkBiB,iBAAiBf;QACjD;QAEAY,QAAQ,IAAI,CAACS;IACf;IAEA,OAAO;QAAET;IAAQ;AACnB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createUpdateExportsCommand: ()=>createUpdateExportsCommand
|
|
28
|
+
});
|
|
29
|
+
const external_process_package_cjs_namespaceObject = require("./process-package.cjs");
|
|
30
|
+
const logger_cjs_namespaceObject = require("../../lib/logger.cjs");
|
|
31
|
+
function createUpdateExportsCommand(program) {
|
|
32
|
+
program.command("update-exports").description("Updates exports for all packages").option("-p, --package <package>", "Filter by package name").option("-d, --dry-run", "Run without making changes").option("-v, --verbose", "Show detailed output").option("-c, --config <path>", "Path to configuration file").action(async (options)=>{
|
|
33
|
+
const processorOptions = {
|
|
34
|
+
packageFilter: options.package,
|
|
35
|
+
dryRun: Boolean(options.dryRun),
|
|
36
|
+
verbose: Boolean(options.verbose),
|
|
37
|
+
configPath: options.config
|
|
38
|
+
};
|
|
39
|
+
const logger = new logger_cjs_namespaceObject.Logger({
|
|
40
|
+
verbose: processorOptions.verbose
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
await (0, external_process_package_cjs_namespaceObject.processAllPackages)(processorOptions, logger);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error("Error processing packages:", error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.createUpdateExportsCommand = __webpack_exports__.createUpdateExportsCommand;
|
|
51
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
52
|
+
"createUpdateExportsCommand"
|
|
53
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
54
|
+
Object.defineProperty(exports, '__esModule', {
|
|
55
|
+
value: true
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=command.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands/update-exports/command.cjs","sources":["webpack://@codefast/cli/./src/commands/update-exports/command.ts"],"sourcesContent":["import type { Command } from \"commander\";\n\nimport type { ProcessOptions } from \"@/commands/update-exports/types\";\n\nimport { processAllPackages } from \"@/commands/update-exports/process-package\";\nimport { Logger } from \"@/lib/logger\";\n\n/**\n * Creates a commander command for updating exports\n * @param program - Commander program instance\n */\nexport function createUpdateExportsCommand(program: Command): void {\n // noinspection RequiredAttributes\n program\n .command(\"update-exports\")\n .description(\"Updates exports for all packages\")\n .option(\"-p, --package <package>\", \"Filter by package name\")\n .option(\"-d, --dry-run\", \"Run without making changes\")\n .option(\"-v, --verbose\", \"Show detailed output\")\n .option(\"-c, --config <path>\", \"Path to configuration file\")\n .action(async (options) => {\n const processorOptions: ProcessOptions = {\n packageFilter: options.package,\n dryRun: Boolean(options.dryRun),\n verbose: Boolean(options.verbose),\n configPath: options.config,\n };\n\n const logger = new Logger({ verbose: processorOptions.verbose });\n\n try {\n await processAllPackages(processorOptions, logger);\n } catch (error) {\n logger.error(\"Error processing packages:\", error);\n process.exit(1);\n }\n });\n}\n"],"names":["createUpdateExportsCommand","program","options","processorOptions","Boolean","logger","Logger","processAllPackages","error","process"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,SAASA,2BAA2BC,OAAgB;IAEzDA,QACG,OAAO,CAAC,kBACR,WAAW,CAAC,oCACZ,MAAM,CAAC,2BAA2B,0BAClC,MAAM,CAAC,iBAAiB,8BACxB,MAAM,CAAC,iBAAiB,wBACxB,MAAM,CAAC,uBAAuB,8BAC9B,MAAM,CAAC,OAAOC;QACb,MAAMC,mBAAmC;YACvC,eAAeD,QAAQ,OAAO;YAC9B,QAAQE,QAAQF,QAAQ,MAAM;YAC9B,SAASE,QAAQF,QAAQ,OAAO;YAChC,YAAYA,QAAQ,MAAM;QAC5B;QAEA,MAAMG,SAAS,IAAIC,2BAAAA,MAAMA,CAAC;YAAE,SAASH,iBAAiB,OAAO;QAAC;QAE9D,IAAI;YACF,MAAMI,AAAAA,IAAAA,6CAAAA,kBAAAA,AAAAA,EAAmBJ,kBAAkBE;QAC7C,EAAE,OAAOG,OAAO;YACdH,OAAO,KAAK,CAAC,8BAA8BG;YAC3CC,QAAQ,IAAI,CAAC;QACf;IACF;AACJ"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
getConfig: ()=>getConfig,
|
|
37
|
+
getPackageConfig: ()=>getPackageConfig,
|
|
38
|
+
defaultConfig: ()=>defaultConfig
|
|
39
|
+
});
|
|
40
|
+
const external_lodash_es_namespaceObject = require("lodash-es");
|
|
41
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
42
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
43
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
44
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
45
|
+
const external_types_cjs_namespaceObject = require("./types.cjs");
|
|
46
|
+
let cachedConfig = null;
|
|
47
|
+
function loadConfigFile(configPath) {
|
|
48
|
+
if (!configPath) return {};
|
|
49
|
+
try {
|
|
50
|
+
const fullPath = external_node_path_default().resolve(configPath);
|
|
51
|
+
if (!external_node_fs_default().existsSync(fullPath)) {
|
|
52
|
+
console.warn(`Configuration file not found at ${fullPath}`);
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
const configContent = external_node_fs_default().readFileSync(fullPath, "utf8");
|
|
56
|
+
const config = JSON.parse(configContent);
|
|
57
|
+
return external_types_cjs_namespaceObject.ScriptConfigSchema.parse(config);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("Error reading configuration file:", error);
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getConfig(configPath) {
|
|
64
|
+
if (cachedConfig && !configPath) return cachedConfig;
|
|
65
|
+
const userConfig = loadConfigFile(configPath);
|
|
66
|
+
const config = (0, external_lodash_es_namespaceObject.merge)({}, defaultConfig, userConfig);
|
|
67
|
+
if (!configPath) cachedConfig = config;
|
|
68
|
+
return config;
|
|
69
|
+
}
|
|
70
|
+
function getPackageConfig(packageName, config) {
|
|
71
|
+
const configObj = config ?? getConfig();
|
|
72
|
+
const customConfig = configObj.customPackageConfigs[packageName] ?? {};
|
|
73
|
+
return {
|
|
74
|
+
...configObj.defaultPackageConfig,
|
|
75
|
+
...customConfig
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const defaultConfig = {
|
|
79
|
+
packagesGlob: "./packages/**/package.json",
|
|
80
|
+
defaultPackageConfig: {
|
|
81
|
+
cjsOutputPattern: "./dist/cjs/{dir}/{name}.cjs",
|
|
82
|
+
esmOutputPattern: "./dist/esm/{dir}/{name}.js",
|
|
83
|
+
packageJsonPath: "package.json",
|
|
84
|
+
srcIndexPath: "src/index.ts",
|
|
85
|
+
typesOutputCjsPattern: "./dist/types/{dir}/{name}.d.ts",
|
|
86
|
+
typesOutputPattern: "./dist/types/{dir}/{name}.d.ts"
|
|
87
|
+
},
|
|
88
|
+
customPackageConfigs: {
|
|
89
|
+
"@codefast/ui": {
|
|
90
|
+
exportPathPrefixesToRemove: [
|
|
91
|
+
"components"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"@codefast/style-guide": {
|
|
95
|
+
exportPathPrefixesToRemove: [
|
|
96
|
+
"configs"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.defaultConfig = __webpack_exports__.defaultConfig;
|
|
102
|
+
exports.getConfig = __webpack_exports__.getConfig;
|
|
103
|
+
exports.getPackageConfig = __webpack_exports__.getPackageConfig;
|
|
104
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
105
|
+
"defaultConfig",
|
|
106
|
+
"getConfig",
|
|
107
|
+
"getPackageConfig"
|
|
108
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
109
|
+
Object.defineProperty(exports, '__esModule', {
|
|
110
|
+
value: true
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands/update-exports/config.cjs","sources":["webpack://@codefast/cli/./src/commands/update-exports/config.ts"],"sourcesContent":["import { merge } from \"lodash-es\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { PackageConfig, ScriptConfig } from \"@/commands/update-exports/types\";\n\nimport { ScriptConfigSchema } from \"@/commands/update-exports/types\";\n\n// Cache for storing configuration to avoid repeated file reads\nlet cachedConfig: null | ScriptConfig = null;\n\n/**\n * Loads and validates configuration from a file\n * @param configPath - Optional path to the config file\n * @returns Partial ScriptConfig or empty object if not found/invalid\n */\nfunction loadConfigFile(configPath?: string): Partial<ScriptConfig> {\n if (!configPath) {\n return {};\n }\n\n try {\n const fullPath = path.resolve(configPath);\n\n if (!fs.existsSync(fullPath)) {\n console.warn(`Configuration file not found at ${fullPath}`);\n\n return {};\n }\n\n const configContent = fs.readFileSync(fullPath, \"utf8\");\n const config = JSON.parse(configContent);\n\n // Validate against schema\n return ScriptConfigSchema.parse(config);\n } catch (error) {\n console.error(\"Error reading configuration file:\", error);\n\n return {};\n }\n}\n\n/**\n * Retrieves merged configuration, using cache if no path is provided\n * @param configPath - Optional path to override default config\n * @returns Merged ScriptConfig\n */\nexport function getConfig(configPath?: string): ScriptConfig {\n if (cachedConfig && !configPath) {\n return cachedConfig;\n }\n\n const userConfig = loadConfigFile(configPath);\n const config = merge({}, defaultConfig, userConfig) as ScriptConfig;\n\n // Cache config if no path is provided\n if (!configPath) {\n cachedConfig = config;\n }\n\n return config;\n}\n\n/**\n * Retrieves configuration for a specific package\n * @param packageName - Name of the package\n * @param config - Optional ScriptConfig to use\n * @returns PackageConfig combining defaults and custom settings\n */\nexport function getPackageConfig(packageName: string, config?: ScriptConfig): PackageConfig {\n const configObj = config ?? getConfig();\n const customConfig = configObj.customPackageConfigs[packageName] ?? {};\n\n return {\n ...configObj.defaultPackageConfig,\n ...customConfig,\n };\n}\n\n// Default configuration for the script\nexport const defaultConfig: ScriptConfig = {\n packagesGlob: \"./packages/**/package.json\",\n defaultPackageConfig: {\n cjsOutputPattern: \"./dist/cjs/{dir}/{name}.cjs\",\n esmOutputPattern: \"./dist/esm/{dir}/{name}.js\",\n packageJsonPath: \"package.json\",\n srcIndexPath: \"src/index.ts\",\n typesOutputCjsPattern: \"./dist/types/{dir}/{name}.d.ts\",\n typesOutputPattern: \"./dist/types/{dir}/{name}.d.ts\",\n },\n customPackageConfigs: {\n \"@codefast/ui\": {\n exportPathPrefixesToRemove: [\"components\"],\n },\n \"@codefast/style-guide\": {\n exportPathPrefixesToRemove: [\"configs\"],\n },\n },\n};\n"],"names":["cachedConfig","loadConfigFile","configPath","fullPath","path","fs","console","configContent","config","JSON","ScriptConfigSchema","error","getConfig","userConfig","merge","defaultConfig","getPackageConfig","packageName","configObj","customConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAIA,eAAoC;AAOxC,SAASC,eAAeC,UAAmB;IACzC,IAAI,CAACA,YACH,OAAO,CAAC;IAGV,IAAI;QACF,MAAMC,WAAWC,6BAAAA,OAAY,CAACF;QAE9B,IAAI,CAACG,2BAAAA,UAAa,CAACF,WAAW;YAC5BG,QAAQ,IAAI,CAAC,CAAC,gCAAgC,EAAEH,UAAU;YAE1D,OAAO,CAAC;QACV;QAEA,MAAMI,gBAAgBF,2BAAAA,YAAe,CAACF,UAAU;QAChD,MAAMK,SAASC,KAAK,KAAK,CAACF;QAG1B,OAAOG,mCAAAA,kBAAAA,CAAAA,KAAwB,CAACF;IAClC,EAAE,OAAOG,OAAO;QACdL,QAAQ,KAAK,CAAC,qCAAqCK;QAEnD,OAAO,CAAC;IACV;AACF;AAOO,SAASC,UAAUV,UAAmB;IAC3C,IAAIF,gBAAgB,CAACE,YACnB,OAAOF;IAGT,MAAMa,aAAaZ,eAAeC;IAClC,MAAMM,SAASM,AAAAA,IAAAA,mCAAAA,KAAAA,AAAAA,EAAM,CAAC,GAAGC,eAAeF;IAGxC,IAAI,CAACX,YACHF,eAAeQ;IAGjB,OAAOA;AACT;AAQO,SAASQ,iBAAiBC,WAAmB,EAAET,MAAqB;IACzE,MAAMU,YAAYV,UAAUI;IAC5B,MAAMO,eAAeD,UAAU,oBAAoB,CAACD,YAAY,IAAI,CAAC;IAErE,OAAO;QACL,GAAGC,UAAU,oBAAoB;QACjC,GAAGC,YAAY;IACjB;AACF;AAGO,MAAMJ,gBAA8B;IACzC,cAAc;IACd,sBAAsB;QACpB,kBAAkB;QAClB,kBAAkB;QAClB,iBAAiB;QACjB,cAAc;QACd,uBAAuB;QACvB,oBAAoB;IACtB;IACA,sBAAsB;QACpB,gBAAgB;YACd,4BAA4B;gBAAC;aAAa;QAC5C;QACA,yBAAyB;YACvB,4BAA4B;gBAAC;aAAU;QACzC;IACF;AACF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
fileExists: ()=>fileExists,
|
|
37
|
+
saveExportsAnalysis: ()=>saveExportsAnalysis,
|
|
38
|
+
readPackageJson: ()=>readPackageJson,
|
|
39
|
+
backupPackageJson: ()=>backupPackageJson,
|
|
40
|
+
saveExportsPreview: ()=>saveExportsPreview,
|
|
41
|
+
savePackageJson: ()=>savePackageJson,
|
|
42
|
+
saveJsonToFile: ()=>saveJsonToFile
|
|
43
|
+
});
|
|
44
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
45
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
46
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
47
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
48
|
+
const EXPORTS_ANALYSIS_DIR = ".exports-analysis";
|
|
49
|
+
const EXPORTS_PREVIEW_FILE = "exports-preview.json";
|
|
50
|
+
const EXPORTS_ANALYSIS_FILE = "exports-analysis.json";
|
|
51
|
+
const ENCODING = "utf8";
|
|
52
|
+
const JSON_INDENT = 2;
|
|
53
|
+
const FileUtils = {
|
|
54
|
+
exists (filePath) {
|
|
55
|
+
return external_node_fs_default().existsSync(filePath);
|
|
56
|
+
},
|
|
57
|
+
ensureDirectoryExists (dirPath) {
|
|
58
|
+
if (!external_node_fs_default().existsSync(dirPath)) external_node_fs_default().mkdirSync(dirPath, {
|
|
59
|
+
recursive: true
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
readJsonFile (filePath) {
|
|
63
|
+
try {
|
|
64
|
+
const content = external_node_fs_default().readFileSync(filePath, ENCODING);
|
|
65
|
+
return JSON.parse(content);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`Error reading JSON file at ${filePath}:`, error);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
writeJsonFile (filePath, content) {
|
|
72
|
+
try {
|
|
73
|
+
external_node_fs_default().writeFileSync(filePath, `${JSON.stringify(content, null, JSON_INDENT)}\n`, ENCODING);
|
|
74
|
+
return true;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error(`Error writing JSON file at ${filePath}:`, error);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
getAnalysisDir (packageDir) {
|
|
81
|
+
const outputDir = external_node_path_default().join(packageDir, EXPORTS_ANALYSIS_DIR);
|
|
82
|
+
this.ensureDirectoryExists(outputDir);
|
|
83
|
+
return outputDir;
|
|
84
|
+
},
|
|
85
|
+
createBackupFilename (baseFilename) {
|
|
86
|
+
const timestamp = new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
87
|
+
return `${baseFilename}.backup.${timestamp}`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function fileExists(filePath) {
|
|
91
|
+
return FileUtils.exists(filePath);
|
|
92
|
+
}
|
|
93
|
+
function readPackageJson(filePath) {
|
|
94
|
+
return FileUtils.readJsonFile(filePath);
|
|
95
|
+
}
|
|
96
|
+
function backupPackageJson(filePath) {
|
|
97
|
+
try {
|
|
98
|
+
const content = external_node_fs_default().readFileSync(filePath, ENCODING);
|
|
99
|
+
const dir = external_node_path_default().dirname(filePath);
|
|
100
|
+
const backupDir = external_node_path_default().join(dir, EXPORTS_ANALYSIS_DIR);
|
|
101
|
+
FileUtils.ensureDirectoryExists(backupDir);
|
|
102
|
+
const baseName = external_node_path_default().basename(filePath);
|
|
103
|
+
const backupPath = external_node_path_default().join(backupDir, FileUtils.createBackupFilename(baseName));
|
|
104
|
+
external_node_fs_default().writeFileSync(backupPath, content, ENCODING);
|
|
105
|
+
return true;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(`Error backing up package.json at ${filePath}:`, error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function savePackageJson(filePath, content) {
|
|
112
|
+
return FileUtils.writeJsonFile(filePath, content);
|
|
113
|
+
}
|
|
114
|
+
function saveJsonToFile(packageDir, fileName, content) {
|
|
115
|
+
const outputDir = FileUtils.getAnalysisDir(packageDir);
|
|
116
|
+
FileUtils.writeJsonFile(external_node_path_default().join(outputDir, fileName), content);
|
|
117
|
+
}
|
|
118
|
+
function saveExportsAnalysis(packageDir, analysis) {
|
|
119
|
+
saveJsonToFile(packageDir, EXPORTS_ANALYSIS_FILE, analysis);
|
|
120
|
+
}
|
|
121
|
+
function saveExportsPreview(packageDir, exports1) {
|
|
122
|
+
saveJsonToFile(packageDir, EXPORTS_PREVIEW_FILE, exports1);
|
|
123
|
+
}
|
|
124
|
+
exports.backupPackageJson = __webpack_exports__.backupPackageJson;
|
|
125
|
+
exports.fileExists = __webpack_exports__.fileExists;
|
|
126
|
+
exports.readPackageJson = __webpack_exports__.readPackageJson;
|
|
127
|
+
exports.saveExportsAnalysis = __webpack_exports__.saveExportsAnalysis;
|
|
128
|
+
exports.saveExportsPreview = __webpack_exports__.saveExportsPreview;
|
|
129
|
+
exports.saveJsonToFile = __webpack_exports__.saveJsonToFile;
|
|
130
|
+
exports.savePackageJson = __webpack_exports__.savePackageJson;
|
|
131
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
132
|
+
"backupPackageJson",
|
|
133
|
+
"fileExists",
|
|
134
|
+
"readPackageJson",
|
|
135
|
+
"saveExportsAnalysis",
|
|
136
|
+
"saveExportsPreview",
|
|
137
|
+
"saveJsonToFile",
|
|
138
|
+
"savePackageJson"
|
|
139
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
140
|
+
Object.defineProperty(exports, '__esModule', {
|
|
141
|
+
value: true
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=file-utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands/update-exports/file-utils.cjs","sources":["webpack://@codefast/cli/./src/commands/update-exports/file-utils.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type { AnalysisResult, PackageExports, PackageJson } from \"@/commands/update-exports/types\";\n\n// Constants for file operations\nconst EXPORTS_ANALYSIS_DIR = \".exports-analysis\";\nconst EXPORTS_PREVIEW_FILE = \"exports-preview.json\";\nconst EXPORTS_ANALYSIS_FILE = \"exports-analysis.json\";\nconst ENCODING = \"utf8\";\nconst JSON_INDENT = 2;\n/**\n * Utility functions for file and directory operations\n */\nconst FileUtils = {\n /**\n * Checks if a file exists\n * @param filePath - Path to check\n * @returns True if a file exists\n */\n exists(filePath: string): boolean {\n return fs.existsSync(filePath);\n },\n\n /**\n * Creates a directory if it doesn't exist\n * @param dirPath - Directory path\n */\n ensureDirectoryExists(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n fs.mkdirSync(dirPath, { recursive: true });\n }\n },\n\n /**\n * Reads and parses a JSON file\n * @param filePath - Path to JSON file\n * @returns Parsed content or null if error\n */\n readJsonFile<T>(filePath: string): null | T {\n try {\n const content = fs.readFileSync(filePath, ENCODING);\n\n return JSON.parse(content) as T;\n } catch (error) {\n console.error(`Error reading JSON file at ${filePath}:`, error);\n\n return null;\n }\n },\n\n /**\n * Writes content to a JSON file\n * @param filePath - Path to write\n * @param content - Content to write\n * @returns True if successful\n */\n writeJsonFile<T>(filePath: string, content: T): boolean {\n try {\n fs.writeFileSync(filePath, `${JSON.stringify(content, null, JSON_INDENT)}\\n`, ENCODING);\n\n return true;\n } catch (error) {\n console.error(`Error writing JSON file at ${filePath}:`, error);\n\n return false;\n }\n },\n\n /**\n * Gets the exports analysis directory path\n * @param packageDir - Package directory\n * @returns Analysis directory path\n */\n getAnalysisDir(packageDir: string): string {\n const outputDir = path.join(packageDir, EXPORTS_ANALYSIS_DIR);\n\n this.ensureDirectoryExists(outputDir);\n\n return outputDir;\n },\n\n /**\n * Creates a timestamped backup filename\n * @param baseFilename - Original filename\n * @returns Backup filename with timestamp\n */\n createBackupFilename(baseFilename: string): string {\n const timestamp = new Date().toISOString().replaceAll(/[:.]/g, \"-\");\n\n return `${baseFilename}.backup.${timestamp}`;\n },\n};\n\n/**\n * Checks if a file exists\n * @param filePath - Path to check\n * @returns True if a file exists\n */\nexport function fileExists(filePath: string): boolean {\n return FileUtils.exists(filePath);\n}\n\n/**\n * Reads and parses package.json content\n * @param filePath - Path to package.json\n * @returns Parsed PackageJson or null if error\n */\nexport function readPackageJson(filePath: string): null | PackageJson {\n return FileUtils.readJsonFile<PackageJson>(filePath);\n}\n\n/**\n * Creates a backup of package.json\n * @param filePath - Path to package.json\n * @returns True if backup was successful\n */\nexport function backupPackageJson(filePath: string): boolean {\n try {\n const content = fs.readFileSync(filePath, ENCODING);\n const dir = path.dirname(filePath);\n const backupDir = path.join(dir, EXPORTS_ANALYSIS_DIR);\n\n FileUtils.ensureDirectoryExists(backupDir);\n\n const baseName = path.basename(filePath);\n const backupPath = path.join(backupDir, FileUtils.createBackupFilename(baseName));\n\n fs.writeFileSync(backupPath, content, ENCODING);\n\n return true;\n } catch (error) {\n console.error(`Error backing up package.json at ${filePath}:`, error);\n\n return false;\n }\n}\n\n/**\n * Saves updated package.json content\n * @param filePath - Path to package.json\n * @param content - Updated content\n * @returns True if save was successful\n */\nexport function savePackageJson(filePath: string, content: PackageJson): boolean {\n return FileUtils.writeJsonFile(filePath, content);\n}\n\n/**\n * Saves the given JSON content to a specified file within the analysis directory.\n *\n * @param packageDir - The root directory where the analysis directory resides.\n * @param fileName - The name of the file to which the JSON content will be written.\n * @param content - The JSON content to save to the file.\n */\nexport function saveJsonToFile<T>(packageDir: string, fileName: string, content: T): void {\n const outputDir = FileUtils.getAnalysisDir(packageDir);\n\n FileUtils.writeJsonFile(path.join(outputDir, fileName), content);\n}\n\n/**\n * Saves exports analysis results\n * @param packageDir - Package directory\n * @param analysis - Analysis results\n */\nexport function saveExportsAnalysis(packageDir: string, analysis: AnalysisResult): void {\n saveJsonToFile(packageDir, EXPORTS_ANALYSIS_FILE, analysis);\n}\n\n/**\n * Saves preview of generated exports\n * @param packageDir - Package directory\n * @param exports - Generated exports\n */\nexport function saveExportsPreview(packageDir: string, exports: PackageExports): void {\n saveJsonToFile(packageDir, EXPORTS_PREVIEW_FILE, exports);\n}\n"],"names":["EXPORTS_ANALYSIS_DIR","EXPORTS_PREVIEW_FILE","EXPORTS_ANALYSIS_FILE","ENCODING","JSON_INDENT","FileUtils","filePath","fs","dirPath","content","JSON","error","console","packageDir","outputDir","path","baseFilename","timestamp","Date","fileExists","readPackageJson","backupPackageJson","dir","backupDir","baseName","backupPath","savePackageJson","saveJsonToFile","fileName","saveExportsAnalysis","analysis","saveExportsPreview","exports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAMA,uBAAuB;AAC7B,MAAMC,uBAAuB;AAC7B,MAAMC,wBAAwB;AAC9B,MAAMC,WAAW;AACjB,MAAMC,cAAc;AAIpB,MAAMC,YAAY;IAMhB,QAAOC,QAAgB;QACrB,OAAOC,2BAAAA,UAAa,CAACD;IACvB;IAMA,uBAAsBE,OAAe;QACnC,IAAI,CAACD,2BAAAA,UAAa,CAACC,UACjBD,2BAAAA,SAAY,CAACC,SAAS;YAAE,WAAW;QAAK;IAE5C;IAOA,cAAgBF,QAAgB;QAC9B,IAAI;YACF,MAAMG,UAAUF,2BAAAA,YAAe,CAACD,UAAUH;YAE1C,OAAOO,KAAK,KAAK,CAACD;QACpB,EAAE,OAAOE,OAAO;YACdC,QAAQ,KAAK,CAAC,CAAC,2BAA2B,EAAEN,SAAS,CAAC,CAAC,EAAEK;YAEzD,OAAO;QACT;IACF;IAQA,eAAiBL,QAAgB,EAAEG,OAAU;QAC3C,IAAI;YACFF,2BAAAA,aAAgB,CAACD,UAAU,GAAGI,KAAK,SAAS,CAACD,SAAS,MAAML,aAAa,EAAE,CAAC,EAAED;YAE9E,OAAO;QACT,EAAE,OAAOQ,OAAO;YACdC,QAAQ,KAAK,CAAC,CAAC,2BAA2B,EAAEN,SAAS,CAAC,CAAC,EAAEK;YAEzD,OAAO;QACT;IACF;IAOA,gBAAeE,UAAkB;QAC/B,MAAMC,YAAYC,6BAAAA,IAAS,CAACF,YAAYb;QAExC,IAAI,CAAC,qBAAqB,CAACc;QAE3B,OAAOA;IACT;IAOA,sBAAqBE,YAAoB;QACvC,MAAMC,YAAY,IAAIC,OAAO,WAAW,GAAG,UAAU,CAAC,SAAS;QAE/D,OAAO,GAAGF,aAAa,QAAQ,EAAEC,WAAW;IAC9C;AACF;AAOO,SAASE,WAAWb,QAAgB;IACzC,OAAOD,UAAU,MAAM,CAACC;AAC1B;AAOO,SAASc,gBAAgBd,QAAgB;IAC9C,OAAOD,UAAU,YAAY,CAAcC;AAC7C;AAOO,SAASe,kBAAkBf,QAAgB;IAChD,IAAI;QACF,MAAMG,UAAUF,2BAAAA,YAAe,CAACD,UAAUH;QAC1C,MAAMmB,MAAMP,6BAAAA,OAAY,CAACT;QACzB,MAAMiB,YAAYR,6BAAAA,IAAS,CAACO,KAAKtB;QAEjCK,UAAU,qBAAqB,CAACkB;QAEhC,MAAMC,WAAWT,6BAAAA,QAAa,CAACT;QAC/B,MAAMmB,aAAaV,6BAAAA,IAAS,CAACQ,WAAWlB,UAAU,oBAAoB,CAACmB;QAEvEjB,2BAAAA,aAAgB,CAACkB,YAAYhB,SAASN;QAEtC,OAAO;IACT,EAAE,OAAOQ,OAAO;QACdC,QAAQ,KAAK,CAAC,CAAC,iCAAiC,EAAEN,SAAS,CAAC,CAAC,EAAEK;QAE/D,OAAO;IACT;AACF;AAQO,SAASe,gBAAgBpB,QAAgB,EAAEG,OAAoB;IACpE,OAAOJ,UAAU,aAAa,CAACC,UAAUG;AAC3C;AASO,SAASkB,eAAkBd,UAAkB,EAAEe,QAAgB,EAAEnB,OAAU;IAChF,MAAMK,YAAYT,UAAU,cAAc,CAACQ;IAE3CR,UAAU,aAAa,CAACU,6BAAAA,IAAS,CAACD,WAAWc,WAAWnB;AAC1D;AAOO,SAASoB,oBAAoBhB,UAAkB,EAAEiB,QAAwB;IAC9EH,eAAed,YAAYX,uBAAuB4B;AACpD;AAOO,SAASC,mBAAmBlB,UAAkB,EAAEmB,QAAuB;IAC5EL,eAAed,YAAYZ,sBAAsB+B;AACnD"}
|