-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget-package-deps.ts
More file actions
129 lines (117 loc) · 4.32 KB
/
get-package-deps.ts
File metadata and controls
129 lines (117 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2026 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// generated with AI
/*
* Script to extract version info from manifest_*.yml files in ./tools/cmsis-toolbox
* and print a dependency graph in the format used in the GitHub Actions summary.
* Usage: npx tsx scripts/print-toolbox-deps.ts <nightlyVersion>
*/
import fs from 'fs';
import path from 'path';
import yaml from 'yaml';
import { fileURLToPath } from 'url';
// ESM-compatible __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const TOOLBOX_DIR = path.join(__dirname, '../tools/cmsis-toolbox');
const UV2CSOLUTION_DIR = path.join(__dirname, '../tools/uv2csolution');
const PACKAGE_JSON_PATH = path.join(__dirname, '../package.json');
const MANIFEST_PATTERN = /^manifest_.*\.yml$/;
// Children of cmsis-toolbox (in display order)
const TOOLBOX_CHILDREN = [
'cbridge',
'cbuild',
'cbuild2cmake',
'cbuildgen',
'cpackget',
'csolution',
'packchk',
'svdconv',
'vidx2pidx',
];
function findManifestFiles(dir: string): string[] {
return fs.readdirSync(dir)
.filter(f => MANIFEST_PATTERN.test(f))
.map(f => path.join(dir, f));
}
function parseManifest(file: string): Record<string, string> {
const doc = yaml.parse(fs.readFileSync(file, 'utf8')) as any;
const versions: Record<string, string> = {};
// Top-level cmsis-toolbox version
if (doc?.version) {
versions['cmsis-toolbox'] = doc.version;
}
// binaries is a map: { cbridge: { version: '...' }, cbuild: { version: '...' }, ... }
if (doc?.binaries && typeof doc.binaries === 'object') {
for (const [name, info] of Object.entries(doc.binaries as Record<string, any>)) {
if (info?.version) {
versions[name] = info.version;
}
}
}
return versions;
}
function getUv2csolutionVersion(): string | undefined {
// Try version.txt in the uv2csolution folder first
const versionFile = path.join(UV2CSOLUTION_DIR, 'version.txt');
if (fs.existsSync(versionFile)) {
const v = fs.readFileSync(versionFile, 'utf8').trim();
if (v) return v;
}
// Fall back to package.json csolution.uv2csolutionVersion
if (fs.existsSync(PACKAGE_JSON_PATH)) {
const pkg = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'));
const v = pkg?.csolution?.uv2csolutionVersion;
if (v) return String(v);
}
return undefined;
}
function mergeVersions(manifests: Record<string, string>[]): Record<string, string> {
const merged: Record<string, string> = {};
for (const m of manifests) {
for (const [k, v] of Object.entries(m)) {
merged[k] = v;
}
}
return merged;
}
function printDependencyGraph(versions: Record<string, string>, uv2csolutionVersion: string | undefined, nightlyVersion: string) {
console.log('```text');
console.log(`vscode-cmsis-solution ${nightlyVersion}`);
console.log(` └── cmsis-toolbox v${versions['cmsis-toolbox'] ?? 'unknown'}`);
for (let i = 0; i < TOOLBOX_CHILDREN.length; ++i) {
const tool = TOOLBOX_CHILDREN[i];
const ver = versions[tool] ?? 'unknown';
const isLast = i === TOOLBOX_CHILDREN.length - 1;
const prefix = isLast ? ' │ └──' : ' │ ├──';
console.log(`${prefix} ${tool} v${ver}`);
}
console.log(` └─── uv2csolution v${uv2csolutionVersion ?? 'unknown'}`);
console.log('```');
}
function main() {
const nightlyVersion = process.argv[2] || process.env.NIGHTLY_VERSION || 'unknown';
const manifestFiles = findManifestFiles(TOOLBOX_DIR);
if (manifestFiles.length === 0) {
console.error('No manifest_*.yml files found in', TOOLBOX_DIR);
process.exit(1);
}
const manifests = manifestFiles.map(parseManifest);
const versions = mergeVersions(manifests);
const uv2csolutionVersion = getUv2csolutionVersion();
printDependencyGraph(versions, uv2csolutionVersion, nightlyVersion);
}
main();