From 66fa53b809db35fccfbbc8ac8aaca10f04521041 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Tue, 26 Jul 2022 14:54:34 +0100 Subject: [PATCH] Add check for files expected in certain app types - remove warnings about `textinput` --- bin/sanitycheck.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/sanitycheck.js b/bin/sanitycheck.js index 53ef3403d..1e79d3ebc 100755 --- a/bin/sanitycheck.js +++ b/bin/sanitycheck.js @@ -81,6 +81,10 @@ const METADATA_TYPES = ["app","clock","widget","bootloader","RAM","launch","text const FORBIDDEN_FILE_NAME_CHARS = /[,;]/; // used as separators in appid.info const VALID_DUPLICATES = [ '.tfmodel', '.tfnames' ]; const GRANDFATHERED_ICONS = ["s7clk", "snek", "astral", "alpinenav", "slomoclock", "arrow", "pebble", "rebble"]; +const INTERNAL_FILES_IN_APP_TYPE = { // list of app types and files they SHOULD provide... + 'textinput' : ['textinput'], + // notify? +}; function globToRegex(pattern) { const ESCAPE = '.*+-?^${}()|[]\\'; @@ -163,6 +167,7 @@ apps.forEach((app,appIdx) => { } else ERROR(`App ${app.id} 'dependencies' must be an object`, {file:metadataFile}); } + var fileNames = []; app.storage.forEach((file) => { if (!file.name) ERROR(`App ${app.id} has a file with no name`, {file:metadataFile}); @@ -179,7 +184,12 @@ apps.forEach((app,appIdx) => { ERROR(`App ${app.id} file ${file.name} has unknown device in 'supports' field - ${dev}`, {file:metadataFile}); }); fileNames.push(file.name); - allFiles.push({app: app.id, file: file.name}); + var fileInternal = false; + if (app.type && INTERNAL_FILES_IN_APP_TYPE[app.type]) { + if (INTERNAL_FILES_IN_APP_TYPE[app.type].includes(file.name)) + fileInternal = true; + } + allFiles.push({app: app.id, file: file.name, internal:fileInternal}); if (file.url) if (!fs.existsSync(appDir+file.url)) ERROR(`App ${app.id} file ${file.url} doesn't exist`, {file:metadataFile}); if (!file.url && !file.content && !app.custom) ERROR(`App ${app.id} file ${file.name} has no contents`, {file:metadataFile}); var fileContents = ""; @@ -294,6 +304,12 @@ apps.forEach((app,appIdx) => { for (const key in app) { if (!APP_KEYS.includes(key)) ERROR(`App ${app.id} has unknown key ${key}`, {file:metadataFile}); } + if (app.type && INTERNAL_FILES_IN_APP_TYPE[app.type]) { + INTERNAL_FILES_IN_APP_TYPE[app.type].forEach(fileName => { + if (!fileNames.includes(fileName)) + ERROR(`App ${app.id} should include file named ${fileName} but it doesn't`, {file:metadataFile}); + }); + } }); @@ -313,7 +329,7 @@ while(fileA=allFiles.pop()) { if (globA.test(nameB)||globB.test(nameA)) { if (isGlob(nameA)||isGlob(nameB)) ERROR(`App ${fileB.app} ${typeB} file ${nameB} matches app ${fileA.app} ${typeB} file ${nameA}`); - else if (fileA.app != fileB.app) + else if (fileA.app != fileB.app && (!fileA.internal) && (!fileB.internal)) WARN(`App ${fileB.app} ${typeB} file ${nameB} is also listed as ${typeA} file for app ${fileA.app}`); } })