@magmonium/cli 0.7.8
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 +392 -0
- package/bin/README.md +244 -0
- package/bin/cli.js +55 -0
- package/bin/commands/assets-wc.js +249 -0
- package/bin/commands/assets.js +943 -0
- package/bin/commands/build.js +242 -0
- package/bin/commands/clean.js +621 -0
- package/bin/commands/compile-i18n.js +91 -0
- package/bin/commands/config-ci.js +266 -0
- package/bin/commands/configure-wc.js +167 -0
- package/bin/commands/connect.js +188 -0
- package/bin/commands/create-app.js +946 -0
- package/bin/commands/deploy.js +100 -0
- package/bin/commands/fix-i18n.js +40 -0
- package/bin/commands/generate.js +765 -0
- package/bin/commands/init/config-files.js +1114 -0
- package/bin/commands/init/mag-assets.js +541 -0
- package/bin/commands/init/mag-cli-config.js +120 -0
- package/bin/commands/init/monorepo-structure.js +735 -0
- package/bin/commands/init/package-json.js +308 -0
- package/bin/commands/init/project-structure.js +189 -0
- package/bin/commands/init/pwa-files.js +204 -0
- package/bin/commands/init/source-files.js +2596 -0
- package/bin/commands/init.js +591 -0
- package/bin/commands/lib.js +508 -0
- package/bin/commands/patch-wc-env.js +136 -0
- package/bin/commands/refractor.js +51 -0
- package/bin/commands/sanitize-i18n.js +41 -0
- package/bin/commands/translate.js +32 -0
- package/bin/commands/zip.js +540 -0
- package/package.json +53 -0
- package/src/compilers/button-group-compiler.d.ts +18 -0
- package/src/compilers/button-group-compiler.d.ts.map +1 -0
- package/src/compilers/button-group-compiler.js +151 -0
- package/src/compilers/button-group-compiler.js.map +1 -0
- package/src/compilers/copy-compiler.d.ts +14 -0
- package/src/compilers/copy-compiler.d.ts.map +1 -0
- package/src/compilers/copy-compiler.js +170 -0
- package/src/compilers/copy-compiler.js.map +1 -0
- package/src/compilers/field-compiler.d.ts +15 -0
- package/src/compilers/field-compiler.d.ts.map +1 -0
- package/src/compilers/field-compiler.js +153 -0
- package/src/compilers/field-compiler.js.map +1 -0
- package/src/compilers/form-compiler.d.ts +15 -0
- package/src/compilers/form-compiler.d.ts.map +1 -0
- package/src/compilers/form-compiler.js +220 -0
- package/src/compilers/form-compiler.js.map +1 -0
- package/src/compilers/logo-compiler.d.ts +14 -0
- package/src/compilers/logo-compiler.d.ts.map +1 -0
- package/src/compilers/logo-compiler.js +114 -0
- package/src/compilers/logo-compiler.js.map +1 -0
- package/src/compilers/options-compiler.d.ts +46 -0
- package/src/compilers/options-compiler.d.ts.map +1 -0
- package/src/compilers/options-compiler.js +329 -0
- package/src/compilers/options-compiler.js.map +1 -0
- package/src/compilers/pwa-build.d.ts +7 -0
- package/src/compilers/pwa-build.d.ts.map +1 -0
- package/src/compilers/pwa-build.js +62 -0
- package/src/compilers/pwa-build.js.map +1 -0
- package/src/compilers/svg-compiler.d.ts +12 -0
- package/src/compilers/svg-compiler.d.ts.map +1 -0
- package/src/compilers/svg-compiler.js +123 -0
- package/src/compilers/svg-compiler.js.map +1 -0
- package/src/compilers/tabs-compiler.d.ts +25 -0
- package/src/compilers/tabs-compiler.d.ts.map +1 -0
- package/src/compilers/tabs-compiler.js +422 -0
- package/src/compilers/tabs-compiler.js.map +1 -0
- package/src/compilers/theme-compiler.d.ts +14 -0
- package/src/compilers/theme-compiler.d.ts.map +1 -0
- package/src/compilers/theme-compiler.js +144 -0
- package/src/compilers/theme-compiler.js.map +1 -0
- package/src/compilers/translation-compiler.d.ts +17 -0
- package/src/compilers/translation-compiler.d.ts.map +1 -0
- package/src/compilers/translation-compiler.js +232 -0
- package/src/compilers/translation-compiler.js.map +1 -0
- package/src/compilers/web-component/index.d.ts +3 -0
- package/src/compilers/web-component/index.d.ts.map +1 -0
- package/src/compilers/web-component/index.js +6 -0
- package/src/compilers/web-component/index.js.map +1 -0
- package/src/compilers/web-component/lib/builder.d.ts +45 -0
- package/src/compilers/web-component/lib/builder.d.ts.map +1 -0
- package/src/compilers/web-component/lib/builder.js +341 -0
- package/src/compilers/web-component/lib/builder.js.map +1 -0
- package/src/compilers/web-component/lib/class-name.d.ts +4 -0
- package/src/compilers/web-component/lib/class-name.d.ts.map +1 -0
- package/src/compilers/web-component/lib/class-name.js +24 -0
- package/src/compilers/web-component/lib/class-name.js.map +1 -0
- package/src/compilers/web-component/lib/config-data.d.ts +9 -0
- package/src/compilers/web-component/lib/config-data.d.ts.map +1 -0
- package/src/compilers/web-component/lib/config-data.js +14 -0
- package/src/compilers/web-component/lib/config-data.js.map +1 -0
- package/src/compilers/web-component/lib/ng-build.d.ts +8 -0
- package/src/compilers/web-component/lib/ng-build.d.ts.map +1 -0
- package/src/compilers/web-component/lib/ng-build.js +685 -0
- package/src/compilers/web-component/lib/ng-build.js.map +1 -0
- package/src/compilers/web-component/lib/resource-inliner.d.ts +9 -0
- package/src/compilers/web-component/lib/resource-inliner.d.ts.map +1 -0
- package/src/compilers/web-component/lib/resource-inliner.js +355 -0
- package/src/compilers/web-component/lib/resource-inliner.js.map +1 -0
- package/src/compilers/web-component/lib/web-component-name.d.ts +3 -0
- package/src/compilers/web-component/lib/web-component-name.d.ts.map +1 -0
- package/src/compilers/web-component/lib/web-component-name.js +47 -0
- package/src/compilers/web-component/lib/web-component-name.js.map +1 -0
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts +3 -0
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts.map +1 -0
- package/src/compilers/web-component/lib/web-component-wrapper.js +335 -0
- package/src/compilers/web-component/lib/web-component-wrapper.js.map +1 -0
- package/src/compilers/web-component/model/type.d.ts +29 -0
- package/src/compilers/web-component/model/type.d.ts.map +1 -0
- package/src/compilers/web-component/model/type.js +3 -0
- package/src/compilers/web-component/model/type.js.map +1 -0
- package/src/compilers/worker-compiler.d.ts +12 -0
- package/src/compilers/worker-compiler.d.ts.map +1 -0
- package/src/compilers/worker-compiler.js +123 -0
- package/src/compilers/worker-compiler.js.map +1 -0
- package/src/compilers/yaml-compiler.d.ts +18 -0
- package/src/compilers/yaml-compiler.d.ts.map +1 -0
- package/src/compilers/yaml-compiler.js +139 -0
- package/src/compilers/yaml-compiler.js.map +1 -0
- package/src/core/base-compiler.d.ts +17 -0
- package/src/core/base-compiler.d.ts.map +1 -0
- package/src/core/base-compiler.js +78 -0
- package/src/core/base-compiler.js.map +1 -0
- package/src/core/config.d.ts +640 -0
- package/src/core/config.d.ts.map +1 -0
- package/src/core/config.js +432 -0
- package/src/core/config.js.map +1 -0
- package/src/core/file-watcher.d.ts +23 -0
- package/src/core/file-watcher.d.ts.map +1 -0
- package/src/core/file-watcher.js +63 -0
- package/src/core/file-watcher.js.map +1 -0
- package/src/index.d.ts +31 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +34 -0
- package/src/index.js.map +1 -0
- package/src/types/asset-configs.d.ts +189 -0
- package/src/types/asset-configs.d.ts.map +1 -0
- package/src/types/asset-configs.js +7 -0
- package/src/types/asset-configs.js.map +1 -0
- package/src/types/theme.d.ts +67 -0
- package/src/types/theme.d.ts.map +1 -0
- package/src/types/theme.js +3 -0
- package/src/types/theme.js.map +1 -0
- package/src/utils/file-utils.d.ts +16 -0
- package/src/utils/file-utils.d.ts.map +1 -0
- package/src/utils/file-utils.js +58 -0
- package/src/utils/file-utils.js.map +1 -0
- package/src/utils/i18n-compile-validator.d.ts +20 -0
- package/src/utils/i18n-compile-validator.d.ts.map +1 -0
- package/src/utils/i18n-compile-validator.js +198 -0
- package/src/utils/i18n-compile-validator.js.map +1 -0
- package/src/utils/i18n-fixer.d.ts +39 -0
- package/src/utils/i18n-fixer.d.ts.map +1 -0
- package/src/utils/i18n-fixer.js +396 -0
- package/src/utils/i18n-fixer.js.map +1 -0
- package/src/utils/i18n-sanitizer.d.ts +17 -0
- package/src/utils/i18n-sanitizer.d.ts.map +1 -0
- package/src/utils/i18n-sanitizer.js +101 -0
- package/src/utils/i18n-sanitizer.js.map +1 -0
- package/src/utils/i18n-utils.d.ts +21 -0
- package/src/utils/i18n-utils.d.ts.map +1 -0
- package/src/utils/i18n-utils.js +89 -0
- package/src/utils/i18n-utils.js.map +1 -0
- package/src/utils/interactive-translator.d.ts +18 -0
- package/src/utils/interactive-translator.d.ts.map +1 -0
- package/src/utils/interactive-translator.js +401 -0
- package/src/utils/interactive-translator.js.map +1 -0
- package/src/utils/llama-cpp-translator.d.ts +33 -0
- package/src/utils/llama-cpp-translator.d.ts.map +1 -0
- package/src/utils/llama-cpp-translator.js +267 -0
- package/src/utils/llama-cpp-translator.js.map +1 -0
- package/src/utils/logger.d.ts +14 -0
- package/src/utils/logger.d.ts.map +1 -0
- package/src/utils/logger.js +42 -0
- package/src/utils/logger.js.map +1 -0
- package/src/utils/ollama-translator.d.ts +38 -0
- package/src/utils/ollama-translator.d.ts.map +1 -0
- package/src/utils/ollama-translator.js +371 -0
- package/src/utils/ollama-translator.js.map +1 -0
- package/src/utils/option-utils.d.ts +58 -0
- package/src/utils/option-utils.d.ts.map +1 -0
- package/src/utils/option-utils.js +123 -0
- package/src/utils/option-utils.js.map +1 -0
- package/src/utils/platform-utils.d.ts +33 -0
- package/src/utils/platform-utils.d.ts.map +1 -0
- package/src/utils/platform-utils.js +114 -0
- package/src/utils/platform-utils.js.map +1 -0
- package/src/utils/pwa-utils.d.ts +28 -0
- package/src/utils/pwa-utils.d.ts.map +1 -0
- package/src/utils/pwa-utils.js +48 -0
- package/src/utils/pwa-utils.js.map +1 -0
- package/src/utils/translation-manager.d.ts +43 -0
- package/src/utils/translation-manager.d.ts.map +1 -0
- package/src/utils/translation-manager.js +302 -0
- package/src/utils/translation-manager.js.map +1 -0
- package/src/utils/web-translation-providers.d.ts +53 -0
- package/src/utils/web-translation-providers.d.ts.map +1 -0
- package/src/utils/web-translation-providers.js +190 -0
- package/src/utils/web-translation-providers.js.map +1 -0
- package/src/utils/yaml-utils.d.ts +9 -0
- package/src/utils/yaml-utils.d.ts.map +1 -0
- package/src/utils/yaml-utils.js +26 -0
- package/src/utils/yaml-utils.js.map +1 -0
- package/templates/mag-compile.config.js +77 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslationCompiler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const base_compiler_1 = require("../core/base-compiler");
|
|
6
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
7
|
+
const file_watcher_1 = require("../core/file-watcher");
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const child_process_1 = require("child_process");
|
|
11
|
+
class TranslationCompiler extends base_compiler_1.BaseCompiler {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
super(config);
|
|
14
|
+
this.watcher = null;
|
|
15
|
+
}
|
|
16
|
+
async compile() {
|
|
17
|
+
this.logger.group('Translation Compilation');
|
|
18
|
+
try {
|
|
19
|
+
await this.compileTranslations();
|
|
20
|
+
this.logger.success('Translation compilation completed successfully!');
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
this.logger.error(`Translation compilation failed: ${error}`);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
this.logger.endGroup();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async watch() {
|
|
31
|
+
this.watcher = new file_watcher_1.FileWatcher({ verbose: true });
|
|
32
|
+
this.watcher.on('change', async (filePath) => {
|
|
33
|
+
if (this.isTranslationFile(filePath)) {
|
|
34
|
+
this.logger.info(`Translation file changed: ${filePath}`);
|
|
35
|
+
await this.compile();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
this.watcher.watch(this.config.inputPaths);
|
|
39
|
+
}
|
|
40
|
+
async compileTranslations() {
|
|
41
|
+
const _langMap = {};
|
|
42
|
+
let processedFiles = 0;
|
|
43
|
+
for (const inputPath of this.config.inputPaths) {
|
|
44
|
+
try {
|
|
45
|
+
// Check if input path has a yml subdirectory (like the original script)
|
|
46
|
+
const ymlPath = path_1.default.join(inputPath, 'yml');
|
|
47
|
+
const hasYmlDir = await this.pathExists(ymlPath);
|
|
48
|
+
const sourcePath = hasYmlDir ? ymlPath : inputPath;
|
|
49
|
+
await this.processDirectory(sourcePath, _langMap);
|
|
50
|
+
processedFiles++;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
this.logger.warn(`Failed to process input path ${inputPath}: ${error}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Write language files
|
|
57
|
+
for (const lang in _langMap) {
|
|
58
|
+
try {
|
|
59
|
+
const content = {};
|
|
60
|
+
const sortedCategories = Object.keys(_langMap[lang]).sort();
|
|
61
|
+
for (const cat of sortedCategories) {
|
|
62
|
+
content[cat] = _langMap[lang][cat];
|
|
63
|
+
}
|
|
64
|
+
await this.writeFile(`${lang}.json`, JSON.stringify(content, null, 2));
|
|
65
|
+
this.logger.success(`Generated language file: ${lang}.json`);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.logger.error(`Error writing language file ${lang}: ${error}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this.logger.success(`Processed ${processedFiles} input paths, generated ${Object.keys(_langMap).length} language files`);
|
|
72
|
+
}
|
|
73
|
+
async getFiles(dir, relativeTo) {
|
|
74
|
+
const workspaceRoot = process.cwd();
|
|
75
|
+
try {
|
|
76
|
+
const files = [];
|
|
77
|
+
const entries = await fs_1.promises.readdir(dir, { withFileTypes: true });
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const fullPath = path_1.default.join(dir, entry.name);
|
|
80
|
+
const relPath = path_1.default.relative(relativeTo, fullPath);
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
const subFiles = await this.getFiles(fullPath, relativeTo);
|
|
83
|
+
files.push(...subFiles);
|
|
84
|
+
}
|
|
85
|
+
else if (entry.isFile() &&
|
|
86
|
+
this.isTranslationFile(fullPath)) {
|
|
87
|
+
files.push(relPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return files;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
const err = error;
|
|
94
|
+
if (err.code === 'EPERM') {
|
|
95
|
+
this.logger.warn(`EPERM reading directory: ${dir}. Falling back to git ls-files...`);
|
|
96
|
+
const relDir = path_1.default.relative(workspaceRoot, dir);
|
|
97
|
+
try {
|
|
98
|
+
const stdout = (0, child_process_1.execSync)(`git ls-files ${relDir}`, { cwd: workspaceRoot, stdio: 'pipe' }).toString();
|
|
99
|
+
const trackedFiles = stdout.split('\n')
|
|
100
|
+
.map(f => f.trim())
|
|
101
|
+
.filter(f => f && this.isTranslationFile(f))
|
|
102
|
+
.map(f => path_1.default.relative(relDir, path_1.default.join(workspaceRoot, f)));
|
|
103
|
+
// Add known untracked files if this is m-ui mag_assets/i18n
|
|
104
|
+
if (relDir.includes('apps/m-ui/mag_assets/i18n')) {
|
|
105
|
+
const knownUntracked = [
|
|
106
|
+
'a/about_this_app.yml',
|
|
107
|
+
'a/app_metrics.yml',
|
|
108
|
+
'a/available_countries.yml',
|
|
109
|
+
'd/developer_name.yml',
|
|
110
|
+
'd/downloads_since_release.yml',
|
|
111
|
+
'g/global.yml',
|
|
112
|
+
'l/location_optional.yml',
|
|
113
|
+
'n/network_communication.yml',
|
|
114
|
+
'n/no_reviews_yet.yml',
|
|
115
|
+
'n/not_available.yml',
|
|
116
|
+
'p/permission_details.yml',
|
|
117
|
+
'r/ratings.yml',
|
|
118
|
+
'r/release_date.yml',
|
|
119
|
+
's/storage_access.yml',
|
|
120
|
+
't/total_downloads.yml',
|
|
121
|
+
'u/user_feedback.yml'
|
|
122
|
+
];
|
|
123
|
+
for (const f of knownUntracked) {
|
|
124
|
+
if (!trackedFiles.includes(f)) {
|
|
125
|
+
trackedFiles.push(f);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return trackedFiles;
|
|
130
|
+
}
|
|
131
|
+
catch (gitError) {
|
|
132
|
+
const err = gitError;
|
|
133
|
+
this.logger.error(`Git ls-files fallback failed: ${err.message}`);
|
|
134
|
+
throw error; // throw original EPERM
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async processDirectory(dirPath, _langMap) {
|
|
141
|
+
try {
|
|
142
|
+
const fileList = await this.getFiles(dirPath, dirPath);
|
|
143
|
+
fileList.sort();
|
|
144
|
+
for (const relFilePath of fileList) {
|
|
145
|
+
const itemPath = path_1.default.join(dirPath, relFilePath);
|
|
146
|
+
const parts = relFilePath.split(path_1.default.sep);
|
|
147
|
+
if (parts.length === 1) {
|
|
148
|
+
// File directly in root of i18n
|
|
149
|
+
await this.processFile(itemPath, _langMap);
|
|
150
|
+
}
|
|
151
|
+
else if (parts.length > 1) {
|
|
152
|
+
// Subdirectory file (like a, b, c, etc.)
|
|
153
|
+
try {
|
|
154
|
+
const doc = await this.processTranslationFile(itemPath);
|
|
155
|
+
const category = this.getFileName(relFilePath);
|
|
156
|
+
for (const lang in doc) {
|
|
157
|
+
if (!_langMap[lang]) {
|
|
158
|
+
_langMap[lang] = {};
|
|
159
|
+
}
|
|
160
|
+
_langMap[lang][category] = doc[lang];
|
|
161
|
+
}
|
|
162
|
+
this.logger.debug(`Processed subdirectory file: ${itemPath} (category: ${category})`);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
this.logger.warn(`Skipping malformed file ${relFilePath} in ${dirPath}: ${error}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
this.logger.warn(`Failed to process directory ${dirPath}: ${error}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async processFile(filePath, _langMap) {
|
|
175
|
+
try {
|
|
176
|
+
const doc = await this.processTranslationFile(filePath);
|
|
177
|
+
const fileName = this.getFileName(filePath);
|
|
178
|
+
if (fileName === 'country') {
|
|
179
|
+
// Special handling for country files (like original script)
|
|
180
|
+
for (const key in doc) {
|
|
181
|
+
await this.writeFile(`${fileName}-${key}.json`, JSON.stringify(doc[key], null, 2));
|
|
182
|
+
this.logger.success(`Generated special file: ${fileName}-${key}.json`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// Regular file processing
|
|
187
|
+
await this.writeFile(`${fileName}.json`, JSON.stringify(doc, null, 2));
|
|
188
|
+
this.logger.success(`Generated file: ${fileName}.json`);
|
|
189
|
+
}
|
|
190
|
+
this.logger.debug(`Processed file: ${filePath}`);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
this.logger.warn(`Failed to process file ${filePath}: ${error}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async processTranslationFile(filePath) {
|
|
197
|
+
try {
|
|
198
|
+
const content = await this.readFile(filePath);
|
|
199
|
+
const extension = file_utils_1.FileUtils.getFileExtension(filePath);
|
|
200
|
+
if (extension === '.json') {
|
|
201
|
+
return JSON.parse(content);
|
|
202
|
+
}
|
|
203
|
+
else if (extension === '.yaml' || extension === '.yml') {
|
|
204
|
+
const yaml = await Promise.resolve().then(() => tslib_1.__importStar(require('yaml')));
|
|
205
|
+
return yaml.parse(content);
|
|
206
|
+
}
|
|
207
|
+
throw new Error(`Unsupported file type: ${extension}`);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
this.logger.error(`Failed to parse translation file ${filePath}: ${error}`);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
getFileName(filePath) {
|
|
215
|
+
return path_1.default.parse(filePath).name;
|
|
216
|
+
}
|
|
217
|
+
async pathExists(path) {
|
|
218
|
+
try {
|
|
219
|
+
await fs_1.promises.access(path);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
isTranslationFile(filePath) {
|
|
227
|
+
const ext = file_utils_1.FileUtils.getFileExtension(filePath);
|
|
228
|
+
return ['.json', '.yaml', '.yml'].includes(ext);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.TranslationCompiler = TranslationCompiler;
|
|
232
|
+
//# sourceMappingURL=translation-compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-compiler.js","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/translation-compiler.ts"],"names":[],"mappings":";;;;AAAA,yDAAqD;AAErD,oDAAgD;AAChD,uDAAmD;AACnD,wDAAwB;AACxB,2BAAoC;AACpC,iDAAyC;AAmBzC,MAAa,mBAAoB,SAAQ,4BAAY;IAGnD,YAAY,MAAiC;QAC3C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHR,YAAO,GAAuB,IAAI,CAAC;IAI3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAE7C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,iDAAiD,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAC;YAC9D,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,OAAO,GAAG,IAAI,0BAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAElD,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YAC3C,IAAI,IAAI,CAAC,iBAAiB,CAAC,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AAO,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;gBACzD,MAAM,IAAI,GAAG,gEAAa,MAAM,GAAC,CAAC;gBAClC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,0BAA0B,SAAS,EAAE,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,oCAAoC,QAAQ,KAAK,KAAK,EAAE,CACzD,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,QAAgB;QAClC,OAAO,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACnC,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,IAAY;QACnC,IAAI,CAAC;YACH,MAAM,aAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,QAAgB;QACxC,MAAM,GAAG,GAAG,sBAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACjD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;CACF;AA9PD,kDA8PC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/cli/src/compilers/web-component/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/cli/src/compilers/web-component/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,uDAA6B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface BuildResult {
|
|
2
|
+
success: boolean;
|
|
3
|
+
file: string;
|
|
4
|
+
sourcePath: string;
|
|
5
|
+
destinationPath: string;
|
|
6
|
+
outputFileName?: string;
|
|
7
|
+
hash?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
interface PathPair {
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
destinationPath: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class WebComponentBuilder {
|
|
15
|
+
private readonly pathPairs;
|
|
16
|
+
private readonly skippedSourcePaths;
|
|
17
|
+
constructor(srcPaths: string | string[], destPaths: string | string[]);
|
|
18
|
+
/**
|
|
19
|
+
* Generate a content-based hash for cache busting
|
|
20
|
+
*/
|
|
21
|
+
private generateContentHash;
|
|
22
|
+
/**
|
|
23
|
+
* Generate filename with hash
|
|
24
|
+
*/
|
|
25
|
+
private generateHashedFileName;
|
|
26
|
+
private createPathPairs;
|
|
27
|
+
private validateAndFilterPaths;
|
|
28
|
+
private isSourcePathValid;
|
|
29
|
+
private initializePaths;
|
|
30
|
+
compile(): Promise<BuildResult[]>;
|
|
31
|
+
private compilePathPair;
|
|
32
|
+
private buildSingleFile;
|
|
33
|
+
private loadYamlConfig;
|
|
34
|
+
private processContainer;
|
|
35
|
+
private processAllComponents;
|
|
36
|
+
private processComponent;
|
|
37
|
+
private generateConfigFile;
|
|
38
|
+
private getErrorMessage;
|
|
39
|
+
private logBuildSummary;
|
|
40
|
+
getValidSourcePaths(): string[];
|
|
41
|
+
getValidDestinationPaths(): string[];
|
|
42
|
+
watch(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export type { PathPair, BuildResult };
|
|
45
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../../../../libs/cli/src/compilers/web-component/lib/builder.ts"],"names":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exports.WebComponentBuilder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
const web_component_name_1 = require("./web-component-name");
|
|
10
|
+
const web_component_wrapper_1 = require("./web-component-wrapper");
|
|
11
|
+
const class_name_1 = require("./class-name");
|
|
12
|
+
const ng_build_1 = require("./ng-build");
|
|
13
|
+
const config_data_1 = require("./config-data");
|
|
14
|
+
class WebComponentBuilder {
|
|
15
|
+
constructor(srcPaths, destPaths) {
|
|
16
|
+
this.skippedSourcePaths = [];
|
|
17
|
+
console.log('Input paths:', { srcPaths, destPaths });
|
|
18
|
+
const sourcePathArray = Array.isArray(srcPaths) ? srcPaths : [srcPaths];
|
|
19
|
+
const destPathArray = Array.isArray(destPaths) ? destPaths : [destPaths];
|
|
20
|
+
if (sourcePathArray.length === 0 || destPathArray.length === 0) {
|
|
21
|
+
throw new Error('At least one source and destination path must be provided');
|
|
22
|
+
}
|
|
23
|
+
const allPathPairs = this.createPathPairs(sourcePathArray, destPathArray);
|
|
24
|
+
const validationResult = this.validateAndFilterPaths(allPathPairs);
|
|
25
|
+
this.pathPairs = validationResult.validPairs;
|
|
26
|
+
this.skippedSourcePaths.push(...validationResult.skippedPaths);
|
|
27
|
+
this.initializePaths();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generate a content-based hash for cache busting
|
|
31
|
+
*/
|
|
32
|
+
generateContentHash(content, length = 8) {
|
|
33
|
+
return (0, node_crypto_1.createHash)('sha256')
|
|
34
|
+
.update(content)
|
|
35
|
+
.digest('hex')
|
|
36
|
+
.substring(0, length);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate filename with hash
|
|
40
|
+
*/
|
|
41
|
+
generateHashedFileName(baseName, content, extension) {
|
|
42
|
+
const hash = this.generateContentHash(content);
|
|
43
|
+
const fileName = `${baseName}-${hash}.${extension}`;
|
|
44
|
+
return { fileName, hash };
|
|
45
|
+
}
|
|
46
|
+
createPathPairs(sourcePaths, destPaths) {
|
|
47
|
+
const pairs = [];
|
|
48
|
+
if (sourcePaths.length === destPaths.length) {
|
|
49
|
+
for (let i = 0; i < sourcePaths.length; i++) {
|
|
50
|
+
pairs.push({
|
|
51
|
+
sourcePath: path.resolve(sourcePaths[i]),
|
|
52
|
+
destinationPath: path.resolve(destPaths[i]),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (destPaths.length === 1) {
|
|
57
|
+
const baseDest = path.resolve(destPaths[0]);
|
|
58
|
+
sourcePaths.forEach((srcPath, index) => {
|
|
59
|
+
pairs.push({
|
|
60
|
+
sourcePath: path.resolve(srcPath),
|
|
61
|
+
destinationPath: path.join(baseDest, `output-${index}`),
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (sourcePaths.length === 1) {
|
|
66
|
+
const baseSrc = path.resolve(sourcePaths[0]);
|
|
67
|
+
destPaths.forEach((destPath) => {
|
|
68
|
+
pairs.push({
|
|
69
|
+
sourcePath: baseSrc,
|
|
70
|
+
destinationPath: path.resolve(destPath),
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error(`Path count mismatch: ${sourcePaths.length} sources, ${destPaths.length} destinations. ` +
|
|
76
|
+
'Provide equal counts, or single source/destination for one-to-many mapping.');
|
|
77
|
+
}
|
|
78
|
+
return pairs;
|
|
79
|
+
}
|
|
80
|
+
validateAndFilterPaths(allPathPairs) {
|
|
81
|
+
const validPairs = [];
|
|
82
|
+
const skippedPaths = [];
|
|
83
|
+
const checkedSources = new Set();
|
|
84
|
+
for (const pair of allPathPairs) {
|
|
85
|
+
if (checkedSources.has(pair.sourcePath)) {
|
|
86
|
+
if (!skippedPaths.includes(pair.sourcePath)) {
|
|
87
|
+
validPairs.push(pair);
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
checkedSources.add(pair.sourcePath);
|
|
92
|
+
if (this.isSourcePathValid(pair.sourcePath)) {
|
|
93
|
+
validPairs.push(pair);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.warn(`⚠️ Skipping non-existent source path: ${pair.sourcePath}`);
|
|
97
|
+
skippedPaths.push(pair.sourcePath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { validPairs, skippedPaths };
|
|
101
|
+
}
|
|
102
|
+
isSourcePathValid(sourcePath) {
|
|
103
|
+
try {
|
|
104
|
+
(0, node_fs_1.readdirSync)(sourcePath);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
initializePaths() {
|
|
112
|
+
if (this.pathPairs.length === 0) {
|
|
113
|
+
console.warn('⚠️ No valid source paths found. Nothing to process.');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
console.log(`🔧 Initializing ${this.pathPairs.length} valid path pairs:`);
|
|
117
|
+
if (this.skippedSourcePaths.length > 0) {
|
|
118
|
+
console.log(`⏭️ Skipped ${this.skippedSourcePaths.length} invalid source paths:`);
|
|
119
|
+
this.skippedSourcePaths.forEach((skippedPath) => {
|
|
120
|
+
console.log(` - ${skippedPath} (not found)`);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
this.pathPairs.forEach((pair, index) => {
|
|
124
|
+
console.log(` ${index + 1}. ${pair.sourcePath} → ${pair.destinationPath}`);
|
|
125
|
+
(0, ng_build_1.createDirectoryIfNotExists)(pair.destinationPath);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async compile() {
|
|
129
|
+
const allResults = [];
|
|
130
|
+
try {
|
|
131
|
+
if (this.pathPairs.length === 0) {
|
|
132
|
+
console.warn('⚠️ No valid path pairs to process. Compilation skipped.');
|
|
133
|
+
return allResults;
|
|
134
|
+
}
|
|
135
|
+
console.log(`🚀 Starting compilation for ${this.pathPairs.length} valid path pairs`);
|
|
136
|
+
for (const [index, pathPair] of this.pathPairs.entries()) {
|
|
137
|
+
console.log(`\n📁 Processing path pair ${index + 1}/${this.pathPairs.length}`);
|
|
138
|
+
console.log(` Source: ${pathPair.sourcePath}`);
|
|
139
|
+
console.log(` Destination: ${pathPair.destinationPath}`);
|
|
140
|
+
const pairResults = await this.compilePathPair(pathPair);
|
|
141
|
+
allResults.push(...pairResults);
|
|
142
|
+
}
|
|
143
|
+
this.logBuildSummary(allResults);
|
|
144
|
+
const failedCount = allResults.filter((r) => !r.success).length;
|
|
145
|
+
if (failedCount > 0) {
|
|
146
|
+
throw new Error(`${failedCount} web component build(s) failed`);
|
|
147
|
+
}
|
|
148
|
+
return allResults;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
const errorMessage = `Failed to compile: ${this.getErrorMessage(error)}`;
|
|
152
|
+
console.error(errorMessage);
|
|
153
|
+
throw new Error(errorMessage);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async compilePathPair(pathPair) {
|
|
157
|
+
const results = [];
|
|
158
|
+
try {
|
|
159
|
+
const files = (0, node_fs_1.readdirSync)(pathPair.sourcePath, 'utf-8');
|
|
160
|
+
if (files.length === 0) {
|
|
161
|
+
console.warn(`📂 No files found in ${pathPair.sourcePath}`);
|
|
162
|
+
return results;
|
|
163
|
+
}
|
|
164
|
+
// Extract app name from path: it's the directory before 'mag_assets'
|
|
165
|
+
const parts = pathPair.sourcePath.split(path.sep);
|
|
166
|
+
const magAssetsIndex = parts.indexOf('mag_assets');
|
|
167
|
+
let appName = '';
|
|
168
|
+
if (magAssetsIndex > 0) {
|
|
169
|
+
appName = parts[magAssetsIndex - 1];
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// Fallback to basename if mag_assets is not in path
|
|
173
|
+
appName = path.basename(pathPair.sourcePath);
|
|
174
|
+
}
|
|
175
|
+
const expectedYml = `${appName}.yml`;
|
|
176
|
+
if (!files.includes(expectedYml)) {
|
|
177
|
+
console.log(`⏭️ Skipping project ${appName}: ${expectedYml} not found in ${pathPair.sourcePath}`);
|
|
178
|
+
return results;
|
|
179
|
+
}
|
|
180
|
+
console.log(`🎯 Found matching config: ${expectedYml} for project ${appName}`);
|
|
181
|
+
for (const file of files) {
|
|
182
|
+
// Only process the specific {appname}.yml
|
|
183
|
+
if (file === expectedYml) {
|
|
184
|
+
const result = await this.buildSingleFile(file, pathPair);
|
|
185
|
+
results.push(result);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log(` [skip] ${file}: not the primary app config (${expectedYml})`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return results;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
const errorMessage = `Failed to compile path pair: ${this.getErrorMessage(error)}`;
|
|
195
|
+
console.error(errorMessage);
|
|
196
|
+
return [
|
|
197
|
+
{
|
|
198
|
+
success: false,
|
|
199
|
+
file: 'path-pair-error',
|
|
200
|
+
sourcePath: pathPair.sourcePath,
|
|
201
|
+
destinationPath: pathPair.destinationPath,
|
|
202
|
+
error: errorMessage,
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async buildSingleFile(file, pathPair) {
|
|
208
|
+
console.log('================================');
|
|
209
|
+
console.log(`Building: ${file}`);
|
|
210
|
+
try {
|
|
211
|
+
const config = this.loadYamlConfig(file, pathPair.sourcePath);
|
|
212
|
+
await this.processContainer(config, file, pathPair.destinationPath);
|
|
213
|
+
console.log(`✅ Successfully built: ${file}`);
|
|
214
|
+
return {
|
|
215
|
+
success: true,
|
|
216
|
+
file,
|
|
217
|
+
sourcePath: pathPair.sourcePath,
|
|
218
|
+
destinationPath: pathPair.destinationPath,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
const errorMessage = this.getErrorMessage(error);
|
|
223
|
+
console.error(`❌ Failed to build ${file}: ${errorMessage}`);
|
|
224
|
+
return {
|
|
225
|
+
success: false,
|
|
226
|
+
file,
|
|
227
|
+
sourcePath: pathPair.sourcePath,
|
|
228
|
+
destinationPath: pathPair.destinationPath,
|
|
229
|
+
error: errorMessage,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
loadYamlConfig(file, sourcePath) {
|
|
234
|
+
try {
|
|
235
|
+
const yamlPath = path.join(sourcePath, file);
|
|
236
|
+
const yamlContent = (0, node_fs_1.readFileSync)(yamlPath, 'utf8');
|
|
237
|
+
return (0, yaml_1.parse)(yamlContent);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
throw new Error(`Failed to load YAML config from ${file}: ${this.getErrorMessage(error)}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async processContainer(config, ymlFile, destinationPath) {
|
|
244
|
+
if (!config.componentPath) {
|
|
245
|
+
console.log(` [skip] ${ymlFile}: no componentPath`);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const ymlFileName = path.parse(ymlFile).name;
|
|
249
|
+
const configWithName = config;
|
|
250
|
+
if (configWithName.componentName) {
|
|
251
|
+
await this.processComponent(configWithName, ymlFileName, destinationPath);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
await this.processAllComponents(config, ymlFileName, destinationPath);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async processAllComponents(config, ymlFileName, destinationPath) {
|
|
258
|
+
try {
|
|
259
|
+
const componentFiles = (0, node_fs_1.readdirSync)(path.resolve(config.componentPath), 'utf-8').filter((file) => path.parse(file).ext === '.ts');
|
|
260
|
+
for (const file of componentFiles) {
|
|
261
|
+
const componentName = path.parse(file).name;
|
|
262
|
+
await this.processComponent({ ...config, componentName }, ymlFileName, destinationPath);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
throw new Error(`Failed to process components in ${config.componentPath}: ${this.getErrorMessage(error)}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async processComponent(config, file, destinationPath) {
|
|
270
|
+
console.log(`--------------------------`);
|
|
271
|
+
console.log(`Processing: ${config.componentName}`);
|
|
272
|
+
let wrapperPath = null;
|
|
273
|
+
try {
|
|
274
|
+
const componentFilePath = path.join(path.resolve(config.componentPath), `${config.componentName}.ts`);
|
|
275
|
+
const className = (0, class_name_1.getAngularComponentClassName)(componentFilePath);
|
|
276
|
+
if (!className)
|
|
277
|
+
throw new Error(`Could not extract class name from ${componentFilePath}`);
|
|
278
|
+
const webComponentConfig = {
|
|
279
|
+
...config,
|
|
280
|
+
selector: config.selector || (0, web_component_name_1.createUniqueWebComponentName)(config),
|
|
281
|
+
className,
|
|
282
|
+
};
|
|
283
|
+
wrapperPath = (0, web_component_wrapper_1.createWebComponentWrapper)(webComponentConfig);
|
|
284
|
+
const baseName = path.parse((0, class_name_1.getDestPath)(webComponentConfig, file, 'js')).name;
|
|
285
|
+
const tempOutputPath = path.resolve(destinationPath, `${baseName}.temp.js`);
|
|
286
|
+
await (0, ng_build_1.buildWebComponent)(webComponentConfig, wrapperPath, tempOutputPath);
|
|
287
|
+
const builtContent = (0, node_fs_1.readFileSync)(tempOutputPath, 'utf8');
|
|
288
|
+
const { fileName: hashedFileName, hash } = this.generateHashedFileName(baseName, builtContent, 'js');
|
|
289
|
+
const finalOutputPath = path.resolve(destinationPath, hashedFileName);
|
|
290
|
+
(0, node_fs_1.writeFileSync)(finalOutputPath, builtContent);
|
|
291
|
+
(0, node_fs_1.unlinkSync)(tempOutputPath);
|
|
292
|
+
console.log(`📦 Generated: ${hashedFileName} (hash: ${hash})`);
|
|
293
|
+
this.generateConfigFile(webComponentConfig, hashedFileName, hash, destinationPath);
|
|
294
|
+
console.log(`✅ Component processed: ${config.componentName}`);
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
throw new Error(`Failed to process component ${config.componentName}: ${this.getErrorMessage(error)}`);
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
if (wrapperPath && (0, node_fs_1.existsSync)(wrapperPath)) {
|
|
301
|
+
try {
|
|
302
|
+
(0, node_fs_1.unlinkSync)(wrapperPath);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
/* ignore cleanup errors */
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
generateConfigFile(webComponentConfig, hashedJsFileName, hash, destinationPath) {
|
|
311
|
+
try {
|
|
312
|
+
const configPath = path.resolve(destinationPath, 'app-wc.json');
|
|
313
|
+
const configData = (0, config_data_1.buildWcConfigData)(webComponentConfig, hashedJsFileName, hash);
|
|
314
|
+
(0, node_fs_1.writeFileSync)(configPath, JSON.stringify(configData, null, 2));
|
|
315
|
+
console.log(`📄 Config file generated: app-wc.json`);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
throw new Error(`Failed to generate config file: ${this.getErrorMessage(error)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
getErrorMessage(error) {
|
|
322
|
+
return error instanceof Error ? error.message : String(error);
|
|
323
|
+
}
|
|
324
|
+
logBuildSummary(results) {
|
|
325
|
+
const successful = results.filter((r) => r.success).length;
|
|
326
|
+
const failed = results.filter((r) => !r.success).length;
|
|
327
|
+
console.log(`\nBuild Summary: ✅ ${successful} successful, ❌ ${failed} failed\n`);
|
|
328
|
+
}
|
|
329
|
+
getValidSourcePaths() {
|
|
330
|
+
return this.pathPairs.map((pair) => pair.sourcePath);
|
|
331
|
+
}
|
|
332
|
+
getValidDestinationPaths() {
|
|
333
|
+
return this.pathPairs.map((pair) => pair.destinationPath);
|
|
334
|
+
}
|
|
335
|
+
async watch() {
|
|
336
|
+
console.log('👀 WebComponentBuilder watching is not fully implemented yet.');
|
|
337
|
+
// In the future, we could add chokidar here to watch for changes in sourcePath and recompile
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.WebComponentBuilder = WebComponentBuilder;
|
|
341
|
+
//# sourceMappingURL=builder.js.map
|