@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,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security step: installed versions against the minimum safe versions shipped with sdk-tools
|
|
3
|
+
* (data/security-floors.json). The lockfile gives every installed copy, so a transitive package
|
|
4
|
+
* below its floor is reported with the override that fixes it.
|
|
5
|
+
* Ids: MFE_SEC_DEPS_002..010 (001 and 011, a missing package.json or security script, are doctor's).
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
|
|
9
|
+
import { finding } from './finding.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
13
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
14
|
+
* @typedef {{ direct: Record<string, string>, overrides: Record<string, string>, nestedOverrides: Record<string, string>, scripts: Record<string, string> }} Floors
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @returns {Floors} */
|
|
18
|
+
function loadFloors() {
|
|
19
|
+
return JSON.parse(readFileSync(new URL('../../data/security-floors.json', import.meta.url), 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The lowest x.y.z a version or range allows (`^19.2.3` is 19.2.3), or null.
|
|
24
|
+
* @param {unknown} raw
|
|
25
|
+
* @returns {number[] | null}
|
|
26
|
+
*/
|
|
27
|
+
function parseVersion(raw) {
|
|
28
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(String(raw ?? '').replace(/^[\s~^>=<v]+/, ''));
|
|
29
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {unknown} version
|
|
34
|
+
* @param {string} floor
|
|
35
|
+
*/
|
|
36
|
+
function meetsFloor(version, floor) {
|
|
37
|
+
const actual = parseVersion(version);
|
|
38
|
+
const minimum = parseVersion(floor);
|
|
39
|
+
if (!actual || !minimum) return true; // a tag, URL or workspace range: nothing to compare
|
|
40
|
+
for (let index = 0; index < 3; index += 1) if (actual[index] !== minimum[index]) return actual[index] > minimum[index];
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {ProjectInfo} project
|
|
46
|
+
* @param {Floors} [floors]
|
|
47
|
+
* @returns {Finding[]}
|
|
48
|
+
*/
|
|
49
|
+
export function securityStep(project, floors = loadFloors()) {
|
|
50
|
+
const pkg = project.packageJson;
|
|
51
|
+
if (!pkg) return [];
|
|
52
|
+
/** @type {Finding[]} */
|
|
53
|
+
const findings = [];
|
|
54
|
+
const declared = { ...pkg.optionalDependencies, ...pkg.devDependencies, ...pkg.dependencies };
|
|
55
|
+
for (const [name, floor] of Object.entries(floors.direct)) {
|
|
56
|
+
if (!(name in declared)) {
|
|
57
|
+
if (project.role)
|
|
58
|
+
findings.push(
|
|
59
|
+
finding('MFE_SEC_DEPS_002', 'package.json', `Missing the direct dependency ${name} (floor ${floor}). Fix: npm install -D ${name}@${floor}`),
|
|
60
|
+
);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const installed = project.installed(name).find((copy) => copy.path === `node_modules/${name}`)?.version;
|
|
64
|
+
const version = installed ?? declared[name];
|
|
65
|
+
if (!meetsFloor(version, floor))
|
|
66
|
+
findings.push(
|
|
67
|
+
finding(
|
|
68
|
+
'MFE_SEC_DEPS_003',
|
|
69
|
+
'package.json',
|
|
70
|
+
`${name} is ${installed ? `installed at ${installed}` : declared[name]} (declared ${declared[name]}); the floor is ${floor}. Fix: npm install ${name}@${floor}${name.startsWith('@angular/') ? ' with the other @angular packages in lockstep' : ''}.`,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const overrides = pkg.overrides && typeof pkg.overrides === 'object' ? /** @type {Record<string, any>} */ (pkg.overrides) : null;
|
|
76
|
+
/** @type {string[]} */
|
|
77
|
+
const unpinned = [];
|
|
78
|
+
for (const [name, floor] of Object.entries(floors.overrides)) {
|
|
79
|
+
// A copy under a parent with its own nested floor is judged there (MFE_SEC_DEPS_007/008).
|
|
80
|
+
const nested = Object.keys(floors.nestedOverrides)
|
|
81
|
+
.filter((dotted) => dotted.endsWith(`.${name}`))
|
|
82
|
+
.map((dotted) => `node_modules/${dotted.slice(0, -name.length - 1)}/node_modules/${name}`);
|
|
83
|
+
const below = project.installed(name).filter((copy) => !meetsFloor(copy.version, floor) && !nested.some((path) => copy.path.endsWith(path)));
|
|
84
|
+
const pinned = typeof overrides?.[name] === 'string' ? overrides[name] : null;
|
|
85
|
+
if (pinned !== null && !meetsFloor(pinned, floor)) {
|
|
86
|
+
findings.push(
|
|
87
|
+
finding(
|
|
88
|
+
'MFE_SEC_DEPS_006',
|
|
89
|
+
'package.json',
|
|
90
|
+
`The override for ${name} is ${pinned}; the floor is ${floor}. Fix: set "overrides": { "${name}": "${floor}" } and run npm install.`,
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (!below.length) continue;
|
|
96
|
+
const where = below.map((copy) => `${copy.version} at ${copy.path}`).join(', ');
|
|
97
|
+
if (pinned === null) {
|
|
98
|
+
unpinned.push(name);
|
|
99
|
+
if (overrides)
|
|
100
|
+
findings.push(
|
|
101
|
+
finding(
|
|
102
|
+
'MFE_SEC_DEPS_005',
|
|
103
|
+
'package.json',
|
|
104
|
+
`${name} is installed below its floor ${floor} (${where}). Fix: add "overrides": { "${name}": "${floor}" } and run npm install.`,
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
} else
|
|
108
|
+
findings.push(
|
|
109
|
+
finding(
|
|
110
|
+
'MFE_SEC_DEPS_006',
|
|
111
|
+
'package.json',
|
|
112
|
+
`${name} is still installed below its floor ${floor} (${where}) despite the override. Fix: run npm install to apply the override.`,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (!overrides && unpinned.length)
|
|
117
|
+
findings.push(
|
|
118
|
+
finding(
|
|
119
|
+
'MFE_SEC_DEPS_004',
|
|
120
|
+
'package.json',
|
|
121
|
+
`Transitive packages are installed below their floors (${unpinned.join(', ')}) and package.json has no "overrides" block. Fix: add one pinning ${unpinned.map((name) => `"${name}": "${floors.overrides[name]}"`).join(', ')}, then npm install.`,
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
for (const [dotted, floor] of Object.entries(floors.nestedOverrides)) {
|
|
126
|
+
const at = dotted.lastIndexOf('.');
|
|
127
|
+
const [parent, child] = [dotted.slice(0, at), dotted.slice(at + 1)];
|
|
128
|
+
const pinned = overrides?.[parent]?.[child];
|
|
129
|
+
const below = project
|
|
130
|
+
.installed(child)
|
|
131
|
+
.filter((copy) => copy.path.includes(`node_modules/${parent}/node_modules/${child}`) && !meetsFloor(copy.version, floor));
|
|
132
|
+
if (typeof pinned === 'string' && !meetsFloor(pinned, floor))
|
|
133
|
+
findings.push(
|
|
134
|
+
finding(
|
|
135
|
+
'MFE_SEC_DEPS_008',
|
|
136
|
+
'package.json',
|
|
137
|
+
`The nested override ${parent} > ${child} is ${pinned}; the floor is ${floor}. Fix: set "overrides": { "${parent}": { "${child}": "${floor}" } }.`,
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
else if (below.length)
|
|
141
|
+
findings.push(
|
|
142
|
+
finding(
|
|
143
|
+
typeof pinned === 'string' ? 'MFE_SEC_DEPS_008' : 'MFE_SEC_DEPS_007',
|
|
144
|
+
'package.json',
|
|
145
|
+
`${child} under ${parent} is installed at ${below.map((copy) => copy.version).join(', ')}, below its floor ${floor}. Fix: ${typeof pinned === 'string' ? 'run npm install to apply the override' : `add "overrides": { "${parent}": { "${child}": "${floor}" } } and run npm install`}.`,
|
|
146
|
+
),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (project.role) {
|
|
151
|
+
for (const [name, expected] of Object.entries(floors.scripts)) {
|
|
152
|
+
if (pkg.scripts?.[name] !== expected)
|
|
153
|
+
findings.push(
|
|
154
|
+
finding(
|
|
155
|
+
'MFE_SEC_DEPS_009',
|
|
156
|
+
'package.json',
|
|
157
|
+
`Script "${name}" must be exactly "${expected}" (it is ${pkg.scripts?.[name] === undefined ? 'missing' : JSON.stringify(pkg.scripts[name])}).`,
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (!String(pkg.scripts?.lint ?? '').includes('security:check'))
|
|
162
|
+
findings.push(finding('MFE_SEC_DEPS_010', 'package.json', 'Script "lint" must run "npm run security:check" before eslint (CI runs lint).'));
|
|
163
|
+
}
|
|
164
|
+
return findings;
|
|
165
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project-level steps of `check`, run over one read of the project. Each finding's rule is
|
|
3
|
+
* the stable mfe-tools id (MFE_*, DS_*), repeated as its `id`, so a script or an exception can match it.
|
|
4
|
+
*/
|
|
5
|
+
import { readProject } from '../project/project.mjs';
|
|
6
|
+
import { configStep } from './config.mjs';
|
|
7
|
+
import { federationStep } from './federation.mjs';
|
|
8
|
+
import { harnessStep } from './harness.mjs';
|
|
9
|
+
import { i18nStep } from './i18n.mjs';
|
|
10
|
+
import { securityStep } from './security.mjs';
|
|
11
|
+
import { stylesStep } from './styles.mjs';
|
|
12
|
+
import { wiringStep } from './wiring.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
16
|
+
* @typedef {import('../types.js').ProjectStep} ProjectStep
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** @type {Record<string, ProjectStep>} */
|
|
20
|
+
const PROJECT_STEPS = {
|
|
21
|
+
federation: federationStep,
|
|
22
|
+
harness: harnessStep,
|
|
23
|
+
wiring: wiringStep,
|
|
24
|
+
config: configStep,
|
|
25
|
+
i18n: i18nStep,
|
|
26
|
+
styles: stylesStep,
|
|
27
|
+
security: (project) => securityStep(project),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} root
|
|
32
|
+
* @returns {Finding[]}
|
|
33
|
+
*/
|
|
34
|
+
export function projectFindings(root) {
|
|
35
|
+
const project = readProject(root);
|
|
36
|
+
return Object.values(PROJECT_STEPS).flatMap((step) => step(project).map((item) => ({ ...item, id: item.rule })));
|
|
37
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS and theme step: the design-system contract over the app's own stylesheets (styles.css and
|
|
3
|
+
* component .css) and its theme catalogs. Literal colors belong to theme definitions only: the
|
|
4
|
+
* catalogs under src/assets/themes and `@plugin "daisyui/theme"` / `@theme` blocks. Sass and Less
|
|
5
|
+
* files are a finding: the kit is Tailwind CSS 4 over plain CSS, and their rules are checked like CSS.
|
|
6
|
+
* Component styles (a component's inline `styles` and its `styleUrl`/`styleUrls` files) also must not
|
|
7
|
+
* select kit internals (`.st-*` classes, `st-*` elements); the Tailwind entry and other global
|
|
8
|
+
* stylesheets are not component styles.
|
|
9
|
+
* Ids: DS_COLOR_LITERAL, DS_COLOR_PALETTE, DS_SHADOW_RAW, DS_FONT_FAMILY, DS_THEME_TOKEN_OVERRIDE,
|
|
10
|
+
* DS_THEME_DUPLICATE, DS_MODIFIER_UNSAFE, DS_THEME_STALE_IDENTITY, DS_SIXBELL_LEGACY (review: warn),
|
|
11
|
+
* DS_POPPINS_LEGACY, DS_SCSS_FILE, DS_COMPONENT_COLOR_LITERAL, DS_KIT_RESTYLE, MFE_STATUS_CSS_001.
|
|
12
|
+
*/
|
|
13
|
+
import { dirname, join, normalize } from 'node:path/posix';
|
|
14
|
+
|
|
15
|
+
import { readJson, readText, walk } from '../project/project.mjs';
|
|
16
|
+
import { finding, position } from './finding.mjs';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
20
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const COLOR_LITERAL = /(?<![&\w-])#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3,4})\b|\b(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb)\(/i;
|
|
24
|
+
const PALETTE_COLOR =
|
|
25
|
+
/\b(?:bg|text|border|ring|fill|stroke|from|via|to|outline|decoration|caret|accent|shadow|divide)-(?:red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|slate|gray|zinc|neutral|stone)-(?:50|[1-9]00|950)\b|\b(?:bg|text|border|ring|fill|stroke)-(?:white|black)\b/;
|
|
26
|
+
const BOX_SHADOW = /\bbox-shadow\s*:\s*([^;}]+)/i;
|
|
27
|
+
const FONT_FAMILY = /\bfont-family\s*:\s*([^;}]+)/i;
|
|
28
|
+
const TOKEN_OVERRIDE = /(?:^|[\s;{])(--(?:radius-[\w-]+|size-(?:field|selector)|border|depth|noise))\s*:/;
|
|
29
|
+
const ALLOWED_BOX_SHADOW = /^(?:var\(--shadow-[\w-]+\)|none|inherit|initial|unset)(?:\s*!important)?$/;
|
|
30
|
+
const ALLOWED_FONT_FAMILY = /^(?:var\(--font-[\w-]+|inherit|initial|unset|ui-monospace|monospace)/;
|
|
31
|
+
const MODIFIER_UNSAFE = /\.(?:btn|badge|input|select|textarea|checkbox|radio|link|progress|toggle|menu|tabs|alert)\b[^{]*:not\(([^)]*)\)/gi;
|
|
32
|
+
const MODIFIER_COLOR =
|
|
33
|
+
/\.(?:btn|badge|input|select|textarea|checkbox|radio|link|progress|toggle|menu|tabs|alert)-(?:primary|secondary|tertiary|neutral|accent|info|success|warning|error)\b/g;
|
|
34
|
+
|
|
35
|
+
/** Blanks every character but newlines, so offsets and line numbers hold. */
|
|
36
|
+
const blank = (/** @type {string} */ text) => text.replace(/[^\n]/g, ' ');
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `css` with comments and theme definition blocks blanked (same length, newlines kept), so line
|
|
40
|
+
* numbers hold and theme colors are not reported.
|
|
41
|
+
* @param {string} css
|
|
42
|
+
*/
|
|
43
|
+
function blankThemeBlocks(css) {
|
|
44
|
+
let out = css.replace(/\/\*[\s\S]*?\*\//g, blank);
|
|
45
|
+
for (const opener of out.matchAll(/@plugin\s+["']daisyui\/theme["']\s*\{|@theme\b[^{;]*\{/g)) {
|
|
46
|
+
let depth = 0;
|
|
47
|
+
const start = opener.index + opener[0].length - 1;
|
|
48
|
+
for (let index = start; index < out.length; index += 1) {
|
|
49
|
+
if (out[index] === '{') depth += 1;
|
|
50
|
+
else if (out[index] === '}' && --depth === 0) {
|
|
51
|
+
out = out.slice(0, start + 1) + blank(out.slice(start + 1, index)) + out.slice(index);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Findings for one app stylesheet.
|
|
61
|
+
* @param {string} file
|
|
62
|
+
* @param {string} css
|
|
63
|
+
* @returns {Finding[]}
|
|
64
|
+
*/
|
|
65
|
+
function stylesheetFindings(file, css) {
|
|
66
|
+
/** @type {Finding[]} */
|
|
67
|
+
const findings = [];
|
|
68
|
+
const scanned = blankThemeBlocks(css);
|
|
69
|
+
const lines = scanned.split('\n');
|
|
70
|
+
for (const [index, line] of lines.entries()) {
|
|
71
|
+
const at = (/** @type {string} */ evidence) => ({ line: index + 1, column: Math.max(1, line.indexOf(evidence) + 1) });
|
|
72
|
+
const color = COLOR_LITERAL.exec(line);
|
|
73
|
+
if (color && !/url\(/i.test(line))
|
|
74
|
+
findings.push(
|
|
75
|
+
finding('DS_COLOR_LITERAL', file, `Literal color ${color[0]}: use a DaisyUI semantic color or a theme token (var(--color-*)).`, at(color[0])),
|
|
76
|
+
);
|
|
77
|
+
const palette = /@apply\b/.test(line) ? PALETTE_COLOR.exec(line) : null;
|
|
78
|
+
if (palette) findings.push(finding('DS_COLOR_PALETTE', file, `Palette color ${palette[0]}: use a DaisyUI semantic color.`, at(palette[0])));
|
|
79
|
+
const shadow = BOX_SHADOW.exec(line)?.[1]?.trim();
|
|
80
|
+
if (shadow && !ALLOWED_BOX_SHADOW.test(shadow))
|
|
81
|
+
findings.push(
|
|
82
|
+
finding('DS_SHADOW_RAW', file, `box-shadow: ${shadow}: use var(--shadow-main), var(--shadow-main-lg) or var(--shadow-backdrop).`, at(shadow)),
|
|
83
|
+
);
|
|
84
|
+
const family = FONT_FAMILY.exec(line)?.[1]?.trim();
|
|
85
|
+
if (family && !ALLOWED_FONT_FAMILY.test(family))
|
|
86
|
+
findings.push(finding('DS_FONT_FAMILY', file, `font-family: ${family}: use var(--font-body), var(--font-heading) or inherit.`, at(family)));
|
|
87
|
+
const token = TOKEN_OVERRIDE.exec(line)?.[1];
|
|
88
|
+
if (token)
|
|
89
|
+
findings.push(
|
|
90
|
+
finding('DS_THEME_TOKEN_OVERRIDE', file, `${token} belongs to the theme: pick a different role utility instead of overriding it.`, at(token)),
|
|
91
|
+
);
|
|
92
|
+
if (/\bsixbell_telco\b/i.test(line))
|
|
93
|
+
findings.push(
|
|
94
|
+
finding('DS_SIXBELL_LEGACY', file, 'The sixbell_telco theme is legacy: use enghouse_networks.', { severity: 'warn', ...at('sixbell_telco') }),
|
|
95
|
+
);
|
|
96
|
+
if (/\bPoppins\b/i.test(line) && !family)
|
|
97
|
+
findings.push(
|
|
98
|
+
finding('DS_POPPINS_LEGACY', file, 'Poppins is the legacy font: the theme font is Nunito Sans (var(--font-body)).', at('Poppins')),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
/** @type {Set<string>} */
|
|
102
|
+
const themes = new Set();
|
|
103
|
+
for (const match of css.matchAll(/@plugin\s+["']daisyui\/theme["']\s*\{[^}]*name:\s*["']([^"']+)["']/g)) {
|
|
104
|
+
if (themes.has(match[1]))
|
|
105
|
+
findings.push(finding('DS_THEME_DUPLICATE', file, `The DaisyUI theme "${match[1]}" is registered twice.`, position(css, match.index)));
|
|
106
|
+
themes.add(match[1]);
|
|
107
|
+
}
|
|
108
|
+
for (const match of scanned.matchAll(MODIFIER_UNSAFE)) {
|
|
109
|
+
if ((match[1].match(MODIFIER_COLOR) ?? []).length >= 3)
|
|
110
|
+
findings.push(
|
|
111
|
+
finding(
|
|
112
|
+
'DS_MODIFIER_UNSAFE',
|
|
113
|
+
file,
|
|
114
|
+
'A :not() stack over three or more kit color modifiers: scope the style to a marker class you own.',
|
|
115
|
+
position(scanned, match.index),
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return findings;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A selector that reaches a kit component: an `.st-*` class or an `st-*` element. */
|
|
123
|
+
const KIT_SELECTOR = /(?<![\w-])\.st-[a-z][\w-]*|(?<=^|[\s>+~,(])st-[a-z][\w-]*/i;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The string literals of a decorator property value at `index` (one string, or an array of them),
|
|
127
|
+
* with the offset of each body in the file.
|
|
128
|
+
* @param {string} text
|
|
129
|
+
* @param {number} index
|
|
130
|
+
* @returns {{ body: string, offset: number }[]}
|
|
131
|
+
*/
|
|
132
|
+
function stringLiterals(text, index) {
|
|
133
|
+
/** @type {{ body: string, offset: number }[]} */
|
|
134
|
+
const strings = [];
|
|
135
|
+
let at = index;
|
|
136
|
+
const skip = () => {
|
|
137
|
+
while (at < text.length && /[\s,]/.test(text[at])) at += 1;
|
|
138
|
+
};
|
|
139
|
+
skip();
|
|
140
|
+
const array = text[at] === '[';
|
|
141
|
+
if (array) at += 1;
|
|
142
|
+
for (;;) {
|
|
143
|
+
skip();
|
|
144
|
+
const quote = text[at];
|
|
145
|
+
if (quote !== "'" && quote !== '"' && quote !== '`') break;
|
|
146
|
+
let end = at + 1;
|
|
147
|
+
while (end < text.length && text[end] !== quote) end += text[end] === '\\' ? 2 : 1;
|
|
148
|
+
strings.push({ body: text.slice(at + 1, end), offset: at + 1 });
|
|
149
|
+
at = end + 1;
|
|
150
|
+
if (!array) break;
|
|
151
|
+
}
|
|
152
|
+
return strings;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Inline styles and style files of each `@Component` under src.
|
|
157
|
+
* @param {string} root
|
|
158
|
+
* @returns {{ file: string, text: string, inline: { body: string, offset: number }[], urls: string[] }[]}
|
|
159
|
+
*/
|
|
160
|
+
function components(root) {
|
|
161
|
+
/** @type {{ file: string, text: string, inline: { body: string, offset: number }[], urls: string[] }[]} */
|
|
162
|
+
const found = [];
|
|
163
|
+
for (const file of walk(root, 'src', (name) => name.endsWith('.ts') && !/\.(?:spec|stories)\.ts$/.test(name))) {
|
|
164
|
+
const text = readText(root, file) ?? '';
|
|
165
|
+
for (const decorator of text.matchAll(/@Component\(\s*\{/g)) {
|
|
166
|
+
const end = text.slice(decorator.index).search(/^\s*(?:export\s+)?(?:default\s+)?(?:abstract\s+)?class\s/m);
|
|
167
|
+
const body = text.slice(decorator.index, end < 0 ? undefined : decorator.index + end);
|
|
168
|
+
const property = (/** @type {string} */ name) => {
|
|
169
|
+
const match = new RegExp(`\\b${name}\\s*:`).exec(body);
|
|
170
|
+
return match ? stringLiterals(text, decorator.index + match.index + match[0].length) : [];
|
|
171
|
+
};
|
|
172
|
+
const urls = [...property('styleUrl'), ...property('styleUrls')].map(({ body: url }) => normalize(join(dirname(file), url)));
|
|
173
|
+
found.push({ file, text, inline: property('styles'), urls });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return found;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The kit declaration a `.st-*` class or `st-*` element belongs to: the longest manifest selector
|
|
181
|
+
* the name starts with (`st-dialog-panel` belongs to `st-dialog`).
|
|
182
|
+
* @param {any} manifest
|
|
183
|
+
* @param {string} name
|
|
184
|
+
* @returns {{ selector: string, inputs?: { name: string, values?: string[] }[] } | undefined}
|
|
185
|
+
*/
|
|
186
|
+
function kitDeclaration(manifest, name) {
|
|
187
|
+
/** @type {{ selector: string, inputs?: { name: string, values?: string[] }[] }[]} */
|
|
188
|
+
const declarations = (manifest?.declarations ?? []).filter((/** @type {any} */ d) => typeof d.selector === 'string');
|
|
189
|
+
return declarations
|
|
190
|
+
.filter((d) => name === d.selector || name.startsWith(`${d.selector}-`))
|
|
191
|
+
.sort((a, b) => b.selector.length - a.selector.length)[0];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {string} selector
|
|
196
|
+
* @param {any} manifest
|
|
197
|
+
*/
|
|
198
|
+
function restyleMessage(selector, manifest) {
|
|
199
|
+
const declaration = kitDeclaration(manifest, selector.replace(/^\./, ''));
|
|
200
|
+
const owner = declaration ? `the kit ${declaration.selector}` : 'a kit component';
|
|
201
|
+
const what = selector.startsWith('.') ? `the internals of ${owner}` : owner;
|
|
202
|
+
const inputs = (declaration?.inputs ?? [])
|
|
203
|
+
.slice(0, 6)
|
|
204
|
+
.map((input) => (input.values?.length ? `${input.name}: ${input.values.join(' | ')}` : input.name))
|
|
205
|
+
.join('; ');
|
|
206
|
+
const use = inputs ? `set its inputs instead (${inputs})` : 'set its inputs instead (get_component in the MCP server lists them)';
|
|
207
|
+
return `${selector} restyles ${what} from component styles: kit components own their look; ${use}, or style an element you own.`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Literal colors in inline `styles` and kit selectors in all component styles, reported in the
|
|
212
|
+
* file that holds them.
|
|
213
|
+
* @param {ProjectInfo} project
|
|
214
|
+
* @returns {Finding[]}
|
|
215
|
+
*/
|
|
216
|
+
function componentStyleFindings(project) {
|
|
217
|
+
const { root } = project;
|
|
218
|
+
const manifest = readJson(root, 'node_modules/@sixbell-telco/sdk/manifest.json');
|
|
219
|
+
/** @type {Finding[]} */
|
|
220
|
+
const findings = [];
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} file
|
|
223
|
+
* @param {string} text the whole file, for positions
|
|
224
|
+
* @param {string} css
|
|
225
|
+
* @param {number} offset where `css` starts in `text`
|
|
226
|
+
* @param {boolean} colors
|
|
227
|
+
*/
|
|
228
|
+
const scan = (file, text, css, offset, colors) => {
|
|
229
|
+
const scanned = css.replace(/\/\*[\s\S]*?\*\//g, blank);
|
|
230
|
+
if (colors) {
|
|
231
|
+
let start = 0;
|
|
232
|
+
for (const line of scanned.split('\n')) {
|
|
233
|
+
const color = COLOR_LITERAL.exec(line);
|
|
234
|
+
if (color && !/url\(/i.test(line)) {
|
|
235
|
+
const index = start + color.index;
|
|
236
|
+
const property = scanned.slice(Math.max(scanned.lastIndexOf(';', index), scanned.lastIndexOf('{', index)) + 1, index);
|
|
237
|
+
const use = /shadow\s*:/i.test(property)
|
|
238
|
+
? 'a shadow token (var(--shadow-main), var(--shadow-main-lg), var(--shadow-backdrop))'
|
|
239
|
+
: 'a DaisyUI semantic color or a theme token (var(--color-*))';
|
|
240
|
+
findings.push(
|
|
241
|
+
finding('DS_COMPONENT_COLOR_LITERAL', file, `Literal color ${color[0]} in component styles: use ${use}.`, position(text, offset + index)),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
start += line.length + 1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const prelude of scanned.matchAll(/[^{};]*(?=\{)/g)) {
|
|
248
|
+
if (prelude[0].trim().startsWith('@')) continue;
|
|
249
|
+
const kit = KIT_SELECTOR.exec(prelude[0]);
|
|
250
|
+
if (kit) findings.push(finding('DS_KIT_RESTYLE', file, restyleMessage(kit[0], manifest), position(text, offset + prelude.index + kit.index)));
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/** @type {Set<string>} */
|
|
254
|
+
const seen = new Set();
|
|
255
|
+
for (const component of components(root)) {
|
|
256
|
+
for (const style of component.inline) scan(component.file, component.text, style.body, style.offset, true);
|
|
257
|
+
for (const url of component.urls) {
|
|
258
|
+
const css = seen.has(url) ? null : readText(root, url);
|
|
259
|
+
seen.add(url);
|
|
260
|
+
// Literal colors in style files are DS_COLOR_LITERAL, from the stylesheet scan.
|
|
261
|
+
if (css !== null) scan(url, css, css, 0, false);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return findings;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* themes.json and catalog/*.json: literal colors are allowed here; identity and legacy names are not.
|
|
269
|
+
* @param {ProjectInfo} project
|
|
270
|
+
* @returns {Finding[]}
|
|
271
|
+
*/
|
|
272
|
+
function themeCatalogs(project) {
|
|
273
|
+
const { root } = project;
|
|
274
|
+
/** @type {Finding[]} */
|
|
275
|
+
const findings = [];
|
|
276
|
+
for (const file of walk(root, 'src/assets/themes', (name) => name.endsWith('.json') && !name.startsWith('src/assets/themes/assets/'))) {
|
|
277
|
+
const text = readText(root, file) ?? '';
|
|
278
|
+
const parsed = readJson(root, file);
|
|
279
|
+
if (!parsed) continue;
|
|
280
|
+
const at = (/** @type {string} */ needle) => position(text, Math.max(0, text.indexOf(needle)));
|
|
281
|
+
if (file.endsWith('/themes.json')) {
|
|
282
|
+
if (parsed.defaultTheme && parsed.defaultTheme !== 'enghouse_networks')
|
|
283
|
+
findings.push(
|
|
284
|
+
finding('DS_THEME_STALE_IDENTITY', file, `defaultTheme is "${parsed.defaultTheme}": the kit default is enghouse_networks.`, {
|
|
285
|
+
severity: 'warn',
|
|
286
|
+
...at(parsed.defaultTheme),
|
|
287
|
+
}),
|
|
288
|
+
);
|
|
289
|
+
/** @type {Set<string>} */
|
|
290
|
+
const seen = new Set();
|
|
291
|
+
for (const theme of Array.isArray(parsed.themes) ? parsed.themes.map(String) : []) {
|
|
292
|
+
if (seen.has(theme)) findings.push(finding('DS_THEME_DUPLICATE', file, `Theme "${theme}" is listed twice.`, at(theme)));
|
|
293
|
+
seen.add(theme);
|
|
294
|
+
if (/sixbell_telco/i.test(theme))
|
|
295
|
+
findings.push(
|
|
296
|
+
finding('DS_SIXBELL_LEGACY', file, 'The sixbell_telco theme is legacy: use enghouse_networks.', { severity: 'warn', ...at(theme) }),
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
} else if (/\/catalog\/[^/]+\.json$/.test(file)) {
|
|
300
|
+
const name = String(parsed.meta?.name ?? '');
|
|
301
|
+
if (/sixbell_telco/i.test(name))
|
|
302
|
+
findings.push(
|
|
303
|
+
finding('DS_SIXBELL_LEGACY', file, 'The sixbell_telco catalog is legacy: use enghouse_networks.', { severity: 'warn', ...at(name) }),
|
|
304
|
+
);
|
|
305
|
+
if (/poppins/i.test(text))
|
|
306
|
+
findings.push(finding('DS_POPPINS_LEGACY', file, 'Poppins is the legacy font: the theme font is Nunito Sans.', at('oppins')));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return findings;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @param {ProjectInfo} project
|
|
314
|
+
* @returns {Finding[]}
|
|
315
|
+
*/
|
|
316
|
+
export function stylesStep(project) {
|
|
317
|
+
const { root } = project;
|
|
318
|
+
/** @type {Finding[]} */
|
|
319
|
+
const findings = [];
|
|
320
|
+
for (const file of walk(root, 'src', (name) => /\.(?:s[ac]ss|less)$/.test(name)))
|
|
321
|
+
findings.push(
|
|
322
|
+
finding(
|
|
323
|
+
'DS_SCSS_FILE',
|
|
324
|
+
file,
|
|
325
|
+
'Sass and Less are not used with the kit: move the rules to plain CSS (Tailwind CSS 4 utilities, @apply or theme tokens).',
|
|
326
|
+
),
|
|
327
|
+
);
|
|
328
|
+
for (const file of walk(root, 'src', (name) => /\.(?:css|s[ac]ss|less)$/.test(name) && !name.startsWith('src/assets/themes/'))) {
|
|
329
|
+
findings.push(...stylesheetFindings(file, readText(root, file) ?? ''));
|
|
330
|
+
}
|
|
331
|
+
findings.push(...componentStyleFindings(project));
|
|
332
|
+
if (walk(root, 'src/app', (name) => name.endsWith('-illustration.component.html')).length) {
|
|
333
|
+
const styles = readText(root, 'src/styles.css') ?? '';
|
|
334
|
+
const missing = ['sp-shield-breathe', 'sp-wave-die', 'sp-cable-sway', 'sp-x-blink', 'prefers-reduced-motion'].filter(
|
|
335
|
+
(token) => !styles.includes(token),
|
|
336
|
+
);
|
|
337
|
+
if (missing.length)
|
|
338
|
+
findings.push(
|
|
339
|
+
finding(
|
|
340
|
+
'MFE_STATUS_CSS_001',
|
|
341
|
+
'src/styles.css',
|
|
342
|
+
`The status illustrations animate with the sp-* block of the template styles.css, which lacks ${missing.join(', ')}: copy it from the template.`,
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return [...findings, ...themeCatalogs(project)];
|
|
347
|
+
}
|