Skip to content

Commit

Permalink
Made changes in name and fixed bug in AIM build
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyash-x committed Apr 21, 2023
1 parent eced02b commit 94eb4b6
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 165 deletions.
2 changes: 2 additions & 0 deletions Aim.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Aim extends Task {
basedir,
"aim.md",
"index.html",
[],
[],
lu_label
);
}
Expand Down
4 changes: 0 additions & 4 deletions Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ class Task extends Unit {
}

finalPath(modules){
if (typeof modules === "string") {
// modules = [modules];
return [];
}
let final_paths = [];
for (let module of modules) {
if(this.isURL(module)){
Expand Down
4 changes: 2 additions & 2 deletions lab_build/LabGen.js → lab_build/lab-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
const glob = require("glob");
const { nextVersion } = require("./Tags");
const { loadExperiments, expList } = require("./ExpUtils");
const validator = require("../validateDescriptor.js");
const {validateLabDescriptor} = require("../validation/validateDescriptor.js")
const config = require("./labConfig.json");
const log = require("../Logger.js");
const {
Expand Down Expand Up @@ -113,7 +113,7 @@ function buildLab(labpath, release_type) {
const lab_descriptor_path = path.resolve(labpath, "lab-descriptor.json");

log.info("Validating lab descriptor");
const isValid = validator.validateLabDescriptor(lab_descriptor_path);
const isValid = validateLabDescriptor(lab_descriptor_path);
if (!isValid) {
log.error("Lab descriptor is invalid");
return;
Expand Down
8 changes: 5 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const minimist = require("minimist");
const Config = require("./Config.js");
const path = require("path");
const log = require("./Logger");
const {buildLab} = require("./lab_build/LabGen.js");
const {buildLab} = require("./lab_build/lab-gen.js");
// Build/run
// Flags = clean build, with plugin, without plugin, validation on off, also deploy locally

Expand Down Expand Up @@ -162,7 +162,10 @@ function deployLocal(src) {
// Deploy
try {
log.debug("Deploying locally");
shell.exec(`npx http-server -p 0 ${bp} -o /index.html`);
const child = shell.exec(`npx http-server -p 0 ${bp} -o /index.html`, {async:true});
child.stdout.on('data', function(data) {
console.log(data);
});
} catch (e) {
log.error("Error deploying locally", e);
}
Expand Down Expand Up @@ -252,7 +255,6 @@ function main() {
case "deploy":
log.info("Calling deploy");
deployLocal(src);
log.info("Deploy Complete");
break;

case "buildLab":
Expand Down
206 changes: 103 additions & 103 deletions labDescSchema.json → validation/schemas/labDescSchema.json
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"required": ["lab", "lab_display_name", "broadArea", "phase", "collegeName",
"baseUrl", "introduction", "objective",
"targetAudience", "courseAlignment"],
"properties": {
"lab": {"type": "string"},
"lab_display_name": {"type": "string"},
"broadArea": {
"type": "object",
"properties": {
"name": {"type": "string"},
"link": {"type": "string", "format": "uri"}
}
},
"phase": {"type": "number"},
"collegeName": {"type": "string"},
"baseUrl": {
"type": "string",
"format": "hostname"
},
"introduction": {"type": "string"},
"objective": {"type": "string"},
"experiments": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "short-name",
"repo", "tag", "deploy"],
"properties": {
"name": {"type": "string"},
"short-name": {"type": "string"},
"repo": {"type": "string", "format": "uri"},
"tag": {
"type": "string",
"minLength": 6,
"maxLength": 6,
"pattern": "^v([0-9]{1,2}\\.){2}[0-9]$"
},
"deploy": {"type": "boolean"}
},
"additionalProperties": false
}
},
"experiment-sections": {
"type": "array",
"items": {
"type": "object",
"required": ["sect-name", "experiments"],
"properties": {
"sect-name": {"type": "string"},
"experiments": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "short-name",
"repo", "tag", "deploy"],
"properties": {
"name": {"type": "string"},
"short-name": {"type": "string"},
"repo": {"type": "string", "format": "uri"},
"tag": {
"type": "string",
"minLength": 6,
"maxLength": 6,
"pattern": "^v([0-9]{1,2}\\.){2}[0-9]$"
},
"deploy": {"type": "boolean"}
},
"additionalProperties": false
}
}
}
}
},
"targetAudience": {
"type": "object",
"properties": {
"UG": {
"type": "array",
"items": {"type": "string"}
},
"PG": {
"type": "array",
"items": {"type": "string"}
}
}
},
"courseAlignment": {
"type": "object",
"properties": {
"description": {"type": "string"},
"universities": {
"type": "array",
"minItems": 1,
"items": {"type": "string"}
}
}
}
}
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"required": ["lab", "lab_display_name", "broadArea", "phase", "collegeName",
"baseUrl", "introduction", "objective",
"targetAudience", "courseAlignment"],
"properties": {
"lab": {"type": "string"},
"lab_display_name": {"type": "string"},
"broadArea": {
"type": "object",
"properties": {
"name": {"type": "string"},
"link": {"type": "string", "format": "uri"}
}
},
"phase": {"type": "number"},
"collegeName": {"type": "string"},
"baseUrl": {
"type": "string",
"format": "hostname"
},
"introduction": {"type": "string"},
"objective": {"type": "string"},
"experiments": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "short-name",
"repo", "tag", "deploy"],
"properties": {
"name": {"type": "string"},
"short-name": {"type": "string"},
"repo": {"type": "string", "format": "uri"},
"tag": {
"type": "string",
"minLength": 6,
"maxLength": 6,
"pattern": "^v([0-9]{1,2}\\.){2}[0-9]$"
},
"deploy": {"type": "boolean"}
},
"additionalProperties": false
}
},
"experiment-sections": {
"type": "array",
"items": {
"type": "object",
"required": ["sect-name", "experiments"],
"properties": {
"sect-name": {"type": "string"},
"experiments": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "short-name",
"repo", "tag", "deploy"],
"properties": {
"name": {"type": "string"},
"short-name": {"type": "string"},
"repo": {"type": "string", "format": "uri"},
"tag": {
"type": "string",
"minLength": 6,
"maxLength": 6,
"pattern": "^v([0-9]{1,2}\\.){2}[0-9]$"
},
"deploy": {"type": "boolean"}
},
"additionalProperties": false
}
}
}
}
},
"targetAudience": {
"type": "object",
"properties": {
"UG": {
"type": "array",
"items": {"type": "string"}
},
"PG": {
"type": "array",
"items": {"type": "string"}
}
}
},
"courseAlignment": {
"type": "object",
"properties": {
"description": {"type": "string"},
"universities": {
"type": "array",
"minItems": 1,
"items": {"type": "string"}
}
}
}
}
}
108 changes: 55 additions & 53 deletions validateDescriptor.js → validation/validateDescriptor.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
const Ajv = require('ajv');
const addFormats = require("ajv-formats")
const figures = require('figures');
const chalk = require('chalk');
const path = require('path');

