@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
package/src/format.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human output for sdk-tools. Agents use --json; this is for people in a terminal.
|
|
3
|
+
*
|
|
4
|
+
* Colors come from node:util styleText, which turns them off when stdout is not a terminal, when
|
|
5
|
+
* NO_COLOR is set, or in CI logs without color support (and FORCE_COLOR turns them on).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { styleText } from 'node:util';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('./types.js').Finding} Finding
|
|
12
|
+
* @typedef {import('./types.js').CheckResult} CheckResult
|
|
13
|
+
* @typedef {Parameters<typeof styleText>[0]} Style
|
|
14
|
+
* @typedef {(format: Style, text: string | number) => string} Paint
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A painter that colors only when `stream` supports it.
|
|
19
|
+
* @param {NodeJS.WriteStream} [stream]
|
|
20
|
+
* @returns {Paint}
|
|
21
|
+
*/
|
|
22
|
+
function painter(stream = process.stdout) {
|
|
23
|
+
return (format, text) => styleText(format, String(text), { validateStream: true, stream });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} n
|
|
28
|
+
* @param {string} word
|
|
29
|
+
*/
|
|
30
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Findings grouped by file, then a summary: totals, the most frequent rules, fixable count, time.
|
|
34
|
+
* @param {CheckResult} result
|
|
35
|
+
* @param {{ paint?: Paint, quiet?: boolean, durationMs?: number, maxWarnings?: number }} [options]
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
export function formatCheck({ findings, counts, excepted = [] }, { paint = painter(), quiet = false, durationMs, maxWarnings } = {}) {
|
|
39
|
+
const shown = quiet ? findings.filter((f) => f.severity === 'error') : findings;
|
|
40
|
+
/** @type {string[]} */
|
|
41
|
+
const lines = [];
|
|
42
|
+
/** @type {Map<string, Finding[]>} */
|
|
43
|
+
const byFile = new Map();
|
|
44
|
+
for (const finding of shown) {
|
|
45
|
+
const key = [finding.repo, finding.file].filter(Boolean).join('/') || '(project)';
|
|
46
|
+
const list = byFile.get(key) ?? [];
|
|
47
|
+
list.push(finding);
|
|
48
|
+
byFile.set(key, list);
|
|
49
|
+
}
|
|
50
|
+
for (const [file, list] of byFile) {
|
|
51
|
+
lines.push('', paint('underline', file));
|
|
52
|
+
const width = Math.max(...list.map((f) => `${f.line}:${f.column}`.length));
|
|
53
|
+
for (const f of list) {
|
|
54
|
+
const where = paint('dim', `${f.line}:${f.column}`.padEnd(width));
|
|
55
|
+
const severity = f.severity === 'error' ? paint('red', 'error') : paint('yellow', 'warn ');
|
|
56
|
+
const fix = f.fixable ? paint('green', ' (fixable)') : '';
|
|
57
|
+
lines.push(` ${where} ${severity} ${f.message}${fix} ${paint('dim', f.rule)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
lines.push('');
|
|
62
|
+
if (excepted.length) lines.push(paint('dim', `${plural(excepted.length, 'finding')} excepted by sdk-tools.exceptions.json (see --json)`));
|
|
63
|
+
const total = counts.errors + counts.warnings;
|
|
64
|
+
if (!total) {
|
|
65
|
+
lines.push(`${paint('green', '✔')} No problems${durationMs !== undefined ? paint('dim', ` (${(durationMs / 1000).toFixed(1)}s)`) : ''}`);
|
|
66
|
+
return lines.join('\n').replace(/^\n/, '');
|
|
67
|
+
}
|
|
68
|
+
const failed = counts.errors > 0 || (maxWarnings !== undefined && counts.warnings > maxWarnings);
|
|
69
|
+
const mark = failed ? paint('red', '✖') : paint('yellow', '⚠');
|
|
70
|
+
const parts = [
|
|
71
|
+
counts.errors ? paint('red', plural(counts.errors, 'error')) : plural(0, 'error'),
|
|
72
|
+
counts.warnings ? paint('yellow', plural(counts.warnings, 'warning')) : plural(0, 'warning'),
|
|
73
|
+
];
|
|
74
|
+
lines.push(
|
|
75
|
+
`${mark} ${plural(total, 'problem')} (${parts.join(', ')})${durationMs !== undefined ? paint('dim', ` in ${(durationMs / 1000).toFixed(1)}s`) : ''}`,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
/** @type {Map<string, number>} */
|
|
79
|
+
const byRule = new Map();
|
|
80
|
+
for (const f of findings) byRule.set(f.rule, (byRule.get(f.rule) ?? 0) + 1);
|
|
81
|
+
const top = [...byRule].sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
82
|
+
if (byRule.size > 1) lines.push(paint('dim', ` most frequent: ${top.map(([rule, n]) => `${rule} ${n}`).join(', ')}`));
|
|
83
|
+
|
|
84
|
+
const fixable = findings.filter((f) => f.fixable).length;
|
|
85
|
+
if (fixable) lines.push(` ${paint('green', plural(fixable, 'problem'))} fixable with ${paint('bold', '--fix')}`);
|
|
86
|
+
if (quiet && counts.warnings) lines.push(paint('dim', ` ${plural(counts.warnings, 'warning')} hidden by --quiet`));
|
|
87
|
+
if (maxWarnings !== undefined && counts.warnings > maxWarnings) lines.push(paint('red', ` more than --max-warnings ${maxWarnings}`));
|
|
88
|
+
return lines.join('\n').replace(/^\n/, '');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Progress for slow steps, on stderr, only in an interactive terminal (never seen by pipes or agents).
|
|
93
|
+
* @param {NodeJS.WriteStream} [stream]
|
|
94
|
+
* @returns {(message: string) => void}
|
|
95
|
+
*/
|
|
96
|
+
export function progress(stream = process.stderr) {
|
|
97
|
+
if (!stream.isTTY || process.env.CI) return () => {};
|
|
98
|
+
const paint = painter(stream);
|
|
99
|
+
return (message) => {
|
|
100
|
+
stream.write(`\r\u001b[2K${message ? `${paint('cyan', '›')} ${message}` : ''}`);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdk-tools info`: the project context skills load at start (`npx @sixbell-telco/sdk-tools info --json`). It reads
|
|
3
|
+
* files only (no lint, no type check, no npm), so it stays fast, and it always answers: a folder that
|
|
4
|
+
* is not an app is `role: "none"` with empty fields. The JSON shape is versioned by `schemaVersion`
|
|
5
|
+
* and documented in the README; add fields, never rename or remove them.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { join, resolve } from 'node:path';
|
|
9
|
+
import { readJson, readProject, readText, walk } from '../project/project.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('../types.js').ContextInfo} ContextInfo
|
|
13
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
14
|
+
* @typedef {import('../types.js').PackageJson} PackageJson
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const INFO_SCHEMA_VERSION = 1;
|
|
18
|
+
const SDK = '@sixbell-telco/sdk';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The version range package.json declares for `name` (dependencies, then dev, then peer).
|
|
22
|
+
* @param {PackageJson | null} pkg
|
|
23
|
+
* @param {string} name
|
|
24
|
+
* @returns {string | null}
|
|
25
|
+
*/
|
|
26
|
+
export function declaredRange(pkg, name) {
|
|
27
|
+
return pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name] ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The installed version of `name`: node_modules first (what runs), else the top-level lock entry.
|
|
32
|
+
* @param {ProjectInfo} project
|
|
33
|
+
* @param {string} name
|
|
34
|
+
* @returns {string | null}
|
|
35
|
+
*/
|
|
36
|
+
function installedVersion(project, name) {
|
|
37
|
+
const fromModules = readJson(project.root, `node_modules/${name}/package.json`)?.version;
|
|
38
|
+
if (typeof fromModules === 'string') return fromModules;
|
|
39
|
+
return project.installed(name).find((entry) => entry.path === `node_modules/${name}`)?.version ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The SDK entry points the app's sources import (static and dynamic imports), sorted.
|
|
44
|
+
* @param {string} root
|
|
45
|
+
* @returns {string[]}
|
|
46
|
+
*/
|
|
47
|
+
function kitEntryPoints(root) {
|
|
48
|
+
const found = new Set();
|
|
49
|
+
const pattern = /(?:from|import)\s*\(?\s*['"](@sixbell-telco\/sdk(?:\/[^'"]+)?)['"]/g;
|
|
50
|
+
for (const file of walk(root, 'src', (name) => name.endsWith('.ts'))) {
|
|
51
|
+
const source = readText(root, file) ?? '';
|
|
52
|
+
if (!source.includes(SDK)) continue;
|
|
53
|
+
for (const match of source.matchAll(pattern)) found.add(match[1]);
|
|
54
|
+
}
|
|
55
|
+
return [...found].sort();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The themes the app ships: src/assets/themes/themes.json (default and catalog names), else the
|
|
60
|
+
* `themes` list of mfe-foundation.config.json.
|
|
61
|
+
* @param {string} root
|
|
62
|
+
* @param {any} foundation
|
|
63
|
+
* @returns {ContextInfo['theme']}
|
|
64
|
+
*/
|
|
65
|
+
function themes(root, foundation) {
|
|
66
|
+
const file = 'src/assets/themes/themes.json';
|
|
67
|
+
const index = readJson(root, file);
|
|
68
|
+
if (index && typeof index === 'object') {
|
|
69
|
+
/** @type {unknown[]} */
|
|
70
|
+
const entries = Array.isArray(index.themes) ? index.themes : [];
|
|
71
|
+
const names = entries
|
|
72
|
+
.filter((entry) => typeof entry === 'string')
|
|
73
|
+
.map((/** @type {string} */ entry) => (entry.split('/').pop() ?? entry).replace(/\.json$/, ''));
|
|
74
|
+
return { default: typeof index.defaultTheme === 'string' ? index.defaultTheme : (names[0] ?? null), themes: names, source: file };
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(foundation?.themes)) {
|
|
77
|
+
const names = foundation.themes.filter((/** @type {unknown} */ name) => typeof name === 'string');
|
|
78
|
+
return { default: names[0] ?? null, themes: names, source: 'mfe-foundation.config.json' };
|
|
79
|
+
}
|
|
80
|
+
return { default: null, themes: [], source: null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Reads the project context of the app at `cwd`.
|
|
85
|
+
* @param {{ cwd?: string }} [options]
|
|
86
|
+
* @returns {ContextInfo}
|
|
87
|
+
*/
|
|
88
|
+
export function info({ cwd = process.cwd() } = {}) {
|
|
89
|
+
const root = resolve(cwd);
|
|
90
|
+
const project = readProject(root);
|
|
91
|
+
const foundation = readJson(root, 'mfe-foundation.config.json');
|
|
92
|
+
const layout = foundation?.layout;
|
|
93
|
+
return {
|
|
94
|
+
schemaVersion: INFO_SCHEMA_VERSION,
|
|
95
|
+
root,
|
|
96
|
+
name: typeof project.packageJson?.name === 'string' ? project.packageJson.name : null,
|
|
97
|
+
role: project.role ?? 'none',
|
|
98
|
+
roleSource: project.roleSource,
|
|
99
|
+
kit: {
|
|
100
|
+
declared: declaredRange(project.packageJson, SDK),
|
|
101
|
+
installed: installedVersion(project, SDK),
|
|
102
|
+
entryPoints: kitEntryPoints(root),
|
|
103
|
+
},
|
|
104
|
+
angular: {
|
|
105
|
+
declared: declaredRange(project.packageJson, '@angular/core'),
|
|
106
|
+
installed: installedVersion(project, '@angular/core'),
|
|
107
|
+
},
|
|
108
|
+
theme: themes(root, foundation),
|
|
109
|
+
layout: layout && typeof layout === 'object' && !Array.isArray(layout) ? layout : null,
|
|
110
|
+
federation: project.federation ? { name: project.federation.name, exposes: project.federation.exposes, remotes: project.remotes } : null,
|
|
111
|
+
files: {
|
|
112
|
+
designMd: existsSync(join(root, 'DESIGN.md')),
|
|
113
|
+
agentsMd: existsSync(join(root, 'AGENTS.md')),
|
|
114
|
+
foundationConfig: existsSync(join(root, 'mfe-foundation.config.json')),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {ContextInfo} data
|
|
121
|
+
* @returns {string}
|
|
122
|
+
*/
|
|
123
|
+
export function formatInfo(data) {
|
|
124
|
+
/** @param {boolean} value */
|
|
125
|
+
const yes = (value) => (value ? 'yes' : 'no');
|
|
126
|
+
const exposes = data.federation ? Object.keys(data.federation.exposes) : [];
|
|
127
|
+
const lines = [
|
|
128
|
+
`${data.name ?? data.root}`,
|
|
129
|
+
` role ${data.role} (${data.roleSource})`,
|
|
130
|
+
` kit ${data.kit.installed ?? 'not installed'}${data.kit.declared ? ` (package.json ${data.kit.declared})` : ''}`,
|
|
131
|
+
` angular ${data.angular.installed ?? 'not installed'}${data.angular.declared ? ` (package.json ${data.angular.declared})` : ''}`,
|
|
132
|
+
` theme ${data.theme.default ?? 'none'}${data.theme.themes.length ? ` of ${data.theme.themes.join(', ')}` : ''}`,
|
|
133
|
+
` layout ${
|
|
134
|
+
data.layout
|
|
135
|
+
? Object.entries(data.layout)
|
|
136
|
+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
137
|
+
.join(' ')
|
|
138
|
+
: 'none'
|
|
139
|
+
}`,
|
|
140
|
+
];
|
|
141
|
+
if (data.federation) {
|
|
142
|
+
lines.push(` federation ${data.federation.name ?? '(no name)'}`);
|
|
143
|
+
if (exposes.length) lines.push(` exposes ${exposes.join(', ')}`);
|
|
144
|
+
if (data.federation.remotes.length) lines.push(` remotes ${data.federation.remotes.join(', ')}`);
|
|
145
|
+
}
|
|
146
|
+
lines.push(` DESIGN.md ${yes(data.files.designMd)}`, ` AGENTS.md ${yes(data.files.agentsMd)}`);
|
|
147
|
+
lines.push(` entry points ${data.kit.entryPoints.length ? '' : 'none'}`, ...data.kit.entryPoints.map((entry) => ` ${entry}`));
|
|
148
|
+
return lines.join('\n');
|
|
149
|
+
}
|