aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-09-28 12:59:31 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-09-28 12:59:31 +0200
commit53d4e1d6e527b8d900967f1b0285bcb9e36bdf07 (patch)
treecfc3f6f69f01bf694584ddfc019769a9351c719c /scripts
parentAdd uncompressed recipes (diff)
downloadferdium-recipes-53d4e1d6e527b8d900967f1b0285bcb9e36bdf07.tar.gz
ferdium-recipes-53d4e1d6e527b8d900967f1b0285bcb9e36bdf07.tar.zst
ferdium-recipes-53d4e1d6e527b8d900967f1b0285bcb9e36bdf07.zip
Add packaging script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/package.js101
-rw-r--r--scripts/package.json16
-rw-r--r--scripts/recipe_src/readme.txt2
-rw-r--r--scripts/yarn.lock199
4 files changed, 318 insertions, 0 deletions
diff --git a/scripts/package.js b/scripts/package.js
new file mode 100644
index 0000000..581d23c
--- /dev/null
+++ b/scripts/package.js
@@ -0,0 +1,101 @@
1/**
2 * Package recipe into tar.gz file
3 */
4const targz = require('targz');
5const fs = require('fs-extra');
6const path = require('path');
7
8console.log('Ferdi Recipe Packager v1.0.0');
9
10// Publicly availible link to this repository's uncompressed folder
11// Used for generating public icon URLs
12const repo = 'https://cdn.jsdelivr.net/gh/getferdi/recipes/uncompressed/';
13
14// Helper: Compress src folder into dest file
15const compress = (src, dest) => new Promise((resolve, reject) => {
16 targz.compress({
17 src,
18 dest,
19 }, (err) => {
20 if (err) {
21 reject(err);
22 } else {
23 resolve(dest);
24 }
25 });
26});
27
28// Create paths to important files
29const recipeSrc = path.join(__dirname, 'recipe_src');
30const packageJson = path.join(recipeSrc, 'package.json');
31const svgIcon = path.join(recipeSrc, 'icon.svg');
32const pngIcon = path.join(recipeSrc, 'icon.png');
33const allJson = path.join('../', 'all.json');
34
35// Let us work in an async environment
36(async () => {
37 // Check that package.json exists
38 if (!await fs.pathExists(packageJson)) {
39 console.log(`Error: Please add your recipe to ${recipeSrc}. (package.json not found)`);
40 return;
41 }
42 // Check that icons exist
43 if (!await fs.pathExists(svgIcon) || !await fs.pathExists(pngIcon)) {
44 console.log(`Error: Please make sure your recipe contains an icon.png and an icon.svg file.`);
45 return;
46 }
47
48 // Read package.json
49 const config = await fs.readJson(packageJson)
50
51 // Make sure it contains all required fields
52 if (!config || !config.id || !config.name || !config.config) {
53 console.log(`Error: Your package.json does not contain all required fields.
54Please make sure it contains: id, name, config`);
55 return;
56 }
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
62 console.log(`Packaging ${config.id}...`);
63 compress(recipeSrc, path.join('../', `${config.id}.tar.gz`));
64
65 // Copy recipe src folder to /uncompressed/:id folder
66 console.log('Copying to uncompressed recipes');
67 await fs.copy('recipe_src', path.join('../', 'uncompressed', `${config.id}`));
68
69 // Add recipe to all.json
70 console.log('Adding to all.json');
71 const packageInfo = {
72 "author": config.author || '',
73 "featured": false,
74 "id": config.id,
75 "name": config.name,
76 "version": config.version || '1.0.0',
77 "icons": {
78 "png": `${repo}${config.id}/icon.png`,
79 "svg": `${repo}${config.id}/icon.svg`,
80 },
81 };
82 let all = await fs.readJson(allJson);
83 // Check if package ID already exists
84 const packageIndex = all.findIndex(e => e.id === config.id)
85 if (packageIndex !== -1) {
86 console.log('Package with ID already exists - overwriting');
87 all[packageIndex] = packageInfo;
88 } else {
89 console.log('No package with ID found - creating new.');
90 all.push(packageInfo);
91 }
92 await fs.writeJson(allJson, all, {
93 spaces: 2,
94 EOL: '\n',
95 });
96
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}`);
101})(); \ No newline at end of file
diff --git a/scripts/package.json b/scripts/package.json
new file mode 100644
index 0000000..b491b01
--- /dev/null
+++ b/scripts/package.json
@@ -0,0 +1,16 @@
1{
2 "name": "ferdi-recipes-scripts",
3 "version": "1.0.0",
4 "description": "Scripts for managing the ferdi-recipes repository",
5 "main": "index.js",
6 "repository": "https://github.com/getferdi/recipes",
7 "author": "The Ferdi Team",
8 "license": "MIT",
9 "dependencies": {
10 "fs-extra": "^8.1.0",
11 "targz": "^1.0.1"
12 },
13 "scripts": {
14 "package": "node package.js"
15 }
16}
diff --git a/scripts/recipe_src/readme.txt b/scripts/recipe_src/readme.txt
new file mode 100644
index 0000000..730ba44
--- /dev/null
+++ b/scripts/recipe_src/readme.txt
@@ -0,0 +1,2 @@
1Please put your recipe files into this directory.
2Do 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
new file mode 100644
index 0000000..1fba1d2
--- /dev/null
+++ b/scripts/yarn.lock
@@ -0,0 +1,199 @@
1# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2# yarn lockfile v1
3
4
5bl@^1.0.0:
6 version "1.2.2"
7 resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c"
8 integrity sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==
9 dependencies:
10 readable-stream "^2.3.5"
11 safe-buffer "^5.1.1"
12
13buffer-alloc-unsafe@^1.1.0:
14 version "1.1.0"
15 resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"
16 integrity sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==
17
18buffer-alloc@^1.2.0:
19 version "1.2.0"
20 resolved "https://registry.yarnpkg.com/buffer-alloc/-/buffer-alloc-1.2.0.tgz#890dd90d923a873e08e10e5fd51a57e5b7cce0ec"
21 integrity sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==
22 dependencies:
23 buffer-alloc-unsafe "^1.1.0"
24 buffer-fill "^1.0.0"
25
26buffer-fill@^1.0.0:
27 version "1.0.0"
28 resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-1.0.0.tgz#f8f78b76789888ef39f205cd637f68e702122b2c"
29 integrity sha1-+PeLdniYiO858gXNY39o5wISKyw=
30
31chownr@^1.0.1:
32 version "1.1.3"
33 resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.3.tgz#42d837d5239688d55f303003a508230fa6727142"
34 integrity sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==
35
36core-util-is@~1.0.0:
37 version "1.0.2"
38 resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
39 integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
40
41end-of-stream@^1.0.0, end-of-stream@^1.1.0:
42 version "1.4.4"
43 resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
44 integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
45 dependencies:
46 once "^1.4.0"
47
48fs-constants@^1.0.0:
49 version "1.0.0"
50 resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
51 integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
52
53fs-extra@^8.1.0:
54 version "8.1.0"
55 resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
56 integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
57 dependencies:
58 graceful-fs "^4.2.0"
59 jsonfile "^4.0.0"
60 universalify "^0.1.0"
61
62graceful-fs@^4.1.6, graceful-fs@^4.2.0:
63 version "4.2.2"
64 resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02"
65 integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==
66
67inherits@~2.0.3:
68 version "2.0.4"
69 resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
70 integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
71
72isarray@~1.0.0:
73 version "1.0.0"
74 resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
75 integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
76
77jsonfile@^4.0.0:
78 version "4.0.0"
79 resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
80 integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
81 optionalDependencies:
82 graceful-fs "^4.1.6"
83
84minimist@0.0.8:
85 version "0.0.8"
86 resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
87 integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=
88
89mkdirp@^0.5.1:
90 version "0.5.1"
91 resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
92 integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
93 dependencies:
94 minimist "0.0.8"
95
96once@^1.3.1, once@^1.4.0:
97 version "1.4.0"
98 resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
99 integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
100 dependencies:
101 wrappy "1"
102
103process-nextick-args@~2.0.0:
104 version "2.0.1"
105 resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
106 integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
107
108pump@^1.0.0:
109 version "1.0.3"
110 resolved "https://registry.yarnpkg.com/pump/-/pump-1.0.3.tgz#5dfe8311c33bbf6fc18261f9f34702c47c08a954"
111 integrity sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==
112 dependencies:
113 end-of-stream "^1.1.0"
114 once "^1.3.1"
115
116readable-stream@^2.3.0, readable-stream@^2.3.5:
117 version "2.3.6"
118 resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
119 integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==
120 dependencies:
121 core-util-is "~1.0.0"
122 inherits "~2.0.3"
123 isarray "~1.0.0"
124 process-nextick-args "~2.0.0"
125 safe-buffer "~5.1.1"
126 string_decoder "~1.1.1"
127 util-deprecate "~1.0.1"
128
129safe-buffer@^5.1.1:
130 version "5.2.0"
131 resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
132 integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==
133
134safe-buffer@~5.1.0, safe-buffer@~5.1.1:
135 version "5.1.2"
136 resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
137 integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
138
139string_decoder@~1.1.1:
140 version "1.1.1"
141 resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
142 integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
143 dependencies:
144 safe-buffer "~5.1.0"
145
146tar-fs@^1.8.1:
147 version "1.16.3"
148 resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-1.16.3.tgz#966a628841da2c4010406a82167cbd5e0c72d509"
149 integrity sha512-NvCeXpYx7OsmOh8zIOP/ebG55zZmxLE0etfWRbWok+q2Qo8x/vOR/IJT1taADXPe+jsiu9axDb3X4B+iIgNlKw==
150 dependencies:
151 chownr "^1.0.1"
152 mkdirp "^0.5.1"
153 pump "^1.0.0"
154 tar-stream "^1.1.2"
155
156tar-stream@^1.1.2:
157 version "1.6.2"
158 resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-1.6.2.tgz#8ea55dab37972253d9a9af90fdcd559ae435c555"
159 integrity sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==
160 dependencies:
161 bl "^1.0.0"
162 buffer-alloc "^1.2.0"
163 end-of-stream "^1.0.0"
164 fs-constants "^1.0.0"
165 readable-stream "^2.3.0"
166 to-buffer "^1.1.1"
167 xtend "^4.0.0"
168
169targz@^1.0.1:
170 version "1.0.1"
171 resolved "https://registry.yarnpkg.com/targz/-/targz-1.0.1.tgz#8f76a523694cdedfbb5d60a4076ff6eeecc5398f"
172 integrity sha1-j3alI2lM3t+7XWCkB2/27uzFOY8=
173 dependencies:
174 tar-fs "^1.8.1"
175
176to-buffer@^1.1.1:
177 version "1.1.1"
178 resolved "https://registry.yarnpkg.com/to-buffer/-/to-buffer-1.1.1.tgz#493bd48f62d7c43fcded313a03dcadb2e1213a80"
179 integrity sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==
180
181universalify@^0.1.0:
182 version "0.1.2"
183 resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
184 integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
185
186util-deprecate@~1.0.1:
187 version "1.0.2"
188 resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
189 integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
190
191wrappy@1:
192 version "1.0.2"
193 resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
194 integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
195
196xtend@^4.0.0:
197 version "4.0.2"
198 resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
199 integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==