-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-language.js
58 lines (52 loc) · 1.64 KB
/
check-language.js
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
const fs = require('fs');
const yaml = require('js-yaml');
const path = require('path');
const languageFile = process.argv[2];
if (!languageFile) {
console.error('No language file specified');
process.exit(1);
} else if (!fs.existsSync(languageFile)) {
console.error('Language file does not exist');
process.exit(1);
}
const languageContent = fs.readFileSync(languageFile, 'utf8');
const language = yaml.load(languageContent);
const nameFromFilename = path.basename(languageFile, '.yaml');
console.log(`Checking language file ${nameFromFilename}...`);
const expectedPublishContent = {
image: `dcc://${nameFromFilename}`,
labels: {
'org.opencontainers.image.source':
'https://github.com/dhhyi/devcontainer-creator',
'org.opencontainers.image.description': `VSCode devcontainer for ${nameFromFilename}`,
},
};
const dumpOptions = { sortKeys: true, flowLevel: -1, lineWidth: -1 };
const publish = yaml.dump(language?.devcontainer?.publish, dumpOptions);
const expected = yaml.dump(expectedPublishContent, dumpOptions);
if (publish !== expected) {
console.error(
'devcontainer.publish does not match expected content',
publish,
expectedPublishContent
);
console.log(
'Expected:',
'\n',
yaml.dump({ publish: expectedPublishContent }, dumpOptions)
);
if (!language?.devcontainer?.publish) {
console.log('trying to fix...');
const newContent = languageContent.replace(
'devcontainer:',
yaml
.dump(
{ devcontainer: { publish: expectedPublishContent } },
dumpOptions
)
.trim()
);
fs.writeFileSync(languageFile, newContent);
}
process.exit(1);
}