From 5e1374221a5b14b2bdc6f723b3948ae259c3d240 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Tue, 14 Apr 2020 19:50:44 +0300 Subject: [PATCH 1/5] implement export as action --- cases/0-hello-world/src/index.heta | 31 +++++++++++++++++++++++- src/builder/index.js | 7 +++--- src/container.js | 39 ++++++++++++++++++++++++++++-- src/core/_export.js | 1 + src/gsk-xlsx-export/index.js | 2 +- src/json-export/index.js | 2 +- src/julia-export/index.js | 2 +- src/matlab-export/index.js | 2 +- src/mrgsolve-export/index.js | 2 +- src/sbml-export/index.js | 4 +-- src/simbio-export/index.js | 2 +- src/slv-export/index.js | 2 +- src/xlsx-export/index.js | 2 +- src/yaml-export/index.js | 2 +- 14 files changed, 82 insertions(+), 18 deletions(-) diff --git a/cases/0-hello-world/src/index.heta b/cases/0-hello-world/src/index.heta index 78353110..ae24ead8 100644 --- a/cases/0-hello-world/src/index.heta +++ b/cases/0-hello-world/src/index.heta @@ -28,10 +28,39 @@ end space: mm }; +#export { + format: SBML, + filepath: mm_sbml, + eventsOff: true +}; +#export { + format: Simbio, + filepath: mm_simbio, +}; +#export { + format: JSON, + filepath: full_json, +}; +#export { + format: YAML, + filepath: full_yaml, +}; +#export { + format: SLV, + filepath: mm_slv, +}; +#export { + format: Matlab, + filepath: matlab1, +}; + + mm::mm_sbml @SBMLExport { title: Exported mm model}; +/* mm::mm_simbio @SimbioExport; mm::full_json @JSONExport; mm::full_yaml @YAMLExport; mm::mm_slv @SLVExport; mm::mm_mrg @MrgsolveExport { title: export to mrgsolve }; -mm::matlab1 @MatlabExport { filepath: matlab }; \ No newline at end of file +mm::matlab1 @MatlabExport { filepath: matlab }; +*/ diff --git a/src/builder/index.js b/src/builder/index.js index 5d0b4984..89b82b23 100644 --- a/src/builder/index.js +++ b/src/builder/index.js @@ -108,13 +108,12 @@ class Builder { } exportMany(){ if (!this.options.skipExport) { - let exportElements = this.container - .toArray() - .filter((obj) => obj.instanceOf('_Export')); + let exportElements = this.container.exportStorage; this.logger.info(`Start exporting to files, total: ${exportElements.length}.`); exportElements.forEach((exportItem) => { - let msg = `Exporting "${exportItem.index}" component of type "${exportItem.className}"...`; + let fullPath = path.resolve(this._distDirname, exportItem.filepath); + let msg = `Exporting to "${fullPath}" of format "${exportItem.format}"...`; this.logger.info(msg); exportItem.makeAndSave(this._distDirname); this.logger.pushMany(exportItem.logger); diff --git a/src/container.js b/src/container.js index 46abe50a..3bb5790b 100644 --- a/src/container.js +++ b/src/container.js @@ -31,6 +31,8 @@ class Container { let nameless = new Namespace('nameless'); nameless._isAbstract = false; this._namespaces.set('nameless', nameless); + // array to store _Export Instances + this.exportStorage = []; } get namespaces(){ return this._namespaces; @@ -324,11 +326,40 @@ class Container { return clone; } */ + export(q = {}){ + let logger = new Logger(); + let space = q.space || 'nameless'; + + let namespace = this.namespaces.get(space); + if (namespace === undefined) + logger.error(`#export action is reffered to namespace "${space}", which is not set.`, 'QueueError'); + + if (q.format === undefined) { + logger.error('Empty format option in #export', 'QueueError'); + } else if (typeof this.exports[q.format] !== 'function') { + logger.error(`Unknown format "${q.format}" in #export action.`, 'QueueError'); + } + + if (!logger.hasErrors) { + // create export instance + let exportInstance = new this.exports[q.format](); + exportInstance.merge(q); + exportInstance.namespace = namespace; + logger.pushMany(exportInstance.logger); + // push to storage + this.exportStorage.push(exportInstance); + } + + this.logger.pushMany(logger); + } load(q, isCore = false){ // estimate action, default is upsert let actionName = _.get(q, 'action', 'upsert'); - // do action - return this[actionName](q, isCore); + if (typeof this[actionName] !== 'function') { + this.logger.error(`Action #${actionName} is unknown and will be skipped.`, 'QueueError'); + } else { + return this[actionName](q, isCore); + } } loadMany(qArr, isCore = false){ qArr.forEach((q) => this.load(q, isCore)); @@ -378,6 +409,9 @@ Container.prototype.classes = { Const }; +// storage of Export classes +Container.prototype.exports = {}; + // converts {id: 'k1', space: 'one'} => 'one::k1' function getIndexFromQ(q = {}){ if(q.space!==undefined){ @@ -386,4 +420,5 @@ function getIndexFromQ(q = {}){ return q.id; } } + module.exports = Container; diff --git a/src/core/_export.js b/src/core/_export.js index 79f95907..80d95e8d 100644 --- a/src/core/_export.js +++ b/src/core/_export.js @@ -18,6 +18,7 @@ class _Export extends _Component { merge(q = {}){ super.merge(q); let validationLogger = _Export.isValid(q); + this.format = q.format; this.logger.pushMany(validationLogger); if (!validationLogger.hasErrors) { diff --git a/src/gsk-xlsx-export/index.js b/src/gsk-xlsx-export/index.js index c5ade3c0..7484ca33 100644 --- a/src/gsk-xlsx-export/index.js +++ b/src/gsk-xlsx-export/index.js @@ -153,7 +153,7 @@ class GSKXLSXExport extends XLSXExport { } } -Container.prototype.classes.GSKXLSXExport = GSKXLSXExport; +Container.prototype.exports.GSKXLSX = GSKXLSXExport; module.exports = { GSKXLSXExport diff --git a/src/json-export/index.js b/src/json-export/index.js index 4e6d1f5b..47f9f5d3 100644 --- a/src/json-export/index.js +++ b/src/json-export/index.js @@ -21,6 +21,6 @@ class JSONExport extends _Export { } } -Container.prototype.classes.JSONExport = JSONExport; +Container.prototype.exports.JSON = JSONExport; module.exports = { JSONExport }; diff --git a/src/julia-export/index.js b/src/julia-export/index.js index d094e77e..bafdd40a 100644 --- a/src/julia-export/index.js +++ b/src/julia-export/index.js @@ -122,6 +122,6 @@ class JuliaExport extends _Export { } } -Container.prototype.classes.JuliaExport = JuliaExport; +Container.prototype.exports.Julia = JuliaExport; module.exports = { JuliaExport }; diff --git a/src/matlab-export/index.js b/src/matlab-export/index.js index 016ca2e2..d5709353 100644 --- a/src/matlab-export/index.js +++ b/src/matlab-export/index.js @@ -133,6 +133,6 @@ class MatlabExport extends _Export { } } -Container.prototype.classes.MatlabExport = MatlabExport; +Container.prototype.exports.Matlab = MatlabExport; module.exports = { MatlabExport }; diff --git a/src/mrgsolve-export/index.js b/src/mrgsolve-export/index.js index f3b0c107..912fcd43 100644 --- a/src/mrgsolve-export/index.js +++ b/src/mrgsolve-export/index.js @@ -97,7 +97,7 @@ class MrgsolveExport extends _Export { MrgsolveExport._requirements = { }; -Container.prototype.classes.MrgsolveExport = MrgsolveExport; +Container.prototype.exports.Mrgsolve = MrgsolveExport; module.exports = { MrgsolveExport diff --git a/src/sbml-export/index.js b/src/sbml-export/index.js index 90aa72fe..a89ad61b 100644 --- a/src/sbml-export/index.js +++ b/src/sbml-export/index.js @@ -5,7 +5,7 @@ require('./expression'); const legalUnits = require('./legal-units'); class SBMLExport extends _Export { - merge(q={}, skipChecking){ + merge(q = {}, skipChecking){ super.merge(q, skipChecking); return this; @@ -52,7 +52,7 @@ class SBMLExport extends _Export { SBMLExport._requirements = { }; -Container.prototype.classes.SBMLExport = SBMLExport; +Container.prototype.exports.SBML = SBMLExport; module.exports = { SBMLExport diff --git a/src/simbio-export/index.js b/src/simbio-export/index.js index b46b6cda..8f6aebad 100644 --- a/src/simbio-export/index.js +++ b/src/simbio-export/index.js @@ -57,7 +57,7 @@ class SimbioExport extends _Export{ SimbioExport._requirements = { }; -Container.prototype.classes.SimbioExport = SimbioExport; +Container.prototype.exports.Simbio = SimbioExport; module.exports = { SimbioExport diff --git a/src/slv-export/index.js b/src/slv-export/index.js index f3227f90..74e4129a 100644 --- a/src/slv-export/index.js +++ b/src/slv-export/index.js @@ -167,7 +167,7 @@ class SLVExport extends _Export{ SLVExport._requirements = { }; -Container.prototype.classes.SLVExport = SLVExport; +Container.prototype.exports.SLV = SLVExport; module.exports = { SLVExport diff --git a/src/xlsx-export/index.js b/src/xlsx-export/index.js index 0cc9cda3..15bdb023 100644 --- a/src/xlsx-export/index.js +++ b/src/xlsx-export/index.js @@ -102,6 +102,6 @@ class XLSXExport extends _Export { } } -Container.prototype.classes.XLSXExport = XLSXExport; +Container.prototype.exports.XLSX = XLSXExport; module.exports = { XLSXExport }; diff --git a/src/yaml-export/index.js b/src/yaml-export/index.js index 156a19b8..2660c2ea 100644 --- a/src/yaml-export/index.js +++ b/src/yaml-export/index.js @@ -40,6 +40,6 @@ function fromOrderToCompare(order=[]){ }; } -Container.prototype.classes.YAMLExport = YAMLExport; +Container.prototype.exports.YAML = YAMLExport; module.exports = { YAMLExport }; From 5225e2103283564e40dfac689c3fb2c8dd0ea9b6 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Tue, 14 Apr 2020 23:39:10 +0300 Subject: [PATCH 2/5] use #export in cases and tests --- bin/init/index.json | 6 +-- bin/init/index.yml | 6 +-- bin/init/index0.heta | 14 +++---- bin/init/index1.heta | 14 +++---- cases/0-hello-world/master/full_json.json | 38 ------------------- cases/0-hello-world/master/full_yaml.yml | 24 ------------ cases/0-hello-world/master/mm_sbml.xml | 2 +- cases/0-hello-world/src/index.heta | 13 ++++++- cases/1-one-compartment/src/dividing.heta | 11 +++--- .../src/shared-constants.heta | 14 +++---- cases/1-one-compartment/src/single-model.heta | 7 ++-- cases/10-functions/src/index.heta | 4 +- cases/11-time-switcher/src/single-model.heta | 6 +-- cases/12-to-sbml/master/output.json | 12 ------ cases/12-to-sbml/master/sbml.xml | 2 +- cases/12-to-sbml/src/index.heta | 18 +++++---- cases/13-to-matlab/src/index.heta | 14 +++---- cases/14-sbml-module/src/index.heta | 8 +--- cases/2-cells/src/index.heta | 17 +++++---- cases/3-mixed-modules/src/index.heta | 2 +- cases/4-superexample/src/index.heta | 18 +++------ cases/5-tasks/src/index.heta | 10 ++--- cases/6-import/master/output_json.json | 10 ----- cases/6-import/master/output_sbml.xml | 2 +- cases/6-import/src/index.heta | 4 +- cases/7-importNS/src/index.heta | 3 +- cases/8-tables/src/index.heta | 2 +- cases/9-cs/src/index.heta | 3 +- cases/x-testing/src/index.heta | 6 +-- package.json | 2 +- src/namespace.js | 2 +- src/sbml-export/template.xml.njk | 2 +- test/cases/0.js | 24 +++--------- test/cases/12.js | 5 +-- test/cases/6.js | 4 +- test/space/index.js | 6 +-- 36 files changed, 118 insertions(+), 217 deletions(-) diff --git a/bin/init/index.json b/bin/init/index.json index faa1e90a..357ff4bd 100644 --- a/bin/init/index.json +++ b/bin/init/index.json @@ -8,9 +8,9 @@ } }, { - "action": "upsert", - "class": "SBMLExport", - "id": "output_sbml", + "action": "export", + "format": "SBML", + "filepath": "output_sbml", "version": "L2V4" } ] diff --git a/bin/init/index.yml b/bin/init/index.yml index feba6f0c..01af166b 100644 --- a/bin/init/index.yml +++ b/bin/init/index.yml @@ -6,7 +6,7 @@ assignments: start_: 1 - - action: upsert - class: SBMLExport - id: output_sbml + action: export + format: SBML + filepath: output_sbml version: L2V4 diff --git a/bin/init/index0.heta b/bin/init/index0.heta index 9f967d8c..f5f45ef7 100644 --- a/bin/init/index0.heta +++ b/bin/init/index0.heta @@ -12,10 +12,10 @@ include ./qsp-units.heta p1 @Record .= 1; // exports -output_sbml @SBMLExport { filepath: sbml, version: L2V4 }; -//output_slv @SLVExport { filepath: model, eventsOff: false }; -//output_json @JSONExport { filepath: output }; -//output_yaml @YAMLExport { filepath: output }; -//output_simbio @SimbioExport { filepath: simbio }; -//output_mrg @MrgsolveExport { filepath: mrgsolve }; -//output_xlsx @XLSXExport { filepath: table, omitRows: 3, splitByClass: true }; +#export { format: SBML, filepath: sbml, version: L2V4 }; +//#export { format: SLV, filepath: model, eventsOff: false }; +//#export { format: JSON, filepath: output }; +//#export { format: YAML, filepath: output }; +//#export { format: Simbio, filepath: simbio }; +//#export { format: Mrgsolve, filepath: mrgsolve }; +//#export { format: XLSX, filepath: table, omitRows: 3, splitByClass: true }; diff --git a/bin/init/index1.heta b/bin/init/index1.heta index 182f1401..18dcdfa8 100644 --- a/bin/init/index1.heta +++ b/bin/init/index1.heta @@ -21,10 +21,10 @@ include ./table.xlsx type xlsx with { sheet: 5, omitRows: 3 } p1 @Record .= 1; // exports -output_sbml @SBMLExport { filepath: sbml, version: L2V4 }; -//output_slv @SLVExport { filepath: model, eventsOff: false }; -//output_json @JSONExport { filepath: output }; -//output_yaml @YAMLExport { filepath: output }; -//output_simbio @SimbioExport { filepath: simbio }; -//output_mrg @MrgsolveExport { filepath: mrgsolve }; -//output_xlsx @XLSXExport { filepath: table, omitRows: 3, splitByClass: true }; +#export { format: SBML, filepath: sbml, version: L2V4 }; +//#export { format: SLV, filepath: model, eventsOff: false }; +//#export { format: JSON, filepath: output }; +//#export { format: YAML, filepath: output }; +//#export { format: Simbio, filepath: simbio }; +//#export { format: Mrgsolve, filepath: mrgsolve }; +//#export { format: XLSX, filepath: table, omitRows: 3, splitByClass: true }; diff --git a/cases/0-hello-world/master/full_json.json b/cases/0-hello-world/master/full_json.json index 89061871..becb0a05 100644 --- a/cases/0-hello-world/master/full_json.json +++ b/cases/0-hello-world/master/full_json.json @@ -715,43 +715,5 @@ "space": "mm", "units": "uM", "num": 2.5 - }, - { - "class": "SBMLExport", - "id": "mm_sbml", - "space": "mm", - "title": "Exported mm model" - }, - { - "class": "SimbioExport", - "id": "mm_simbio", - "space": "mm" - }, - { - "class": "JSONExport", - "id": "full_json", - "space": "mm" - }, - { - "class": "YAMLExport", - "id": "full_yaml", - "space": "mm" - }, - { - "class": "SLVExport", - "id": "mm_slv", - "space": "mm" - }, - { - "class": "MrgsolveExport", - "id": "mm_mrg", - "space": "mm", - "title": "export to mrgsolve" - }, - { - "class": "MatlabExport", - "id": "matlab1", - "space": "mm", - "filepath": "matlab" } ] \ No newline at end of file diff --git a/cases/0-hello-world/master/full_yaml.yml b/cases/0-hello-world/master/full_yaml.yml index 382fcb0a..fe1a5556 100644 --- a/cases/0-hello-world/master/full_yaml.yml +++ b/cases/0-hello-world/master/full_yaml.yml @@ -306,27 +306,3 @@ space: mm units: uM num: 2.5 -- class: SBMLExport - id: mm_sbml - space: mm - title: Exported mm model -- class: SimbioExport - id: mm_simbio - space: mm -- class: JSONExport - id: full_json - space: mm -- class: YAMLExport - id: full_yaml - space: mm -- class: SLVExport - id: mm_slv - space: mm -- class: MrgsolveExport - id: mm_mrg - space: mm - title: export to mrgsolve -- class: MatlabExport - id: matlab1 - space: mm - filepath: matlab diff --git a/cases/0-hello-world/master/mm_sbml.xml b/cases/0-hello-world/master/mm_sbml.xml index 31531196..cf82cc22 100644 --- a/cases/0-hello-world/master/mm_sbml.xml +++ b/cases/0-hello-world/master/mm_sbml.xml @@ -1,6 +1,6 @@ - + - + - + x2 } := k1*x1*comp1; -sbml1 @SBMLExport { filepath: sbml.xml }; -//slv1 @SLVExport { filepath: model }; +#export { filepath: sbml.xml, format: SBML }; // switcher cond1 @Record := 6-x1; diff --git a/cases/x-testing/src/index.heta b/cases/x-testing/src/index.heta index 183501e4..70b9885d 100644 --- a/cases/x-testing/src/index.heta +++ b/cases/x-testing/src/index.heta @@ -5,9 +5,7 @@ k1 @Const = 1.4; c1 @Compartment .= 1; -excel @XLSXExport { filepath: table, omitRows: 3, sheet: one, splitByClass: true }; -json @JSONExport { filepath: output }; -//yaml @YAMLExport { filepath: output }; -//slv @SLVExport { filepath: model }; +#export { format: XLSX, filepath: table, omitRows: 3, sheet: one, splitByClass: true }; +#export { format: JSON, filepath: output }; include 1.heta type heta diff --git a/package.json b/package.json index 649fb882..5b89e359 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Programming platform for Quantitative Systems Pharmacology modeling in NodeJS", "main": "src/index.js", "scripts": { - "test:dev": "mocha --recursive --exclude **/*.tmp.js test/core/species.js", + "test:dev": "mocha --recursive --exclude **/*.tmp.js test/cases/6.js", "test": "mocha test --recursive --exclude **/*.tmp.js", "jsdoc": "jsdoc -r -c .jsdoc.json --readme api-references.md -d docs src", "test:cov": "nyc --reporter=lcov npm run test", diff --git a/src/namespace.js b/src/namespace.js index 08fe1d88..0a04c308 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const Logger = require('./logger'); class Namespace extends Map { - constructor(spaceName){ + constructor(spaceName){ super(); //if (typeof spaceName !== 'string') // throw new TypeError(`spaceName argument must be string, got ${spaceName}`); diff --git a/src/sbml-export/template.xml.njk b/src/sbml-export/template.xml.njk index f626f329..f86e707b 100644 --- a/src/sbml-export/template.xml.njk +++ b/src/sbml-export/template.xml.njk @@ -1,6 +1,6 @@ - + {% if image.notes %}{{image.notesHTML}}{% endif %} {%- set listOfCompartments = image.population.selectByClassName('Compartment') -%} diff --git a/test/cases/0.js b/test/cases/0.js index 81c7e212..f6b3fc2b 100644 --- a/test/cases/0.js +++ b/test/cases/0.js @@ -39,15 +39,14 @@ describe('Testing "cases/0-hello-world"', () => { }); it('Run @SBMLExport, check and compare.', () => { - let sbml_export = b.container.select({id: 'mm_sbml', space: 'mm'}); + let sbml_export = b.container.exportStorage[0]; let code = sbml_export.make()[0].content; expect(code).xml.to.to.be.valid(); expect(code).xml.be.deep.equal(sbml_correct); - //console.log(code); }); it('Run @MrgsolveExport, check and compare.', () => { - let mm_mrg = b.container.select({id: 'mm_mrg', space: 'mm'}); + let mm_mrg = b.container.exportStorage[5]; let code = mm_mrg.make()[0].content; let filename = './diagnostics/0/mm_mrg.cpp'; fs.outputFileSync(filename, code); @@ -55,11 +54,7 @@ describe('Testing "cases/0-hello-world"', () => { }); it('Run @JSONExport, check and compare.', () => { - const JSONExport = b.container.classes.JSONExport; - let json_export = new JSONExport; - json_export._id = 'json_export'; - json_export.namespace = b.container.namespaces.get('mm'); - + let json_export = b.container.exportStorage[2]; let code = json_export.make()[0].content; let obj = JSON.parse(code); expect(obj).to.be.deep.equal(json_correct); @@ -67,11 +62,7 @@ describe('Testing "cases/0-hello-world"', () => { }); it('Run @YAMLExport, check and compare.', () => { - const YAMLExport = b.container.classes.YAMLExport; - let yaml_export = new YAMLExport; - yaml_export._id = 'yaml_export'; - yaml_export.namespace = b.container.namespaces.get('mm'); - + let yaml_export = b.container.exportStorage[3]; let code = yaml_export.make()[0].content; let obj = safeLoad(code); expect(obj).to.be.deep.equal(yaml_correct); @@ -79,14 +70,11 @@ describe('Testing "cases/0-hello-world"', () => { }); it('Run @SLVExport, check and compare.', () => { - const SLVExport = b.container.classes.SLVExport; - let slv_export = new SLVExport; - slv_export._id = 'slv_export'; - slv_export.namespace = b.container.namespaces.get('mm'); - + let slv_export = b.container.exportStorage[4]; let code = slv_export.make()[0].content; let obj = slvParse.parse(code); expect(obj).to.be.deep.equal(slv_correct); //console.log(obj); }); + }); diff --git a/test/cases/12.js b/test/cases/12.js index e73c0e5b..4824f5b9 100644 --- a/test/cases/12.js +++ b/test/cases/12.js @@ -35,9 +35,8 @@ describe('Testing "cases/12-to-sbml"', () => { }); it('Run @SBMLExport, check and compare.', () => { - const SBMLExport = b.container.classes.SBMLExport; + const SBMLExport = b.container.exports.SBML; let sbml_export = new SBMLExport; - sbml_export._id = 'output_sbml'; sbml_export.namespace = b.container.namespaces.get('first'); let code = sbml_export.make()[0].content; @@ -47,7 +46,7 @@ describe('Testing "cases/12-to-sbml"', () => { }); it('Run @JSONExport, check and compare.', () => { - const JSONExport = b.container.classes.JSONExport; + const JSONExport = b.container.exports.JSON; let json_export = new JSONExport; json_export._id = 'json_export'; json_export.namespace = b.container.namespaces.get('first'); diff --git a/test/cases/6.js b/test/cases/6.js index 7ea7dcd6..b0f98067 100644 --- a/test/cases/6.js +++ b/test/cases/6.js @@ -34,7 +34,7 @@ describe('Testing "cases/6-import"', () => { }); it('Run @SBMLExport, check and compare.', () => { - let sbml_export = b.container.select({id: 'output_sbml', space: 'model'}); + let sbml_export = b.container.exportStorage[0]; let code = sbml_export.make()[0].content; expect(code).xml.to.to.be.valid(); expect(code).xml.be.deep.equal(sbml_correct); @@ -42,7 +42,7 @@ describe('Testing "cases/6-import"', () => { }); it('Run @JSONExport, check and compare.', () => { - const JSONExport = b.container.classes.JSONExport; + const JSONExport = b.container.exports.JSON; let json_export = new JSONExport; json_export._id = 'output_json'; json_export.namespace = b.container.namespaces.get('model'); diff --git a/test/space/index.js b/test/space/index.js index ac1dda66..30753122 100644 --- a/test/space/index.js +++ b/test/space/index.js @@ -30,9 +30,9 @@ describe('Testing anonimous space.', () => { space: 'one' }, { - id: 'json1', + action: 'export', space: 'one', - class: 'JSONExport' + format: 'JSON' }, { id: 'p1', @@ -52,6 +52,6 @@ describe('Testing anonimous space.', () => { } ]); - expect(c).to.have.property('length', 6); + expect(c).to.have.property('length', 5); }); }); From 0695a395f43acdb3e4b4ea5a61015d98977bf502 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Wed, 15 Apr 2020 23:35:38 +0300 Subject: [PATCH 3/5] add old export deprication --- cases/0-hello-world/src/index.heta | 3 +-- package.json | 2 +- src/container.js | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cases/0-hello-world/src/index.heta b/cases/0-hello-world/src/index.heta index b72ca9ba..e091f9c2 100644 --- a/cases/0-hello-world/src/index.heta +++ b/cases/0-hello-world/src/index.heta @@ -65,9 +65,8 @@ end filepath: matlab1, }; - /* -mm::mm_sbml @SBMLExport { title: Exported mm model}; +mm::mm_sbml @SBMExport { title: Exported mm model}; mm::mm_simbio @SimbioExport; mm::full_json @JSONExport; mm::full_yaml @YAMLExport; diff --git a/package.json b/package.json index 5b89e359..d6956972 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Programming platform for Quantitative Systems Pharmacology modeling in NodeJS", "main": "src/index.js", "scripts": { - "test:dev": "mocha --recursive --exclude **/*.tmp.js test/cases/6.js", + "test:dev": "mocha --recursive --exclude **/*.tmp.js test/container/container-actions.js", "test": "mocha test --recursive --exclude **/*.tmp.js", "jsdoc": "jsdoc -r -c .jsdoc.json --readme api-references.md -d docs src", "test:cov": "nyc --reporter=lcov npm run test", diff --git a/src/container.js b/src/container.js index 3bb5790b..4c837a0c 100644 --- a/src/container.js +++ b/src/container.js @@ -48,7 +48,25 @@ class Container { if(reservedWords.indexOf(q.id)!==-1) logger.error(`${ind} id cannot be one of reserved word, but have "${q.id}". reservedWords = [${reservedWords}]`, 'QueueError'); if(!q.class || typeof q.class !== 'string') - logger.error(`${ind} No class or unsuitable class for "insert": ${q.class}`); + logger.error(`${ind} No class or unsuitable class for "insert": ${q.class}`, 'QueueError'); + + // STOP + if (logger.hasErrors) { + this.logger.pushMany(logger); + return; + } + + let exportCheck = q.class.match(/^(\w+)Export$/); + if (exportCheck !== null) { // check if old export syntax is used + logger.warn(`Usage of Export is depricated starting from v0.5.0, use syntax: #export {format: ${exportCheck[1]}, ...}`) + this.logger.pushMany(logger); + let exportQ = _.omit(q, ['class', 'id']); + _.defaults(exportQ, { + format: exportCheck[1], + filepath: q.id + }); + return this.export(exportQ); + } // check if class is in the list let selectedClass = this.classes[q.class]; From e5e896d9f3a2c88777797e96b16be3ff438463d5 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Wed, 22 Apr 2020 12:35:24 +0300 Subject: [PATCH 4/5] check index file before building --- bin/heta-build.js | 53 ++++++++++++++++-------------- cases/0-hello-world/src/index.heta | 4 +-- src/builder/index.js | 9 ++++- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/bin/heta-build.js b/bin/heta-build.js index fde5c247..e8722fb8 100644 --- a/bin/heta-build.js +++ b/bin/heta-build.js @@ -22,14 +22,14 @@ program .description('Compile Heta based platform and create set of export files.') //.arguments(' [dir]') .usage('[options] [dir]') - .option('-d, --declaration ', 'platform declaration file without extension, search extensions: ["", ".json", ".json5", ".yml"]', 'platform') + .option('-d, --declaration ', 'declaration file name without extension to search throught extensions: ["", ".json", ".json5", ".yml"]', 'platform') // options - .option('--skip-export', 'do not export files to local directory') - .option('--log-mode ', 'When to create log file.') - .option('--debug', 'If set the raw module output will be stored in "meta".') + .option('-S, --skip-export', 'do not export files to local directory') + .option('-L, --log-mode ', 'When to create log file.') + .option('-d, --debug', 'If set the raw module output will be stored in "meta".') // moduleImport - .option('--source ', 'path to main heta module.') - .option('--type ', 'type of source file.') + .option('-s, --source ', 'path to main heta module.') + .option('-t, --type ', 'type of source file.') .parse(process.argv); // set target directory of platform @@ -46,17 +46,16 @@ let extensionNumber = searches .indexOf(true); // is declaration file found ? if (extensionNumber === -1) { + process.stdout.write('Running compilation without declaration file...\n'); var declaration = {}; - //console.log( 'Declaration file is not found in paths:\n', JSON.stringify(searches, null, 2)); - console.log('Running compilation without declaration file.'); } else { - let delarationFile = searches[extensionNumber]; - console.log(`Running compilation with declaration "${delarationFile}"`); - let declarationText = fs.readFileSync(delarationFile); + let declarationFile = searches[extensionNumber]; + process.stdout.write(`Running compilation with declaration file "${declarationFile}"...\n`); + let declarationText = fs.readFileSync(declarationFile); try { declaration = safeLoad(declarationText); } catch (e) { - console.log('Wrong format of declaration file:', e.message); + process.stdout.write(`Wrong format of declaration file: \n"${e.message}"\n`); process.exit(1); } } @@ -74,7 +73,7 @@ let CLIDeclaration = { } }; -// === combine options === +// === combine options CLI => declaration => default index === let integralDeclaration = _.defaultsDeep(CLIDeclaration, declaration); // wrong version throws, if no version stated than skip @@ -82,31 +81,35 @@ let satisfiesVersion = integralDeclaration.builderVersion ? semver.satisfies(version, integralDeclaration.builderVersion) : true; if (!satisfiesVersion) { - console.log(`Version of declaration file "${integralDeclaration.builderVersion}" does not satisfy current builder.`); + process.stdout.write(`Version of declaration file "${integralDeclaration.builderVersion}" does not satisfy current builder.\n`); process.exit(1); } -// === runBuilder === -let builder = new Builder(integralDeclaration, targetDir); +// === this part uses "send errors to developer" message === +try { + var builder = new Builder(integralDeclaration, targetDir); +} catch(e) { + process.stdout.write(contactMessage + '\n'); + throw e; +} if (builder.logger.hasErrors) { - console.log('Declaration ERROR! See logs.'); + process.stdout.write('Declaration ERROR! See logs.\n'); process.exit(1); } -// send errors to developer try { builder.run(); } catch(e) { - console.log(contactMessage); + process.stdout.write(contactMessage + '\n'); throw e; } - if (builder.logger.hasErrors) { - console.log('Compilation ERROR! See logs.'); - integralDeclaration.options.exitWithoutError - ? process.exit(0) - : process.exit(1); + process.stdout.write('Compilation ERROR! See logs.\n'); + if (integralDeclaration.options.exitWithoutError) + process.exit(0); + else + process.exit(1); } else { - console.log('Compilation OK!'); + process.stdout.write('Compilation OK!\n'); process.exit(0); } diff --git a/cases/0-hello-world/src/index.heta b/cases/0-hello-world/src/index.heta index e091f9c2..507c8bd5 100644 --- a/cases/0-hello-world/src/index.heta +++ b/cases/0-hello-world/src/index.heta @@ -65,8 +65,8 @@ end filepath: matlab1, }; -/* -mm::mm_sbml @SBMExport { title: Exported mm model}; +/* +mm::mm_sbml @SBMLExport { title: Exported mm model}; mm::mm_simbio @SimbioExport; mm::full_json @JSONExport; mm::full_yaml @YAMLExport; diff --git a/src/builder/index.js b/src/builder/index.js index 89b82b23..d97ccf47 100644 --- a/src/builder/index.js +++ b/src/builder/index.js @@ -48,7 +48,7 @@ class Builder { return; } - // assignments + // file paths Object.assign(this, declaration); this._coreDirname = path.resolve(coreDirname); this._distDirname = path.resolve(coreDirname, declaration.options.distDir); @@ -58,7 +58,14 @@ class Builder { // create container this.container = new Container(); this.logger.info(`Builder initialized in directory "${this._coreDirname}".`); + + // index file not found + let indexFilepath = path.resolve(coreDirname, declaration.importModule.source); + if (!fs.existsSync(indexFilepath)) { + this.logger.error(`index file "${indexFilepath}" does not exist.`, 'BuilderError'); + } } + run(){ this.logger.info(`Compilation of module "${this.importModule.source}" of type "${this.importModule.type}"...`); From ea222c412e1e34a22b16291ed381afe4da271007 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Thu, 23 Apr 2020 10:40:00 +0300 Subject: [PATCH 5/5] update version to 0.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6956972..c8c0a591 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "heta-compiler", - "version": "0.4.32", + "version": "0.5.0", "description": "Programming platform for Quantitative Systems Pharmacology modeling in NodeJS", "main": "src/index.js", "scripts": {