Skip to content

Commit

Permalink
Separate JS templating into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed May 10, 2018
1 parent 1a9e539 commit eb9a2de
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 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.16.0",
"version": "1.16.1",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 1 addition & 12 deletions src/fn/compile-app-settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('../lib/sync-fs');
const readJs = require('../lib/read-templated-js');

module.exports = (projectDir /*, couchUrl */) => {

Expand Down Expand Up @@ -47,18 +48,6 @@ module.exports = (projectDir /*, couchUrl */) => {

};

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 =>
s.trim()
.replace(/\s*\/\/.*/, '') // single-line comments (like this one)
).join('')
.replace(/\s*\/\*(?:(?!\*\/).)*\*\/\s*/g, ''); /* this kind of comment */

function applyTransforms(app_settings, inherited) {
doDelete(app_settings, inherited.delete);
doReplace(app_settings, inherited.replace);
Expand Down
14 changes: 14 additions & 0 deletions src/lib/read-templated-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('../lib/sync-fs');

const cleanJs = js =>
js.split('\n')
.map(s =>
s.trim()
.replace(/\s*\/\/.*/, '') // single-line comments (like this one)
).join('')
.replace(/\s*\/\*(?:(?!\*\/).)*\*\/\s*/g, ''); /* this kind of comment */

module.exports = (projectDir, rootFile) =>
cleanJs(fs.read(`${projectDir}/${rootFile}`)
.replace(/__include_inline__\('\s*([^_]*)'\s*\);/g, (_, includedFile) =>
fs.read(`${projectDir}/${includedFile}`)));

0 comments on commit eb9a2de

Please sign in to comment.