aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/add_github.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/add_github.js')
-rw-r--r--scripts/add_github.js44
1 files changed, 26 insertions, 18 deletions
diff --git a/scripts/add_github.js b/scripts/add_github.js
index 543e347..4a5cfce 100644
--- a/scripts/add_github.js
+++ b/scripts/add_github.js
@@ -6,6 +6,7 @@ const targz = require('targz');
6const fs = require('fs-extra'); 6const fs = require('fs-extra');
7const path = require('path'); 7const path = require('path');
8const GitUrlParse = require("git-url-parse"); 8const GitUrlParse = require("git-url-parse");
9const packageRecipe = require('./api/package');
9 10
10// Helper: Download file to filesystem 11// Helper: Download file to filesystem
11const downloadFile = (async (url, path) => { 12const downloadFile = (async (url, path) => {
@@ -30,7 +31,7 @@ const decompress = (src, dest) => {
30 dest 31 dest
31 }, function (err) { 32 }, function (err) {
32 if (err) { 33 if (err) {
33 console.log('Error while decompressing recipe:', err); 34 console.log('⚠️ Could not add your recipe: There was an error while decompressing your GitHub repository file: ', err);
34 } 35 }
35 resolve(); 36 resolve();
36 }); 37 });
@@ -40,7 +41,11 @@ const decompress = (src, dest) => {
40const repo = process.argv[2]; 41const repo = process.argv[2];
41 42
42if (!repo || !/https:\/\/github\.com\/[^\/]+\/[^\/]+\/?/gi.test(repo)) { 43if (!repo || !/https:\/\/github\.com\/[^\/]+\/[^\/]+\/?/gi.test(repo)) {
43 console.log("Please provide a valid repository URL"); 44 console.log(`⚠️ Could not add your recipe: The GitHub URL you provided doesn't seem to be valid.
45You should use this command like "yarn github https://github.com/user/repo".
46Please make sure you provide a URL in the format "https://github.com/user/repo"
47For more information about this script visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#publishing
48If you want to package a local recipe, please use "yarn package" instead.`);
44 return; 49 return;
45} 50}
46 51
@@ -54,24 +59,24 @@ const compressed = path.join(__dirname, 'tmp.tar.gz');
54 59
55// Let us work in an async environment 60// Let us work in an async environment
56(async () => { 61(async () => {
57 console.log("Creating temporary directory"); 62 console.log("[Info] Creating temporary directory");
58 63
59 await fs.ensureDir(tempDir); 64 await fs.ensureDir(tempDir);
60 await fs.ensureDir(recipeSrc); 65 await fs.ensureDir(recipeSrc);
61 await fs.ensureDir(recipeSrcTmp); 66 await fs.ensureDir(recipeSrcTmp);
62 67
63 console.log("Downloading " + repo); 68 console.log("[Info] Downloading " + repo);
64 69
65 await downloadFile( 70 await downloadFile(
66 `https://github.com/${repoInfo.owner}/${repoInfo.name}/archive/master.tar.gz`, 71 `https://github.com/${repoInfo.owner}/${repoInfo.name}/archive/master.tar.gz`,
67 compressed 72 compressed
68 ); 73 );
69 74
70 console.log("Decompressing tarball"); 75 console.log("[Info] Decompressing repository");
71 76
72 await decompress(compressed, tempDir); 77 await decompress(compressed, tempDir);
73 78
74 console.log("Moving directories"); 79 console.log("[Info] Moving 'recipe_src' to 'recipe_src_tmp'");
75 80
76 await fs.move(recipeSrc, recipeSrcTmp, {overwrite: true}); 81 await fs.move(recipeSrc, recipeSrcTmp, {overwrite: true});
77 await fs.move( 82 await fs.move(
@@ -80,18 +85,21 @@ const compressed = path.join(__dirname, 'tmp.tar.gz');
80 {overwrite: true} 85 {overwrite: true}
81 ); 86 );
82 87
83 console.log("Adding to repository"); 88 console.log("[Info] Packaging your recipe");
84 require('./package.js'); 89 try {
85 console.log("Continuing in 1.5 seconds"); 90 await packageRecipe();
91 } catch(e) {
92 return;
93 }
86 94
87 setTimeout(async () => { 95 console.log("[Info] Deleting temporarydownloaded repository");
88 console.log("Deleting downloaded files");
89 96
90 await fs.remove(compressed); 97 await fs.remove(compressed);
91 await fs.remove(recipeSrc); 98 await fs.remove(recipeSrc);
92 99
93 console.log("Moving back recipe folder"); 100 console.log("[Info] Moving back 'recipe_src_tmp' to 'recipe_src'");
94 101
95 await fs.move(recipeSrcTmp, recipeSrc); 102 await fs.move(recipeSrcTmp, recipeSrc);
96 }, 1500); 103
104 console.log(`✅ Successfully packaged the recipe from your GitHub repository`);
97})(); \ No newline at end of file 105})(); \ No newline at end of file