aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar cybermoloch <cybermoloch@magitekai.com>2020-09-19 11:54:56 -0600
committerLibravatar GitHub <noreply@github.com>2020-09-19 18:54:56 +0100
commitfaf7f00b862c6d7fc9b7813d7592dcb879fbff67 (patch)
tree2e5e7515169618ac26b67cf4404c74b6a0c713fa /scripts
parentFix wrong notifications count for Slack (#271) (diff)
downloadferdium-recipes-faf7f00b862c6d7fc9b7813d7592dcb879fbff67.tar.gz
ferdium-recipes-faf7f00b862c6d7fc9b7813d7592dcb879fbff67.tar.zst
ferdium-recipes-faf7f00b862c6d7fc9b7813d7592dcb879fbff67.zip
Add check to ensure SVG icon is a square (#161)
* Add check to ensure SVG icon is a square * Collect all errors and output at the end Moves error messages on all checks to an arrary. At the end of the script if array is not empty and exits. * Error message consistency fixes and mutli-error output Modified text to be consitent across all errors (It looks like, pleae make sure., ..) and modify output so multiple errors would be more legible in the console. * Add link for JSON linter Co-authored-by: Amine <amine@mouafik.fr>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/api/package.js138
1 files changed, 77 insertions, 61 deletions
diff --git a/scripts/api/package.js b/scripts/api/package.js
index de7e641..c64132f 100644
--- a/scripts/api/package.js
+++ b/scripts/api/package.js
@@ -40,45 +40,52 @@ module.exports = async () => {
40 const allJson = path.join(__dirname, '../../', 'all.json'); 40 const allJson = path.join(__dirname, '../../', 'all.json');
41 let all = await fs.readJson(allJson); 41 let all = await fs.readJson(allJson);
42 42
43 let errorMessages = []
44
43 // Check that package.json exists 45 // Check that package.json exists
44 if (!await fs.pathExists(packageJson)) { 46 if (!await fs.pathExists(packageJson)) {
45 console.log(`⚠️ Could not add your recipe: Please add your recipe to ${recipeSrc} and make sure that folder contains a "package.json". 47 errorMessages.push(`⚠️ It looks like your recipe is missing the "package.json" file.
46For more information on how to add your recipe visit https://github.com/getferdi/recipes/blob/master/docs/integration.md`); 48 Please add your recipe to ${recipeSrc} and make sure that folder contains a "package.json".
47 return; 49 ℹ For more information on how to add your recipe visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md`);
48 } 50 }
49 51
50 // Check that icons exist 52 // Check that icons exist
51 const hasSvg = await fs.pathExists(svgIcon); 53 const hasSvg = await fs.pathExists(svgIcon);
54 if (!hasSvg) {
55 errorMessages.push(`⚠️ It looks like your recipe is missing the "icon.svg" file.
56 ↪ Please make sure your recipe contains an icon.svg file.
57 ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
58 }
59
52 const hasPng = await fs.pathExists(pngIcon); 60 const hasPng = await fs.pathExists(pngIcon);
53 if (!hasSvg && !hasPng) { 61 if (!hasPng) {
54 console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.png and an icon.svg file. 62 errorMessages.push(`⚠️ It looks like your recipe is missing the "icon.png" file.
55Those icons should be the logo of the recipe you are trying to add. 63 ↪ Please make sure your recipe contains an icon.png file.
56Please also make sure that your icons are 1024x1024px in size. 64 ↪ Please also make sure that your PNG icon is 1024x1024px in size.
57For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); 65 ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
58 return;
59 } else if (!hasSvg) {
60 console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.svg file.
61Your recipe already contains an "icon.png" but it also requires an "icon.svg" to display properly.
62Please also make sure that your icons are 1024x1024px in size.
63For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
64 return;
65 } else if (!hasPng) {
66 console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.png file.
67Your recipe already contains an "icon.svg" but it also requires an "icon.png" to display properly.
68Please also make sure that your icons are 1024x1024px in size.
69For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
70 return;
71 } 66 }
72 67
73 // Check that icons have the right dimensions 68 // Check that icons have the right dimensions
74 const pngSize = sizeOf(pngIcon); 69 if (hasSvg) {
75 const pngHasRightSize = pngSize.width === 1024 && pngSize.height === 1024; 70 const svgSize = sizeOf(svgIcon);
76 if (!pngHasRightSize) { 71 const svgHasRightSize = svgSize.width === svgSize.height;
77 console.log(`⚠️ Could not add your recipe: "icon.png" should be to be 1024x1024px in size. 72 if (!svgHasRightSize) {
78Please make sure that your "icon.png" has the right size of 1024x1024px in size. 73 errorMessages.push(`⚠️ It looks like your "icon.svg" is not a square.
79You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons. 74 ↪ Please make sure that your "icon.svg" has the right dimensions to make a square- width and height should be the same.
80For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); 75 ℹ You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons.
81 return; 76 ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
77 }
78 }
79
80 if (hasPng) {
81 const pngSize = sizeOf(pngIcon);
82 const pngHasRightSize = pngSize.width === 1024 && pngSize.height === 1024;
83 if (hasPng && !pngHasRightSize) {
84 errorMessages.push(`⚠️ it looks like your "icon.png" is not 1024x1024 in size.
85 ↪ Please make sure that your "icon.png" has the right dimeensions of 1024x1024px.
86 ℹ You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons.
87 ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`);
88 }
82 } 89 }
83 90
84 // Read package.json 91 // Read package.json
@@ -86,34 +93,39 @@ For more information about recipe icons visit https://github.com/getferdi/recipe
86 93
87 // Make sure it contains all required fields 94 // Make sure it contains all required fields
88 if (!config) { 95 if (!config) {
89 console.log(`⚠️ Could not add your recipe: We could not read or parse your "package.json" configuration. 96 errorMessages.push(`⚠️ It looks like your "package.json" file could not read or parsed.
90Please make sure your "package.json" contains valid JSON. 97Please make sure your "package.json" contains valid JSON.
91For more information about the package.json file visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); 98 ℹ You can use a JSON Validator like JSONLint: https://jsonlint.com/
92 return; 99 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
93 } 100 }
94 let configErrors = []; 101
95 if (!config.id) { 102 if (!config.id) {
96 configErrors.push("Your package.json contains no 'id' field. This field should contain a unique ID made of lowercase letters (a-z), numbers (0-9), hyphens (-), periods (.), and underscores (_)"); 103 errorMessages.push(`⚠️ It looks like your "package.json" does not contain an "id" field.
97 } else if (!/^[a-z0-9._\-]+$/.test(config.id)) { 104 ↪ Please make sure the "id" field contains a unique ID made of lowercase letters (a-z), numbers (0-9), hyphens (-), periods (.), and underscores (_)
98 configErrors.push("Your package.json defines an invalid recipe ID. Please make sure the 'id' field only contains lowercase letters (a-z), numbers (0-9), hyphens (-), periods (.), and underscores (_)"); 105 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
106 } else if (!/^[a-z._\-]+$/.test(config.id)) {
107 errorMessages.push(`⚠️ It looks like your "package.json" defines an invalid recipe ID.
108 ↪ Please make sure the "id" field only contains lowercase letters (a-z), numbers (0-9), hyphens (-), periods (.), and underscores (_)
109 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
99 } 110 }
100 if (!config.name) { 111 if (!config.name) {
101 configErrors.push("Your package.json contains no 'name' field. This field should contain the name of the service (e.g. 'Google Keep')"); 112 errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "name" field.
113 ↪ Please make sure the "name" field contains the name of the service (e.g. "Google Keep")
114 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
102 } 115 }
103 if (!config.version) { 116 if (!config.version) {
104 configErrors.push("Your package.json contains no 'version' field. This field should contain the a semver-compatible version number for your recipe (e.g. '1.0.0')"); 117 errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "version" field.
118 ↪ Please make sure the "version" field contains a semver-compatible version number for your recipe (e.g. "1.0.0")
119 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
105 } 120 }
106 if (!config.config || typeof config.config !== "object") { 121 if (!config.config || typeof config.config !== "object") {
107 configErrors.push("Your package.json contains no 'config' object. This field should contain a configuration for your service."); 122 errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "config" object.
123 ↪ Please make sure the "config" object contains a configuration for your service.
124 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
108 } else if (!config.config.serviceURL) { 125 } else if (!config.config.serviceURL) {
109 configErrors.push("Your package.json contains a 'config' object with no 'serviceURL' field. This field should contain the URL of your service."); 126 errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "config" object without a "serviceURL" field.
110 } 127 ↪ Please make sure the "serviceURL" contains the URL of your service.
111 128 ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
112 if (configErrors.length > 0) {
113 console.log(`⚠️ Could not add your recipe: There were errors in your package.json:
114${configErrors.reduce((str, err) => `${str}\n${err}`)}
115For more information about the package.json file visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md`);
116 return;
117 } 129 }
118 130
119 // Index of the current recipe in all.json 131 // Index of the current recipe in all.json
@@ -123,25 +135,29 @@ For more information about the package.json file visit https://github.com/getfer
123 const currentVersion = config.version; 135 const currentVersion = config.version;
124 const repoVersion = all[packageIndex].version; 136 const repoVersion = all[packageIndex].version;
125 137
126 if (semver.gte(repoVersion, currentVersion)) { 138 if (semver.gte(repoVersion, currentVersion)) {
127 console.log(`⚠️ Could not add your recipe: It looks like your recipe is using the same version number as the current recipe. 139 errorMessages.push(`⚠️ It looks like your recipe is using the same version number as the current recipe.
128Please make sure to increase the version number inside your "package.json" everytime you want to repackage (e.g. '1.0.0' to '1.0.1'). 140 ↪ Please make sure to increase the version number inside your "package.json" everytime you want to repackage (e.g. '1.0.0' to '1.0.1').
129If you don't increase your version number, Ferdi cannot detect that you have made changes to the recipe. 141 ↪ If you don't increase your version number, Ferdi cannot detect that you have made changes to the recipe.
130For more information about versioning of recipes visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md#config-flags`); 142 ℹ For more information about versioning of recipes visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md#config-flags`);
131 return;
132 } 143 }
133 } 144 }
134 145
135 if (!await fs.exists(path.join(recipeSrc, 'webview.js'))) { 146 if (!await fs.exists(path.join(recipeSrc, 'webview.js'))) {
136 console.log(`⚠️ Could not add your recipe: It looks like your recipe doesn't contain a "webview.js" file. 147 errorMessages.push(`⚠️ It looks like your recipe doesn't contain a "webview.js" file.
137Please make sure to create that file and add your features to it. 148 ↪ Please make sure to create that file and add your features to it.
138For more information about the webview.js file visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#webviewjs and https://github.com/getferdi/recipes/blob/master/docs/frontend_api.md`); 149 ℹ For more information about the webview.js file visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#webviewjs and https://github.com/getferdi/recipes/blob/master/docs/frontend_api.md`);
139 return;
140 } 150 }
141 if (!await fs.exists(path.join(recipeSrc, 'index.js'))) { 151 if (!await fs.exists(path.join(recipeSrc, 'index.js'))) {
142 console.log(`⚠️ Could not add your recipe: It looks like your recipe doesn't contain a "index.js" file. 152 errorMessages.push(`⚠️ It looks like your recipe doesn't contain a "index.js" file.
143Please make sure to create that file and add your features to it. For most recipes it is enough to simply add the basic template found at https://github.com/getferdi/recipes/blob/master/docs/integration.md#indexjs 153 ↪ Please make sure to create that file and add your features to it. For most recipes it is enough to simply add the basic template found at https://github.com/getferdi/recipes/blob/master/docs/integration.md#indexjs
144For more information about the webview.js file visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#indexjs and https://github.com/getferdi/recipes/blob/master/docs/backend_api.md`); 154 ℹ For more information about the webview.js file visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#indexjs and https://github.com/getferdi/recipes/blob/master/docs/backend_api.md`);
155 }
156
157 if (errorMessages.length > 0) {
158 console.log(`❌ Could not add your recipe, the following ${errorMessages.length} error(s) were found:
159${errorMessages.reduce((str, err) => `${str}\n${err}`)}
160ℹ For more information, visit: https://github.com/getferdi/recipes/tree/master/docs`);
145 return; 161 return;
146 } 162 }
147 163