Repository navigation
Expand file tree
/
Copy pathvalidate-structure.js
More file actions
139 lines (115 loc) · 3.1 KB
/
Copy pathvalidate-structure.js
File metadata and controls
139 lines (115 loc) · 3.1 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
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env node
/**
* Read-only structure validator for the portable AI plugin restructure.
*
* Validates required top-level source folders and their README/index files.
* If the pilot plugin package exists, validates its basic package shape too.
*
* @module scripts/validation/validate-structure
* @license GPL-3.0-or-later
*/
const fs = require('fs');
const path = require('path');
const REQUIRED_PORTABLE_FOLDERS = [
'.schemas',
'agents',
'cookbook',
'hooks',
'instructions',
'plugins',
'skills',
'workflows',
];
function parseArgs(argv) {
const config = {
root: process.cwd(),
};
for (let index = 0; index < argv.length; index++) {
const arg = argv[index];
switch (arg) {
case '--root':
config.root = path.resolve(argv[++index]);
break;
case '--help':
case '-h':
config.help = true;
break;
default:
throw new Error(`Unknown option: ${arg}`);
}
}
return config;
}
function hasIndexFile(root, folder) {
return ['README.md', 'index.md'].some((fileName) =>
fs.existsSync(path.join(root, folder, fileName))
);
}
function validateStructure(root) {
const errors = [];
for (const folder of REQUIRED_PORTABLE_FOLDERS) {
const folderPath = path.join(root, folder);
if (!fs.existsSync(folderPath) || !fs.statSync(folderPath).isDirectory()) {
errors.push(`Missing required directory: ${folder}`);
continue;
}
if (!hasIndexFile(root, folder)) {
errors.push(`Missing README.md or index.md in required directory: ${folder}`);
}
}
const pilotPlugin = path.join(root, 'plugins', 'lightspeed-github-ops');
if (fs.existsSync(pilotPlugin)) {
if (!fs.statSync(pilotPlugin).isDirectory()) {
errors.push('Pilot plugin path exists but is not a directory: plugins/lightspeed-github-ops');
} else {
for (const fileName of ['README.md']) {
const filePath = path.join(pilotPlugin, fileName);
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
errors.push(`Missing pilot plugin file: plugins/lightspeed-github-ops/${fileName}`);
}
}
}
}
return errors;
}
function printHelp() {
console.log(`Structure Validation Tool
Usage:
node scripts/validation/validate-structure.js [--root <path>]
Checks:
- Required portable source folders exist.
- Each required folder has README.md or index.md.
- If plugins/lightspeed-github-ops exists, it has basic package files.
`);
}
function main() {
let config;
try {
config = parseArgs(process.argv.slice(2));
} catch (error) {
console.error(error.message);
return 2;
}
if (config.help) {
printHelp();
return 0;
}
const errors = validateStructure(config.root);
if (errors.length > 0) {
console.error('Structure validation failed:');
for (const error of errors) {
console.error(`- ${error}`);
}
return 1;
}
console.log('Structure validation passed.');
return 0;
}
if (require.main === module) {
process.exit(main());
}
module.exports = {
REQUIRED_PORTABLE_FOLDERS,
hasIndexFile,
validateStructure,
};