-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathgetFileValidationTask.ts
More file actions
95 lines (83 loc) · 2.49 KB
/
getFileValidationTask.ts
File metadata and controls
95 lines (83 loc) · 2.49 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
import { ListrTask } from "listr/index.js";
import { PackageToBuildProps, ListrContextBuild } from "../../types.js";
import {
validateComposeSchema,
validateManifestSchema,
validateSetupWizardSchema,
validateDappnodeCompose,
validateNotificationsSchema
} from "@dappnode/schemas";
import { getComposePath } from "../../files/index.js";
import { CliError } from "../../params.js";
export function getFileValidationTask({
packagesToBuildProps,
skipComposeValidation
}: {
packagesToBuildProps: PackageToBuildProps[];
skipComposeValidation?: boolean;
}): ListrTask<ListrContextBuild> {
return {
title: `Validate files`,
task: async () =>
await validatePackageFiles({
packagesToBuildProps,
skipComposeValidation
})
};
}
async function validatePackageFiles({
packagesToBuildProps,
skipComposeValidation
}: {
packagesToBuildProps: PackageToBuildProps[];
skipComposeValidation?: boolean;
}): Promise<void> {
for (const pkgProps of packagesToBuildProps)
await validateVariantFiles(pkgProps, skipComposeValidation);
}
async function validateVariantFiles(
pkgProps: PackageToBuildProps,
skipComposeValidation?: boolean
): Promise<void> {
const {
manifest,
compose,
composePaths,
notifications,
setupWizard
} = pkgProps;
console.log(
`Validating files for ${manifest.name} (version ${manifest.version})`
);
// Validate manifest schema
validateManifestSchema(manifest);
validatePackageName(manifest.name);
validatePackageVersion(manifest.version);
// Validate compose file using docker compose
await validateComposeSchema(
composePaths.map(pathObj => getComposePath(pathObj))
);
// Validate compose file specifically for Dappnode requirements
if (skipComposeValidation) {
console.log(`Skipping Dappnode compose validation for ${manifest.name}`);
} else {
validateDappnodeCompose(compose, manifest);
}
// Validate notifications schema
if (notifications) validateNotificationsSchema(notifications);
// Validate setup wizard schema
if (setupWizard) validateSetupWizardSchema(setupWizard);
}
function validatePackageName(name: string): void {
if (/[A-Z]/.test(name))
throw new CliError(
`Package name (${name}) in the manifest must be lowercase`
);
}
function validatePackageVersion(version: string): void {
if (!/^\d+\.\d+\.\d+$/.test(version)) {
throw new CliError(
`Version in the manifest (${version}) must follow Semantic Versioning (SemVer) format (x.x.x)`
);
}
}