Skip to content

Commit

Permalink
Code Editor build support
Browse files Browse the repository at this point in the history
  • Loading branch information
RhythmAgg committed Dec 31, 2023
1 parent 5ff8fca commit 9f34929
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Lab = {
const Experiment = {
descriptor_name: "experiment-descriptor.json",
default_descriptor: "default-experiment-descriptor.json",
default_codeditor: "default-codeditor.json",
build_dir: "build",
exp_dir: "experiment",
ui_template_name: "templates",
Expand Down
5 changes: 5 additions & 0 deletions default-codeditor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "",
"inputs": [],
"expectedOutputs": ""
}
1 change: 1 addition & 0 deletions default-experiment-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"label": "",
"basedir": ".",
"LaTeXinMD": false,
"includeCodeEditor": true,
"service-worker": "/path/to/service-worker.js",
"units": [
{
Expand Down
1 change: 1 addition & 0 deletions enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ContentTypes = {
SIMULATION: "simulation",
ASSESMENT: "assesment",
ASSESSMENT: "assessment",
COMPONENT: "component",
};

const BuildEnvs = {
Expand Down
21 changes: 20 additions & 1 deletion exp_build/exp_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,31 @@ function run(src, lab_data, build_options) {
plugin.attributes.columnValue = lab_data.exp_short_name;
}
});

// Include Codeditor.json if the code editor is included
if(exp.descriptor.includeCodeEditor)
{
if (!shell.test("-f", Experiment.codeditorPath(src))) {
shell.cp(
path.resolve(Config.Experiment.default_codeditor),
path.resolve(this.src, Experiment.codeditorPath(src))
);
}
log.info("Code Editor included")
build_options.codeditor = true;
exp.includeCodeEditor();
}
else{
build_options.codeditor = false;
log.info("Code Editor Not included")
}

exp.init(Handlebars);
// Validation
if (build_options.isValidate)
{
exp.validate(build_options);
}
}

// if the experiment repo contains contributors.md file we will add its lu to the descriptor.
if (shell.test("-f", Experiment.contributorsPath(src))) {
Expand Down
21 changes: 21 additions & 0 deletions exp_build/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Experiment {
return path.resolve(src, Config.Experiment.descriptor_name);
}

static codeditorPath(src) {
return path.resolve(`${src}/experiment`, "codeditor.json");
}

static contributorsPath(src) {
return path.resolve(`${src}/experiment`, "contributors.md");
}
Expand Down Expand Up @@ -192,6 +196,12 @@ class Experiment {
bp: Config.build_path(this.src) + "/",
};

if(options.codeditor) {
const [codeditor_id, div_id] = Plugin.loadCodeEditor(options);
exp_info.codeditor_id = codeditor_id;
exp_info.codeditor_div_id = div_id;
}

if (options.plugins) {
Plugin.loadAllPlugins(options);
exp_info.plugins = Plugin.processExpScopePlugins(
Expand Down Expand Up @@ -246,6 +256,17 @@ class Experiment {
};
this.descriptor.units.push(contributors);
}

includeCodeEditor() {
const codeditor = {
"target": "codeditor.html",
"label": "CodeEditor",
"source": "codeditor.json",
"unit-type": "task",
"content-type": "component",
};
this.descriptor.units.push(codeditor);
}
}

module.exports = { Experiment };
Expand Down
6 changes: 6 additions & 0 deletions exp_build/plugin-config.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const config = [
imagesDirectory: "./plugins/svc-rating/images/",
},
},
{
id: "VLABS-code-editor",
div_id: "code-editor",
repo: "https://github.com/RhythmAgg/VLABS-code-editor",
label: "Code Editor",
},
];

module.exports = config;
16 changes: 16 additions & 0 deletions exp_build/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,28 @@ class Plugin {
shell.exec("mkdir plugins");
}
pluginConfig.map((plugin) => {
if(plugin.label == 'Code Editor') {
return;
}
shell.cd("plugins");
prepareRepo(plugin);
shell.cd("..");
});
}

static loadCodeEditor(options) {
const pluginConfigFile = Plugin.getConfigFileName(options.env);
const codeditor = require(pluginConfigFile).find(plugin => plugin.label == "Code Editor")

if (!fs.existsSync("plugins")) {
shell.exec("mkdir plugins");
}
shell.cd("plugins");
prepareRepo(codeditor);
shell.cd("..");
return [codeditor.id, codeditor.div_id]
}

static processExpScopePlugins(exp_info, hb, lab_data, options) {
log.debug("Processing experiment scope plugins");
let pluginConfig = require(Plugin.getConfigFileName(options.env));
Expand Down
9 changes: 9 additions & 0 deletions exp_build/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ class Task extends Unit {
}
}
break;

case ContentTypes.COMPONENT:
page_data.isComponent = true;
const css_module = [`plugins/${exp_info.codeditor_id}/css/codeditor.css`];
const js_module = [`plugins/${exp_info.codeditor_id}/js/codeditor.js`];
page_data.js_modules = this.finalPath(js_module);
page_data.css_modules = this.finalPath(css_module);
page_data.codeditor_div_id = exp_info.codeditor_div_id;
break;
}

const page_template = fs.readFileSync(
Expand Down
3 changes: 3 additions & 0 deletions exp_build/templates/partials/content.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
{{#if isText}}
{{{content}}}
{{/if}}
{{#if isComponent}}
<div id = "{{codeditor_div_id}}"></div>
{{/if}}
{{#if isVideo}}
{{{content}}}
{{/if}}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f34929

Please sign in to comment.