diff --git a/config.js b/config.js index 0eb11c31..33dce8d2 100644 --- a/config.js +++ b/config.js @@ -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", diff --git a/default-codeditor.json b/default-codeditor.json new file mode 100644 index 00000000..c10921a3 --- /dev/null +++ b/default-codeditor.json @@ -0,0 +1,5 @@ +{ + "name": "", + "inputs": [], + "expectedOutputs": "" +} diff --git a/default-experiment-descriptor.json b/default-experiment-descriptor.json index dfd22d21..038e378e 100644 --- a/default-experiment-descriptor.json +++ b/default-experiment-descriptor.json @@ -3,6 +3,7 @@ "label": "", "basedir": ".", "LaTeXinMD": false, + "includeCodeEditor": true, "service-worker": "/path/to/service-worker.js", "units": [ { diff --git a/enums.js b/enums.js index 8690a3cf..6ba40aa9 100644 --- a/enums.js +++ b/enums.js @@ -10,6 +10,7 @@ const ContentTypes = { SIMULATION: "simulation", ASSESMENT: "assesment", ASSESSMENT: "assessment", + COMPONENT: "component", }; const BuildEnvs = { diff --git a/exp_build/exp_gen.js b/exp_build/exp_gen.js index 9b7c5001..3ec0afb5 100644 --- a/exp_build/exp_gen.js +++ b/exp_build/exp_gen.js @@ -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))) { diff --git a/exp_build/experiment.js b/exp_build/experiment.js index 85165990..d544882f 100644 --- a/exp_build/experiment.js +++ b/exp_build/experiment.js @@ -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"); } @@ -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( @@ -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 }; diff --git a/exp_build/plugin-config.testing.js b/exp_build/plugin-config.testing.js index fbd7bf40..e17071b9 100644 --- a/exp_build/plugin-config.testing.js +++ b/exp_build/plugin-config.testing.js @@ -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; diff --git a/exp_build/plugin.js b/exp_build/plugin.js index 8a117d1d..dd4e860a 100644 --- a/exp_build/plugin.js +++ b/exp_build/plugin.js @@ -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)); diff --git a/exp_build/task.js b/exp_build/task.js index 4d06e8d1..f82d24de 100644 --- a/exp_build/task.js +++ b/exp_build/task.js @@ -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( diff --git a/exp_build/templates/partials/content.handlebars b/exp_build/templates/partials/content.handlebars index a80a1b0c..3b2491a1 100644 --- a/exp_build/templates/partials/content.handlebars +++ b/exp_build/templates/partials/content.handlebars @@ -12,6 +12,9 @@ {{#if isText}} {{{content}}} {{/if}} + {{#if isComponent}} +
+ {{/if}} {{#if isVideo}} {{{content}}} {{/if}} diff --git a/package-lock.json b/package-lock.json index 8921168f..f1c42637 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@babel/core": "^7.12.16", "@babel/plugin-proposal-class-properties": "^7.12.13", "@types/shelljs": "^0.8.8", - "@virtual-labs/service_worker": "^1.0.0", + "@virtual-labs/service_worker": "^1.0.1", "ajv": "^8.6.0", "ajv-errors": "^3.0.0", "ajv-formats": "^2.1.1", @@ -2211,9 +2211,9 @@ "integrity": "sha512-I3pkr8j/6tmQtKV/ZzHtuaqYSQvyjGRKH4go60Rr0IDLlFxuRT5V32uvB1mecM5G1EVAUyF/4r4QZ1GHgz+mxA==" }, "node_modules/@virtual-labs/service_worker": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@virtual-labs/service_worker/-/service_worker-1.0.0.tgz", - "integrity": "sha512-3Y9V6DxLuSfrshkyRCpr8PjOkzo3zm/DCt/timG8h0BdS84MqzM7bNOesJTe3KcR8/+EAesCF0aR8T6thsX4QA==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@virtual-labs/service_worker/-/service_worker-1.0.1.tgz", + "integrity": "sha512-iSDaJk92MWjHyHrdKFLxRHXEJyFARvB5SgtLLRHAbVIMyQBwsxYW4oNwzkavJu/LqZvF4BcGxFWIr0+J05i3kw==" }, "node_modules/abab": { "version": "2.0.6", @@ -10154,9 +10154,9 @@ "integrity": "sha512-I3pkr8j/6tmQtKV/ZzHtuaqYSQvyjGRKH4go60Rr0IDLlFxuRT5V32uvB1mecM5G1EVAUyF/4r4QZ1GHgz+mxA==" }, "@virtual-labs/service_worker": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@virtual-labs/service_worker/-/service_worker-1.0.0.tgz", - "integrity": "sha512-3Y9V6DxLuSfrshkyRCpr8PjOkzo3zm/DCt/timG8h0BdS84MqzM7bNOesJTe3KcR8/+EAesCF0aR8T6thsX4QA==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@virtual-labs/service_worker/-/service_worker-1.0.1.tgz", + "integrity": "sha512-iSDaJk92MWjHyHrdKFLxRHXEJyFARvB5SgtLLRHAbVIMyQBwsxYW4oNwzkavJu/LqZvF4BcGxFWIr0+J05i3kw==" }, "abab": { "version": "2.0.6",