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
140
141
142
143
144
145
146
147
148
149
|
/*jshint esversion: 6 */
const path = require('path');
const yaml = require('yaml');
const fs = require('fs-extra');
const PUBLIC = `public`;
const pathOfPublic = path.join(__dirname, '..', PUBLIC);
// validating version 4
function validateV4() {
const version = '4';
const pathOfVersion = path.join(pathOfPublic, 'v' + version);
const pathOfApps = path.join(pathOfVersion, 'apps');
return fs.readdir(pathOfApps)
.then(function (items) {
const apps = items.filter(v => v.includes('.yml'));
if (items.length !== apps.length) {
throw new Error('All files in v4 must end with .yml');
}
for (var i = 0; i < apps.length; i++) {
const contentString = fs.readFileSync(path.join(pathOfApps, apps[i]), 'utf-8');
const content = yaml.parse(contentString);
const captainVersion = (content.captainVersion + '');
const versionString = (version + '');
if (versionString !== captainVersion)
throw new Error(`unmatched versions ${versionString} ${captainVersion} for ${apps[i]}`);
apps[i] = apps[i].replace('.yml', '');
if (!content.caproverOneClickApp) {
throw new Error(`Cannot find caproverOneClickApp for ${apps[i]}`);
}
if (!content.caproverOneClickApp.description) {
throw new Error(`Cannot find description for ${apps[i]}`);
}
if (content.caproverOneClickApp.description.length > 200) {
throw new Error(`Description too long for ${apps[i]} - keep it below 200 chars`);
}
if (!content.caproverOneClickApp.instructions ||
!content.caproverOneClickApp.instructions.start ||
!content.caproverOneClickApp.instructions.end) {
throw new Error(`Cannot find instructions.start or instructions.end for ${apps[i]}`);
}
if (!content.services) {
throw new Error(`Cannot find services for ${apps[i]}`);
}
Object.keys(content.services).forEach(
(serviceName) => { // jshint ignore:line
const s = content.services[serviceName];
if (s.image && s.image.endsWith(':latest')) {
// throw new Error(`"latest" tag is not allowed as it can change and break the setup, see ${apps[i]}`);
}
});
const logoFileName = apps[i] + '.png';
const logoFullPath = path.join(pathOfVersion, 'logos', logoFileName);
if (!fs.existsSync(logoFullPath) ||
!fs.statSync(logoFullPath).isFile()) {
let printablePath = logoFullPath;
printablePath = printablePath.substr(printablePath.indexOf(`/${PUBLIC}`));
throw new Error(`Cannot find logo for ${apps[i]} ${printablePath}`);
}
console.log(`Validated ${apps[i]}`);
}
});
}
// validating version 2
function validateV2() {
const version = '2';
const pathOfVersion = path.join(pathOfPublic, 'v' + version);
const pathOfApps = path.join(pathOfVersion, 'apps');
if (!fs.existsSync(pathOfApps)) {
return;
}
return fs.readdir(pathOfApps)
.then(function (items) {
const apps = items.filter(v => v.includes('.json'));
if (items.length !== apps.length) {
throw new Error('All files in v2 must end with .json');
}
for (var i = 0; i < apps.length; i++) {
const contentString = fs.readFileSync(path.join(pathOfApps, apps[i]));
const content = JSON.parse(contentString);
const captainVersion = (content.captainVersion + '');
const versionString = (version + '');
if (versionString !== captainVersion)
throw new Error(`unmatched versions ${versionString} ${captainVersion} for ${apps[i]}`);
apps[i] = apps[i].replace('.json', '');
if (!content.description) {
throw new Error(`Cannot find description for ${apps[i]}`);
}
if (content.description.length > 200) {
throw new Error(`Description too long for ${apps[i]} - keep it below 200 chars`);
}
const logoFileName = apps[i] + '.png';
const logoFullPath = path.join(pathOfVersion, 'logos', logoFileName);
if (!fs.existsSync(logoFullPath) ||
!fs.statSync(logoFullPath).isFile()) {
let printablePath = logoFullPath;
printablePath = printablePath.substr(printablePath.indexOf(`/${PUBLIC}`));
throw new Error(`Cannot find logo for ${apps[i]} ${printablePath}`);
}
console.log(`Validated ${apps[i]}`);
}
});
}
Promise.resolve()
.then(function () {
return validateV2();
})
.then(function () {
return validateV4();
})
.catch(function (err) {
console.error(err);
process.exit(127);
});
|