@sixbell-telco/sdk-tools 0.0.0 → 0.1.1
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/CHANGELOG.md +38 -0
- package/README.md +277 -2
- package/data/security-floors.json +47 -0
- package/package.json +40 -4
- package/recipes/README.md +53 -0
- package/recipes/crud-list.md +21 -0
- package/recipes/custom-component.md +35 -0
- package/recipes/detail-page.md +19 -0
- package/recipes/form-dialog.md +17 -0
- package/recipes/parts/crud-list/i18n.json +83 -0
- package/recipes/parts/crud-list/src/app/features/__name__/__name__.routes.ts.tpl +30 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.html.tpl +102 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.spec.ts.tpl +101 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.ts.tpl +143 -0
- package/recipes/parts/detail-page/i18n.json +32 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.html.tpl +35 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.spec.ts.tpl +58 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.ts.tpl +68 -0
- package/recipes/parts/entity/i18n.json +5 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.model.ts.tpl +9 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.spec.ts.tpl +29 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.ts.tpl +33 -0
- package/recipes/parts/form-dialog/i18n.json +35 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.html.tpl +33 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.spec.ts.tpl +69 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.ts.tpl +73 -0
- package/src/add/add.mjs +251 -0
- package/src/check/config.mjs +112 -0
- package/src/check/exceptions.mjs +103 -0
- package/src/check/federation.mjs +224 -0
- package/src/check/finding.mjs +23 -0
- package/src/check/harness.mjs +146 -0
- package/src/check/i18n.mjs +218 -0
- package/src/check/integration.mjs +566 -0
- package/src/check/security.mjs +165 -0
- package/src/check/steps.mjs +37 -0
- package/src/check/styles.mjs +347 -0
- package/src/check/wiring.mjs +198 -0
- package/src/check.mjs +333 -0
- package/src/cli.mjs +551 -0
- package/src/docs/docs.mjs +154 -0
- package/src/doctor/doctor.mjs +492 -0
- package/src/format.mjs +102 -0
- package/src/info/info.mjs +149 -0
- package/src/init/init.mjs +490 -0
- package/src/init/merge.mjs +191 -0
- package/src/init/template.mjs +292 -0
- package/src/mcp/catalog.mjs +248 -0
- package/src/mcp/glossary.mjs +75 -0
- package/src/mcp/manifest.mjs +53 -0
- package/src/mcp/recipes.mjs +198 -0
- package/src/mcp/server.mjs +249 -0
- package/src/mcp/upgrade-guide.mjs +116 -0
- package/src/mcp/usage.mjs +48 -0
- package/src/project/project.mjs +220 -0
- package/src/types.d.ts +448 -0
- package/src/upgrade/lockstep.mjs +153 -0
- package/src/upgrade/upgrade.mjs +623 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18n step: the runtime translation config, the app bundles per language, and the SDK bundles
|
|
3
|
+
* served from the installed package.
|
|
4
|
+
* Ids: MFE_I18N_001..009, MFE_CHILD_I18N_001..005, MFE_CHILD_I18N_WARN_001, MFE_TRANSLATIONS_001,
|
|
5
|
+
* MFE_ASSET_I18N_001, MFE_I18N_SDK_001.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { readJson, readText, walk } from '../project/project.mjs';
|
|
11
|
+
import { finding } from './finding.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
15
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const TRANSLATION = 'src/assets/translation/translation.json';
|
|
19
|
+
const SDK_LANGUAGES = ['en', 'es', 'pt'];
|
|
20
|
+
const SDK_I18N = 'node_modules/@sixbell-telco/sdk/i18n/sdk';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Dot paths of `common.default_page_title` at any depth.
|
|
24
|
+
* @param {unknown} bundle
|
|
25
|
+
* @param {string[]} [trail]
|
|
26
|
+
* @returns {string[]}
|
|
27
|
+
*/
|
|
28
|
+
function hostTitleKeys(bundle, trail = []) {
|
|
29
|
+
if (!bundle || typeof bundle !== 'object') return [];
|
|
30
|
+
return Object.entries(bundle).flatMap(([key, value]) => {
|
|
31
|
+
const path = [...trail, key];
|
|
32
|
+
return [...(key === 'default_page_title' && path.at(-2) === 'common' ? [path.join('.')] : []), ...hostTitleKeys(value, path)];
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {ProjectInfo} project
|
|
38
|
+
* @returns {Finding[]}
|
|
39
|
+
*/
|
|
40
|
+
function runtimeConfig(project) {
|
|
41
|
+
const { root, role } = project;
|
|
42
|
+
const child = role === 'child';
|
|
43
|
+
const id = (/** @type {number} */ n) => (child ? `MFE_CHILD_I18N_00${n}` : `MFE_I18N_00${n}`);
|
|
44
|
+
const translation = readJson(root, TRANSLATION);
|
|
45
|
+
if (!translation) {
|
|
46
|
+
if (readText(root, TRANSLATION) !== null) return []; // invalid JSON: MFE_JSON_001
|
|
47
|
+
return [finding(id(1), TRANSLATION, 'The runtime translation config is missing (sdk-tools init creates it).')];
|
|
48
|
+
}
|
|
49
|
+
/** @type {Finding[]} */
|
|
50
|
+
const findings = [];
|
|
51
|
+
if (!translation.meta || !translation.defaultLang || !Array.isArray(translation.translationPaths) || !translation.locale?.languageToLocale)
|
|
52
|
+
findings.push(
|
|
53
|
+
finding(
|
|
54
|
+
id(2),
|
|
55
|
+
TRANSLATION,
|
|
56
|
+
'translation.json follows the SDK runtime schema: meta, defaultLang, translationPaths (strings) and locale.languageToLocale.',
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
const languages = Object.keys(translation.locale?.languageToLocale ?? {});
|
|
60
|
+
if (translation.defaultLang && languages.length && !languages.includes(translation.defaultLang))
|
|
61
|
+
findings.push(
|
|
62
|
+
finding(id(3), TRANSLATION, `defaultLang "${translation.defaultLang}" is not one of locale.languageToLocale (${languages.join(', ')}).`),
|
|
63
|
+
);
|
|
64
|
+
if (translation.meta && Array.isArray(translation.additionalLanguages)) {
|
|
65
|
+
for (const [index, entry] of translation.additionalLanguages.entries()) {
|
|
66
|
+
if (!entry || typeof entry !== 'object' || typeof entry.code !== 'string' || typeof entry.name !== 'string')
|
|
67
|
+
findings.push(
|
|
68
|
+
finding(
|
|
69
|
+
'MFE_TRANSLATIONS_001',
|
|
70
|
+
TRANSLATION,
|
|
71
|
+
`additionalLanguages[${index}] is ${JSON.stringify(entry)}: each entry is { "code": "<language>", "name": "<display name>" }.`,
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const language of languages) {
|
|
77
|
+
const file = `src/assets/i18n/${language}.json`;
|
|
78
|
+
const bundle = readJson(root, file);
|
|
79
|
+
if (!bundle) {
|
|
80
|
+
if (readText(root, file) === null)
|
|
81
|
+
findings.push(finding(child ? 'MFE_CHILD_I18N_004' : 'MFE_I18N_005', file, `Missing the i18n bundle of the enabled language "${language}".`));
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (child) {
|
|
85
|
+
const keys = hostTitleKeys(bundle);
|
|
86
|
+
if (keys.length)
|
|
87
|
+
findings.push(finding('MFE_CHILD_I18N_005', file, `A child does not ship the host-owned title key: remove ${keys.join(', ')}.`));
|
|
88
|
+
if (!JSON.stringify(bundle).includes('mfe_'))
|
|
89
|
+
findings.push(
|
|
90
|
+
finding('MFE_CHILD_I18N_WARN_001', file, 'Child keys live under the mfe_<name>.* namespace, so they never collide in the host.', {
|
|
91
|
+
severity: 'warn',
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!bundle.common) findings.push(finding('MFE_I18N_006', file, 'Missing the common.* baseline translations.'));
|
|
97
|
+
if (!bundle.status_pages) findings.push(finding('MFE_I18N_007', file, 'The host status routes need the status_pages.* baseline translations.'));
|
|
98
|
+
const permissions = `src/assets/i18n/permissions/${language}.json`;
|
|
99
|
+
if (!existsSync(join(root, permissions)))
|
|
100
|
+
findings.push(finding('MFE_I18N_008', permissions, `Missing the permissions bundle of the enabled language "${language}".`));
|
|
101
|
+
}
|
|
102
|
+
if (!child) {
|
|
103
|
+
const appText = walk(root, 'src/app', (file) => /\.(ts|html)$/.test(file) && !file.endsWith('.spec.ts'))
|
|
104
|
+
.map((file) => readText(root, file) ?? '')
|
|
105
|
+
.join('\n');
|
|
106
|
+
const selector = /getAvailableLanguagesConfig|\[showLanguageSelector\]\s*=\s*"(?!false)/.test(appText);
|
|
107
|
+
if (languages.length === 1 && selector)
|
|
108
|
+
findings.push(finding('MFE_I18N_004', 'src/app', 'Hide the language selector: only one language is enabled.'));
|
|
109
|
+
if (languages.length > 1 && !selector)
|
|
110
|
+
findings.push(finding('MFE_I18N_009', 'src/app', 'Show the language selector: more than one language is enabled.'));
|
|
111
|
+
}
|
|
112
|
+
return findings;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Whether every `assets` array in angular.json serves the SDK i18n bundles from node_modules.
|
|
117
|
+
* @param {ProjectInfo} project
|
|
118
|
+
* @returns {boolean | null} null when angular.json declares no assets
|
|
119
|
+
*/
|
|
120
|
+
function servesSdkI18n(project) {
|
|
121
|
+
const arrays = Object.values(project.angular?.projects ?? {}).flatMap((ngProject) =>
|
|
122
|
+
Object.values(ngProject.targets).flatMap((target) =>
|
|
123
|
+
[target.options?.assets, ...Object.values(target.configurations ?? {}).map((c) => c?.assets)].filter(Array.isArray),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
if (!arrays.length) return null;
|
|
127
|
+
return arrays.every((assets) =>
|
|
128
|
+
assets.some(
|
|
129
|
+
(asset) =>
|
|
130
|
+
typeof asset === 'object' &&
|
|
131
|
+
asset &&
|
|
132
|
+
/node_modules\/@sixbell-telco\/sdk\/i18n\/sdk\/?$/.test(String(asset.input ?? '')) &&
|
|
133
|
+
/assets\/i18n\/sdk\/?$/.test(String(asset.output ?? '')),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Translation keys the installed SDK build references (sdk.* literals in fesm2022).
|
|
140
|
+
* @param {string} root
|
|
141
|
+
*/
|
|
142
|
+
function installedSdkKeys(root) {
|
|
143
|
+
const dir = join(root, 'node_modules/@sixbell-telco/sdk/fesm2022');
|
|
144
|
+
if (!existsSync(dir)) return null;
|
|
145
|
+
/** @type {Set<string>} */
|
|
146
|
+
const keys = new Set();
|
|
147
|
+
for (const name of readdirSync(dir).filter((entry) => entry.endsWith('.mjs'))) {
|
|
148
|
+
for (const [, key] of (readText(dir, name) ?? '').matchAll(/['"`](sdk(?:\.[A-Za-z0-9_]+)+)['"`]/g)) keys.add(key);
|
|
149
|
+
}
|
|
150
|
+
return [...keys].sort();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {unknown} bundle
|
|
155
|
+
* @param {string} key
|
|
156
|
+
*/
|
|
157
|
+
function hasKey(bundle, key) {
|
|
158
|
+
/** @type {any} */
|
|
159
|
+
let node = bundle;
|
|
160
|
+
for (const part of key.split('.')) node = node && typeof node === 'object' ? node[part] : undefined;
|
|
161
|
+
return typeof node === 'string';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* MFE_ASSET_I18N_001: no copied SDK bundles, the node_modules asset glob in place.
|
|
166
|
+
* MFE_I18N_SDK_001: the served bundles hold every key the installed SDK uses.
|
|
167
|
+
* @param {ProjectInfo} project
|
|
168
|
+
* @returns {Finding[]}
|
|
169
|
+
*/
|
|
170
|
+
function sdkBundles(project) {
|
|
171
|
+
const { root } = project;
|
|
172
|
+
/** @type {Finding[]} */
|
|
173
|
+
const findings = [];
|
|
174
|
+
const copies = SDK_LANGUAGES.map((language) => `src/assets/i18n/sdk/${language}.json`).filter((file) => existsSync(join(root, file)));
|
|
175
|
+
for (const file of copies)
|
|
176
|
+
findings.push(
|
|
177
|
+
finding(
|
|
178
|
+
'MFE_ASSET_I18N_001',
|
|
179
|
+
file,
|
|
180
|
+
'Delete the copied SDK i18n bundle: angular.json serves node_modules/@sixbell-telco/sdk/i18n/sdk through an asset glob.',
|
|
181
|
+
),
|
|
182
|
+
);
|
|
183
|
+
if (servesSdkI18n(project) === false)
|
|
184
|
+
findings.push(
|
|
185
|
+
finding(
|
|
186
|
+
'MFE_ASSET_I18N_001',
|
|
187
|
+
'angular.json',
|
|
188
|
+
'Every assets array serves the SDK i18n bundles: add { "glob": "**/*.json", "input": "node_modules/@sixbell-telco/sdk/i18n/sdk", "output": "assets/i18n/sdk" }.',
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
const keys = installedSdkKeys(root);
|
|
192
|
+
if (!keys) return findings;
|
|
193
|
+
const bundles = copies.length
|
|
194
|
+
? copies
|
|
195
|
+
: SDK_LANGUAGES.map((language) => `${SDK_I18N}/${language}.json`).filter((file) => existsSync(join(root, file)));
|
|
196
|
+
for (const file of bundles) {
|
|
197
|
+
const bundle = readJson(root, file);
|
|
198
|
+
const missing = keys.filter((key) => !hasKey(bundle, key));
|
|
199
|
+
if (missing.length)
|
|
200
|
+
findings.push(
|
|
201
|
+
finding(
|
|
202
|
+
'MFE_I18N_SDK_001',
|
|
203
|
+
file,
|
|
204
|
+
`The SDK i18n bundle lacks ${missing.length} key(s) the installed SDK uses: ${missing.slice(0, 10).join(', ')}${missing.length > 10 ? ', …' : ''}. Reinstall the SDK; do not copy its bundles.`,
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return findings;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @param {ProjectInfo} project
|
|
213
|
+
* @returns {Finding[]}
|
|
214
|
+
*/
|
|
215
|
+
export function i18nStep(project) {
|
|
216
|
+
if (!project.role) return [];
|
|
217
|
+
return [...runtimeConfig(project), ...sdkBundles(project)];
|
|
218
|
+
}
|