Skip to content

Commit

Permalink
Only display pyxform installation suggestion if xls2xform cannot be f…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
alxndrsn committed Jun 11, 2017
1 parent 36e5428 commit e95c45b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ This tool expects a project to be sctructured as follows:
* add PNGout as somehow part of the form conversion step. But make sure it's cleanly separated from XML processing step
* remove `beta-` prefix from `--version` output
* define configure-all as separate action; convert argument order to <action>-first? How to allow multiple actions (if at all?)?
* improve xls2xform-medic error - manually detect whether it's installed before suggesting in the error message that it may not be
* parse xls2xform JSON output and display nicely
16 changes: 15 additions & 1 deletion src/lib/convert-forms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const error = require('../lib/log').error;
const execSync = require('child_process').execSync;
const exec = require('../lib/exec-promise');
const fs = require('../lib/sync-fs');
const info = require('../lib/log').info;
Expand Down Expand Up @@ -36,7 +37,9 @@ module.exports = (project, subDirectory, options) => {
const xls2xform = (sourcePath, targetPath) =>
exec('xls2xform-medic', sourcePath, targetPath)
.catch(e => {
error('There was a problem executing xls2xform. It may not be installed. To install, run ' + require('../cli/xls2xform-installation-command'));
if(!executableAvailable()) {
error('There was a problem executing xls2xform. It may not be installed. To install, run ' + require('../cli/xls2xform-installation-command'));
}
throw e;
});

Expand Down Expand Up @@ -64,6 +67,17 @@ const fixXml = path => {
fs.write(path, xml);
};

function executableAvailable() {
try {
execSync('xls2xform-medic -h', {
stdio: ['ignore', 'ignore', 'ignore'],
});
return true;
} catch(e) {
return false;
}
}

const shiftThingsAroundInTheModel = (path, xml) => {
const baseName = fs.path.parse(path).name;
let matchedBlock;
Expand Down

0 comments on commit e95c45b

Please sign in to comment.