aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/verify-all.js
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2020-03-06 11:45:10 +0100
committerLibravatar vantezzen <hello@vantezzen.io>2020-03-06 11:45:10 +0100
commit7a289d410cda7ba63efcabca24ca287f8edcb48c (patch)
treecf571d80e1e7878aca66e19465aedfa8eac6c0d2 /scripts/verify-all.js
parentMerge branch 'master' of https://github.com/getferdi/recipes (diff)
downloadferdium-recipes-7a289d410cda7ba63efcabca24ca287f8edcb48c.tar.gz
ferdium-recipes-7a289d410cda7ba63efcabca24ca287f8edcb48c.tar.zst
ferdium-recipes-7a289d410cda7ba63efcabca24ca287f8edcb48c.zip
Add verify-all script
Diffstat (limited to 'scripts/verify-all.js')
-rw-r--r--scripts/verify-all.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/verify-all.js b/scripts/verify-all.js
new file mode 100644
index 0000000..6683d7a
--- /dev/null
+++ b/scripts/verify-all.js
@@ -0,0 +1,77 @@
1/**
2 * Verify all archived recipes to match uncompressed recipes
3 */
4const targz = require('targz');
5const fs = require('fs-extra');
6const dircompare = require('dir-compare');
7const path = require('path');
8
9// Helper: Compress src folder into dest file
10const decompress = (src, dest) => new Promise((resolve, reject) => {
11 targz.decompress({
12 src,
13 dest,
14 }, (err) => {
15 if (err) {
16 reject(err);
17 } else {
18 resolve(dest);
19 }
20 });
21});
22
23// Let us work in an async environment
24(async () => {
25 // Read list of all recipes
26 const allJsonPath = path.join(__dirname, '../', 'all.json');
27 const all = await fs.readJSON(allJsonPath);
28
29 const tempUncompressed = path.join(__dirname, `uncompressed/`);
30
31 for (const recipeInfo of all) {
32 // Get recipe infos
33 const recipe = recipeInfo.id;
34 const recipeNum = all.findIndex(e => e === recipeInfo);
35 const compressedRecipe = path.join(__dirname, '../', `${recipe}.tar.gz`);
36 const uncompressedRecipe = path.join(__dirname, '../', 'uncompressed', recipe);
37
38 // Check that recipe exists
39 if (!await fs.pathExists(compressedRecipe) || !await fs.pathExists(uncompressedRecipe)) {
40 console.log(`Error: Recipe "${recipe}" exists in all.json but not found.`);
41 process.exit(1);
42 }
43
44 // Clear temporary extraction folder
45 if (await fs.pathExists(tempUncompressed)) {
46 await fs.remove(tempUncompressed);
47 }
48 await fs.mkdir(tempUncompressed);
49
50 // Package to uncompressed recipe to .tar.gz
51 console.log(`Decompressing ${recipe} (${recipeNum + 1} of ${all.length})...`);
52 await decompress(compressedRecipe, tempUncompressed);
53
54 // Compare directories
55 const compare = dircompare.compareSync(uncompressedRecipe, tempUncompressed, {
56 compareContent: true,
57 });
58
59 if (compare.same) {
60 console.log(`✓ ${recipe} is valid`);
61 } else {
62 console.log(`❌ Compressed and uncompressed files for "${recipe}" are NOT equal:`);
63
64 // Output information about differences
65 for (const file of compare.diffSet) {
66 if (file.state !== 'equal') {
67 console.log(`- "${file.name1}" is not equal (${file.type1} in uncompressed, ${file.type2} in archive)`);
68 }
69 }
70
71 process.exit(1);
72 }
73
74 // Remove temporary compressed file
75 await fs.remove(tempUncompressed);
76 }
77})(); \ No newline at end of file