-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-structure.mjs
77 lines (62 loc) · 2.02 KB
/
validate-structure.mjs
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
#!/usr/bin/env node
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { join } from "node:path";
const ROOT_DIR = process.cwd();
const MANIFEST_FILE = join(ROOT_DIR, "manifest.json");
const PLUGIN_FILENAME = "plugin.js";
const VIEW_FILENAME = "view.xml";
const DATA_FILENAME = "data.json";
const PLUGINS_DIR = join(ROOT_DIR, "src");
const validateStructure = () => {
if (!existsSync(MANIFEST_FILE)) {
console.error("Missing manifest.json in the root directory");
process.exit(1);
}
const manifest = JSON.parse(readFileSync(MANIFEST_FILE, "utf-8"));
if (!Array.isArray(manifest)) {
console.error("manifest.json must be an array");
process.exit(1);
}
if (!existsSync(PLUGINS_DIR)) {
console.error("Missing src directory");
process.exit(1);
}
const folders = readdirSync(PLUGINS_DIR, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const errors = [];
for (const folder of folders) {
const pluginFile = join(PLUGINS_DIR, folder, PLUGIN_FILENAME);
const viewFile = join(PLUGINS_DIR, folder, VIEW_FILENAME);
const dataFile = join(PLUGINS_DIR, folder, DATA_FILENAME);
if (!existsSync(pluginFile)) {
errors.push(`Missing ${PLUGIN_FILENAME} in "${folder}"`);
}
if (!existsSync(viewFile)) {
errors.push(`Missing ${VIEW_FILENAME} in "${folder}"`);
}
if (!existsSync(dataFile)) {
errors.push(`Missing ${DATA_FILENAME} in "${folder}"`);
}
const manifestEntry = manifest.find((entry) => entry.path === folder);
if (!manifestEntry) {
errors.push(`Folder "${folder}" is missing in manifest.json`);
} else if (
!manifestEntry.title ||
!manifestEntry.description ||
typeof manifestEntry.private !== "boolean"
) {
errors.push(
`Invalid manifest entry for "${folder}". It must have a title, description, private flag, and path.`,
);
}
}
if (errors.length > 0) {
for (const error of errors) {
console.error(error);
}
process.exit(1);
}
console.log("Folder structure is correct.");
};
validateStructure();