From faf7f00b862c6d7fc9b7813d7592dcb879fbff67 Mon Sep 17 00:00:00 2001 From: cybermoloch Date: Sat, 19 Sep 2020 11:54:56 -0600 Subject: 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 --- scripts/api/package.js | 138 +++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 61 deletions(-) (limited to 'scripts/api/package.js') 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 () => { const allJson = path.join(__dirname, '../../', 'all.json'); let all = await fs.readJson(allJson); + let errorMessages = [] + // Check that package.json exists if (!await fs.pathExists(packageJson)) { - console.log(`⚠️ Could not add your recipe: Please add your recipe to ${recipeSrc} and make sure that folder contains a "package.json". -For more information on how to add your recipe visit https://github.com/getferdi/recipes/blob/master/docs/integration.md`); - return; + errorMessages.push(`⚠️ It looks like your recipe is missing the "package.json" file. + ↪ Please add your recipe to ${recipeSrc} and make sure that folder contains a "package.json". + ℹ For more information on how to add your recipe visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md`); } // Check that icons exist const hasSvg = await fs.pathExists(svgIcon); + if (!hasSvg) { + errorMessages.push(`⚠️ It looks like your recipe is missing the "icon.svg" file. + ↪ Please make sure your recipe contains an icon.svg file. + ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); + } + const hasPng = await fs.pathExists(pngIcon); - if (!hasSvg && !hasPng) { - console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.png and an icon.svg file. -Those icons should be the logo of the recipe you are trying to add. -Please also make sure that your icons are 1024x1024px in size. -For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); - return; - } else if (!hasSvg) { - console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.svg file. -Your recipe already contains an "icon.png" but it also requires an "icon.svg" to display properly. -Please also make sure that your icons are 1024x1024px in size. -For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); - return; - } else if (!hasPng) { - console.log(`⚠️ Could not add your recipe: Please make sure your recipe contains an icon.png file. -Your recipe already contains an "icon.svg" but it also requires an "icon.png" to display properly. -Please also make sure that your icons are 1024x1024px in size. -For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); - return; + if (!hasPng) { + errorMessages.push(`⚠️ It looks like your recipe is missing the "icon.png" file. + ↪ Please make sure your recipe contains an icon.png file. + ↪ Please also make sure that your PNG icon is 1024x1024px in size. + ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); } // Check that icons have the right dimensions - const pngSize = sizeOf(pngIcon); - const pngHasRightSize = pngSize.width === 1024 && pngSize.height === 1024; - if (!pngHasRightSize) { - console.log(`⚠️ Could not add your recipe: "icon.png" should be to be 1024x1024px in size. -Please make sure that your "icon.png" has the right size of 1024x1024px in size. -You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons. -For more information about recipe icons visit https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); - return; + if (hasSvg) { + const svgSize = sizeOf(svgIcon); + const svgHasRightSize = svgSize.width === svgSize.height; + if (!svgHasRightSize) { + errorMessages.push(`⚠️ It looks like your "icon.svg" is not a square. + ↪ Please make sure that your "icon.svg" has the right dimensions to make a square- width and height should be the same. + ℹ You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons. + ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); + } + } + + if (hasPng) { + const pngSize = sizeOf(pngIcon); + const pngHasRightSize = pngSize.width === 1024 && pngSize.height === 1024; + if (hasPng && !pngHasRightSize) { + errorMessages.push(`⚠️ it looks like your "icon.png" is not 1024x1024 in size. + ↪ Please make sure that your "icon.png" has the right dimeensions of 1024x1024px. + ℹ You can use software like Photoshop, GIMP or Photopea (https://www.photopea.com/) to resize your icons. + ℹ For more information about recipe icons visit: https://github.com/getferdi/recipes/blob/master/docs/integration.md#icons`); + } } // Read package.json @@ -86,34 +93,39 @@ For more information about recipe icons visit https://github.com/getferdi/recipe // Make sure it contains all required fields if (!config) { - console.log(`⚠️ Could not add your recipe: We could not read or parse your "package.json" configuration. -Please make sure your "package.json" contains valid JSON. -For more information about the package.json file visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); - return; + errorMessages.push(`⚠️ It looks like your "package.json" file could not read or parsed. + ↪ Please make sure your "package.json" contains valid JSON. + ℹ You can use a JSON Validator like JSONLint: https://jsonlint.com/ + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } - let configErrors = []; + if (!config.id) { - 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 (_)"); - } else if (!/^[a-z0-9._\-]+$/.test(config.id)) { - 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 (_)"); + errorMessages.push(`⚠️ It looks like your "package.json" does not contain an "id" field. + ↪ Please make sure the "id" field contains a unique ID made of lowercase letters (a-z), numbers (0-9), hyphens (-), periods (.), and underscores (_) + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); + } else if (!/^[a-z._\-]+$/.test(config.id)) { + errorMessages.push(`⚠️ It looks like 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 (_) + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } if (!config.name) { - configErrors.push("Your package.json contains no 'name' field. This field should contain the name of the service (e.g. 'Google Keep')"); + errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "name" field. + ↪ Please make sure the "name" field contains the name of the service (e.g. "Google Keep") + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } if (!config.version) { - 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')"); + errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "version" field. + ↪ Please make sure the "version" field contains a semver-compatible version number for your recipe (e.g. "1.0.0") + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } if (!config.config || typeof config.config !== "object") { - configErrors.push("Your package.json contains no 'config' object. This field should contain a configuration for your service."); + errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "config" object. + ↪ Please make sure the "config" object contains a configuration for your service. + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } else if (!config.config.serviceURL) { - configErrors.push("Your package.json contains a 'config' object with no 'serviceURL' field. This field should contain the URL of your service."); - } - - if (configErrors.length > 0) { - console.log(`⚠️ Could not add your recipe: There were errors in your package.json: -${configErrors.reduce((str, err) => `${str}\n${err}`)} -For more information about the package.json file visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); - return; + errorMessages.push(`⚠️ It looks like your "package.json" does not contain a "config" object without a "serviceURL" field. + ↪ Please make sure the "serviceURL" contains the URL of your service. + ℹ For more information about the package.json file visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md`); } // 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 const currentVersion = config.version; const repoVersion = all[packageIndex].version; - if (semver.gte(repoVersion, currentVersion)) { - console.log(`⚠️ Could not add your recipe: It looks like your recipe is using the same version number as the current recipe. -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'). -If you don't increase your version number, Ferdi cannot detect that you have made changes to the recipe. -For more information about versioning of recipes visit https://github.com/getferdi/recipes/blob/master/docs/configuration.md#config-flags`); - return; + if (semver.gte(repoVersion, currentVersion)) { + errorMessages.push(`⚠️ It looks like your recipe is using the same version number as the current recipe. + ↪ 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'). + ↪ If you don't increase your version number, Ferdi cannot detect that you have made changes to the recipe. + ℹ For more information about versioning of recipes visit: https://github.com/getferdi/recipes/blob/master/docs/configuration.md#config-flags`); } } if (!await fs.exists(path.join(recipeSrc, 'webview.js'))) { - console.log(`⚠️ Could not add your recipe: It looks like your recipe doesn't contain a "webview.js" file. -Please make sure to create that file and add your features to it. -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`); - return; + errorMessages.push(`⚠️ It looks like your recipe doesn't contain a "webview.js" file. + ↪ Please make sure to create that file and add your features to it. + ℹ 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`); } if (!await fs.exists(path.join(recipeSrc, 'index.js'))) { - console.log(`⚠️ Could not add your recipe: It looks like your recipe doesn't contain a "index.js" file. -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 -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`); + errorMessages.push(`⚠️ It looks like your recipe doesn't contain a "index.js" file. + ↪ 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 + ℹ 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`); + } + + if (errorMessages.length > 0) { + console.log(`❌ Could not add your recipe, the following ${errorMessages.length} error(s) were found: +${errorMessages.reduce((str, err) => `${str}\n${err}`)} +ℹ For more information, visit: https://github.com/getferdi/recipes/tree/master/docs`); return; } -- cgit v1.2.3-54-g00ecf