diff --git a/assets_plugins/json/bug-report-questions.js b/assets_plugins/json/bug-report-questions.js index 08c910a9..7467fbaf 100644 --- a/assets_plugins/json/bug-report-questions.js +++ b/assets_plugins/json/bug-report-questions.js @@ -1,4 +1,4 @@ -const { ContentTypes } = require("../../Enums"); +const { ContentTypes } = require("../../enums"); const issues = { [ContentTypes.TEXT]: ["Insufficient Content"], diff --git a/lab_build/exp_utils.js b/lab_build/exp_utils.js index 13fef74d..cdb5c736 100644 --- a/lab_build/exp_utils.js +++ b/lab_build/exp_utils.js @@ -74,7 +74,7 @@ function loadExperiments(labpath) { const ldpath = path.resolve(labpath, "lab-descriptor.json"); const lab_descriptor = require(ldpath); - const config = require("./labConfig.json"); + const config = require("./lab_config.json"); const exp_dir = config["exp_dir"]; const deployment_dest = config["deployment_dest"]; const lab_dir_name = toDirName(lab_descriptor.lab); diff --git a/lab_build/lab_gen.js b/lab_build/lab_gen.js index 5cc47ece..43b815f5 100644 --- a/lab_build/lab_gen.js +++ b/lab_build/lab_gen.js @@ -4,7 +4,7 @@ const fs = require("fs"); const glob = require("glob"); const { nextVersion } = require("./tags.js"); const { loadExperiments, expList } = require("./exp_utils"); -const {validateLabDescriptor} = require("../validation/validate_descriptor.js") +const { validateLabDescriptor } = require("../validation/validate_descriptor.js") const config = require("./lab_config.json"); const log = require("../logger.js"); const { @@ -54,8 +54,8 @@ function generateLab(labpath) { buildLabPages(config.pages, labpath, template_file, component_files); } -function deployLab(labpath) { - const config = require("./labConfig.json"); +function moveToDeployDir(labpath) { + const config = require("./lab_config.json"); const deployment_dest = config["deployment_dest"]; const lab_descriptor = require(path.resolve(labpath, "lab-descriptor.json")); const lab_dir_name = toDirName(lab_descriptor.lab); @@ -96,44 +96,35 @@ function deployLab(labpath) { ); } -function buildLab(labpath, release_type) { - // convert to absolute path - labpath = path.resolve(labpath); - // console.log(chalk`{bold Lab Path} ${labpath}`); - log.info(`Building lab at ${labpath}`); - log.info(`Release: ${release_type}`); +function validation(labpath){ + const lab_descriptor_path = path.resolve(labpath, "lab-descriptor.json"); - // Generate lab - // Check if labpath is valid + log.info("Validating lab descriptor"); + const isValid = validateLabDescriptor(lab_descriptor_path); + if (!isValid) { + log.error("Lab descriptor is invalid"); + return false; + } + log.info("Lab descriptor is valid"); + return true; +} + +function deployLab(labpath, release_type) { + log.info(`Release: ${release_type}`); if (!fs.existsSync(labpath)) { // console.error(chalk`{red Invalid Lab Path} '${labpath}'`); log.error(`Invalid Lab Path '${labpath}'`); } else { - - const lab_descriptor_path = path.resolve(labpath, "lab-descriptor.json"); - - log.info("Validating lab descriptor"); - const isValid = validateLabDescriptor(lab_descriptor_path); - if (!isValid) { - log.error("Lab descriptor is invalid"); - return; - } - log.info("Lab descriptor is valid"); - // 1 : Build all lab pages by rendering templates and loading components - log.info("Generating lab pages"); - generateLab(labpath); - // 2 : Load all experiments in the lab (Clone, build, and stage) - log.info("Loading all experiments"); - loadExperiments(labpath); // 3 : Stage the lab + const lab_descriptor_path = path.resolve(labpath, "lab-descriptor.json"); log.info("Staging lab"); stageLab( `${labpath}/build/*`, path.resolve("/var/www/html/stage", getLabName(lab_descriptor_path)) ); // 4 : Move all staged experiments to the deployment directory (/var/www/html/) - log.info("Deploying lab"); - deployLab(labpath); + log.info("Moving lab to deployment directory"); + moveToDeployDir(labpath); // 5 : Update lab version in lab-descriptor.json // Get next version number const newVersion = nextVersion(labpath, release_type); @@ -146,10 +137,31 @@ function buildLab(labpath, release_type) { log.info(`Releasing Version ${newVersion}`); releaseLab(labpath, newVersion); + log.info("Lab Deploy complete"); + } +} + +function buildLab(labpath) { + log.info(`Building lab at ${labpath}`); + + // Generate lab + // Check if labpath is valid + if (!fs.existsSync(labpath)) { + // console.error(chalk`{red Invalid Lab Path} '${labpath}'`); + log.error(`Invalid Lab Path '${labpath}'`); + } else { + // 1 : Build all lab pages by rendering templates and loading components + log.info("Generating lab pages"); + generateLab(labpath); + // 2 : Load all experiments in the lab (Clone, build, and stage) + log.info("Loading all experiments"); + loadExperiments(labpath); log.info("Lab build complete"); } } module.exports = { buildLab, + deployLab, + validation }; diff --git a/main.js b/main.js index a20d25fe..7b184af0 100644 --- a/main.js +++ b/main.js @@ -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/lab_gen.js"); +const {buildLab, deployLab,validation} = require("./lab_build/lab_gen.js"); // Build/run // Flags = clean build, with plugin, without plugin, validation on off, also deploy locally @@ -212,6 +212,9 @@ function main() { return; } + let release = args.release || "minor"; + let labpath = ""; + switch (option) { case "build": let isClean = args.clean || false; @@ -258,11 +261,29 @@ function main() { break; case "buildLab": - let release = args.release || "minor"; log.info("Calling buildLab"); - buildLab(src, release); - log.info("BuildLab Complete"); + labpath = path.resolve(src); + if(validation(labpath)){ + buildLab(labpath); + log.info("BuildLab Complete"); + if(args.deploy) + { + log.info("Calling deploy Lab"); + + deployLab(labpath, release); + log.info("Deploy Lab Complete"); + } + } break; + + case "deployLab": + log.info("Calling deploy Lab"); + labpath = path.resolve(src); + if(validation){ + deployLab(src, release); + log.info("Deploy Lab Complete"); + break; + } default: log.error("Invalid Arguments"); diff --git a/package.json b/package.json index da5b8525..72cf3f14 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,9 @@ "build-exp-deploy": "node main.js build --validateEslint --validateExpdesc --deploy --src=../", "build-exp-noplugin": "node main.js build --validateEslint --validateExpdesc --disablePlugin --src=../", "build-exp-novalidate": "node main.js build --src=../", - "build-lab": "node main.js buildLab --release=patch --src=../", + "build-lab": "node main.js buildLab --src=../", + "build-and-deploy-lab": "node main.js buildLab --release=patch --deploy --src=../", + "deploy-lab": "node main.js deployLab --release=patch --src=../", "clean": "node main.js clean --src=../", "validate": "node main.js validate --eslint --expdesc --src=../", "deploy": "node main.js deploy --src=../"