@sixbell-telco/sdk-tools 0.0.0 → 0.1.0
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 +32 -0
- package/README.md +277 -2
- package/data/security-floors.json +47 -0
- package/package.json +35 -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,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Federation lockstep for `sdk-tools upgrade`: a host and the remotes it loads share one
|
|
3
|
+
* @sixbell-telco/sdk at run time, so they move to a new SDK version together.
|
|
4
|
+
*
|
|
5
|
+
* - In a host, every remote named in mfe-foundation.config.json (else federation.config.js) is looked
|
|
6
|
+
* up as a local checkout and its installed SDK is compared with the target. A remote on another
|
|
7
|
+
* version blocks; a remote with no local checkout is a warning naming what to verify.
|
|
8
|
+
* - In a child, the hosts found locally that load it are listed: they move together with it.
|
|
9
|
+
*
|
|
10
|
+
* Checkouts are found below the search roots (`--root`, else `SDK_TOOLS_FLEET_ROOT`, path-delimited,
|
|
11
|
+
* else the folders above the app), bounded in depth and skipping hidden and build folders, as
|
|
12
|
+
* `sdk-tools init` finds templates. A remote matches a checkout by its GitHub origin when the remote
|
|
13
|
+
* entry names a `repo` (`org/name`), else by the federation name the checkout declares
|
|
14
|
+
* (mfe-foundation.config.json `identity.projectName`, else the `name` in federation.config.js).
|
|
15
|
+
*/
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { delimiter, dirname, join, resolve, sep } from 'node:path';
|
|
19
|
+
import { repoSlug } from '../init/template.mjs';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {import('../types.js').FleetApp} FleetApp
|
|
23
|
+
* @typedef {import('../types.js').Lockstep} Lockstep
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const SKIP = new Set(['node_modules', 'dist', 'coverage', 'build', 'out', 'target', 'vendor']);
|
|
27
|
+
const MAX_DEPTH = 4;
|
|
28
|
+
const LEVELS_UP = 5;
|
|
29
|
+
|
|
30
|
+
/** @param {string} file */
|
|
31
|
+
function readJson(file) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {string} file */
|
|
40
|
+
function readText(file) {
|
|
41
|
+
try {
|
|
42
|
+
return readFileSync(file, 'utf8');
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The role, federation name and remotes an app declares.
|
|
50
|
+
* @param {string} dir
|
|
51
|
+
* @returns {{ role: 'host' | 'child' | null, name: string | null, remotes: { name: string, repo?: string }[] | null, source: string | null }}
|
|
52
|
+
*/
|
|
53
|
+
export function federationOf(dir) {
|
|
54
|
+
const config = readJson(join(dir, 'mfe-foundation.config.json'));
|
|
55
|
+
const federation = readText(join(dir, 'federation.config.js'));
|
|
56
|
+
const federationName = federation ? (/\bname\s*:\s*['"]([^'"]+)['"]/.exec(federation)?.[1] ?? null) : null;
|
|
57
|
+
const name = (typeof config?.identity?.projectName === 'string' ? config.identity.projectName : null) ?? federationName;
|
|
58
|
+
if (config && Array.isArray(config.remotes)) {
|
|
59
|
+
const remotes = config.remotes
|
|
60
|
+
.filter((/** @type {any} */ r) => r && typeof r.name === 'string')
|
|
61
|
+
.map((/** @type {any} */ r) => ({ name: r.name, ...(typeof r.repo === 'string' ? { repo: r.repo } : {}) }));
|
|
62
|
+
return { role: config.role === 'child' ? 'child' : 'host', name, remotes, source: 'mfe-foundation.config.json' };
|
|
63
|
+
}
|
|
64
|
+
if (config?.role === 'child' || config?.role === 'host')
|
|
65
|
+
return { role: config.role, name, remotes: config.role === 'host' ? [] : null, source: 'mfe-foundation.config.json' };
|
|
66
|
+
if (!federation) return { role: null, name, remotes: null, source: null };
|
|
67
|
+
const block = /\bremotes\s*:\s*([[{])([\s\S]*?)[\]}]/.exec(federation);
|
|
68
|
+
const remotes = block
|
|
69
|
+
? [...block[2].matchAll(block[1] === '{' ? /['"]?([\w@./-]+)['"]?\s*:/g : /['"]([\w@./-]+)['"]/g)].map((m) => ({ name: m[1] }))
|
|
70
|
+
: [];
|
|
71
|
+
const role = /\bexposes\s*:/.test(federation) ? 'child' : 'host';
|
|
72
|
+
return { role, name, remotes: role === 'host' ? remotes : null, source: 'federation.config.js' };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Search roots: the given ones, else SDK_TOOLS_FLEET_ROOT, else the folders above the app.
|
|
77
|
+
* @param {string} cwd
|
|
78
|
+
* @param {string[]} roots
|
|
79
|
+
*/
|
|
80
|
+
function fleetRoots(cwd, roots = []) {
|
|
81
|
+
if (roots.length) return roots.map((r) => resolve(cwd, r));
|
|
82
|
+
const fromEnv = (process.env.SDK_TOOLS_FLEET_ROOT ?? '').split(delimiter).filter(Boolean);
|
|
83
|
+
if (fromEnv.length) return fromEnv.map((r) => resolve(r));
|
|
84
|
+
let current = resolve(cwd);
|
|
85
|
+
for (let i = 0; i < LEVELS_UP && dirname(current) !== current; i++) current = dirname(current);
|
|
86
|
+
return [current];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Git checkouts below `roots` with their origin slug, federation identity and installed SDK.
|
|
91
|
+
* @param {string[]} roots
|
|
92
|
+
* @param {(dir: string) => string | null} installed
|
|
93
|
+
* @param {string} self the app being upgraded (left out)
|
|
94
|
+
* @returns {FleetApp[]}
|
|
95
|
+
*/
|
|
96
|
+
function discoverFleet(roots, installed, self) {
|
|
97
|
+
/** @type {FleetApp[]} */
|
|
98
|
+
const found = [];
|
|
99
|
+
const seen = new Set([resolve(self)]);
|
|
100
|
+
/** @param {string} dir @param {number} depth */
|
|
101
|
+
const walk = (dir, depth) => {
|
|
102
|
+
let entries;
|
|
103
|
+
try {
|
|
104
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
105
|
+
} catch {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!seen.has(dir) && entries.some((e) => e.name === 'package.json') && entries.some((e) => e.name === '.git')) {
|
|
109
|
+
seen.add(dir);
|
|
110
|
+
let origin = null;
|
|
111
|
+
try {
|
|
112
|
+
origin = repoSlug(
|
|
113
|
+
execFileSync('git', ['config', '--get', 'remote.origin.url'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }),
|
|
114
|
+
);
|
|
115
|
+
} catch {
|
|
116
|
+
// no origin remote
|
|
117
|
+
}
|
|
118
|
+
const federation = federationOf(dir);
|
|
119
|
+
if (federation.role) found.push({ dir, origin, ...federation, sdk: installed(dir) });
|
|
120
|
+
}
|
|
121
|
+
if (depth >= MAX_DEPTH) return;
|
|
122
|
+
for (const e of entries) if (e.isDirectory() && !e.name.startsWith('.') && !SKIP.has(e.name)) walk(join(dir, e.name), depth + 1);
|
|
123
|
+
};
|
|
124
|
+
for (const root of roots) walk(resolve(root), 0);
|
|
125
|
+
return found.sort((a, b) => a.dir.split(sep).length - b.dir.split(sep).length || a.dir.localeCompare(b.dir));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The lockstep check of the app at `cwd` against `target`.
|
|
130
|
+
* @param {{ cwd: string, target: string, roots?: string[], installed: (dir: string) => string | null }} options
|
|
131
|
+
* @returns {Lockstep}
|
|
132
|
+
*/
|
|
133
|
+
export function lockstep({ cwd, target, roots = [], installed }) {
|
|
134
|
+
const self = federationOf(cwd);
|
|
135
|
+
const searched = fleetRoots(cwd, roots);
|
|
136
|
+
/** @type {Lockstep} */
|
|
137
|
+
const result = { role: self.role, searched, mismatched: [], matched: [], unknown: [], hosts: [] };
|
|
138
|
+
if (!self.role) return result;
|
|
139
|
+
const fleet = discoverFleet(searched, installed, cwd);
|
|
140
|
+
if (self.role === 'host') {
|
|
141
|
+
for (const remote of self.remotes ?? []) {
|
|
142
|
+
const want = remote.repo?.toLowerCase();
|
|
143
|
+
const app = fleet.find((a) => (want ? a.origin === want : a.role === 'child' && a.name === remote.name));
|
|
144
|
+
if (!app) result.unknown.push({ name: remote.name, ...(remote.repo ? { repo: remote.repo } : {}) });
|
|
145
|
+
else if (app.sdk !== target) result.mismatched.push({ name: remote.name, dir: app.dir, sdk: app.sdk });
|
|
146
|
+
else result.matched.push({ name: remote.name, dir: app.dir, sdk: app.sdk });
|
|
147
|
+
}
|
|
148
|
+
} else if (self.name) {
|
|
149
|
+
for (const host of fleet.filter((a) => a.role === 'host' && (a.remotes ?? []).some((r) => r.name === self.name)))
|
|
150
|
+
result.hosts.push({ name: host.name ?? host.dir, dir: host.dir, sdk: host.sdk });
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|