diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | scripts/package.json | 1 | ||||
-rw-r--r-- | scripts/verify-all.js | 77 |
3 files changed, 79 insertions, 0 deletions
@@ -1,4 +1,5 @@ | |||
1 | .DS_Store | 1 | .DS_Store |
2 | scripts/node_modules | 2 | scripts/node_modules |
3 | scripts/recipe_src/* | 3 | scripts/recipe_src/* |
4 | scripts/uncompressed/* | ||
4 | !scripts/recipe_src/readme.txt \ No newline at end of file | 5 | !scripts/recipe_src/readme.txt \ No newline at end of file |
diff --git a/scripts/package.json b/scripts/package.json index 56c62ed..2df0082 100644 --- a/scripts/package.json +++ b/scripts/package.json | |||
@@ -17,6 +17,7 @@ | |||
17 | "scripts": { | 17 | "scripts": { |
18 | "package": "node package.js", | 18 | "package": "node package.js", |
19 | "verify": "node verify.js", | 19 | "verify": "node verify.js", |
20 | "verify-all": "node verify-all.js", | ||
20 | "update": "node update.js", | 21 | "update": "node update.js", |
21 | "github": "node add_github.js", | 22 | "github": "node add_github.js", |
22 | "load": "node load.js" | 23 | "load": "node load.js" |
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 | */ | ||
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 | }, (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 | ||