@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,266 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function configCiCommand(program) {
|
|
5
|
+
program
|
|
6
|
+
.command('config-ci')
|
|
7
|
+
.description(
|
|
8
|
+
'Generate a GitHub Actions CI/CD pipeline: CI builds assets & web component, CD deploys to Magmonium'
|
|
9
|
+
)
|
|
10
|
+
.requiredOption('--app-id <id>', 'Magmonium app ID')
|
|
11
|
+
.requiredOption('--token <token>', 'Magmonium deploy token')
|
|
12
|
+
.option(
|
|
13
|
+
'--endpoint <url>',
|
|
14
|
+
'Magmonium API endpoint',
|
|
15
|
+
'https://api.magmonium.com'
|
|
16
|
+
)
|
|
17
|
+
.option('--branch <branch>', 'Branch that triggers CD deployment', 'main')
|
|
18
|
+
.option(
|
|
19
|
+
'--remote-yml <path>',
|
|
20
|
+
'Path to app remote YAML for version-check (auto-detected if omitted)'
|
|
21
|
+
)
|
|
22
|
+
.option('--force', 'Overwrite existing workflow file')
|
|
23
|
+
.action(async (options) => {
|
|
24
|
+
try {
|
|
25
|
+
const detected = detectConfig();
|
|
26
|
+
|
|
27
|
+
const workflowDir = '.github/workflows';
|
|
28
|
+
const workflowFile = path.join(workflowDir, 'mag-ci.yml');
|
|
29
|
+
|
|
30
|
+
if (fs.existsSync(workflowFile) && !options.force) {
|
|
31
|
+
console.error(
|
|
32
|
+
`Workflow file already exists: ${workflowFile}\nUse --force to overwrite.`
|
|
33
|
+
);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fs.mkdirSync(workflowDir, { recursive: true });
|
|
38
|
+
|
|
39
|
+
const remoteYmlPath = options.remoteYml || detected.remoteYmlPath;
|
|
40
|
+
const workflow = buildCiWorkflow({
|
|
41
|
+
deployBranch: options.branch,
|
|
42
|
+
nodeVersion: detected.nodeVersion,
|
|
43
|
+
wcDistPath: detected.wcDistPath,
|
|
44
|
+
endpoint: options.endpoint,
|
|
45
|
+
remoteYmlPath,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
fs.writeFileSync(workflowFile, workflow, 'utf-8');
|
|
49
|
+
|
|
50
|
+
console.log(`Generated: ${workflowFile}`);
|
|
51
|
+
console.log('');
|
|
52
|
+
console.log('Add these GitHub Secrets to your repository:');
|
|
53
|
+
console.log(` MAG_APP_ID = ${options.appId}`);
|
|
54
|
+
console.log(` MAG_DEPLOY_TOKEN = ${options.token}`);
|
|
55
|
+
console.log(` MAG_ENDPOINT = ${options.endpoint}`);
|
|
56
|
+
console.log('');
|
|
57
|
+
console.log(
|
|
58
|
+
'Settings > Secrets and variables > Actions > New repository secret'
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`Config CI failed: ${error.message}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function detectConfig() {
|
|
68
|
+
let nodeVersion = '24';
|
|
69
|
+
let wcDistPath = 'dist/wc';
|
|
70
|
+
|
|
71
|
+
// Detect node version from .nvmrc or package.json engines
|
|
72
|
+
if (fs.existsSync('.nvmrc')) {
|
|
73
|
+
nodeVersion = fs.readFileSync('.nvmrc', 'utf-8').trim().replace(/^v/, '');
|
|
74
|
+
} else if (fs.existsSync('package.json')) {
|
|
75
|
+
try {
|
|
76
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
77
|
+
const match = (pkg.engines?.node || '').match(/\d+/);
|
|
78
|
+
if (match) nodeVersion = match[0];
|
|
79
|
+
} catch {
|
|
80
|
+
// keep default
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Detect web component output path
|
|
85
|
+
const detected = detectWcDistPath();
|
|
86
|
+
if (detected) wcDistPath = detected;
|
|
87
|
+
|
|
88
|
+
return { nodeVersion, wcDistPath, remoteYmlPath: detectRemoteYmlPath() };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function detectWcDistPath() {
|
|
92
|
+
// Try angular.json — look for a wc / build-wc target
|
|
93
|
+
if (fs.existsSync('angular.json')) {
|
|
94
|
+
try {
|
|
95
|
+
const angularJson = JSON.parse(fs.readFileSync('angular.json', 'utf-8'));
|
|
96
|
+
for (const projectName of Object.keys(angularJson.projects || {})) {
|
|
97
|
+
const targets = angularJson.projects[projectName]?.architect || {};
|
|
98
|
+
for (const targetName of ['wc', 'build-wc']) {
|
|
99
|
+
const outputPath = targets[targetName]?.options?.outputPath;
|
|
100
|
+
if (outputPath) return outputPath;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
// keep default
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Try project.json (Nx)
|
|
109
|
+
if (fs.existsSync('project.json')) {
|
|
110
|
+
try {
|
|
111
|
+
const projectJson = JSON.parse(fs.readFileSync('project.json', 'utf-8'));
|
|
112
|
+
const targets = projectJson.targets || {};
|
|
113
|
+
for (const targetName of ['wc', 'build-wc']) {
|
|
114
|
+
const outputPath = targets[targetName]?.options?.outputPath;
|
|
115
|
+
if (outputPath) return outputPath;
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
// keep default
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function detectRemoteYmlPath() {
|
|
126
|
+
const configPath = path.resolve('mag-cli.config.js');
|
|
127
|
+
if (!fs.existsSync(configPath)) return null;
|
|
128
|
+
try {
|
|
129
|
+
delete require.cache[configPath];
|
|
130
|
+
const config = require(configPath);
|
|
131
|
+
for (const { source } of Array.isArray(config.paths) ? config.paths : []) {
|
|
132
|
+
const remoteDir = path.join(source, 'remote');
|
|
133
|
+
if (!fs.existsSync(remoteDir)) continue;
|
|
134
|
+
const appName = path.basename(path.dirname(source));
|
|
135
|
+
const ymlFile = path.join(remoteDir, `${appName}.yml`);
|
|
136
|
+
if (fs.existsSync(ymlFile)) return ymlFile.replace(/\\/g, '/');
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
/* ignore config load error */
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function buildVersionCheckJob(remoteYmlPath) {
|
|
145
|
+
return ` version-check:
|
|
146
|
+
name: Check Version Change
|
|
147
|
+
runs-on: ubuntu-latest
|
|
148
|
+
outputs:
|
|
149
|
+
changed: \${{ steps.check.outputs.changed }}
|
|
150
|
+
steps:
|
|
151
|
+
- uses: actions/checkout@v4
|
|
152
|
+
with:
|
|
153
|
+
fetch-depth: 0
|
|
154
|
+
- name: Check if version changed
|
|
155
|
+
id: check
|
|
156
|
+
run: |
|
|
157
|
+
FILE="${remoteYmlPath}"
|
|
158
|
+
if [ "\${{ github.event_name }}" = "pull_request" ]; then
|
|
159
|
+
BASE_SHA="\${{ github.event.pull_request.base.sha }}"
|
|
160
|
+
else
|
|
161
|
+
BASE_SHA="$(git rev-parse HEAD~1)"
|
|
162
|
+
fi
|
|
163
|
+
CHANGED=$(git diff ${BASE_SHA} HEAD --name-only | grep -c "^${FILE}$" || true)
|
|
164
|
+
if [ "$CHANGED" -gt "0" ]; then
|
|
165
|
+
PREV=$(git show ${BASE_SHA}:${FILE} 2>/dev/null | grep '^version:' | awk '{print $2}' || echo "")
|
|
166
|
+
CURR=$(grep '^version:' ${FILE} | awk '{print $2}')
|
|
167
|
+
if [ "$PREV" != "$CURR" ]; then
|
|
168
|
+
echo "changed=true" >> $GITHUB_OUTPUT
|
|
169
|
+
echo "Version changed: $PREV → $CURR"
|
|
170
|
+
else
|
|
171
|
+
echo "changed=false" >> $GITHUB_OUTPUT
|
|
172
|
+
echo "Version unchanged: $CURR (skipping)"
|
|
173
|
+
fi
|
|
174
|
+
else
|
|
175
|
+
echo "changed=false" >> $GITHUB_OUTPUT
|
|
176
|
+
echo "File not modified (skipping)"
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function buildCiWorkflow({
|
|
183
|
+
deployBranch,
|
|
184
|
+
nodeVersion,
|
|
185
|
+
wcDistPath,
|
|
186
|
+
remoteYmlPath,
|
|
187
|
+
}) {
|
|
188
|
+
const hasVersionCheck = Boolean(remoteYmlPath);
|
|
189
|
+
const versionCheckJob = hasVersionCheck
|
|
190
|
+
? buildVersionCheckJob(remoteYmlPath)
|
|
191
|
+
: '';
|
|
192
|
+
const buildNeeds = hasVersionCheck
|
|
193
|
+
? ` needs: version-check\n if: needs.version-check.outputs.changed == 'true'\n`
|
|
194
|
+
: '';
|
|
195
|
+
|
|
196
|
+
const appName = remoteYmlPath
|
|
197
|
+
? path.basename(path.dirname(path.dirname(path.dirname(remoteYmlPath))))
|
|
198
|
+
: 'm-ui';
|
|
199
|
+
|
|
200
|
+
return `name: Magmonium CI/CD
|
|
201
|
+
|
|
202
|
+
on:
|
|
203
|
+
push:
|
|
204
|
+
branches:
|
|
205
|
+
- ${deployBranch}
|
|
206
|
+
paths:
|
|
207
|
+
- 'apps/${appName}/**'
|
|
208
|
+
- '.github/workflows/mag-ci.yml'
|
|
209
|
+
pull_request:
|
|
210
|
+
branches:
|
|
211
|
+
- ${deployBranch}
|
|
212
|
+
paths:
|
|
213
|
+
- 'apps/${appName}/**'
|
|
214
|
+
- '.github/workflows/mag-ci.yml'
|
|
215
|
+
|
|
216
|
+
jobs:
|
|
217
|
+
${versionCheckJob} build:
|
|
218
|
+
name: Build
|
|
219
|
+
${buildNeeds} runs-on: ubuntu-latest
|
|
220
|
+
steps:
|
|
221
|
+
- uses: actions/checkout@v4
|
|
222
|
+
- uses: actions/setup-node@v4
|
|
223
|
+
with:
|
|
224
|
+
node-version: '${nodeVersion}'
|
|
225
|
+
cache: 'npm'
|
|
226
|
+
- name: Install dependencies
|
|
227
|
+
run: npm ci
|
|
228
|
+
- name: Build assets
|
|
229
|
+
run: npx @magmonium/cli assets
|
|
230
|
+
- name: Build web component
|
|
231
|
+
run: npm run build:wc
|
|
232
|
+
- name: Upload web component bundle
|
|
233
|
+
if: github.ref == 'refs/heads/${deployBranch}' && github.event_name == 'push'
|
|
234
|
+
uses: actions/upload-artifact@v4
|
|
235
|
+
with:
|
|
236
|
+
name: wc-bundle
|
|
237
|
+
path: ${wcDistPath}
|
|
238
|
+
retention-days: 1
|
|
239
|
+
|
|
240
|
+
deploy:
|
|
241
|
+
name: Deploy to Magmonium
|
|
242
|
+
needs: build
|
|
243
|
+
if: github.ref == 'refs/heads/${deployBranch}' && github.event_name == 'push'
|
|
244
|
+
runs-on: ubuntu-latest
|
|
245
|
+
steps:
|
|
246
|
+
- name: Download web component bundle
|
|
247
|
+
uses: actions/download-artifact@v4
|
|
248
|
+
with:
|
|
249
|
+
name: wc-bundle
|
|
250
|
+
path: ${wcDistPath}
|
|
251
|
+
- name: Install Magmonium CLI
|
|
252
|
+
run: npm install -g @magmonium/cli
|
|
253
|
+
- name: Deploy to Magmonium
|
|
254
|
+
run: |
|
|
255
|
+
MAG_ENDPOINT="\${{ secrets.MAG_ENDPOINT }}"
|
|
256
|
+
MAG_ENDPOINT="\${MAG_ENDPOINT%/}"
|
|
257
|
+
mag-build deploy
|
|
258
|
+
env:
|
|
259
|
+
MAG_APP_ID: \${{ secrets.MAG_APP_ID }}
|
|
260
|
+
MAG_DEPLOY_TOKEN: \${{ secrets.MAG_DEPLOY_TOKEN }}
|
|
261
|
+
MAG_ENDPOINT: \${{ secrets.MAG_ENDPOINT }}
|
|
262
|
+
MAG_DIST_PATH: ${wcDistPath}
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
module.exports = configCiCommand;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const WC_YAML_NAME = 'app-wc.yml';
|
|
5
|
+
|
|
6
|
+
function configureWcCommand(program) {
|
|
7
|
+
program
|
|
8
|
+
.command('configure-wc')
|
|
9
|
+
.description(
|
|
10
|
+
'Scaffold web component config (app-wc.yml) and CI/CD workflow for an Nx app'
|
|
11
|
+
)
|
|
12
|
+
.requiredOption(
|
|
13
|
+
'--app-path <path>',
|
|
14
|
+
'Path to the app (e.g., apps/m-comics)'
|
|
15
|
+
)
|
|
16
|
+
.option('--force', 'Overwrite existing files')
|
|
17
|
+
.action((options) => {
|
|
18
|
+
try {
|
|
19
|
+
const appPath = options.appPath.replace(/\/$/, '');
|
|
20
|
+
const appName = path.basename(appPath);
|
|
21
|
+
const appNameUpper = appName.toUpperCase().replace(/-/g, '_');
|
|
22
|
+
|
|
23
|
+
console.log(`Configuring web component for: ${appName}`);
|
|
24
|
+
|
|
25
|
+
// 1. Create mag_assets/remote/app-wc.yml
|
|
26
|
+
createAppWcYaml(appPath, appName, options.force);
|
|
27
|
+
|
|
28
|
+
// 2. Create GitHub Actions CI/CD workflow
|
|
29
|
+
createWorkflow(appName, appNameUpper, options.force);
|
|
30
|
+
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log('Done! Next steps:');
|
|
33
|
+
console.log(
|
|
34
|
+
` 1. Fill in selector + componentPath in ${appPath}/mag_assets/remote/${WC_YAML_NAME}`
|
|
35
|
+
);
|
|
36
|
+
console.log(` 2. Register app on Magmonium and set appId in:`);
|
|
37
|
+
console.log(
|
|
38
|
+
` apps/m-ui/public/assets/remote/${appName}/meta.json`
|
|
39
|
+
);
|
|
40
|
+
console.log(` 3. Build & preview locally:`);
|
|
41
|
+
console.log(` npm run assets:compile`);
|
|
42
|
+
console.log(` 4. Add GitHub Secrets:`);
|
|
43
|
+
console.log(` MAG_APP_ID_${appNameUpper}`);
|
|
44
|
+
console.log(` MAG_DEPLOY_TOKEN_${appNameUpper}`);
|
|
45
|
+
console.log(
|
|
46
|
+
` MAG_ENDPOINT (default: https://api.magmonium.com)`
|
|
47
|
+
);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(`configure-wc failed: ${err.message}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─────────────────────────────────────────────────────────────
|
|
56
|
+
// Helpers
|
|
57
|
+
// ─────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
function createAppWcYaml(appPath, appName, force) {
|
|
60
|
+
const dir = path.join(appPath, 'mag_assets', 'remote');
|
|
61
|
+
const dest = path.join(dir, WC_YAML_NAME);
|
|
62
|
+
|
|
63
|
+
if (fs.existsSync(dest) && !force) {
|
|
64
|
+
console.log(` [skip] ${dest} already exists (use --force to overwrite)`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
69
|
+
|
|
70
|
+
const content = `app: ${appName}
|
|
71
|
+
version: 0.0.1
|
|
72
|
+
selector: # TODO: fill in custom element selector (e.g., ${appName}-app)
|
|
73
|
+
componentPath: ${appPath}/src/app/pages/home
|
|
74
|
+
componentName: home
|
|
75
|
+
appConfigPath: ${appPath}/src/app/app.config
|
|
76
|
+
`;
|
|
77
|
+
fs.writeFileSync(dest, content, 'utf-8');
|
|
78
|
+
console.log(` [created] ${dest}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function createWorkflow(appName, appNameUpper, force) {
|
|
82
|
+
const workflowDir = '.github/workflows';
|
|
83
|
+
const workflowFile = path.join(workflowDir, `${appName}-wc.yml`);
|
|
84
|
+
|
|
85
|
+
if (fs.existsSync(workflowFile) && !force) {
|
|
86
|
+
console.log(
|
|
87
|
+
` [skip] ${workflowFile} already exists (use --force to overwrite)`
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fs.mkdirSync(workflowDir, { recursive: true });
|
|
93
|
+
|
|
94
|
+
const nodeVersion = detectNodeVersion();
|
|
95
|
+
const wcDistPath = `dist/apps/${appName}-wc`;
|
|
96
|
+
|
|
97
|
+
const workflow = `name: ${appName} Web Component CI/CD
|
|
98
|
+
|
|
99
|
+
on:
|
|
100
|
+
push:
|
|
101
|
+
pull_request:
|
|
102
|
+
|
|
103
|
+
jobs:
|
|
104
|
+
build:
|
|
105
|
+
name: Build & Package Assets
|
|
106
|
+
runs-on: ubuntu-latest
|
|
107
|
+
steps:
|
|
108
|
+
- uses: actions/checkout@v4
|
|
109
|
+
- uses: actions/setup-node@v4
|
|
110
|
+
with:
|
|
111
|
+
node-version: '${nodeVersion}'
|
|
112
|
+
cache: 'npm'
|
|
113
|
+
- name: Install dependencies
|
|
114
|
+
run: npm ci
|
|
115
|
+
- name: Build assets and package web component
|
|
116
|
+
run: npm run assets:wc
|
|
117
|
+
- name: Upload WC artifact
|
|
118
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
119
|
+
uses: actions/upload-artifact@v4
|
|
120
|
+
with:
|
|
121
|
+
name: ${appName}-wc
|
|
122
|
+
path: ${wcDistPath}
|
|
123
|
+
retention-days: 1
|
|
124
|
+
|
|
125
|
+
deploy:
|
|
126
|
+
name: Deploy to Magmonium
|
|
127
|
+
needs: build
|
|
128
|
+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
129
|
+
runs-on: ubuntu-latest
|
|
130
|
+
steps:
|
|
131
|
+
- name: Download WC artifact
|
|
132
|
+
uses: actions/download-artifact@v4
|
|
133
|
+
with:
|
|
134
|
+
name: ${appName}-wc
|
|
135
|
+
path: ${wcDistPath}
|
|
136
|
+
- name: Install Magmonium CLI
|
|
137
|
+
run: npm install -g @magmonium/cli
|
|
138
|
+
- name: Deploy to Magmonium
|
|
139
|
+
run: |
|
|
140
|
+
mag-cli deploy \\
|
|
141
|
+
--app-id \${{ secrets.MAG_APP_ID_${appNameUpper} }} \\
|
|
142
|
+
--token \${{ secrets.MAG_DEPLOY_TOKEN_${appNameUpper} }} \\
|
|
143
|
+
--endpoint \${{ secrets.MAG_ENDPOINT || 'https://api.magmonium.com' }} \\
|
|
144
|
+
--dist-path ${wcDistPath}
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
fs.writeFileSync(workflowFile, workflow, 'utf-8');
|
|
148
|
+
console.log(` [created] ${workflowFile}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function detectNodeVersion() {
|
|
152
|
+
if (fs.existsSync('.nvmrc')) {
|
|
153
|
+
return fs.readFileSync('.nvmrc', 'utf-8').trim().replace(/^v/, '');
|
|
154
|
+
}
|
|
155
|
+
if (fs.existsSync('package.json')) {
|
|
156
|
+
try {
|
|
157
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
158
|
+
const match = (pkg.engines?.node || '').match(/\d+/);
|
|
159
|
+
if (match) return match[0];
|
|
160
|
+
} catch {
|
|
161
|
+
// ignore parse errors
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return '20';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = configureWcCommand;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function connectCommand(program) {
|
|
5
|
+
program
|
|
6
|
+
.command('connect')
|
|
7
|
+
.description(
|
|
8
|
+
'Connect your Angular repository to Magmonium for automated deployment via GitHub Actions'
|
|
9
|
+
)
|
|
10
|
+
.requiredOption('--app-id <id>', 'Magmonium app ID')
|
|
11
|
+
.requiredOption('--token <token>', 'Magmonium deploy token')
|
|
12
|
+
.option(
|
|
13
|
+
'--endpoint <url>',
|
|
14
|
+
'Magmonium API endpoint',
|
|
15
|
+
'https://api.magmonium.com'
|
|
16
|
+
)
|
|
17
|
+
.option('--branch <branch>', 'Branch that triggers deployment', 'main')
|
|
18
|
+
.option('--force', 'Overwrite existing workflow file')
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
try {
|
|
21
|
+
const detected = detectAngularConfig();
|
|
22
|
+
|
|
23
|
+
const workflowDir = '.github/workflows';
|
|
24
|
+
const workflowFile = path.join(workflowDir, 'mag-deploy.yml');
|
|
25
|
+
|
|
26
|
+
if (fs.existsSync(workflowFile) && !options.force) {
|
|
27
|
+
console.error(
|
|
28
|
+
`Workflow file already exists: ${workflowFile}\nUse --force to overwrite.`
|
|
29
|
+
);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fs.mkdirSync(workflowDir, { recursive: true });
|
|
34
|
+
|
|
35
|
+
const workflow = buildWorkflow({
|
|
36
|
+
branch: options.branch,
|
|
37
|
+
nodeVersion: detected.nodeVersion,
|
|
38
|
+
buildCommand: detected.buildCommand,
|
|
39
|
+
distPath: detected.distPath,
|
|
40
|
+
appRoot: detected.appRoot,
|
|
41
|
+
isNx: detected.isNx,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
fs.writeFileSync(workflowFile, workflow, 'utf-8');
|
|
45
|
+
|
|
46
|
+
console.log(`Generated: ${workflowFile}`);
|
|
47
|
+
console.log('');
|
|
48
|
+
console.log('Add these GitHub Secrets to your repository:');
|
|
49
|
+
console.log(` MAG_APP_ID = ${options.appId}`);
|
|
50
|
+
console.log(` MAG_DEPLOY_TOKEN = ${options.token}`);
|
|
51
|
+
console.log(` MAG_ENDPOINT = ${options.endpoint}`);
|
|
52
|
+
console.log('');
|
|
53
|
+
console.log(
|
|
54
|
+
'Settings > Secrets and variables > Actions > New repository secret'
|
|
55
|
+
);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`Connect failed: ${error.message}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function detectAngularConfig() {
|
|
64
|
+
let buildCommand = 'npm run build';
|
|
65
|
+
let distPath = 'dist/browser';
|
|
66
|
+
let nodeVersion = '20';
|
|
67
|
+
let appRoot = '';
|
|
68
|
+
let isNx = false;
|
|
69
|
+
|
|
70
|
+
// Detect from angular.json
|
|
71
|
+
if (fs.existsSync('angular.json')) {
|
|
72
|
+
try {
|
|
73
|
+
const angularJson = JSON.parse(fs.readFileSync('angular.json', 'utf-8'));
|
|
74
|
+
const projectName =
|
|
75
|
+
angularJson.defaultProject ||
|
|
76
|
+
Object.keys(angularJson.projects || {})[0];
|
|
77
|
+
if (projectName) {
|
|
78
|
+
const outputPath =
|
|
79
|
+
angularJson.projects[projectName]?.architect?.build?.options
|
|
80
|
+
?.outputPath;
|
|
81
|
+
if (outputPath) distPath = outputPath;
|
|
82
|
+
buildCommand = `npx ng build ${projectName} --configuration production`;
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
// keep defaults
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Detect Nx monorepo (overrides angular.json defaults)
|
|
90
|
+
if (fs.existsSync('nx.json')) {
|
|
91
|
+
isNx = true;
|
|
92
|
+
const projectJson = findProjectJson(process.cwd());
|
|
93
|
+
if (projectJson) {
|
|
94
|
+
appRoot = projectJson.root || '';
|
|
95
|
+
const projectName = projectJson.name || path.basename(process.cwd());
|
|
96
|
+
buildCommand = `npx nx build ${projectName} --configuration production`;
|
|
97
|
+
const nxOutputPath =
|
|
98
|
+
projectJson.targets?.build?.options?.outputPath ||
|
|
99
|
+
projectJson.targets?.build?.configurations?.production?.outputPath;
|
|
100
|
+
if (nxOutputPath) distPath = nxOutputPath;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Detect Node version
|
|
105
|
+
if (fs.existsSync('.nvmrc')) {
|
|
106
|
+
nodeVersion = fs.readFileSync('.nvmrc', 'utf-8').trim().replace(/^v/, '');
|
|
107
|
+
} else if (fs.existsSync('package.json')) {
|
|
108
|
+
try {
|
|
109
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
110
|
+
const match = (pkg.engines?.node || '').match(/\d+/);
|
|
111
|
+
if (match) nodeVersion = match[0];
|
|
112
|
+
} catch {
|
|
113
|
+
// keep default
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { buildCommand, distPath, nodeVersion, appRoot, isNx };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function findProjectJson(cwd) {
|
|
121
|
+
// Look for project.json in cwd or immediate subdirectories
|
|
122
|
+
const candidates = [
|
|
123
|
+
path.join(cwd, 'project.json'),
|
|
124
|
+
...fs
|
|
125
|
+
.readdirSync(cwd)
|
|
126
|
+
.filter((f) => {
|
|
127
|
+
try {
|
|
128
|
+
return fs.statSync(path.join(cwd, f)).isDirectory();
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
.map((d) => path.join(cwd, d, 'project.json')),
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
for (const candidate of candidates) {
|
|
137
|
+
if (fs.existsSync(candidate)) {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(fs.readFileSync(candidate, 'utf-8'));
|
|
140
|
+
} catch {
|
|
141
|
+
// skip invalid
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function buildWorkflow({
|
|
149
|
+
branch,
|
|
150
|
+
nodeVersion,
|
|
151
|
+
buildCommand,
|
|
152
|
+
distPath,
|
|
153
|
+
appRoot,
|
|
154
|
+
isNx,
|
|
155
|
+
}) {
|
|
156
|
+
const appRootLine = appRoot ? ` working-directory: ${appRoot}\n` : '';
|
|
157
|
+
|
|
158
|
+
const installCmd = isNx ? 'npm ci' : 'npm ci';
|
|
159
|
+
const buildSteps = isNx
|
|
160
|
+
? ` - name: Install dependencies\n run: ${installCmd}\n - name: Build\n run: ${buildCommand}\n${appRootLine}`
|
|
161
|
+
: ` - name: Install dependencies\n run: ${installCmd}\n - name: Build\n run: ${buildCommand}\n`;
|
|
162
|
+
|
|
163
|
+
return `name: Deploy to Magmonium
|
|
164
|
+
on:
|
|
165
|
+
push:
|
|
166
|
+
branches: [${branch}]
|
|
167
|
+
jobs:
|
|
168
|
+
deploy:
|
|
169
|
+
runs-on: ubuntu-latest
|
|
170
|
+
steps:
|
|
171
|
+
- uses: actions/checkout@v4
|
|
172
|
+
- uses: actions/setup-node@v4
|
|
173
|
+
with:
|
|
174
|
+
node-version: '${nodeVersion}'
|
|
175
|
+
cache: 'npm'
|
|
176
|
+
${buildSteps} - name: Install Magmonium CLI
|
|
177
|
+
run: npm install -g @magmonium/cli
|
|
178
|
+
- name: Deploy to Magmonium
|
|
179
|
+
run: mag-build deploy
|
|
180
|
+
env:
|
|
181
|
+
MAG_APP_ID: \${{ secrets.MAG_APP_ID }}
|
|
182
|
+
MAG_DEPLOY_TOKEN: \${{ secrets.MAG_DEPLOY_TOKEN }}
|
|
183
|
+
MAG_ENDPOINT: \${{ secrets.MAG_ENDPOINT }}
|
|
184
|
+
MAG_DIST_PATH: ${distPath}
|
|
185
|
+
`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = connectCommand;
|