diff options
author | 2020-09-22 20:56:48 +0200 | |
---|---|---|
committer | 2020-09-22 19:56:48 +0100 | |
commit | 6f5e4a00588aefdda7a5a1cfe70935870e7e234a (patch) | |
tree | 9e29aa7aa0620a1a4a968ff8739b4b8ba96791a9 /scripts/verify-all.js | |
parent | Updated logos for Outlook/OWA (diff) | |
download | ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.tar.gz ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.tar.zst ferdium-recipes-6f5e4a00588aefdda7a5a1cfe70935870e7e234a.zip |
Unpack recipes and update recipes icons (#292)
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'scripts/verify-all.js')
-rw-r--r-- | scripts/verify-all.js | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/scripts/verify-all.js b/scripts/verify-all.js deleted file mode 100644 index f8702b3..0000000 --- a/scripts/verify-all.js +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | /** | ||
2 | * Verify all archived recipes to match uncompressed recipes | ||
3 | */ | ||
4 | const targz = require('targz'); | ||
5 | const fs = require('fs-extra'); | ||
6 | const dircompare = require('dir-compare'); | ||
7 | const path = require('path'); | ||
8 | |||
9 | // Helper: Compress src folder into dest file | ||
10 | const decompress = (src, dest) => new Promise((resolve, reject) => { | ||
11 | targz.decompress({ | ||
12 | src, | ||
13 | dest, | ||
14 | tar: { | ||
15 | // Don't unpackage .DS_Store files | ||
16 | ignore: function(name) { | ||
17 | return path.basename(name) === '.DS_Store' | ||
18 | } | ||
19 | }, | ||
20 | }, (err) => { | ||
21 | if (err) { | ||
22 | reject(err); | ||
23 | } else { | ||
24 | resolve(dest); | ||
25 | } | ||
26 | }); | ||
27 | }); | ||
28 | |||
29 | // Let Promise errors crash the script | ||
30 | process.on('unhandledRejection', (error) => { | ||
31 | console.log('Promise rejection:', error); | ||
32 | process.exit(1); | ||
33 | }); | ||
34 | |||
35 | // Let us work in an async environment | ||
36 | (async () => { | ||
37 | // Read list of all recipes | ||
38 | const allJsonPath = path.join(__dirname, '../', 'all.json'); | ||
39 | const all = await fs.readJSON(allJsonPath); | ||
40 | |||
41 | const tempUncompressed = path.join(__dirname, `uncompressed/`); | ||
42 | |||
43 | for (const recipeInfo of all) { | ||
44 | try { | ||
45 | // Get recipe infos | ||
46 | const recipe = recipeInfo.id; | ||
47 | const recipeNum = all.findIndex(e => e === recipeInfo); | ||
48 | const compressedRecipe = path.join(__dirname, '../', 'archives', `${recipe}.tar.gz`); | ||
49 | const uncompressedRecipe = path.join(__dirname, '../', 'uncompressed', recipe); | ||
50 | |||
51 | // Check that recipe exists | ||
52 | if (!await fs.pathExists(compressedRecipe) || !await fs.pathExists(uncompressedRecipe)) { | ||
53 | console.log(`Error: Recipe "${recipe}" exists in all.json but not found.`); | ||
54 | process.exit(1); | ||
55 | } | ||
56 | |||
57 | // Clear temporary extraction folder | ||
58 | if (await fs.pathExists(tempUncompressed)) { | ||
59 | await fs.remove(tempUncompressed); | ||
60 | } | ||
61 | await fs.mkdir(tempUncompressed); | ||
62 | |||
63 | // Package to uncompressed recipe to .tar.gz | ||
64 | await decompress(compressedRecipe, tempUncompressed); | ||
65 | |||
66 | // Compare directories | ||
67 | const compare = await dircompare.compare(uncompressedRecipe, tempUncompressed, { | ||
68 | compareContent: true, | ||
69 | // Don't fail because of DS_Store files | ||
70 | excludeFilter: '.DS_Store', | ||
71 | }); | ||
72 | |||
73 | if (compare.same) { | ||
74 | console.log(`✓ ${recipe} is valid (${recipeNum + 1} of ${all.length})`); | ||
75 | } else { | ||
76 | console.log(`❌ Compressed and uncompressed files for "${recipe}" are NOT equal:`); | ||
77 | |||
78 | // Output information about differences | ||
79 | for (const file of compare.diffSet) { | ||
80 | if (file.state !== 'equal') { | ||
81 | console.log(`- "${file.name1 || file.name2}" is not equal (${file.type1} in uncompressed, ${file.type2} in archive)`); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | process.exit(1); | ||
86 | } | ||
87 | |||
88 | // Remove temporary compressed file | ||
89 | await fs.remove(tempUncompressed); | ||
90 | } catch(e) { | ||
91 | console.log('Error while verifying recipe:', e); | ||
92 | process.exit(1); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | console.log('All recipes are valid.'); | ||
97 | })(); | ||