Comparing version 2.3.12 to 2.3.13-beta
@@ -6,2 +6,3 @@ 'use strict' | ||
path = require('path'), | ||
rollup = require('rollup'), | ||
chalk = require('chalk'), | ||
@@ -21,3 +22,3 @@ sh = require('shelljs') | ||
/** | ||
* Loop files paths strings contained in an array remapping them to ad different location | ||
* Loop files paths strings contained in an array remapping them to a different location | ||
* @param { RegExp } extRegex - regular expression containing the file extension | ||
@@ -44,2 +45,73 @@ * @param { String } from - path where the files are located | ||
/** | ||
* Extend any object with other properties | ||
* @param { Object } src - source object | ||
* @returns { Object } the resulting extended object | ||
* | ||
* var obj = { foo: 'baz' } | ||
* extend(obj, {bar: 'bar', foo: 'bar'}) | ||
* console.log(obj) => {bar: 'bar', foo: 'bar'} | ||
* | ||
*/ | ||
extend(src) { | ||
var obj, args = arguments | ||
for (var i = 1; i < args.length; ++i) { | ||
if (obj = args[i]) { | ||
for (var key in obj) { | ||
if (typeof obj[key] === 'object' && typeof src[key] === 'object') | ||
src[key] = this.extend(src[key], obj[key]) | ||
else if (typeof obj[key] !== 'undefined') | ||
src[key] = obj[key] | ||
} | ||
} | ||
} | ||
return src | ||
}, | ||
/** | ||
* Try to read the option from a file | ||
* @param { String } src - path to the config file | ||
* @returns { Object } cli options options | ||
*/ | ||
loadConfigFile(src) { | ||
src = path.resolve(src) | ||
// add the extension if it's missing | ||
if (src.slice(-3) !== '.js') src += '.js' | ||
// borrowed from the rollup cli | ||
// https://github.com/rollup/rollup/blob/master/bin/runRollup.js | ||
return rollup.rollup({ | ||
entry: src, | ||
onwarn: this.log | ||
}).then((bundle) => { | ||
var | ||
opts, | ||
code = bundle.generate({ | ||
format: 'cjs' | ||
}).code | ||
// temporarily override require | ||
var jsLoader = require.extensions['.js'] | ||
require.extensions[ '.js' ] = function(m, filename) { | ||
if (filename === src) m._compile(code, filename) | ||
else jsLoader(m, filename) | ||
} | ||
try { | ||
opts = require(src) | ||
} catch (err) { | ||
this.err(err) | ||
} | ||
require.extensions[ '.js' ] = jsLoader | ||
return opts | ||
}).catch((err) => { | ||
this.log('It was not possible to load your config file, are you sure the path is correct?') | ||
this.err(err) | ||
}) | ||
}, | ||
/** | ||
* Helper to output stuff in the terminal | ||
@@ -67,13 +139,4 @@ * @param { * } msg - normally this should be a string | ||
getVersion() { | ||
var ver | ||
// try to get the riot version | ||
// assuming that this module is located in node_modules/riot-cli/lib | ||
try { | ||
ver = require('../../../package.json').version | ||
} catch (e) { | ||
// otherwise fall back to the riot-compiler version | ||
ver = require('riot-compiler/package.json').version | ||
} | ||
return ver | ||
return `${require('../package.json').version} - compiler ${require('riot-compiler/package.json').version}` | ||
} | ||
} |
@@ -24,3 +24,5 @@ #!/usr/bin/env node | ||
options = require('./options'), | ||
path = require('path'), | ||
chalk = require('chalk'), | ||
co = require('co'), | ||
optionator = require('optionator')(options), | ||
@@ -48,3 +50,3 @@ API = | ||
/* istanbul ignore next */ | ||
function cli() { | ||
function cli(ar) { | ||
@@ -57,3 +59,6 @@ // Get CLI arguments | ||
try { | ||
args = optionator.parse(process.argv, options) | ||
args = optionator.parse( | ||
ar ? ['node', path.resolve('lib')].concat(ar) : process.argv, | ||
options | ||
) | ||
} catch (e) { | ||
@@ -64,38 +69,50 @@ helpers.err(e) | ||
// Translate args into options hash | ||
// read the config file | ||
return co(function*() { | ||
if (args.config) { | ||
return yield helpers.loadConfigFile(args.config) | ||
} else { | ||
return {} | ||
} | ||
}).then(function(opt) { | ||
// Translate args into options hash | ||
// extending eventually the file loaded via config | ||
opt = helpers.extend({ | ||
compiler: { | ||
compact: args.compact, | ||
template: args.template, // html preprocessor | ||
style: args.style, // css preprocessor | ||
type: args.type, // javascript preprocessor | ||
brackets: args.brackets, | ||
entities: !!args.export, | ||
exclude: args.exclude, | ||
expr: args.expr, | ||
modular: args.modular, | ||
silent: args.silent, | ||
whitespace: args.whitespace | ||
}, | ||
ext: args.ext, | ||
css: args.css, | ||
export: args.export, | ||
colors: args.colors, | ||
parsers: opt.parsers, // to extend the default compiler parsers | ||
from: args._.shift(), | ||
to: args._.shift() | ||
}, opt) | ||
var opt = { | ||
compiler: { | ||
compact: args.compact, | ||
template: args.template, // html preprocessor | ||
style: args.style, // css preprocessor | ||
type: args.type, // javascript preprocessor | ||
brackets: args.brackets, | ||
entities: !!args.export, | ||
expr: args.expr, | ||
modular: args.modular, | ||
silent: args.silent, | ||
whitespace: args.whitespace | ||
}, | ||
ext: args.ext, | ||
css: args.css, | ||
export: args.export, | ||
colors: args.colors, | ||
from: args._.shift(), | ||
to: args._.shift() | ||
} | ||
// Call matching method | ||
var method = Object.keys(API).filter((v) => args[v] )[0] || ( opt.from ? 'make' : 'help' ) | ||
// Call matching method | ||
var method = Object.keys(API).filter((v) => args[v] )[0] || ( opt.from ? 'make' : 'help' ) | ||
// check whether the output should be colorized | ||
chalk.constructor({enabled: !!opt.colors }) | ||
// check whether the output should be colorized | ||
chalk.constructor({enabled: !!opt.colors }) | ||
// create isSilent as global variable | ||
global.isSilent = args.silent | ||
// create isSilent as global variable | ||
global.isSilent = args.silent | ||
// flag used to detect wheter a task is triggered via command line or not | ||
opt.isCli = true | ||
// flag used to detect wheter a task is triggered via command line or not | ||
opt.isCli = true | ||
return API[method](opt) | ||
return API[method](opt) | ||
}) | ||
@@ -102,0 +119,0 @@ } |
@@ -21,2 +21,3 @@ const helpers = require('./helpers') | ||
riot foo bar | ||
riot --config riot.config | ||
riot --w foo bar | ||
@@ -26,4 +27,5 @@ riot --watch foo bar | ||
riot foo bar --compact | ||
riot test.tag --type coffeescript --expr | ||
riot test.tag --style sass --export css test.css | ||
riot foo.tag --type coffeescript --expr | ||
riot foo.tag --style sass --export css foo.css | ||
riot foo.tag --exclude css foo.js | ||
@@ -58,2 +60,39 @@ Version ${ helpers.getVersion() } | ||
{ | ||
option: 'modular', | ||
alias: 'm', | ||
type: 'Boolean', | ||
description: 'AMD and CommonJS' | ||
}, | ||
{ | ||
option: 'silent', | ||
alias: 's', | ||
type: 'Boolean', | ||
description: 'Silence build output' | ||
}, | ||
{ | ||
option: 'whitespace', | ||
type: 'Boolean', | ||
description: 'Preserve newlines and whitepace' | ||
}, | ||
{ | ||
option: 'check', | ||
type: 'Boolean', | ||
description: 'Check the syntax errors on a single tag' | ||
}, | ||
{ | ||
option: 'colors', | ||
type: 'Boolean', | ||
description: 'Turn on colorized output' | ||
}, | ||
{ | ||
option: 'expr', | ||
type: 'Boolean', | ||
description: 'Run expressions trough parser defined with --type' | ||
}, | ||
{ | ||
option: 'config', | ||
type: 'String', | ||
description: 'Specify the path to a configuration file to compile your tags' | ||
}, | ||
{ | ||
option: 'export', | ||
@@ -63,3 +102,3 @@ type: 'String', | ||
description: 'Compile and export only the css or html or js from your tags', | ||
example: 'riot test.tag --export css test.css', | ||
example: 'riot foo.tag --export css foo.css', | ||
enum: ['css', 'js', 'html'] | ||
@@ -74,19 +113,10 @@ }, | ||
{ | ||
option: 'check', | ||
type: 'Boolean', | ||
description: 'Check the syntax errors on a single tag' | ||
option: 'exclude', | ||
type: 'String', | ||
description: 'Compile and excluding entities (css, html or js) from the output', | ||
enum: ['css', 'js', 'html'], | ||
example: 'riot foo.tag --exclude css --exclude html foo.js', | ||
concatRepeatedArrays: true | ||
}, | ||
{ | ||
option: 'modular', | ||
alias: 'm', | ||
type: 'Boolean', | ||
description: 'AMD and CommonJS' | ||
}, | ||
{ | ||
option: 'silent', | ||
alias: 's', | ||
type: 'Boolean', | ||
description: 'Silence build output' | ||
}, | ||
{ | ||
option: 'template', | ||
@@ -100,10 +130,5 @@ type: 'String', | ||
description: 'Css pre-processor. Built-in support for: sass, scss, less, stylus', | ||
example: 'riot test.tag --style scss' | ||
example: 'riot foo.tag --style scss' | ||
}, | ||
{ | ||
option: 'whitespace', | ||
type: 'Boolean', | ||
description: 'Preserve newlines and whitepace' | ||
}, | ||
{ | ||
option: 'brackets', | ||
@@ -114,12 +139,2 @@ type: 'String', | ||
{ | ||
option: 'colors', | ||
type: 'Boolean', | ||
description: 'Turn on colorized output' | ||
}, | ||
{ | ||
option: 'expr', | ||
type: 'Boolean', | ||
description: 'Run expressions trough parser defined with --type' | ||
}, | ||
{ | ||
option: 'ext', | ||
@@ -126,0 +141,0 @@ type: 'String', |
@@ -23,4 +23,8 @@ 'use strict' | ||
this.called = true | ||
// make sure the parsers object is always valid | ||
opt.parsers = helpers.extend(opt.parsers || {}, { html: {}, js: {}, css: {} }) | ||
// validate the compiler options | ||
this.error = opt.compiler ? this.validate(opt.compiler) : false | ||
this.error = opt.compiler ? this.validate(opt.compiler, opt.parsers) : false | ||
@@ -78,12 +82,16 @@ // create a regex to figure out whether our user | ||
* @param { Object } opt - compiler options | ||
* @param { Object } parsers - custom parser options | ||
* @returns {String|Boolean} - false if there are no errors | ||
*/ | ||
validate(opt) { | ||
validate(opt, parsers) { | ||
var template = opt.template, | ||
type = opt.type | ||
type = opt.type, | ||
style = opt.style | ||
if (template && !this.has(template)) | ||
if (template && !parsers.html[template] && !this.has(template)) | ||
return PREPROCESSOR_NOT_FOUND('html', template) | ||
else if (type && !this.has(type)) | ||
else if (type && !parsers.js[type] && !this.has(type)) | ||
return PREPROCESSOR_NOT_FOUND('javascript', type) | ||
else if (style && !parsers.css[style] && !this.has(style)) | ||
return PREPROCESSOR_NOT_FOUND('css', type) | ||
@@ -90,0 +98,0 @@ return false |
@@ -41,2 +41,6 @@ 'use strict' | ||
// extend the compiler parsers | ||
if (opt.parsers) | ||
helpers.extend(compiler.parsers, opt.parsers) | ||
// Process files | ||
@@ -96,3 +100,3 @@ if (opt.flow[1] == 'f') | ||
try { | ||
out = compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler) | ||
out = compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler, from) | ||
// take only the css | ||
@@ -99,0 +103,0 @@ } catch (e) { |
{ | ||
"name": "riot-cli", | ||
"version": "2.3.12", | ||
"version": "2.3.13-beta", | ||
"description": "Riot command line utility", | ||
@@ -27,6 +27,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"coveralls": "^2.11.4", | ||
"eslint": "^1.10.1", | ||
"coveralls": "^2.11.6", | ||
"eslint": "^1.10.3", | ||
"expect.js": "^0.3.1", | ||
"istanbul": "^0.4.0", | ||
"istanbul": "^0.4.1", | ||
"mocha": "^2.3.4" | ||
@@ -42,7 +42,9 @@ }, | ||
"chalk": "^1.1.1", | ||
"chokidar": "^1.3.0", | ||
"optionator": "^0.6.0", | ||
"riot-compiler": "^2.3.*", | ||
"chokidar": "^1.4.1", | ||
"co": "^4.6.0", | ||
"optionator": "^0.7.1", | ||
"riot-compiler": "^2.3.16-beta", | ||
"rollup": "^0.21.2", | ||
"shelljs": "^0.5.3" | ||
} | ||
} |
@@ -6,2 +6,3 @@ describe('Cli Tests', function() { | ||
require('./specs/api.spec') | ||
require('./specs/config-file.spec') | ||
}) |
@@ -17,3 +17,3 @@ require('shelljs/global') | ||
it('version', () => { | ||
expect(cli.version()).to.be(require('riot-compiler/package.json').version) | ||
expect(cli.version()).to.be(`${require('../../package.json').version} - compiler ${require('riot-compiler/package.json').version}`) | ||
}) | ||
@@ -29,29 +29,56 @@ | ||
it('make', () => { | ||
expect(cli.make({from: 'some/random/path.tag'}).error).to.be.a('string') | ||
expect(cli.make({from: `${TAGS_FOLDER}/component.tag`}).error).to.be(false) | ||
it('make with the wrong path should return an error', function() { | ||
expect(cli.make({ | ||
from: 'some/random/path.tag' | ||
}).error).to.be.a('string') | ||
}) | ||
it('make with the right path should not return any error', function() { | ||
expect(cli.make({ | ||
from: `${TAGS_FOLDER}/component.tag` | ||
}).error).to.be(false) | ||
}) | ||
it('make all the tags in a folder', function() { | ||
cli.make({ | ||
from: 'test/tags', to: `${GENERATED_FOLDER}/make.js` | ||
}) | ||
// check if the file exists | ||
expect(test('-e', `${GENERATED_FOLDER}/make.js`)).to.be(true) | ||
}) | ||
it('make using the modular flag on a single tag must return compliant UMD code', function() { | ||
cli.make({ | ||
from: `${TAGS_FOLDER}/component.tag`, | ||
to: `${GENERATED_FOLDER}/make-component.js`, | ||
compiler: { modular: true } | ||
}).error).to.be(false) | ||
}) | ||
expect(cli.make({ | ||
expect(test('-e', `${GENERATED_FOLDER}/make-component.js`)).to.be(true) | ||
expect(cat(`${GENERATED_FOLDER}/make-component.js`)).to.match(/require/) | ||
}) | ||
it('make using the modular flag on multiple tags must return compliant UMD code', function() { | ||
cli.make({ | ||
from: `${TAGS_FOLDER}`, | ||
to: `${GENERATED_FOLDER}/make-components.js`, | ||
compiler: { modular: true } | ||
}).error).to.be(false) | ||
}) | ||
expect(cli.make({ | ||
expect(test('-e', `${GENERATED_FOLDER}/make-components.js`)).to.be(true) | ||
expect(cat(`${GENERATED_FOLDER}/make-components.js`)).to.match(/require/) | ||
}) | ||
it('make using a missing preprocessor should throw an error', function() { | ||
var result = cli.make({ | ||
from: `${TAGS_FOLDER}/component.tag`, | ||
compiler: { modular: true, template: 'nope' } | ||
}).error).to.be('The "nope" html preprocessor was not found. Have you installed it locally?') | ||
}) | ||
// check if the file exists | ||
expect(test('-e', `${GENERATED_FOLDER}/make-component.js`)).to.be(true) | ||
expect(cat(`${GENERATED_FOLDER}/make-component.js`)).to.match(/require/) | ||
expect(cat(`${GENERATED_FOLDER}/make-components.js`)).to.match(/require/) | ||
expect(cli.make({from: 'test/tags', to: `${GENERATED_FOLDER}/make.js`}).error).to.be(false) | ||
// check if the file exists | ||
expect(test('-e', `${GENERATED_FOLDER}/make.js`)).to.be(true) | ||
expect(result.error) | ||
.to | ||
.be('The "nope" html preprocessor was not found. Have you installed it locally?') | ||
}) | ||
@@ -104,2 +131,24 @@ | ||
it('make using the --exclude flag', function() { | ||
cli.make({ | ||
from: `${TAGS_FOLDER}/exclude`, | ||
to: `${GENERATED_FOLDER}/exclude/css.js`, | ||
compiler: { | ||
exclude: ['css'] | ||
} | ||
}) | ||
expect(cat(`${GENERATED_FOLDER}/exclude/css.js`)).to.be(cat(`${EXPECTED_FOLDER}/exclude/css.js`)) | ||
cli.make({ | ||
from: `${TAGS_FOLDER}/exclude`, | ||
to: `${GENERATED_FOLDER}/exclude/css-js.js`, | ||
compiler: { | ||
exclude: ['css', 'js'] | ||
} | ||
}) | ||
expect(cat(`${GENERATED_FOLDER}/exclude/css-js.js`)).to.be(cat(`${EXPECTED_FOLDER}/exclude/css-js.js`)) | ||
}) | ||
it('watch folder', (done) => { | ||
@@ -106,0 +155,0 @@ var watcher = cli.watch({from: TAGS_FOLDER}) |
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
64122
58
996
7
1
1
+ Addedco@^4.6.0
+ Addedrollup@^0.21.2
+ Addedamdefine@1.0.1(transitive)
+ Addedco@4.6.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedoptionator@0.7.1(transitive)
+ Addedrollup@0.21.3(transitive)
+ Addedsource-map@0.1.32(transitive)
+ Addedsource-map-support@0.3.3(transitive)
+ Addedwordwrap@1.0.0(transitive)
- Removedoptionator@0.6.0(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedchokidar@^1.4.1
Updatedoptionator@^0.7.1
Updatedriot-compiler@^2.3.16-beta