Comparing version 2.3.0-beta to 2.3.0-beta.2
@@ -6,5 +6,8 @@ 'use strict' | ||
path = require('path'), | ||
sh = require('shelljs') | ||
sh = require('shelljs'), | ||
NO_FILE_FOUND = 'Source path does not exist' | ||
/** | ||
* Base class that will extended to handle all the cli tasks | ||
*/ | ||
class Action { | ||
@@ -14,8 +17,14 @@ constructor(opt) { | ||
/* istanbul ignore next */ | ||
if (this.called) return | ||
this.called = true | ||
this.error = false | ||
// create a regex to figure out whether our user | ||
// wants to compile a single tag or some tags in a folder | ||
this.extRegex = RegExp('\\.' + opt.ext + '$') | ||
// If no target dir, default to source dir | ||
if (!opt.to) opt.to = opt.extRegex.test(opt.from) ? path.dirname(opt.from) : opt.from | ||
if (!opt.to) opt.to = this.extRegex.test(opt.from) ? path.dirname(opt.from) : opt.from | ||
@@ -29,10 +38,26 @@ // Resolve to absolute paths | ||
if (!sh.test('-e', opt.from)) helpers.err('Source path does not exist') | ||
if (!sh.test('-e', opt.from)) { | ||
/* istanbul ignore next */ | ||
if (opt.isCli) | ||
helpers.err(NO_FILE_FOUND) | ||
else { | ||
this.error = NO_FILE_FOUND | ||
return | ||
} | ||
} | ||
// Determine the input/output types | ||
opt.flow = (opt.extRegex.test(opt.from) ? 'f' : 'd') + (/\.js$/.test(opt.to) ? 'f' : 'd') | ||
// [directory, directory] | ||
// [file, directory] | ||
// [directory, file] | ||
// [file, file] | ||
opt.flow = (this.extRegex.test(opt.from) ? 'f' : 'd') + (/\.js$/.test(opt.to) ? 'f' : 'd') | ||
this.run(opt) | ||
// make sure to set always the compiler options | ||
if (!opt.compiler) opt.compiler = {} | ||
// each run method could return different stuff | ||
return this.run(opt) | ||
} | ||
@@ -39,0 +64,0 @@ } |
@@ -12,16 +12,17 @@ 'use strict' | ||
//TODO: analyze each file separatedly | ||
var from = opt.flow[0] == 'f' ? [opt.from] : sh.find(opt.from) | ||
var source = sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */'') | ||
var errors = analyzer(source).filter(function(result) { return result.error }) | ||
var from = opt.flow[0] == 'f' ? [opt.from] : sh.find(opt.from), | ||
source = sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), | ||
errors = analyzer(source).filter((result) => result.error ) | ||
if (errors.length) { | ||
log(chalk.white.bgRed(' Riot Tag Syntax Error ')) | ||
errors.map(function(result) { | ||
log(chalk.gray(result.line + '| ') + result.source) | ||
errors.map((result) => { | ||
log(chalk.yellow(result.line + '| ') + result.source) | ||
log(chalk.red('^^^ ' + result.error)) | ||
}) | ||
log(chalk.gray('Total error: ' + errors.length)) | ||
log(chalk.yellow('Total error: ' + errors.length)) | ||
} else { | ||
log(chalk.green('No syntax error. Ready to compile :)')) | ||
} | ||
return errors | ||
} | ||
@@ -28,0 +29,0 @@ } |
@@ -6,2 +6,3 @@ 'use strict' | ||
helpers = require('../helpers'), | ||
chalk = require('chalk'), | ||
compiler = global.compiler || require('riot-compiler'), | ||
@@ -11,2 +12,6 @@ path = require('path'), | ||
/** | ||
* Compile the tags using the riot-compiler | ||
*/ | ||
class Make extends Action { | ||
@@ -16,5 +21,5 @@ run(opt) { | ||
var from = opt.flow[0] == 'f' ? [opt.from] : helpers.find(opt.extRegex, opt.from), | ||
var from = opt.flow[0] == 'f' ? [opt.from] : helpers.find(this.extRegex, opt.from), | ||
base = opt.flow[0] == 'f' ? path.dirname(opt.from) : opt.from, | ||
to = opt.flow[1] == 'f' ? [opt.to] : helpers.remap(opt.ext, from, opt.to, base) | ||
to = opt.flow[1] == 'f' ? [opt.to] : helpers.remap(this.extRegex, from, opt.to, base) | ||
@@ -24,13 +29,52 @@ // Create any necessary dirs | ||
var dirs = {} | ||
to.map(function(f) { dirs[path.dirname(f)] = 0 }) | ||
to.map((f) => dirs[path.dirname(f)] = 0 ) | ||
sh.mkdir('-p', Object.keys(dirs)) | ||
// Process files | ||
if (opt.flow[1] == 'f') | ||
this.toFile(from, to, opt) | ||
else | ||
this.toDir(from, to, opt) | ||
function encapsulate(from) { | ||
if (!opt.compiler.modular) { | ||
return from | ||
} | ||
// Print what's been done (unless --silent) | ||
var out = ` | ||
/* istanbul ignore next */ | ||
if (!opt.compiler.silent) { | ||
from.map((src, i) => { | ||
helpers.log( | ||
chalk.blue(helpers.toRelative(src)) + | ||
chalk.cyan(' -> ') + | ||
chalk.green(helpers.toRelative(to[i] || to[0])) | ||
) | ||
}) | ||
} | ||
return true | ||
} | ||
toFile(from, to, opt) { | ||
this.encapsulate( | ||
from.map((path) => this.parse(path, opt)).join('\n').to(to[0]), | ||
opt | ||
) | ||
} | ||
toDir(from, to, opt) { | ||
from.map((from, i) => { | ||
return this.encapsulate(this.parse(from, opt), opt).to(to[i]) | ||
}) | ||
} | ||
parse(from, opt) { | ||
var out | ||
try { | ||
out = compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler) | ||
} catch (e) { | ||
helpers.err(e) | ||
} | ||
return out | ||
} | ||
encapsulate(from, opt) { | ||
if (!opt.compiler.modular) return from | ||
var out = ` | ||
(function(tagger) { | ||
@@ -48,17 +92,4 @@ if (typeof define === 'function' && define.amd) { | ||
` | ||
return out | ||
} | ||
return out | ||
function parse(from) { return compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler) } | ||
function toFile(from, to) { encapsulate(from.map(function (path) { return parse(path) }).join('\n')).to(to[0]) } | ||
function toDir(from, to) { from.map(function(from, i) { encapsulate(parse(from)).to(to[i]) }) } | ||
;(opt.flow[1] == 'f' ? toFile : toDir)(from, to) | ||
// Print what's been done (unless --silent) | ||
if (!opt.compiler.silent) { | ||
from.map(function(src, i) { | ||
helpers.log(helpers.toRelative(src) + ' -> ' + helpers.toRelative(to[i] || to[0])) | ||
}) | ||
} | ||
} | ||
@@ -65,0 +96,0 @@ } |
@@ -6,2 +6,3 @@ 'use strict' | ||
Make = require('./Make'), | ||
chalk = require('chalk'), | ||
helpers = require('../helpers'), | ||
@@ -11,5 +12,9 @@ path = require('path'), | ||
/** | ||
* Watch the source file to run a Make command anytime there's a change | ||
*/ | ||
class Watch extends Action { | ||
run(opt) { | ||
// run the first make | ||
new Make(opt) | ||
@@ -21,4 +26,4 @@ | ||
.watch(glob, { ignoreInitial: true }) | ||
.on('ready', function() { helpers.log('Watching ' + helpers.toRelative(glob)) }) | ||
.on('all', function() { new Make(opt) }) | ||
.on('ready', () => helpers.log(chalk.cyan('Watching ' + helpers.toRelative(glob)))) | ||
.on('all', () => new Make(opt)) | ||
} | ||
@@ -25,0 +30,0 @@ } |
@@ -37,3 +37,3 @@ 'use strict' | ||
var results = source.split('\n').map(function(row, n) { | ||
var results = source.split('\n').map((row, n) => { | ||
var m, err = '', type | ||
@@ -40,0 +40,0 @@ |
@@ -6,2 +6,3 @@ 'use strict' | ||
path = require('path'), | ||
chalk = require('chalk'), | ||
sh = require('shelljs') | ||
@@ -11,10 +12,6 @@ | ||
find(extRegex, from) { | ||
return sh.find(from).filter(function(f) { | ||
return extRegex.test(f) && TEMP_FILE_NAME.test(f) | ||
}) | ||
return sh.find(from).filter((f) => extRegex.test(f) && TEMP_FILE_NAME.test(f) ) | ||
}, | ||
remap(ext, from, to, base) { | ||
return from.map(function(from) { | ||
return path.join(to, path.relative(base, from).replace(ext, '.js')) | ||
}) | ||
return from.map((from) => path.join(to, path.relative(base, from).replace(ext, '.js')) ) | ||
}, | ||
@@ -24,8 +21,8 @@ toRelative(path) { | ||
}, | ||
log(msg, isSilent) { | ||
if (!isSilent) console.log(msg) | ||
log(msg) { | ||
if (!global.isSilent) console.log(msg) | ||
}, | ||
err(msg, isSilent) { | ||
err(msg) { | ||
msg += '\n' | ||
if (!isSilent) this.log(msg, isSilent) || process.exit(1) | ||
if (!global.isSilent) this.log(chalk.red(msg)) || process.exit(1) | ||
else throw msg | ||
@@ -32,0 +29,0 @@ }, |
@@ -24,2 +24,3 @@ #!/usr/bin/env node | ||
options = require('./options'), | ||
chalk = require('chalk'), | ||
optionator = require('optionator')(options), | ||
@@ -43,3 +44,3 @@ API = | ||
/* istanbul ignore next */ | ||
function cli() { | ||
@@ -49,4 +50,12 @@ | ||
var args = optionator.parse(process.argv, options) | ||
var args | ||
// was an error thrown parsing the options? | ||
try { | ||
args = optionator.parse(process.argv, options) | ||
} catch (e) { | ||
helpers.err(e) | ||
return e | ||
} | ||
// Translate args into options hash | ||
@@ -66,3 +75,3 @@ | ||
ext: args.ext, | ||
extRegex: RegExp('\\.' + args.ext + '$'), | ||
colors: args.colors, | ||
from: args._.shift(), | ||
@@ -73,10 +82,15 @@ to: args._.shift() | ||
// Call matching method | ||
var method = Object.keys(API).filter((v) => args[v] )[0] || ( opt.from ? 'make' : 'help' ) | ||
var method = Object.keys(API).filter(function(v) { return args[v] })[0] | ||
|| ( opt.from ? 'make' : 'help' ) | ||
// check whether the output should be colorized | ||
chalk.constructor({enabled: !!opt.colors }) | ||
opt.flow = (RegExp('\\.' + opt.extRegex + '$').test(opt.from) ? 'f' : 'd') + (/\.js$/.test(opt.to) ? 'f' : 'd') | ||
// create isSilent as global variable | ||
global.isSilent = args.silent | ||
API[method](opt) | ||
// flag used to detect wheter an action is triggered via command line or not | ||
opt.isCli = true | ||
return API[method](opt) | ||
} | ||
@@ -91,1 +105,3 @@ | ||
} else cli() | ||
@@ -79,3 +79,3 @@ const helpers = require('./helpers') | ||
option: 'template', | ||
type: 'Boolean', | ||
type: 'String', | ||
description: 'HTML pre-processor. Built-in support for: jade' | ||
@@ -94,2 +94,7 @@ }, | ||
{ | ||
option: 'colors', | ||
type: 'Boolean', | ||
description: 'Turn on colorized output' | ||
}, | ||
{ | ||
option: 'expr', | ||
@@ -96,0 +101,0 @@ type: 'Boolean', |
{ | ||
"name": "riot-cli", | ||
"version": "2.3.0-beta", | ||
"version": "2.3.0-beta.2", | ||
"description": "Riot command line utility", | ||
"main": "lib/index.js", | ||
"engines" : { | ||
"node" : ">=4.0.0" | ||
}, | ||
"directories": { | ||
@@ -27,7 +30,4 @@ "lib": "lib" | ||
"expect.js": "^0.3.1", | ||
"karma": "^0.13.10", | ||
"karma-coverage": "^0.5.2", | ||
"karma-mocha": "^0.2.0", | ||
"mocha": "^2.3.3", | ||
"phantomjs": "^1.9.18" | ||
"istanbul": "^0.3.22", | ||
"mocha": "^2.3.3" | ||
}, | ||
@@ -34,0 +34,0 @@ "license": "MIT", |
@@ -1,3 +0,5 @@ | ||
describe('Observable Tests', function() { | ||
describe('Cli Tests', function() { | ||
global.expect = require('expect.js') | ||
require('./specs/output.spec') | ||
require('./specs/api.spec') | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
42543
5
40
521
0
33