diff options
-rw-r--r-- | scripts/add_github.js | 94 | ||||
-rw-r--r-- | scripts/package.js | 6 | ||||
-rw-r--r-- | scripts/package.json | 4 | ||||
-rw-r--r-- | scripts/recipe_src/readme.txt | 2 | ||||
-rw-r--r-- | scripts/yarn.lock | 50 |
5 files changed, 147 insertions, 9 deletions
diff --git a/scripts/add_github.js b/scripts/add_github.js new file mode 100644 index 0000000..add3575 --- /dev/null +++ b/scripts/add_github.js | |||
@@ -0,0 +1,94 @@ | |||
1 | /** | ||
2 | * Add GitHub repository as recipe | ||
3 | */ | ||
4 | const fetch = require('node-fetch'); | ||
5 | const targz = require('targz'); | ||
6 | const fs = require('fs-extra'); | ||
7 | const path = require('path'); | ||
8 | const GitUrlParse = require("git-url-parse"); | ||
9 | |||
10 | // Helper: Download file to filesystem | ||
11 | const downloadFile = (async (url, path) => { | ||
12 | const res = await fetch(url); | ||
13 | const fileStream = fs.createWriteStream(path); | ||
14 | await new Promise((resolve, reject) => { | ||
15 | res.body.pipe(fileStream); | ||
16 | res.body.on("error", (err) => { | ||
17 | reject(err); | ||
18 | }); | ||
19 | fileStream.on("finish", function () { | ||
20 | resolve(); | ||
21 | }); | ||
22 | }); | ||
23 | }); | ||
24 | |||
25 | // Helper: Decompress .tar.gz file | ||
26 | const decompress = (src, dest) => { | ||
27 | return new Promise(resolve => { | ||
28 | targz.decompress({ | ||
29 | src, | ||
30 | dest | ||
31 | }, function (err) { | ||
32 | if (err) { | ||
33 | console.log('Error while decompressing recipe:', err); | ||
34 | } | ||
35 | resolve(); | ||
36 | }); | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | const repo = process.argv[2]; | ||
41 | |||
42 | if (!repo || !/https:\/\/github\.com\/[^\/]+\/[^\/]+\/?/gi.test(repo)) { | ||
43 | console.log("Please provide a valid repository URL"); | ||
44 | return; | ||
45 | } | ||
46 | |||
47 | const repoInfo = GitUrlParse(repo); | ||
48 | const tempDir = path.join(__dirname, 'tmp'); | ||
49 | |||
50 | const recipeSrc = path.join(__dirname, 'recipe_src'); | ||
51 | const recipeSrcTmp = path.join(__dirname, 'recipe_src_tmp'); | ||
52 | |||
53 | const compressed = path.join(__dirname, 'tmp.tar.gz'); | ||
54 | |||
55 | // Let us work in an async environment | ||
56 | (async () => { | ||
57 | console.log("Creating temporary directory"); | ||
58 | |||
59 | await fs.ensureDir(tempDir); | ||
60 | |||
61 | console.log("Downloading " + repo); | ||
62 | |||
63 | await downloadFile( | ||
64 | `https://github.com/${repoInfo.owner}/${repoInfo.name}/archive/master.tar.gz`, | ||
65 | compressed | ||
66 | ); | ||
67 | |||
68 | console.log("Decompressing tarball"); | ||
69 | |||
70 | await decompress(compressed, tempDir); | ||
71 | |||
72 | console.log("Moving directories"); | ||
73 | |||
74 | await fs.move(recipeSrc, recipeSrcTmp); | ||
75 | await fs.move( | ||
76 | path.join(tempDir, `${repoInfo.name}-master`), | ||
77 | recipeSrc | ||
78 | ); | ||
79 | |||
80 | console.log("Adding to repository"); | ||
81 | require('./package.js'); | ||
82 | console.log("Continuing in 1.5 seconds"); | ||
83 | |||
84 | setTimeout(async () => { | ||
85 | console.log("Deleting downloaded files"); | ||
86 | |||
87 | await fs.remove(compressed); | ||
88 | await fs.remove(recipeSrc); | ||
89 | |||
90 | console.log("Moving back recipe folder"); | ||
91 | |||
92 | await fs.move(recipeSrcTmp, recipeSrc); | ||
93 | }, 1500); | ||
94 | })(); \ No newline at end of file | ||
diff --git a/scripts/package.js b/scripts/package.js index 581d23c..2be3a69 100644 --- a/scripts/package.js +++ b/scripts/package.js | |||
@@ -55,9 +55,6 @@ Please make sure it contains: id, name, config`); | |||
55 | return; | 55 | return; |
56 | } | 56 | } |
57 | 57 | ||
58 | // Move readme.txt outside of recipe_src folder | ||
59 | await fs.move(path.join(recipeSrc, 'readme.txt'), './readme.txt'); | ||
60 | |||
61 | // Package to .tar.gz | 58 | // Package to .tar.gz |
62 | console.log(`Packaging ${config.id}...`); | 59 | console.log(`Packaging ${config.id}...`); |
63 | compress(recipeSrc, path.join('../', `${config.id}.tar.gz`)); | 60 | compress(recipeSrc, path.join('../', `${config.id}.tar.gz`)); |
@@ -94,8 +91,5 @@ Please make sure it contains: id, name, config`); | |||
94 | EOL: '\n', | 91 | EOL: '\n', |
95 | }); | 92 | }); |
96 | 93 | ||
97 | // Move readme.txt back into recipe_src | ||
98 | await fs.move('./readme.txt', path.join(recipeSrc, 'readme.txt')); | ||
99 | |||
100 | console.log(`Successfully packaged and added new package ${config.id}`); | 94 | console.log(`Successfully packaged and added new package ${config.id}`); |
101 | })(); \ No newline at end of file | 95 | })(); \ No newline at end of file |
diff --git a/scripts/package.json b/scripts/package.json index 2bfc982..63aeefa 100644 --- a/scripts/package.json +++ b/scripts/package.json | |||
@@ -9,6 +9,7 @@ | |||
9 | "dependencies": { | 9 | "dependencies": { |
10 | "dir-compare": "^1.7.3", | 10 | "dir-compare": "^1.7.3", |
11 | "fs-extra": "^8.1.0", | 11 | "fs-extra": "^8.1.0", |
12 | "git-url-parse": "^11.1.2", | ||
12 | "node-fetch": "^2.6.0", | 13 | "node-fetch": "^2.6.0", |
13 | "semver": "^6.3.0", | 14 | "semver": "^6.3.0", |
14 | "targz": "^1.0.1" | 15 | "targz": "^1.0.1" |
@@ -16,6 +17,7 @@ | |||
16 | "scripts": { | 17 | "scripts": { |
17 | "package": "node package.js", | 18 | "package": "node package.js", |
18 | "verify": "node verify.js", | 19 | "verify": "node verify.js", |
19 | "update": "node update.js" | 20 | "update": "node update.js", |
21 | "github": "node add_github.js" | ||
20 | } | 22 | } |
21 | } | 23 | } |
diff --git a/scripts/recipe_src/readme.txt b/scripts/recipe_src/readme.txt deleted file mode 100644 index 730ba44..0000000 --- a/scripts/recipe_src/readme.txt +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | Please put your recipe files into this directory. | ||
2 | Do not delete this file - the packaging script will ignore it while packaging. \ No newline at end of file | ||
diff --git a/scripts/yarn.lock b/scripts/yarn.lock index a06349c..5f3a5c8 100644 --- a/scripts/yarn.lock +++ b/scripts/yarn.lock | |||
@@ -116,6 +116,21 @@ fs-extra@^8.1.0: | |||
116 | jsonfile "^4.0.0" | 116 | jsonfile "^4.0.0" |
117 | universalify "^0.1.0" | 117 | universalify "^0.1.0" |
118 | 118 | ||
119 | git-up@^4.0.0: | ||
120 | version "4.0.1" | ||
121 | resolved "https://registry.yarnpkg.com/git-up/-/git-up-4.0.1.tgz#cb2ef086653640e721d2042fe3104857d89007c0" | ||
122 | integrity sha512-LFTZZrBlrCrGCG07/dm1aCjjpL1z9L3+5aEeI9SBhAqSc+kiA9Or1bgZhQFNppJX6h/f5McrvJt1mQXTFm6Qrw== | ||
123 | dependencies: | ||
124 | is-ssh "^1.3.0" | ||
125 | parse-url "^5.0.0" | ||
126 | |||
127 | git-url-parse@^11.1.2: | ||
128 | version "11.1.2" | ||
129 | resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-11.1.2.tgz#aff1a897c36cc93699270587bea3dbcbbb95de67" | ||
130 | integrity sha512-gZeLVGY8QVKMIkckncX+iCq2/L8PlwncvDFKiWkBn9EtCfYDbliRTTp6qzyQ1VMdITUfq7293zDzfpjdiGASSQ== | ||
131 | dependencies: | ||
132 | git-up "^4.0.0" | ||
133 | |||
119 | graceful-fs@^4.1.6, graceful-fs@^4.2.0: | 134 | graceful-fs@^4.1.6, graceful-fs@^4.2.0: |
120 | version "4.2.2" | 135 | version "4.2.2" |
121 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" | 136 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" |
@@ -131,6 +146,13 @@ inherits@~2.0.3: | |||
131 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | 146 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" |
132 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | 147 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== |
133 | 148 | ||
149 | is-ssh@^1.3.0: | ||
150 | version "1.3.1" | ||
151 | resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.1.tgz#f349a8cadd24e65298037a522cf7520f2e81a0f3" | ||
152 | integrity sha512-0eRIASHZt1E68/ixClI8bp2YK2wmBPVWEismTs6M+M099jKgrzl/3E976zIbImSIob48N2/XGe9y7ZiYdImSlg== | ||
153 | dependencies: | ||
154 | protocols "^1.1.0" | ||
155 | |||
134 | isarray@~1.0.0: | 156 | isarray@~1.0.0: |
135 | version "1.0.0" | 157 | version "1.0.0" |
136 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" | 158 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" |
@@ -167,6 +189,11 @@ node-fetch@^2.6.0: | |||
167 | resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" | 189 | resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" |
168 | integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== | 190 | integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== |
169 | 191 | ||
192 | normalize-url@^3.3.0: | ||
193 | version "3.3.0" | ||
194 | resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559" | ||
195 | integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg== | ||
196 | |||
170 | once@^1.3.1, once@^1.4.0: | 197 | once@^1.3.1, once@^1.4.0: |
171 | version "1.4.0" | 198 | version "1.4.0" |
172 | resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" | 199 | resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" |
@@ -174,11 +201,34 @@ once@^1.3.1, once@^1.4.0: | |||
174 | dependencies: | 201 | dependencies: |
175 | wrappy "1" | 202 | wrappy "1" |
176 | 203 | ||
204 | parse-path@^4.0.0: | ||
205 | version "4.0.1" | ||
206 | resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-4.0.1.tgz#0ec769704949778cb3b8eda5e994c32073a1adff" | ||
207 | integrity sha512-d7yhga0Oc+PwNXDvQ0Jv1BuWkLVPXcAoQ/WREgd6vNNoKYaW52KI+RdOFjI63wjkmps9yUE8VS4veP+AgpQ/hA== | ||
208 | dependencies: | ||
209 | is-ssh "^1.3.0" | ||
210 | protocols "^1.4.0" | ||
211 | |||
212 | parse-url@^5.0.0: | ||
213 | version "5.0.1" | ||
214 | resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.1.tgz#99c4084fc11be14141efa41b3d117a96fcb9527f" | ||
215 | integrity sha512-flNUPP27r3vJpROi0/R3/2efgKkyXqnXwyP1KQ2U0SfFRgdizOdWfvrrvJg1LuOoxs7GQhmxJlq23IpQ/BkByg== | ||
216 | dependencies: | ||
217 | is-ssh "^1.3.0" | ||
218 | normalize-url "^3.3.0" | ||
219 | parse-path "^4.0.0" | ||
220 | protocols "^1.4.0" | ||
221 | |||
177 | process-nextick-args@~2.0.0: | 222 | process-nextick-args@~2.0.0: |
178 | version "2.0.1" | 223 | version "2.0.1" |
179 | resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" | 224 | resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" |
180 | integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== | 225 | integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== |
181 | 226 | ||
227 | protocols@^1.1.0, protocols@^1.4.0: | ||
228 | version "1.4.7" | ||
229 | resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.7.tgz#95f788a4f0e979b291ffefcf5636ad113d037d32" | ||
230 | integrity sha512-Fx65lf9/YDn3hUX08XUc0J8rSux36rEsyiv21ZGUC1mOyeM3lTRpZLcrm8aAolzS4itwVfm7TAPyxC2E5zd6xg== | ||
231 | |||
182 | pump@^1.0.0: | 232 | pump@^1.0.0: |
183 | version "1.0.3" | 233 | version "1.0.3" |
184 | resolved "https://registry.yarnpkg.com/pump/-/pump-1.0.3.tgz#5dfe8311c33bbf6fc18261f9f34702c47c08a954" | 234 | resolved "https://registry.yarnpkg.com/pump/-/pump-1.0.3.tgz#5dfe8311c33bbf6fc18261f9f34702c47c08a954" |