multicloud_rule_manager 1.0.48 → 1.0.49
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/commands/deploy.js +12 -2
- package/package.json +1 -1
- package/utils/ruleValidator.js +32 -0
package/commands/deploy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { getAlias } from "../utils/aliasManager.js";
|
|
4
|
+
import { validateRule } from "../utils/ruleValidator.js";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
6
7
|
command: "deploy <alias>",
|
|
@@ -38,13 +39,22 @@ export default {
|
|
|
38
39
|
const filePath = path.join(rulesDir, file);
|
|
39
40
|
const content = fs.readFileSync(filePath, "utf8");
|
|
40
41
|
|
|
42
|
+
const validation = validateRule(file, content);
|
|
43
|
+
|
|
44
|
+
if (!validation.valid) {
|
|
45
|
+
console.error("❌ Deploy bloccato");
|
|
46
|
+
console.error(validation.message);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
41
51
|
// estrai guid dal nome file: name_guid.js
|
|
42
52
|
const match = file.match(/_(.+)\.js$/);
|
|
43
53
|
if (!match) {
|
|
44
54
|
console.warn(`⚠️ Nome file non valido, saltato: ${file}`);
|
|
45
55
|
continue;
|
|
46
56
|
}
|
|
47
|
-
|
|
57
|
+
|
|
48
58
|
|
|
49
59
|
// --- POST API ---
|
|
50
60
|
try {
|
|
@@ -55,7 +65,7 @@ export default {
|
|
|
55
65
|
"Content-Type": "application/json"
|
|
56
66
|
},
|
|
57
67
|
body: JSON.stringify({
|
|
58
|
-
|
|
68
|
+
|
|
59
69
|
dsl_internal: content
|
|
60
70
|
})
|
|
61
71
|
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import esprima from "esprima";
|
|
2
|
+
|
|
3
|
+
export function validateRule(fileName, content) {
|
|
4
|
+
|
|
5
|
+
// controllo sintassi JS
|
|
6
|
+
try {
|
|
7
|
+
esprima.parseScript(content, { loc: true });
|
|
8
|
+
} catch (err) {
|
|
9
|
+
return {
|
|
10
|
+
valid: false,
|
|
11
|
+
message: `Errore sintassi in ${fileName} riga ${err.lineNumber}: ${err.description}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// controllo when {}
|
|
16
|
+
if (!/when\s*\{[\s\S]*?\}/.test(content)) {
|
|
17
|
+
return {
|
|
18
|
+
valid: false,
|
|
19
|
+
message: `Blocco "when {}" mancante in ${fileName}`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// controllo then {}
|
|
24
|
+
if (!/then\s*\{[\s\S]*?\}/.test(content)) {
|
|
25
|
+
return {
|
|
26
|
+
valid: false,
|
|
27
|
+
message: `Blocco "then {}" mancante in ${fileName}`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { valid: true };
|
|
32
|
+
}
|