Skip to content

Commit

Permalink
feat(templateloader): Cache external models (#363)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Roberts <[email protected]>
  • Loading branch information
mttrbrts authored Jun 8, 2019
1 parent 57925b3 commit 93b0506
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/cicero-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require('yargs')
argv = Commands.validateParseArgs(argv);
return Commands.parse(argv.template, argv.sample, argv.out, argv.currentTime)
.then((result) => {
Logger.info(JSON.stringify(result));
if(result) {Logger.info(JSON.stringify(result));}
})
.catch((err) => {
Logger.error(err.message);
Expand Down Expand Up @@ -78,7 +78,7 @@ require('yargs')
argv = Commands.validateGenerateTextArgs(argv);
return Commands.generateText(argv.template, argv.data, argv.out)
.then((result) => {
Logger.info(result);
if(result) {Logger.info(JSON.stringify(result));}
})
.catch((err) => {
Logger.error(err.message);
Expand Down Expand Up @@ -147,7 +147,7 @@ require('yargs')
argv = Commands.validateExecuteArgs(argv);
return Commands.execute(argv.template, argv.sample, argv.request, argv.state, argv.currentTime)
.then((result) => {
Logger.info(JSON.stringify(result));
if(result) {Logger.info(JSON.stringify(result));}
})
.catch((err) => {
Logger.error(err.message);
Expand Down Expand Up @@ -176,7 +176,7 @@ require('yargs')
argv = Commands.validateInitArgs(argv);
return Commands.init(argv.template, argv.sample, argv.currentTime)
.then((result) => {
Logger.info(JSON.stringify(result));
if(result) {Logger.info(JSON.stringify(result));}
})
.catch((err) => {
Logger.error(err.message);
Expand Down
1 change: 1 addition & 0 deletions packages/cicero-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"scripts": {
"webpack": "webpack --config webpack.config.js --mode production",
"build": "babel src -d lib --copy-files && nearleyc ./src/tdl.ne -o ./lib/tdl.js && node scripts/nunjucks-precompile.js",
"build:watch": "babel src -d lib --copy-files --watch",
"prepublishOnly": "npm run build && npm run webpack",
"prepare": "npm run build",
"pretest": "npm run lint",
Expand Down
6 changes: 5 additions & 1 deletion packages/cicero-core/src/templateloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ class TemplateLoader {
* @return {Promise<Template>} a Promise to the instantiated template
*/
static async fromDirectory(Template, path, options) {

if (!options) {
options = {};
}
Expand Down Expand Up @@ -306,6 +305,11 @@ class TemplateLoader {
await template.getModelManager().updateExternalModels();
Logger.debug(method, 'Added model files', modelFiles.length);

const externalModelFiles = template.getModelManager().getModels();
externalModelFiles.forEach(function (file) {
fs.writeFileSync(path + '/models/' + file.name, file.content);
});

// load and add the ergo files
if(template.getMetadata().getErgoVersion()) {
const ergoFiles = await TemplateLoader.loadFilesContents(path, /lib\/.*\.ergo$/);
Expand Down

0 comments on commit 93b0506

Please sign in to comment.