Tweaks - now try and parse files

pull/191/head
Gordon Williams 2020-02-28 17:01:29 +00:00
parent dc750df4a9
commit 3998688179
1 changed files with 21 additions and 4 deletions

25
bin/sanitycheck.js Normal file → Executable file
View File

@ -18,11 +18,11 @@ try {
var BASEDIR = __dirname+"/../"; var BASEDIR = __dirname+"/../";
var APPSDIR = BASEDIR+"apps/"; var APPSDIR = BASEDIR+"apps/";
function ERROR(s) { function ERROR(s) {
console.error(s); console.error("ERROR: "+s);
process.exit(1); process.exit(1);
} }
function WARN(s) { function WARN(s) {
console.log(s); console.log("Warning: "+s);
} }
var appsFile, apps; var appsFile, apps;
@ -39,7 +39,7 @@ try{
apps.forEach((app,addIdx) => { apps.forEach((app,addIdx) => {
if (!app.id) ERROR(`App ${appIdx} has no id`); if (!app.id) ERROR(`App ${appIdx} has no id`);
console.log(`Checking ${app.id}...`); //console.log(`Checking ${app.id}...`);
var appDir = APPSDIR+app.id+"/"; var appDir = APPSDIR+app.id+"/";
if (!fs.existsSync(APPSDIR+app.id)) ERROR(`App ${app.id} has no directory`); if (!fs.existsSync(APPSDIR+app.id)) ERROR(`App ${app.id} has no directory`);
if (!app.name) ERROR(`App ${app.id} has no name`); if (!app.name) ERROR(`App ${app.id} has no name`);
@ -59,8 +59,10 @@ apps.forEach((app,addIdx) => {
fileNames.push(file.name); fileNames.push(file.name);
if (file.url) if (!fs.existsSync(appDir+file.url)) ERROR(`App ${app.id} file ${file.url} doesn't exist`); if (file.url) if (!fs.existsSync(appDir+file.url)) ERROR(`App ${app.id} file ${file.url} doesn't exist`);
if (!file.url && !file.content && !app.custom) ERROR(`App ${app.id} file ${file.name} has no contents`); if (!file.url && !file.content && !app.custom) ERROR(`App ${app.id} file ${file.name} has no contents`);
var fileContents = "";
if (file.content) fileContents = file.content;
if (file.url) fileContents = fs.readFileSync(appDir+file.url).toString();
if (file.evaluate) { if (file.evaluate) {
var fileContents = file.content ? file.content : fs.readFileSync(appDir+file.url).toString();
try { try {
acorn.parse("("+fileContents+")"); acorn.parse("("+fileContents+")");
} catch(e) { } catch(e) {
@ -74,6 +76,21 @@ apps.forEach((app,addIdx) => {
ERROR(`App ${app.id}'s ${file.name} has evaluate:true but is not valid JS expression`); ERROR(`App ${app.id}'s ${file.name} has evaluate:true but is not valid JS expression`);
} }
} }
if (file.name.endsWith(".js")) {
// TODO: actual lint?
try {
acorn.parse(fileContents);
} catch(e) {
console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed.");
console.log("");
console.log(e);
console.log("=====================================================");
console.log(fileContents);
console.log("=====================================================");
ERROR(`App ${app.id}'s ${file.name} is a JS file but isn't valid JS`);
}
}
}); });
//console.log(fileNames); //console.log(fileNames);
if (isApp && !fileNames.includes(app.id+".app.js")) ERROR(`App ${app.id} has no entrypoint`); if (isApp && !fileNames.includes(app.id+".app.js")) ERROR(`App ${app.id} has no entrypoint`);