Skip to content

Commit

Permalink
separate commands for build and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-debug15 committed Apr 25, 2023
1 parent 2d94f1f commit 2c0f6c6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 36 deletions.
2 changes: 1 addition & 1 deletion assets_plugins/json/bug-report-questions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ContentTypes } = require("../../Enums");
const { ContentTypes } = require("../../enums");

const issues = {
[ContentTypes.TEXT]: ["Insufficient Content"],
Expand Down
2 changes: 1 addition & 1 deletion lab_build/exp_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
70 changes: 41 additions & 29 deletions 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.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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
};
29 changes: 25 additions & 4 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/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

Expand Down Expand Up @@ -212,6 +212,9 @@ function main() {
return;
}

let release = args.release || "minor";
let labpath = "";

switch (option) {
case "build":
let isClean = args.clean || false;
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=../"
Expand Down

0 comments on commit 2c0f6c6

Please sign in to comment.