@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,508 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
// Detect if we're in a monorepo
|
|
4
|
+
function detectMonorepo() {
|
|
5
|
+
const currentDir = process.cwd();
|
|
6
|
+
let checkDir = currentDir;
|
|
7
|
+
|
|
8
|
+
while (checkDir !== path.dirname(checkDir)) {
|
|
9
|
+
const packageJsonPath = path.join(checkDir, 'package.json');
|
|
10
|
+
const appsPath = path.join(checkDir, 'apps');
|
|
11
|
+
if (fs.existsSync(packageJsonPath) && fs.existsSync(appsPath)) {
|
|
12
|
+
try {
|
|
13
|
+
const packageJson = JSON.parse(
|
|
14
|
+
fs.readFileSync(packageJsonPath, 'utf-8')
|
|
15
|
+
);
|
|
16
|
+
if (packageJson.workspaces || packageJson.name?.includes('-monorepo')) {
|
|
17
|
+
return {
|
|
18
|
+
isMonorepo: true,
|
|
19
|
+
rootPath: checkDir,
|
|
20
|
+
packageJson,
|
|
21
|
+
companyName:
|
|
22
|
+
packageJson.name?.replace('-monorepo', '') || 'company',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// Continue checking parent directories
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
checkDir = path.dirname(checkDir);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { isMonorepo: false };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function createLibraryStructure(libName, monorepoInfo) {
|
|
37
|
+
const libPath = path.join(monorepoInfo.rootPath, 'libs', libName);
|
|
38
|
+
const srcPath = path.join(libPath, 'src');
|
|
39
|
+
const libSrcPath = path.join(srcPath, 'lib');
|
|
40
|
+
|
|
41
|
+
// Create directory structure
|
|
42
|
+
// Create directories
|
|
43
|
+
fs.mkdirSync(libPath, { recursive: true });
|
|
44
|
+
fs.mkdirSync(srcPath, { recursive: true });
|
|
45
|
+
fs.mkdirSync(libSrcPath, { recursive: true });
|
|
46
|
+
|
|
47
|
+
return { libPath, srcPath, libSrcPath };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function createLibraryPackageJson(libName, companyName, libPath) {
|
|
51
|
+
const packageJson = {
|
|
52
|
+
name: `@${companyName}/${libName}`,
|
|
53
|
+
version: '0.0.1',
|
|
54
|
+
description: `${libName} shared library for ${companyName} monorepo`,
|
|
55
|
+
main: 'src/public-api.ts',
|
|
56
|
+
module: 'src/public-api.ts',
|
|
57
|
+
es2020: 'src/public-api.ts',
|
|
58
|
+
esm2020: 'src/public-api.ts',
|
|
59
|
+
fesm2020: 'src/public-api.ts',
|
|
60
|
+
typings: 'src/public-api.ts',
|
|
61
|
+
private: true,
|
|
62
|
+
scripts: {
|
|
63
|
+
build: 'ng build',
|
|
64
|
+
test: 'ng test',
|
|
65
|
+
lint: 'ng lint',
|
|
66
|
+
},
|
|
67
|
+
peerDependencies: {
|
|
68
|
+
'@angular/animations': '^20.0.4',
|
|
69
|
+
'@angular/common': '^20.0.4',
|
|
70
|
+
'@angular/compiler': '^20.0.4',
|
|
71
|
+
'@angular/core': '^20.0.4',
|
|
72
|
+
'@angular/forms': '^20.0.4',
|
|
73
|
+
'@angular/platform-browser': '^20.0.4',
|
|
74
|
+
'@angular/platform-browser-dynamic': '^20.0.4',
|
|
75
|
+
'@angular/router': '^20.0.4',
|
|
76
|
+
rxjs: '~7.8.0',
|
|
77
|
+
tslib: '^2.3.0',
|
|
78
|
+
'zone.js': '~0.15.0',
|
|
79
|
+
},
|
|
80
|
+
keywords: ['angular', 'library', 'shared', companyName],
|
|
81
|
+
author: companyName,
|
|
82
|
+
license: 'MIT',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
fs.writeFileSync(
|
|
86
|
+
path.join(libPath, 'package.json'),
|
|
87
|
+
JSON.stringify(packageJson, null, 2)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function createLibraryFiles(libName, libPath, srcPath, libSrcPath) {
|
|
92
|
+
// Create public-api.ts (barrel export)
|
|
93
|
+
const publicApi = `/*
|
|
94
|
+
* Public API Surface of ${libName}
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
export * from './lib/${libName}.service';
|
|
98
|
+
export * from './lib/${libName}.component';
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
fs.writeFileSync(path.join(srcPath, 'public-api.ts'), publicApi);
|
|
102
|
+
|
|
103
|
+
// Create library service
|
|
104
|
+
const serviceName = libName
|
|
105
|
+
.split('-')
|
|
106
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
107
|
+
.join('');
|
|
108
|
+
const service = `import { Injectable } from '@angular/core';
|
|
109
|
+
|
|
110
|
+
@Injectable({
|
|
111
|
+
providedIn: 'root'
|
|
112
|
+
})
|
|
113
|
+
export class ${serviceName}Service {
|
|
114
|
+
|
|
115
|
+
constructor() { }
|
|
116
|
+
|
|
117
|
+
// Add your service methods here
|
|
118
|
+
getMessage(): string {
|
|
119
|
+
return 'Hello from ${serviceName}Service!';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
fs.writeFileSync(path.join(libSrcPath, `${libName}.service.ts`), service);
|
|
125
|
+
|
|
126
|
+
// Create library component
|
|
127
|
+
const component = `import { Component } from '@angular/core';
|
|
128
|
+
|
|
129
|
+
@Component({
|
|
130
|
+
selector: 'lib-${libName}',
|
|
131
|
+
standalone: true,
|
|
132
|
+
imports: [],
|
|
133
|
+
template: \`
|
|
134
|
+
<div class="lib-${libName}">
|
|
135
|
+
<h2>${serviceName} Component</h2>
|
|
136
|
+
<p>This is a shared component from the ${libName} library.</p>
|
|
137
|
+
</div>
|
|
138
|
+
\`,
|
|
139
|
+
styles: [\`
|
|
140
|
+
.lib-${libName} {
|
|
141
|
+
padding: 1rem;
|
|
142
|
+
border: 1px solid #ccc;
|
|
143
|
+
border-radius: 4px;
|
|
144
|
+
margin: 1rem 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.lib-${libName} h2 {
|
|
148
|
+
color: #333;
|
|
149
|
+
margin: 0 0 0.5rem 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.lib-${libName} p {
|
|
153
|
+
color: #666;
|
|
154
|
+
margin: 0;
|
|
155
|
+
}
|
|
156
|
+
\`]
|
|
157
|
+
})
|
|
158
|
+
export class ${serviceName}Component {
|
|
159
|
+
constructor() { }
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
fs.writeFileSync(path.join(libSrcPath, `${libName}.component.ts`), component);
|
|
164
|
+
|
|
165
|
+
// Don't create module - using standalone components instead
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function createLibraryTsConfig(libName, libPath) {
|
|
169
|
+
// Create tsconfig.json for the library
|
|
170
|
+
const tsConfig = {
|
|
171
|
+
compileOnSave: false,
|
|
172
|
+
compilerOptions: {
|
|
173
|
+
declaration: true,
|
|
174
|
+
declarationMap: true,
|
|
175
|
+
esModuleInterop: true,
|
|
176
|
+
experimentalDecorators: true,
|
|
177
|
+
importHelpers: true,
|
|
178
|
+
lib: ['ES2022', 'dom'],
|
|
179
|
+
module: 'ES2022',
|
|
180
|
+
moduleResolution: 'bundler',
|
|
181
|
+
outDir: '../../dist/out-tsc',
|
|
182
|
+
skipLibCheck: true,
|
|
183
|
+
sourceMap: true,
|
|
184
|
+
strict: true,
|
|
185
|
+
target: 'ES2022',
|
|
186
|
+
},
|
|
187
|
+
include: ['src/**/*'],
|
|
188
|
+
exclude: ['src/test.ts', 'src/**/*.spec.ts', 'node_modules', 'dist'],
|
|
189
|
+
angularCompilerOptions: {
|
|
190
|
+
enableI18nLegacyMessageIdFormat: false,
|
|
191
|
+
strictInjectionParameters: true,
|
|
192
|
+
strictInputAccessModifiers: true,
|
|
193
|
+
strictTemplates: true,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
fs.writeFileSync(
|
|
198
|
+
path.join(libPath, 'tsconfig.json'),
|
|
199
|
+
JSON.stringify(tsConfig, null, 2)
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// Create tsconfig.lib.json for building
|
|
203
|
+
const tsConfigLib = {
|
|
204
|
+
extends: './tsconfig.json',
|
|
205
|
+
compilerOptions: {
|
|
206
|
+
outDir: '../../dist/out-tsc',
|
|
207
|
+
declaration: true,
|
|
208
|
+
declarationMap: true,
|
|
209
|
+
inlineSources: true,
|
|
210
|
+
types: [],
|
|
211
|
+
},
|
|
212
|
+
include: ['src/**/*'],
|
|
213
|
+
exclude: ['src/test.ts', 'src/**/*.spec.ts'],
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
fs.writeFileSync(
|
|
217
|
+
path.join(libPath, 'tsconfig.lib.json'),
|
|
218
|
+
JSON.stringify(tsConfigLib, null, 2)
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
// Create tsconfig.spec.json for testing
|
|
222
|
+
const tsConfigSpec = {
|
|
223
|
+
extends: './tsconfig.json',
|
|
224
|
+
compilerOptions: {
|
|
225
|
+
outDir: '../../dist/out-tsc',
|
|
226
|
+
types: ['jasmine', 'node'],
|
|
227
|
+
},
|
|
228
|
+
files: ['src/test.ts'],
|
|
229
|
+
include: ['src/**/*.spec.ts', 'src/**/*.d.ts'],
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
fs.writeFileSync(
|
|
233
|
+
path.join(libPath, 'tsconfig.spec.json'),
|
|
234
|
+
JSON.stringify(tsConfigSpec, null, 2)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function createAngularJson(libName, libPath) {
|
|
239
|
+
const angularJson = {
|
|
240
|
+
$schema: '../../node_modules/@angular/cli/lib/config/schema.json',
|
|
241
|
+
version: 1,
|
|
242
|
+
newProjectRoot: 'projects',
|
|
243
|
+
projects: {
|
|
244
|
+
[libName]: {
|
|
245
|
+
projectType: 'library',
|
|
246
|
+
root: '',
|
|
247
|
+
sourceRoot: 'src',
|
|
248
|
+
prefix: 'lib',
|
|
249
|
+
architect: {
|
|
250
|
+
build: {
|
|
251
|
+
builder: '@angular-devkit/build-angular:ng-packagr',
|
|
252
|
+
options: {
|
|
253
|
+
project: 'ng-package.json',
|
|
254
|
+
},
|
|
255
|
+
configurations: {
|
|
256
|
+
production: {
|
|
257
|
+
tsConfig: 'tsconfig.lib.prod.json',
|
|
258
|
+
},
|
|
259
|
+
development: {
|
|
260
|
+
tsConfig: 'tsconfig.lib.json',
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
defaultConfiguration: 'production',
|
|
264
|
+
},
|
|
265
|
+
test: {
|
|
266
|
+
builder: '@angular-devkit/build-angular:karma',
|
|
267
|
+
options: {
|
|
268
|
+
tsConfig: 'tsconfig.spec.json',
|
|
269
|
+
polyfills: ['zone.js', 'zone.js/testing'],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
lint: {
|
|
273
|
+
builder: '@angular-eslint/builder:lint',
|
|
274
|
+
options: {
|
|
275
|
+
lintFilePatterns: ['src/**/*.ts', 'src/**/*.html'],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
fs.writeFileSync(
|
|
284
|
+
path.join(libPath, 'angular.json'),
|
|
285
|
+
JSON.stringify(angularJson, null, 2)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function createNgPackage(libName, companyName, libPath) {
|
|
290
|
+
const ngPackage = {
|
|
291
|
+
$schema: '../../node_modules/ng-packagr/ng-package.schema.json',
|
|
292
|
+
dest: `../../dist/${libName}`,
|
|
293
|
+
lib: {
|
|
294
|
+
entryFile: 'src/public-api.ts',
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
fs.writeFileSync(
|
|
299
|
+
path.join(libPath, 'ng-package.json'),
|
|
300
|
+
JSON.stringify(ngPackage, null, 2)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function updateMonorepoTsConfig(libName, companyName, monorepoInfo) {
|
|
305
|
+
const tsconfigPath = path.join(monorepoInfo.rootPath, 'tsconfig.json');
|
|
306
|
+
|
|
307
|
+
let tsconfig = {};
|
|
308
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
309
|
+
try {
|
|
310
|
+
tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
311
|
+
} catch {
|
|
312
|
+
console.warn(
|
|
313
|
+
'⚠️ Could not parse existing tsconfig.json, creating new one'
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Ensure compilerOptions exists
|
|
319
|
+
if (!tsconfig.compilerOptions) {
|
|
320
|
+
tsconfig.compilerOptions = {};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Ensure paths exists
|
|
324
|
+
if (!tsconfig.compilerOptions.paths) {
|
|
325
|
+
tsconfig.compilerOptions.paths = {};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Add library path mapping
|
|
329
|
+
const libraryAlias = `@${companyName}/${libName}`;
|
|
330
|
+
tsconfig.compilerOptions.paths[libraryAlias] = [
|
|
331
|
+
`libs/${libName}/src/public-api.ts`,
|
|
332
|
+
];
|
|
333
|
+
tsconfig.compilerOptions.paths[`${libraryAlias}/*`] = [
|
|
334
|
+
`libs/${libName}/src/*`,
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
// Ensure baseUrl is set for path mapping to work
|
|
338
|
+
if (!tsconfig.compilerOptions.baseUrl) {
|
|
339
|
+
tsconfig.compilerOptions.baseUrl = '.';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Set moduleResolution if not set
|
|
343
|
+
if (!tsconfig.compilerOptions.moduleResolution) {
|
|
344
|
+
tsconfig.compilerOptions.moduleResolution = 'bundler';
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function updateWorkspaceConfig(libName, monorepoInfo) {
|
|
351
|
+
const packageJsonPath = path.join(monorepoInfo.rootPath, 'package.json');
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
355
|
+
|
|
356
|
+
// Update workspaces to include libs
|
|
357
|
+
if (packageJson.workspaces) {
|
|
358
|
+
if (Array.isArray(packageJson.workspaces)) {
|
|
359
|
+
if (!packageJson.workspaces.includes('libs/*')) {
|
|
360
|
+
packageJson.workspaces.push('libs/*');
|
|
361
|
+
}
|
|
362
|
+
} else if (packageJson.workspaces.packages) {
|
|
363
|
+
if (!packageJson.workspaces.packages.includes('libs/*')) {
|
|
364
|
+
packageJson.workspaces.packages.push('libs/*');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
packageJson.workspaces = ['apps/*', 'libs/*'];
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Add library-specific scripts
|
|
372
|
+
if (!packageJson.scripts['build:libs']) {
|
|
373
|
+
packageJson.scripts['build:libs'] =
|
|
374
|
+
'npm run build --workspaces --if-present --workspace-prefix=libs/';
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (!packageJson.scripts['test:libs']) {
|
|
378
|
+
packageJson.scripts['test:libs'] =
|
|
379
|
+
'npm run test --workspaces --if-present --workspace-prefix=libs/';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.error(
|
|
385
|
+
'❌ Failed to update workspace configuration:',
|
|
386
|
+
error.message
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function libCommand(program) {
|
|
392
|
+
program
|
|
393
|
+
.command('lib <library-name>')
|
|
394
|
+
.description('Create a new shared library in monorepo')
|
|
395
|
+
.option('-p, --path <path>', 'Library path (relative to libs/)', '.')
|
|
396
|
+
.action(async (libraryName) => {
|
|
397
|
+
console.log(`📚 Creating new shared library: ${libraryName}`);
|
|
398
|
+
|
|
399
|
+
// Validate library name
|
|
400
|
+
if (!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(libraryName)) {
|
|
401
|
+
console.error(`❌ Invalid library name: ${libraryName}`);
|
|
402
|
+
console.error(
|
|
403
|
+
'Library names should be lowercase, start with a letter, and use hyphens for separation'
|
|
404
|
+
);
|
|
405
|
+
process.exit(1);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const monorepoInfo = detectMonorepo();
|
|
409
|
+
|
|
410
|
+
if (!monorepoInfo.isMonorepo) {
|
|
411
|
+
console.error('❌ This command can only be run inside a monorepo!');
|
|
412
|
+
console.error(
|
|
413
|
+
'💡 Create a monorepo first with: mag-cli init <project-name>'
|
|
414
|
+
);
|
|
415
|
+
process.exit(1);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
console.log(`📁 Detected monorepo at: ${monorepoInfo.rootPath}`);
|
|
419
|
+
console.log(`🏢 Company: ${monorepoInfo.companyName}`);
|
|
420
|
+
|
|
421
|
+
const libPath = path.join(monorepoInfo.rootPath, 'libs', libraryName);
|
|
422
|
+
|
|
423
|
+
// Check if library already exists
|
|
424
|
+
if (fs.existsSync(libPath)) {
|
|
425
|
+
console.error(`❌ Library ${libraryName} already exists at ${libPath}`);
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
console.log('📁 Creating library structure...');
|
|
431
|
+
const {
|
|
432
|
+
libPath: createdLibPath,
|
|
433
|
+
srcPath,
|
|
434
|
+
libSrcPath,
|
|
435
|
+
} = await createLibraryStructure(libraryName, monorepoInfo);
|
|
436
|
+
|
|
437
|
+
console.log('📦 Creating package.json...');
|
|
438
|
+
await createLibraryPackageJson(
|
|
439
|
+
libraryName,
|
|
440
|
+
monorepoInfo.companyName,
|
|
441
|
+
createdLibPath
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
console.log('📂 Creating library files...');
|
|
445
|
+
await createLibraryFiles(
|
|
446
|
+
libraryName,
|
|
447
|
+
createdLibPath,
|
|
448
|
+
srcPath,
|
|
449
|
+
libSrcPath
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
console.log('⚙️ Creating TypeScript configuration...');
|
|
453
|
+
await createLibraryTsConfig(libraryName, createdLibPath);
|
|
454
|
+
|
|
455
|
+
console.log('🅰️ Creating Angular configuration...');
|
|
456
|
+
await createAngularJson(libraryName, createdLibPath);
|
|
457
|
+
|
|
458
|
+
console.log('📋 Creating ng-package configuration...');
|
|
459
|
+
await createNgPackage(
|
|
460
|
+
libraryName,
|
|
461
|
+
monorepoInfo.companyName,
|
|
462
|
+
createdLibPath
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
console.log('🔗 Updating monorepo TypeScript paths...');
|
|
466
|
+
await updateMonorepoTsConfig(
|
|
467
|
+
libraryName,
|
|
468
|
+
monorepoInfo.companyName,
|
|
469
|
+
monorepoInfo
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
console.log('⚙️ Updating workspace configuration...');
|
|
473
|
+
await updateWorkspaceConfig(libraryName, monorepoInfo);
|
|
474
|
+
|
|
475
|
+
console.log(`✅ Library ${libraryName} created successfully!`);
|
|
476
|
+
console.log(`\n📝 Next steps:`);
|
|
477
|
+
console.log(` cd libs/${libraryName}`);
|
|
478
|
+
console.log(` \n📚 Library Usage:`);
|
|
479
|
+
const pascalCaseName = libraryName
|
|
480
|
+
.split('-')
|
|
481
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
482
|
+
.join('');
|
|
483
|
+
console.log(
|
|
484
|
+
` 💡 Import in apps: import { ${pascalCaseName}Service } from '@${monorepoInfo.companyName}/${libraryName}';`
|
|
485
|
+
);
|
|
486
|
+
console.log(` 💡 Build library: npm run build`);
|
|
487
|
+
console.log(` 💡 Test library: npm run test`);
|
|
488
|
+
console.log(` \n🔗 Path Mapping:`);
|
|
489
|
+
console.log(
|
|
490
|
+
` 💡 Library alias: @${monorepoInfo.companyName}/${libraryName}`
|
|
491
|
+
);
|
|
492
|
+
console.log(` 💡 Resolves to: libs/${libraryName}/src/public-api.ts`);
|
|
493
|
+
console.log(` \n🏗️ Development:`);
|
|
494
|
+
console.log(` 💡 Edit library files in libs/${libraryName}/src/lib/`);
|
|
495
|
+
console.log(
|
|
496
|
+
` 💡 Export new components/services in src/public-api.ts`
|
|
497
|
+
);
|
|
498
|
+
console.log(
|
|
499
|
+
` 💡 Use in apps with absolute imports: @${monorepoInfo.companyName}/${libraryName}`
|
|
500
|
+
);
|
|
501
|
+
} catch (error) {
|
|
502
|
+
console.error(`❌ Error creating library: ${error.message}`);
|
|
503
|
+
process.exit(1);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
module.exports = libCommand;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { parse: parseYAML } = require('yaml');
|
|
4
|
+
|
|
5
|
+
// `version` lives only in the base manifest (`mag_assets/remote/*.yml`). An env
|
|
6
|
+
// override that moved it would let one environment claim a release another one
|
|
7
|
+
// never made, and the CI gate that watches that line would fire on the wrong
|
|
8
|
+
// commit.
|
|
9
|
+
const ENV_BLOCKLIST = ['version'];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Layouts this command runs in.
|
|
13
|
+
*
|
|
14
|
+
* A monorepo has many apps under `apps/`, each with its own `mag_assets_env/`
|
|
15
|
+
* and its own compiled `public/assets/remote/app-wc.json`, plus an aggregated
|
|
16
|
+
* copy under the host. An app scaffolded by the m-one-ui editor is a standalone
|
|
17
|
+
* Angular workspace: one app, at the root, with no `apps/` and no host beside
|
|
18
|
+
* it. Detected rather than flagged, because the layout is a fact about the
|
|
19
|
+
* folder and not a choice the caller should have to restate on every build.
|
|
20
|
+
*/
|
|
21
|
+
function resolveApps(root, appFilter) {
|
|
22
|
+
const appsDir = path.join(root, 'apps');
|
|
23
|
+
if (fs.existsSync(appsDir) && fs.statSync(appsDir).isDirectory()) {
|
|
24
|
+
return fs
|
|
25
|
+
.readdirSync(appsDir, { withFileTypes: true })
|
|
26
|
+
.filter((entry) => entry.isDirectory())
|
|
27
|
+
.map((entry) => entry.name)
|
|
28
|
+
.filter((name) => !appFilter || appFilter === name)
|
|
29
|
+
.map((name) => ({ name, dir: path.join(appsDir, name) }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Standalone: the root is the app. Its name comes from package.json rather
|
|
33
|
+
// than from the folder, a checkout being free to sit in a directory named
|
|
34
|
+
// anything at all.
|
|
35
|
+
const pkgPath = path.join(root, 'package.json');
|
|
36
|
+
const name = fs.existsSync(pkgPath)
|
|
37
|
+
? JSON.parse(fs.readFileSync(pkgPath, 'utf8')).name || path.basename(root)
|
|
38
|
+
: path.basename(root);
|
|
39
|
+
if (appFilter && appFilter !== name) return [];
|
|
40
|
+
return [{ name, dir: root }];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Every compiled copy of one app's manifest. All of them are patched, because
|
|
44
|
+
// the running app reads the first, the host reads the second, and the bundle
|
|
45
|
+
// the Store deploys is built from the third — a value in one and not the others
|
|
46
|
+
// is the kind of drift that only shows up in the environment nobody tested.
|
|
47
|
+
function targetsFor(root, app) {
|
|
48
|
+
return [
|
|
49
|
+
path.join(app.dir, 'public', 'assets', 'remote', 'app-wc.json'),
|
|
50
|
+
path.join(root, 'apps', 'm-ui', 'public', 'assets', 'remote', app.name, 'app-wc.json'),
|
|
51
|
+
path.join(root, 'dist', 'apps', `${app.name}-wc`, 'remote', 'app-wc.json'),
|
|
52
|
+
// The standalone build's own output path, which has no `apps/` segment.
|
|
53
|
+
path.join(root, 'dist', `${app.name}-wc`, 'remote', 'app-wc.json'),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function patchFile(filePath, overrides, buildConfig) {
|
|
58
|
+
if (!fs.existsSync(filePath)) return false;
|
|
59
|
+
const json = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
60
|
+
const patched = { ...json, ...overrides };
|
|
61
|
+
// `componentPath` points at workspace source and means nothing to a browser
|
|
62
|
+
// reading the compiled manifest.
|
|
63
|
+
delete patched.componentPath;
|
|
64
|
+
fs.writeFileSync(filePath, JSON.stringify(patched, null, 2));
|
|
65
|
+
console.log(` ✅ Patched ${filePath} with ${buildConfig} overrides`);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function patchWcEnvCommand(program) {
|
|
70
|
+
program
|
|
71
|
+
.command('patch-wc-env')
|
|
72
|
+
.description(
|
|
73
|
+
'Apply mag_assets_env/<BUILD_CONFIG>/remote overrides onto compiled app-wc.json'
|
|
74
|
+
)
|
|
75
|
+
.option('--root <path>', 'Workspace or app root (default: cwd)')
|
|
76
|
+
.option('--app <name>', 'Patch only this app')
|
|
77
|
+
.option('--build-config <config>', 'Overrides BUILD_CONFIG from the environment')
|
|
78
|
+
.action((options) => {
|
|
79
|
+
let buildConfig = options.buildConfig || process.env.BUILD_CONFIG;
|
|
80
|
+
if (buildConfig === 'production') buildConfig = 'prod';
|
|
81
|
+
|
|
82
|
+
// No env-specific values to apply is the normal case for a local build,
|
|
83
|
+
// so it is reported and exits clean rather than failing a pipeline.
|
|
84
|
+
if (!buildConfig || buildConfig === 'development') {
|
|
85
|
+
console.log(
|
|
86
|
+
'ℹ️ No env-specific WC patches (BUILD_CONFIG not set or is development)'
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const root = path.resolve(options.root || process.cwd());
|
|
92
|
+
let patchCount = 0;
|
|
93
|
+
|
|
94
|
+
for (const app of resolveApps(root, options.app)) {
|
|
95
|
+
const envRemoteDir = path.join(
|
|
96
|
+
app.dir,
|
|
97
|
+
'mag_assets_env',
|
|
98
|
+
buildConfig,
|
|
99
|
+
'remote'
|
|
100
|
+
);
|
|
101
|
+
if (!fs.existsSync(envRemoteDir)) continue;
|
|
102
|
+
|
|
103
|
+
const yamlFiles = fs
|
|
104
|
+
.readdirSync(envRemoteDir)
|
|
105
|
+
.filter((file) => file.endsWith('.yml'));
|
|
106
|
+
|
|
107
|
+
for (const yamlFile of yamlFiles) {
|
|
108
|
+
const overrides =
|
|
109
|
+
parseYAML(fs.readFileSync(path.join(envRemoteDir, yamlFile), 'utf8')) ||
|
|
110
|
+
{};
|
|
111
|
+
ENV_BLOCKLIST.forEach((key) => delete overrides[key]);
|
|
112
|
+
|
|
113
|
+
const targets = targetsFor(root, app);
|
|
114
|
+
const patchedAny = targets
|
|
115
|
+
.map((target) => patchFile(target, overrides, buildConfig))
|
|
116
|
+
.some(Boolean);
|
|
117
|
+
|
|
118
|
+
if (!patchedAny) {
|
|
119
|
+
console.warn(
|
|
120
|
+
` ⚠️ No compiled app-wc.json found for ${app.name} — run assets:compile first`
|
|
121
|
+
);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
patchCount++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (patchCount === 0) {
|
|
129
|
+
console.log(`ℹ️ No env patches found for BUILD_CONFIG=${buildConfig}`);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = patchWcEnvCommand;
|
|
135
|
+
module.exports.resolveApps = resolveApps;
|
|
136
|
+
module.exports.targetsFor = targetsFor;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const fs = require('fs').promises;
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function refractorCommand(program) {
|
|
5
|
+
program
|
|
6
|
+
.command('refractor <file>')
|
|
7
|
+
.description(
|
|
8
|
+
'Refractor an Angular file to use modern Signal and Standalone patterns (referenced from m-ref.ts)'
|
|
9
|
+
)
|
|
10
|
+
.option('-v, --verbose', 'Verbose output')
|
|
11
|
+
.action(async (file) => {
|
|
12
|
+
console.log(`🚀 Refractoring ${file}...`);
|
|
13
|
+
|
|
14
|
+
const filePath = path.resolve(process.cwd(), file);
|
|
15
|
+
try {
|
|
16
|
+
await fs.readFile(filePath, 'utf8');
|
|
17
|
+
|
|
18
|
+
console.log(
|
|
19
|
+
`📍 Using reference: libs/one/src/lib/features/nav/ui/m-ref.ts`
|
|
20
|
+
);
|
|
21
|
+
console.log(
|
|
22
|
+
`✨ Applying modern Angular signals and standalone components patterns...`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// This is a placeholder for actual AI-driven refactoring
|
|
26
|
+
// In a real scenario, this would use Ollama or another LLM
|
|
27
|
+
|
|
28
|
+
console.log(`\n📝 Refractor Plan for ${file}:`);
|
|
29
|
+
console.log(
|
|
30
|
+
`1. Convert inputs to signal-based inputs (input.required, input)`
|
|
31
|
+
);
|
|
32
|
+
console.log(
|
|
33
|
+
`2. Replace BehaviorSubjects/Observables with Signals (signal, computed, effect)`
|
|
34
|
+
);
|
|
35
|
+
console.log(
|
|
36
|
+
`3. Ensure Standalone component/directive pattern (no standalone: true needed if using latest patterns)`
|
|
37
|
+
);
|
|
38
|
+
console.log(`4. Use inject() for dependency injection`);
|
|
39
|
+
console.log(`5. Apply private fields with # for internals`);
|
|
40
|
+
|
|
41
|
+
console.log(`\n✅ Refractor command metadata updated in .clinerules.`);
|
|
42
|
+
console.log(
|
|
43
|
+
`👉 Please use the slash command '/refractor' in your AI chat to apply these changes automatically.`
|
|
44
|
+
);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`❌ Error reading file ${file}: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = refractorCommand;
|