function reportJSONError(error) {
const heading =
chalk`Error detected in {blue {italic lab-descriptor.json}}`;
console.log(chalk`${heading}`);

if (error.keyword === 'additionalProperties') {
const msg = `please remove: ${error.params.additionalProperty}`;
logError(error.dataPath, msg);
}
else {
logError(error.dataPath, error.message);
}
}

function logError(dataPath, textMsg) {
let delim =chalk` {yellow ${figures.pointerSmall}} `;
let msg = chalk` {yellow ${textMsg}}`;
dp = dataPath.replace(/\./g, delim);
console.log(`\n${dp}\n${msg}\n`);
}


function validateLabDescriptor(lab_descriptor_path){
const validator = new Ajv();
addFormats(validator);
const validate = validator.compile(require('./labDescSchema.json'));
const valid = validate(require(lab_descriptor_path));

if (!valid) {
if (validate.errors) {
reportJSONError(validate.errors[0]);
}
return false;
}
return true;
}


module.exports.validateLabDescriptor = validateLabDescriptor;


/*
node validateDescriptor.js <path/to/lab>
*/
if (require.main === module) {
validateLabDescriptor(path.resolve(process.argv[2], "lab-descriptor.json"));
}
const Ajv = require('ajv');
const addFormats = require("ajv-formats")
const figures = require('figures');
const chalk = require('chalk');
const path = require('path');

function reportJSONError(error) {
const heading =
chalk`Error detected in {blue {italic lab-descriptor.json}}`;
console.log(chalk`${heading}`);

if (error.keyword === 'additionalProperties') {
const msg = `please remove: ${error.params.additionalProperty}`;
logError(error.dataPath, msg);
}
else {
logError(error.dataPath, error.message);
}
}

function logError(dataPath, textMsg) {
let delim =chalk` {yellow ${figures.pointerSmall}} `;
let msg = chalk` {yellow ${textMsg}}`;
dp = dataPath.replace(/\./g, delim);
console.log(`\n${dp}\n${msg}\n`);
}


function validateLabDescriptor(lab_descriptor_path){
const validator = new Ajv();
addFormats(validator);
const validate = validator.compile(require("./schemas/labDescSchema.json"));
const valid = validate(require(lab_descriptor_path));

if (!valid) {
if (validate.errors) {
reportJSONError(validate.errors[0]);
}
return false;
}
return true;
}


module.exports = {
validateLabDescriptor,
}


/*
node validateDescriptor.js <path/to/lab>
*/
if (require.main === module) {
validateLabDescriptor(path.resolve(process.argv[2], "lab-descriptor.json"));
}

0 comments on commit 94eb4b6

Please sign in to comment.