diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cca1794
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+language: node_js
+
+node_js:
+ - "4.4.3"
+ - "5.11.0"
+ - "6.1"
+
+before_script:
+ - npm install
+
+script:
+ - npm run test
\ No newline at end of file
diff --git a/cli.js b/cli.js
index 7314957..06385a2 100755
--- a/cli.js
+++ b/cli.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env node
'use strict';
const glob = require('glob');
@@ -9,15 +8,6 @@ const sh = require('shelljs');
const mkdirp = require('mkdirp');
const convert = require('./convert');
-const ARGS = yargs
- .describe('output', 'Output file')
- .describe('version', 'Print version number and exit')
- .help('help')
- .alias('o', 'output')
- .alias('h', 'help')
- .alias('v', 'version')
- .argv;
-
const cwd = sh.pwd().toString();
const convertAndWrite = (file, outputPath) => {
@@ -27,49 +17,67 @@ const convertAndWrite = (file, outputPath) => {
output = convert(output);
} catch ( e ) {
console.error('ERROR: convert error. Input code is too complex to convert.');
- process.exit(1);
+ return 1;
}
const outputDir = path.join(cwd, '/' + outputPath);
mkdirp(outputPath);
fs.writeFileSync(outputDir + path.basename(file), output);
+ return 0;
};
-if (ARGS.version || ARGS.v) {
- const json = require('./package.json');
- console.log(json.name + ' ' + json.version);
- process.exit(0);
-}
-
-
-if (ARGS._[0]) {
- const input = ARGS._[0];
- let output = undefined;
- if (ARGS.output || ARGS.o) {
- output = ARGS.output || ARGS.o;
- } else {
- console.error('ERROR: Invalid output');
- process.exit(1);
+const cli = (args) => {
+ if (typeof args === 'undefined') {
+ return 1;
}
- if (fs.existsSync(input)) {
- convertAndWrite(input, output);
- process.exit(0);
+ if (typeof args !== 'object') {
+ return 1;
}
- glob(input, (err, files) => {
- if (err) {
- console.error('ERROR: Invalid glob definition');
- process.exit(1);
+ yargs
+ .describe('output', 'Output file')
+ .describe('version', 'Print version number and exit')
+ .help('help')
+ .alias('o', 'output')
+ .alias('h', 'help')
+ .alias('v', 'version');
+
+ if (args.version || args.v) {
+ const json = require('./package.json');
+ console.log(json.name + ' ' + json.version);
+ return 0;
+ }
+
+
+ if (args._[0]) {
+ const input = args._[0];
+ let output = undefined;
+ if (args.output || args.o) {
+ output = args.output || args.o;
+ } else {
+ console.error('ERROR: Invalid output');
+ return 1;
}
- for (let file of files) {
- convertAndWrite(file, output);
+ if (fs.existsSync(input)) {
+ return convertAndWrite(input, output);
}
- });
- process.exit(0);
-}
+ glob(input, (err, files) => {
+ if (err) {
+ console.error('ERROR: Invalid glob definition');
+ return 1;
+ }
+ for (let file of files) {
+ convertAndWrite(file, output);
+ }
+ });
+ return 0;
+ }
-if ((ARGS.output || ARGS.o) && !ARGS._[0]) {
- console.error('ERROR: Invalid input');
- process.exit(1);
-}
+ if ((args.output || args.o) && !args._[0]) {
+ console.error('ERROR: Invalid input');
+ return 1;
+ }
+
+ console.log('Usage: kaomojify -o