Skip to content

Commit

Permalink
Agrego base para cmd tool
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Oct 11, 2016
1 parent abc706e commit 40978ab
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 209 deletions.
97 changes: 97 additions & 0 deletions bin/txt-to-sql-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env node

"use strict";

var program = require('commander');
var multilang = require('../lib/txt-to-sql.js');
var Promises = require('best-promise');
var fs = require('fs-promise');
var path = require('path');

function realPath(inFile) {
return Promises.start(function() {
if(!inFile) { throw new Error("null file"); }
return fs.exists(inFile);
}).then(function(exists) {
if(! exists) { throw new Error("'"+inFile+"' does not exists"); }
return inFile;
}).then(function(inFile) {
return path.dirname(path.resolve(inFile));
}).catch(function(err) {
return Promise.reject(err);
});
};

function langs(val) {
return val.split(',')
}

program
.version(require('../package').version)
.usage('[options] input.md')
.option('-i, --input [input.md]', 'Name of the input file')
.option('-l, --lang [lang1]', 'Language to generate', langs)
.option('-o, --output [name]', 'Name of the output file. Requires --langs!')
.option('-d, --directory [name]', 'Name of the output directory.')
.option('-c, --check', 'Run multilang generating no files')
.option('-s, --silent', 'Do not output anything')
.option('--strip-comments', 'Remove HTML comments from output')
.option('--no-strip-comments', 'Do not remove HTML comments from output')
.option('-v, --verbose', 'Output all progress informations')
.parse(process.argv);


function isLongOptionSet(ame) {
var a=program.rawArgs;
for(var e=0; e<a.length; ++e) {
if(a[e]===ame) { return true; }
}
return false;
}

if( (""==program.args && !program.input) ){
program.help();
}

var params = {};
params.input = program.input ? program.input : program.args[0];
params.output = program.output;
params.check = program.check;
params.silent = program.silent;
params.langs = program.lang;
params.directory = program.directory;
params.verbose = program.verbose;

if(isLongOptionSet('--no-strip-comments')) {
params.stripComments = false;
} else if(isLongOptionSet('--strip-comments')) {
params.stripComments = true;
}

var doneMsg = params.check ? 'Done checking!' : 'Done!';

if(!params.directory) {
console.log("directory", params);
/*
realPath(params.input).then(function(dir) {
params.directory = dir;
multilang.main(params).then(function(){
if(! params.silent) { process.stderr.write(doneMsg); }
}).catch(function(err){
process.stderr.write("ERROR\n"+err.stack);
});
}).catch(function(err) {
process.stderr.write("ERROR: "+err.message);
program.help();
});
*/
} else {
console.log("file", params);
/*
multilang.main(params).then(function(){
if(! params.silent) { process.stderr.write(doneMsg); }
}).catch(function(err){
process.stderr.write("ERROR: "+err.message);
});
*/
}
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
"repository": "codenautas/txt-to-sql",
"license": "MIT",
"main": "lib/txt-to-sql.js",
"files": ["lib", "web"],
"bin": {
"txt-to-sql": "./bin/txt-to-sql-run.js"
},
"files": ["bin", "lib", "web"],
"dependencies": {
"commander": "2.8.1",
"fs-promise": "~0.5.0",

"best-globals": "~0.5.0"
"best-globals": "~0.5.0",
"best-promise": "~0.2.4",
"mini-tools": "~0.3.3"
},
"devDependencies": {
"browserify": "~13.1.0",
"buffer": "~4.9.1",
"expect.js": "~0.3.1",
"fs-extra": "~0.30.0",
"fs-promise": "~0.5.0",
"iconv-lite": "~0.4.13",
"istanbul": "~0.4.4",
"js-yaml": "~3.6.1",
Expand Down
Loading

0 comments on commit 40978ab

Please sign in to comment.