Comparing version 2.3.0-beta.2 to 2.3.0-beta.3
@@ -61,12 +61,12 @@ 'use strict' | ||
// Style starting | ||
type = 'style_start'; mode = 'style'; block = '' | ||
type = 'style_start'; mode = 'style' | ||
} else if (m = row.match(STYLE_END)) { | ||
// Style ending | ||
type = 'style_end'; mode = 'tag'; block = '' | ||
type = 'style_end'; mode = 'tag' | ||
} else if (m = row.match(SCRIPT_START)) { | ||
// Script starting | ||
type = 'script_start'; mode = 'script'; block = '' | ||
type = 'script_start'; mode = 'script' | ||
} else if (m = row.match(SCRIPT_END)) { | ||
// Script ending | ||
type = 'script_end'; mode = 'tag'; block = '' | ||
type = 'script_end'; mode = 'tag' | ||
} else { | ||
@@ -73,0 +73,0 @@ if (m = row.match(HTML_END_DETECTOR)) type = 'template' |
@@ -10,14 +10,41 @@ 'use strict' | ||
module.exports = { | ||
/** | ||
* Find any file in certain folder | ||
* @param { RegExp } extRegex - regular expression containing the file extension | ||
* @param { String } from - files path | ||
* @returns { Array } array containing the files found | ||
*/ | ||
find(extRegex, from) { | ||
return sh.find(from).filter((f) => extRegex.test(f) && TEMP_FILE_NAME.test(f) ) | ||
}, | ||
remap(ext, from, to, base) { | ||
return from.map((from) => path.join(to, path.relative(base, from).replace(ext, '.js')) ) | ||
/** | ||
* Loop files paths strings contained in an array remapping them to ad different location | ||
* @param { RegExp } extRegex - regular expression containing the file extension | ||
* @param { String } from - path where the files are located | ||
* @param { String } to - path where the new files must be created | ||
* @param { String } base - base path | ||
* @returns { Array } array containing all the paths to the new files that must be created | ||
*/ | ||
remap(extRegex, from, to, base) { | ||
return from.map((from) => path.join(to, path.relative(base, from).replace(extRegex, '.js')) ) | ||
}, | ||
/** | ||
* Relative path to where the command line gets executed | ||
* @param { String } path - the whole file path where a file is located on the machine | ||
* @returns { String } path relative to the current folder where the command line gets executed | ||
*/ | ||
toRelative(path) { | ||
return path.replace(sh.pwd() + '/', '') | ||
}, | ||
/** | ||
* Helper to output stuff in the terminal | ||
* @param { * } msg - normally this should be a string | ||
*/ | ||
log(msg) { | ||
if (!global.isSilent) console.log(msg) | ||
}, | ||
/** | ||
* Throw an error and kill the process | ||
* @param { String } msg - error message | ||
*/ | ||
err(msg) { | ||
@@ -28,5 +55,18 @@ msg += '\n' | ||
}, | ||
/** | ||
* Get the current riot-cli release | ||
* @returns { String } this should always return the riot version in use unless riot-cli gets used as standalone module | ||
*/ | ||
getVersion() { | ||
return require('../package.json').version | ||
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 | ||
} | ||
} |
@@ -17,7 +17,7 @@ #!/usr/bin/env node | ||
// Include the available actions | ||
// Include the available tasks | ||
const | ||
Check = require('./actions/Check'), | ||
Make = require('./actions/Make'), | ||
Watch = require('./actions/Watch'), | ||
Check = require('./tasks/Check'), | ||
Make = require('./tasks/Make'), | ||
Watch = require('./tasks/Watch'), | ||
helpers = require('./helpers'), | ||
@@ -41,3 +41,6 @@ options = require('./options'), | ||
make(opt) { return new Make(opt) }, | ||
watch(opt) { return new Watch(opt) } | ||
watch(opt) { return new Watch(opt) }, | ||
// this could be handy to someone who wants to have | ||
// also access to the private cli parser function | ||
_cli: cli | ||
} | ||
@@ -88,3 +91,3 @@ | ||
// flag used to detect wheter an action is triggered via command line or not | ||
// flag used to detect wheter a task is triggered via command line or not | ||
opt.isCli = true | ||
@@ -91,0 +94,0 @@ |
{ | ||
"name": "riot-cli", | ||
"version": "2.3.0-beta.2", | ||
"version": "2.3.0-beta.3", | ||
"description": "Riot command line utility", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"coveralls": "^2.11.4", | ||
"eslint": "^1.6.0", | ||
"eslint": "^1.7.0", | ||
"expect.js": "^0.3.1", | ||
@@ -31,0 +31,0 @@ "istanbul": "^0.3.22", |
@@ -14,6 +14,10 @@ # Riot cli | ||
### Npm | ||
Normally this tool is available directly installing [riot](https://github.com/riot/riot) via npm: | ||
`$ npm install riot-cli --save` | ||
`$ npm install riot -g` | ||
But it's also available as standalone package: | ||
`$ npm install riot-cli -g` | ||
[travis-image]:https://img.shields.io/travis/riot/cli.svg?style=flat-square | ||
@@ -20,0 +24,0 @@ [travis-url]:https://travis-ci.org/riot/cli |
@@ -0,1 +1,56 @@ | ||
var riot = require('riot') | ||
riot.tag('valid-tag', '<h1>{ title }</h1> <p>{ message }</p>', function(opts) { | ||
<invalid-flagment | ||
this.title = 'Hello world!' | ||
this.message = 'I am hungry...' | ||
}); | ||
<invalid-t | ||
<h1>{ title }</h1> | ||
<p>{ message }</p> | ||
this.title = 'Hello world!' | ||
this.message = 'I am hungry...' | ||
</invalid-t | ||
console.log('end of file') | ||
<tag-not-closed> | ||
<p>Hello!</p> | ||
<tag-unmatch> | ||
<p>Hello!</p> | ||
</tag-unmatch> | ||
</tag-unmatched> | ||
var riot = require('riot') | ||
riot.tag('valid-tag', '<h1>{ title }</h1> <p>{ message }</p>', function(opts) { | ||
this.title = 'Hello world!' | ||
this.message = 'I am hungry...' | ||
}); | ||
riot.tag('line-tag', 'Hello { opts.message }!', function(opts) { | ||
}); | ||
riot.tag('tag-with-style', '<p>Hi!</p>', 'tag-with-style p, [riot-tag="tag-with-style"] p{ color: red }', function(opts) { | ||
}); | ||
riot.tag('tag-with-script', '<h1>{ title }</h1> <p>{ message }</p>', function(opts) { | ||
this.title = 'Hello world!' | ||
this.message = 'I am hungry...' | ||
}); | ||
console.log('end of file') | ||
riot.tag('without-indent', 'riot.tag(\'p\', \'Without indent\', function(opts) { }); <div> Without indent</div>', function(opts) { | ||
}); | ||
riot.tag('component-2', '<div each="{ items }">{ item }</div>', function(opts) { | ||
@@ -2,0 +57,0 @@ |
describe('Cli Tests', function() { | ||
global.expect = require('expect.js') | ||
require('./specs/output.spec') | ||
require('./specs/analyzer.spec') | ||
require('./specs/api.spec') | ||
}) |
require('shelljs/global') | ||
const EXPECTED_LOGS_DIR = 'test/expected/logs', | ||
const TAGS_FOLDER = 'test/tags/', | ||
cli = require('../../lib') | ||
describe('API methods', () => { | ||
describe('API methods', function() { | ||
this.timeout(10000) | ||
// remove the useless stuff | ||
after(() => rm(`${TAGS_FOLDER}component-copy.*`)) | ||
it('help', () => { | ||
var help = cat(`${EXPECTED_LOGS_DIR}/help.log`) | ||
help = help.substring(0, help.length - 1) // remove the last \n | ||
expect(cli.help()).to.be(help) | ||
expect(cli.help()).to.be.a('string') | ||
}) | ||
it('version', () => { | ||
expect(cli.version()).to.be(require('../../package.json').version) | ||
expect(cli.version()).to.be(require('riot-compiler/package.json').version) | ||
}) | ||
it('check', () => { | ||
expect(cli.check({from: 'test/tags/wrong-component.tag'})).to.be.an('array') | ||
expect(cli.check({from: 'test/tags/wrong-component.tag'})).to.have.length(2) | ||
expect(cli.check({from: 'test/tags/component.tag'})).to.have.length(0) | ||
expect(cli.check({from: `${TAGS_FOLDER}wrong-component.tag`})).to.be.an('array') | ||
expect(cli.check({from: `${TAGS_FOLDER}wrong-component.tag`})).to.have.length(2) | ||
expect(cli.check({from: `${TAGS_FOLDER}component.tag`})).to.have.length(0) | ||
}) | ||
@@ -26,4 +29,4 @@ | ||
expect(cli.make({from: 'some/random/path.tag'}).error).to.be.a('string') | ||
expect(cli.make({from: 'test/tags/component.tag'}).error).to.be(false) | ||
expect(cli.make({from: 'test/tags/component.tag', to: 'test/expected/make-component.js'}).error).to.be(false) | ||
expect(cli.make({from: `${TAGS_FOLDER}component.tag`}).error).to.be(false) | ||
expect(cli.make({from: `${TAGS_FOLDER}component.tag`, to: 'test/expected/make-component.js'}).error).to.be(false) | ||
// check if the file exists | ||
@@ -36,2 +39,19 @@ expect(test('-e', 'test/expected/make-component.js')).to.be(true) | ||
it('watch', (done) => { | ||
var watcher = cli.watch({from: TAGS_FOLDER}) | ||
watcher | ||
.on('ready', () => { | ||
cp(`${TAGS_FOLDER}component.tag`, `${TAGS_FOLDER}component-copy.tag`) | ||
watcher.add(`${TAGS_FOLDER}component-copy.tag`) | ||
// hoping that this file gets compiled after 3 seconds | ||
setTimeout(() => { | ||
expect(test('-e', `${TAGS_FOLDER}component-copy.js`)).to.be(true) | ||
watcher.close() | ||
done() | ||
}, 3000) | ||
}) | ||
}) | ||
}) |
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
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
51718
46
709
37