Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

riot-cli

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riot-cli - npm Package Compare versions

Comparing version 2.3.0-beta.4 to 2.3.0-beta.5

19

lib/analyzer/index.js
'use strict'
/**
* Syntax checker for Riot.js
* This is checker is still under development
* It's not yet stable!!
*/

@@ -9,3 +11,3 @@

1. Devide into blocks by line-level analysis
1. Divide into blocks by line-level analysis
2. Validate Tag file layout

@@ -37,9 +39,9 @@ 3. TODO: validate Riot template

tag = '',
results,
lines = source.split('\n')
results
results = lines.map((row, n) => {
results = source.split('\n').map(function(row, n) {
var m, err = '', type
if (m = row.match(TAG_START)) {
// Custam tag starting
// Custom tag starting
type = 'tag_start'

@@ -49,3 +51,3 @@ if (mode == 'tag') { err = ERR_NO_INDENT }

} else if (m = row.match(TAG_END)) {
// Custam tag ending
// Custom tag ending
type = 'tag_end'

@@ -56,3 +58,4 @@ if (tag != m[1]) { err = ERR_TAG_UNMATCH }

// Custom line tag
type = 'tag'; err = ERR_NO_INDENT
if (mode == 'tag') { type = mode; err = ERR_NO_INDENT }
else { type = 'line_tag'; tag = ''; mode = 'outside' }
} else if (m = row.match(INVALID_TAG)) {

@@ -96,3 +99,3 @@ // Other invalid tags

// scan backward to detect script block in tag
for (var t, i = results.length - 1; i <= 0; i--) {
for (var t, i = results.length - 1; i >= 0; i--) {
t = results[i].type

@@ -99,0 +102,0 @@ if (t == 'tag_end') mode = 'script'

@@ -43,2 +43,3 @@ 'use strict'

log(msg) {
/* istanbul ignore next */
if (!global.isSilent) console.log(msg)

@@ -52,2 +53,3 @@ },

msg += '\n'
/* istanbul ignore next */
if (!global.isSilent) this.log(chalk.red(msg)) || process.exit(1)

@@ -54,0 +56,0 @@ else throw msg

@@ -75,2 +75,3 @@ #!/usr/bin/env node

ext: args.ext,
css: args.css,
colors: args.colors,

@@ -103,4 +104,5 @@ from: args._.shift(),

global.isSilent = true
/* istanbul ignore next */
} else cli()

@@ -6,23 +6,43 @@ 'use strict'

sh = require('shelljs'),
helpers = require('../helpers'),
chalk = require('chalk'),
log = require('../helpers').log
log = helpers.log,
find = helpers.find,
toRelative = helpers.toRelative
class Check extends Task {
run(opt) {
//TODO: analyze each file separatedly
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 )
// check input files
var from = opt.flow[0] == 'f' ? [opt.from] : find(this.extRegex, opt.from),
// map the results of the tests
results = from
.map(file => {
// get the content of the tag file analysing it
var results = analyzer(sh.cat(file).replace(/^\uFEFF/g, /* strips BOM */''))
return {
file: toRelative(file),
errors: results.filter(result => result.error)
}
})
// remove the entries without errors
.filter(results => results.errors.length)
if (errors.length) {
log(chalk.white.bgRed(' Riot Tag Syntax Error '))
errors.map((result) => {
log(chalk.yellow(result.line + '| ') + result.source)
log(chalk.red('^^^ ' + result.error))
// errors found
if (results.length) {
log(chalk.white.bgRed('Riot Tag Syntax Error'))
// log the errors
results.forEach(check => {
check.errors.forEach(result => {
log(chalk.yellow(`${result.line} | `) + result.source)
log(chalk.red(`^^^ ${result.error}`))
})
log(chalk.yellow(`Total error: ${check.errors.length} in "${check.file}"`))
})
log(chalk.yellow('Total error: ' + errors.length))
} else {
} else
// congrats no errors found!
log(chalk.green('No syntax error. Ready to compile :)'))
}
return errors
return results
}

@@ -29,0 +49,0 @@ }

@@ -96,2 +96,3 @@ 'use strict'

out = compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler)
// take only the css
} catch (e) {

@@ -98,0 +99,0 @@ helpers.err(e)

{
"name": "riot-cli",
"version": "2.3.0-beta.4",
"version": "2.3.0-beta.5",
"description": "Riot command line utility",

@@ -43,5 +43,5 @@ "main": "lib/index.js",

"optionator": "^0.6.0",
"riot-compiler": "^2.3.0-beta.4",
"riot-compiler": "^2.3.*",
"shelljs": "^0.5.3"
}
}

@@ -21,5 +21,5 @@ require('shelljs/global')

})
it('returns an error if there are no indentations within tag', () => {
it('returns an error within a line tag', () => {
var results = analyzer(cat(`${ANALYZER_TAGS_FOLDER}one-line.tag`))
expect(results[2].error).to.equal('Indentation needed within tag definition')
expect(results).to.have.length(2)
})

@@ -33,3 +33,2 @@ it('returns an error if there are invalid tag fragments', () => {

})
require('shelljs/global')
const TAGS_FOLDER = 'test/tags/',
const TAGS_FOLDER = 'test/tags',
GENERATED_FOLDER = 'test/generated',
cli = require('../../lib')

@@ -10,5 +11,2 @@

// remove the useless stuff
after(() => rm(`${TAGS_FOLDER}component-copy.*`))
it('help', () => {

@@ -23,5 +21,7 @@ expect(cli.help()).to.be.a('string')

it('check', () => {
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)
var check = cli.check({from: `${TAGS_FOLDER}/wrong-component.tag`})[0]
expect(check).to.be.an('object')
expect(check.errors).to.have.length(2)
expect(cli.check({from: `${TAGS_FOLDER}/component.tag`})).to.have.length(0)
expect(cli.check({from: `${TAGS_FOLDER}`})[0].file).to.be.a('string')
})

@@ -31,28 +31,54 @@

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)
expect(cli.make({from: `${TAGS_FOLDER}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: `${GENERATED_FOLDER}/make-component.js`,
compiler: { modular: true }
}).error).to.be(false)
expect(cli.make).withArgs({
from: `${TAGS_FOLDER}/component.tag`,
compiler: { modular: true, template: 'nope' }
}).to.throwError()
// check if the file exists
expect(test('-e', 'test/expected/make-component.js')).to.be(true)
expect(cli.make({from: 'test/tags', to: 'test/expected/make.js'}).error).to.be(false)
expect(test('-e', `${GENERATED_FOLDER}/make-component.js`)).to.be(true)
expect(cli.make({from: 'test/tags', to: `${GENERATED_FOLDER}/make.js`}).error).to.be(false)
// check if the file exists
expect(test('-e', 'test/expected/make.js')).to.be(true)
expect(test('-e', `${GENERATED_FOLDER}/make.js`)).to.be(true)
})
it('watch', (done) => {
it('watch folder', (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)
})
watcher.on('ready', () => {
cp(`${TAGS_FOLDER}/component.tag`, `${TAGS_FOLDER}/component-copy.tag`)
watcher.add(`${TAGS_FOLDER}/component-copy.tag`)
})
watcher.on('change', () => {
setTimeout(() => {
expect(test('-e', `${TAGS_FOLDER}/component-copy.js`)).to.be(true)
rm(`${TAGS_FOLDER}/component-copy.*`)
watcher.close()
done()
}, 1000)
})
})
it('watch file', (done) => {
var watcher = cli.watch({from: `${TAGS_FOLDER}/component.tag`, to: `${GENERATED_FOLDER}/watch-component.js`})
watcher.on('ready', () => {
cat(`${TAGS_FOLDER}/component.tag`).to(`${TAGS_FOLDER}/component.tag`)
})
watcher.on('change', () => {
setTimeout(() => {
expect(test('-e', `${GENERATED_FOLDER}/watch-component.js`)).to.be(true)
watcher.close()
done()
})
})
})
})
require('shelljs/global')
const EXPECTED_LOGS_DIR = 'test/expected/logs',
FIXTURES_LOGS_DIR = 'test/fixtures/logs'
GENERATED_LOGS_DIR = 'test/generated/logs'

@@ -10,5 +10,5 @@ describe('output logs', () => {

logs.forEach((log) => {
expect(cat(`${EXPECTED_LOGS_DIR}/${log}`)).to.be(cat(`${FIXTURES_LOGS_DIR}/${log}`))
expect(cat(`${EXPECTED_LOGS_DIR}/${log}`)).to.be(cat(`${GENERATED_LOGS_DIR}/${log}`))
})
})
})

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc