Skip to content

Commit

Permalink
Allow templating of contact-summary.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed May 10, 2018
1 parent 1a7f570 commit 1a9e539
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-conf",
"version": "1.15.0",
"version": "1.16.0",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 6 additions & 11 deletions src/fn/compile-app-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module.exports = (projectDir /*, couchUrl */) => {
function compileAppSettings(projectDir) {
const files = {
app_settings: fs.readJson(`${projectDir}/app_settings.json`),
contact_summary: readJs(`${projectDir}/contact-summary.js`),
nools: loadNools(projectDir),
contact_summary: readJs(projectDir, 'contact-summary.js'),
nools: readJs(projectDir, 'rules.nools.js'),
targets: fs.readJson(`${projectDir}/targets.json`),
tasks_schedules: fs.readJson(`${projectDir}/tasks.json`),
};
Expand All @@ -47,7 +47,10 @@ module.exports = (projectDir /*, couchUrl */) => {

};

const readJs = path => cleanJs(fs.read(path));
const readJs = (projectDir, rootFile) =>
cleanJs(fs.read(`${projectDir}/${rootFile}`)
.replace(/__include_inline__\('\s*([^_]*)'\s*\);/g, (_, includedFile) =>
fs.read(`${projectDir}/${includedFile}`)));
const cleanJs = js =>
js.split('\n')
.map(s =>
Expand Down Expand Up @@ -121,11 +124,3 @@ function doFilter(target, rules) {
});
});
}

function loadNools(projectDir) {
const noolsBaseFile = `${projectDir}/rules.nools.js`;

return cleanJs(fs.read(noolsBaseFile)
.replace(/__include_inline__\('\s*([^_]*)'\s*\);/g, (_, filename) =>
fs.read(`${projectDir}/${filename}`)));
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"contact_summary": "",
"contact_summary": "function myFn() { console.log('hi'); }",
"tasks": {
"rules": "define Contact {}rule GenerateEvents {when {c: Contact}then {if (c.contact != null && c.contact.type === 'person') {emitTarget(c);}if (c.contact && c.contact.type === 'person') {emitTask(c);}emit('_complete', { _id: true });}}",
"schedules": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__include_inline__('lib/shared-utils.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function myFn() { console.log('hi'); }
4 changes: 2 additions & 2 deletions test/fn/compile-app-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('compile-app-settings', () => {
it('should handle derivative app-settings definitions', () =>
test('derivative/child'));

it('should handle nools templating', () =>
test('nools-templating/project'));
it('should handle nools & contact-summary templating', () =>
test('templating/project'));

});

Expand Down

0 comments on commit 1a9e539

Please sign in to comment.