Socket
Socket
Sign inDemoInstall

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 3.0.0 to 3.0.1

test/expected/stdinout/a.js

2

lib/const.js

@@ -38,3 +38,3 @@ 'use strict'

<style scoped>
<style>
:scope p {

@@ -41,0 +41,0 @@ color: #000;

@@ -11,4 +11,29 @@ 'use strict'

module.exports = {
/**
* Read from Stdin
* @returns { String } captured lines from stdin
*/
readStdin() {
return new Promise((resolve, reject) => {
try {
let str = ''
process.stdin.setEncoding('utf8')
process.stdin.on('readable', () => { str += process.stdin.read() || '' })
process.stdin.on('end', () => { resolve(str) })
} catch (err) {
reject(err)
}
})
},
/**
* Read from a file
* @param { String } from - file path
* @returns { String } captured lines from stdin
*/
readFile(from) {
return sh.cat(from).toString().replace(/^\uFEFF/g, /* strips BOM */'')
},
/**
* Find any file in certain folder

@@ -28,12 +53,13 @@ * @param { RegExp } extRegex - regular expression containing the file extension

* @param { RegExp } extRegex - regular expression containing the file extension
* @param { String } from - path where the files are located
* @param { Array } from - array contains paths where the files are located
* @param { String } to - path where the new files must be created
* @param { String } base - base path
* @param { String } extension - base path
* @param { String } ext - base path
* @returns { Array } array containing all the paths to the new files that must be created
*/
remap(extRegex, from, to, base, extension) {
return from
.map((from) => path.join(to, path.relative(base, from)
.replace(extRegex, `.${extension || 'js'}`)))
remap(extRegex, from, to, base, ext) {
return from.map(from => {
const p = path.relative(base, from).replace(extRegex, `.${ext || 'js'}`)
return path.join(to, p)
})
},

@@ -128,3 +154,4 @@

/* istanbul ignore next */
if (!global.isSilent) console.log(msg)
if (global.isSilent) return
console.log(msg)
},

@@ -138,3 +165,3 @@ /**

/* istanbul ignore next */
if (!global.isSilent) process.stderr.write(chalk.red(msg)) || process.exit(1)
if (!global.isSilent) process.stderr.write(chalk.red(msg)) && process.exit(1)
else throw msg

@@ -141,0 +168,0 @@ },

@@ -44,15 +44,10 @@ #!/usr/bin/env node

make(opt) { return new Make(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
watch(opt) { return new Watch(opt) }
}
/* istanbul ignore next */
function cli(ar) {
const cli = co.wrap(function*(ar) {
// Get CLI arguments
let args, config
var args
// was an error thrown parsing the options?

@@ -64,2 +59,3 @@ try {

)
config = args.config ? yield helpers.loadConfigFile(args.config) : {}
} catch (e) {

@@ -70,61 +66,53 @@ helpers.err(e)

// read the config file
// let's go async here
return co(function*() {
if (args.config)
return yield helpers.loadConfigFile(args.config)
else
return {}
// Translate args into options hash
// extending args with the options loaded via config file
helpers.extend(args, config)
const 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,
exclude: args.exclude,
expr: args.expr,
modular: args.modular,
silent: !!args.stdout || args.silent,
whitespace: args.whitespace
},
ext: args.ext,
css: args.css,
new: args.new,
export: args.export,
colors: args.colors,
parsers: args.parsers, // to extend the default compiler parsers
from: args.from || !args.stdin && args._.shift(),
to: args.to || !args.stdout && args._.shift(),
stdin: !!args.stdin,
stdout: !!args.stdout
}
}).then(function(opt) {
// Translate args into options hash
// extending args with the options loaded via config file
helpers.extend(args, opt)
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,
exclude: args.exclude,
expr: args.expr,
modular: args.modular,
silent: args.silent,
whitespace: args.whitespace
},
ext: args.ext,
css: args.css,
new: args.new,
export: args.export,
colors: args.colors,
parsers: args.parsers, // to extend the default compiler parsers
from: args.from || args._.shift(),
to: args.to || args._.shift()
}
// Call matching method
const method =
Object.keys(API).filter(v => args[v])[0] ||
(opt.from || opt.stdin ? '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)
// this could be handy to someone who wants to have
// also access to the private cli parser function
API._cli = cli
}).catch((e) => helpers.err(e))
}
// Run from CLI or as Node module
if (module.parent) {

@@ -135,3 +123,1 @@ module.exports = API

} else cli()

@@ -6,3 +6,3 @@ 'use strict'

module.exports = {
prepend: `\nBuilds .tag files to .js\n\nOptions:`,
prepend: '\nBuilds .tag files to .js\n\nOptions:',
append: `

@@ -38,2 +38,3 @@ Build a single .tag file:

riot foo.tag --exclude css foo.js
cat foo.tag | riot --stdin --stdout > foo.js

@@ -97,3 +98,3 @@ Version ${ helpers.getVersion() }

type: 'Boolean',
description: 'Run expressions trough parser defined with --type'
description: 'Run expressions through parser defined with --type'
},

@@ -155,4 +156,16 @@ {

description: 'Change tag file extension. Defaults to .tag'
},
{
option: 'stdin',
alias: 'i',
type: 'Boolean',
description: 'Read stdin as tag file'
},
{
option: 'stdout',
alias: 'o',
type: 'Boolean',
description: 'Print output into stdout'
}
]
}
}

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

// Run only once
/* istanbul ignore next */

@@ -24,2 +23,8 @@ if (this.called) return

this.error = null
// create a regex to figure out whether our user
// wants to compile a single tag or some tags in a folder
this.extRegex = new RegExp(`\\.${opt.ext || 'tag' }$`)
// make sure the parsers object is always valid

@@ -31,42 +36,56 @@ opt.parsers = helpers.extend(

// validate the compiler options
this.error = opt.compiler ? this.validate(opt.compiler, opt.parsers) : null
if (opt.compiler) {
// validate the compiler options
const err = this.validate(opt.compiler, opt.parsers)
if (err) return this.handleError(err, opt.isCli)
} else {
// make sure to set always the compiler options
opt.compiler = {}
}
// create a regex to figure out whether our user
// wants to compile a single tag or some tags in a folder
this.extRegex = new RegExp(`\\.${opt.ext || 'tag' }$`)
if (opt.stdin) {
if (opt.from) {
helpers.log('Stdin will be used instead of the files/dirs specified.')
delete opt.stdin
}
} else {
// Resolve to absolute paths
opt.from = path.resolve(opt.from)
// Check if the path exsists
if (!sh.test('-e', opt.from)) return this.handleError(NO_FILE_FOUND, opt.isCli)
}
// If no target dir, default to source dir
if (opt.stdout) {
if (opt.to) {
helpers.log('Stdout will be used instead of the files/dirs specified.')
delete opt.to
}
} else {
// If no target dir, default to source dir
const from = opt.from || ''
opt.to = opt.to || (this.extRegex.test(from) ? path.dirname(from) : from)
// Resolve to absolute paths
opt.to = path.resolve(opt.to)
}
if (!opt.to)
opt.to = this.extRegex.test(opt.from) ? path.dirname(opt.from) : opt.from
/**
* Determine the input/output types
* f: file
* d: directory
* s: stdin/stdout
*/
const
isFile = !opt.stdout && /\.(js|html|css)$/.test(opt.to),
flowIn = opt.stdin ? 's' : this.extRegex.test(opt.from) ? 'f' : 'd',
flowOut = opt.stdout ? 's' : opt.stdin || isFile ? 'f' : 'd'
// Resolve to absolute paths
// 'ff', 'fd', 'fs', 'df', 'dd', 'ds', 'sf' or 'ss'
// note that 'sd' is an imposible combination
opt.flow = flowIn + flowOut
opt.from = path.resolve(opt.from)
opt.to = path.resolve(opt.to)
// Check if the path exsists
if (!sh.test('-e', opt.from)) this.error = NO_FILE_FOUND
// throw the error only in the cli
if (this.error) {
/* istanbul ignore next */
if (opt.isCli)
helpers.err(this.error)
else return this.error
if (opt.stdin && !opt.stdout && !isFile) {
opt.to = path.join(opt.to, `output.${opt.export || 'js'}`)
helpers.log(`Destination is rewrited: ${opt.to}`)
}
// Determine the input/output types
// [directory, directory]
// [file, directory]
// [directory, file]
// [file, file]
opt.flow = (this.extRegex.test(opt.from) ? 'f' : 'd') +
(/\.(js|html|css)$/.test(opt.to) ? 'f' : 'd')
// make sure to set always the compiler options
if (!opt.compiler) opt.compiler = {}
// each run method could return different stuff

@@ -122,4 +141,10 @@ return this.run(opt)

}
handleError(msg, isCli) {
this.error = msg
if (isCli) helpers.err(this.error)
return this.error
}
}
module.exports = Task

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

sh = require('shelljs'),
co = require('co'),
constants = require('./../const'),

@@ -21,24 +22,20 @@ START_FRAG = constants.MODULAR_START_FRAG,

// Generate a list of input/output files
var
const
isStdin = opt.flow[0] == 's',
isStdout = opt.flow[1] == 's',
isInputFile = opt.flow[0] == 'f',
isOutputFile = opt.flow[1] == 'f',
from = isStdin ? null
: isInputFile ? [opt.from]
: helpers.find(this.extRegex, opt.from),
base = isStdin ? process.cwd
: isInputFile ? path.dirname(opt.from)
: opt.from,
to = isStdout ? null
: isOutputFile ? [opt.to]
: helpers.remap(this.extRegex, from, opt.to, base, opt.export)
from = isInputFile ?
[opt.from] :
helpers.find(this.extRegex, opt.from),
base = isInputFile ?
path.dirname(opt.from) :
opt.from,
to = isOutputFile ?
[opt.to] :
helpers.remap(this.extRegex, from, opt.to, base, opt.export)
// Create any necessary dirs
if (!isStdout) to.forEach(f => sh.mkdir('-p', path.dirname(f)))
var dirs = {}
to.map((f) => dirs[path.dirname(f)] = 0 )
sh.mkdir('-p', Object.keys(dirs))
// extend the compiler parsers

@@ -49,3 +46,5 @@ if (opt.parsers)

// Process files
if (isOutputFile)
if (isStdout)
this.toStdout(from, opt)
else if (isOutputFile)
this.toFile(from, to, opt)

@@ -55,9 +54,11 @@ else

// Print what's been done (unless --silent)
/**
* Print what's been done (unless --silent)
* note that opt.compiler.silent is always true when opt.stdout is true
*/
/* istanbul ignore next */
if (!opt.compiler.silent) {
from.map((src, i) => {
(from || [false]).forEach((src, i) => {
helpers.log(
chalk.blue(helpers.toRelative(src)) +
chalk.blue(!src ? 'stdin' : helpers.toRelative(src)) +
chalk.cyan(' -> ') +

@@ -70,3 +71,20 @@ chalk.green(helpers.toRelative(to[i] || to[0]))

return true
}
/**
* Write all the tags compiled in a single file on the file system
* @param { Array } from - source files array
* @param { Object } opt - cli options
* @returns { Promise } resolves when compilation has done
*/
toStdout(from, opt) {
return co(function* () {
const compiled = from
? from.map(f => parse(helpers.readFile(f), opt, f)).join('\n')
: parse(yield helpers.readStdin(), opt, '')
const wrapped = encapsulate(compiled, opt)
// Output to stdout
process.stdout.write(wrapped)
})
}

@@ -76,11 +94,17 @@

* Write all the tags compiled in a single file on the file system
* @param { Array } from - source files array
* @param { String } to - output path
* @param { Object } opt - cli options
* @param { Array } from - source files array
* @param { String } to - output path
* @param { Object } opt - cli options
* @returns { Promise } resolves when compilation has done
*/
toFile(from, to, opt) {
this.encapsulate(
from.map((path) => this.parse(path, opt)).join('\n'),
opt
).to(to[0])
return co(function* () {
const compiled = from
? from.map(f => parse(helpers.readFile(f), opt, f)).join('\n')
: parse(yield helpers.readStdin(), opt, '')
const wrapped = encapsulate(compiled, opt)
// Save to a file
sh.ShellString(wrapped).to(to[0])
})
}

@@ -95,42 +119,40 @@

toDir(from, to, opt) {
from.map((from, i) => {
return this.encapsulate(this.parse(from, opt), opt).to(to[i])
from.forEach((f, i) => {
const compiled = parse(helpers.readFile(f), opt, f)
const wrapped = encapsulate(compiled, opt)
sh.ShellString(wrapped).to(to[i])
})
}
}
/**
* Compile the source files using the riot-compiler
* @param { String } from - source files array
* @param { Object } opt - cli options
* @returns { String } riot-compiler output
*/
parse(from, opt) {
var out
try {
out = compiler.compile(
sh.cat(from).toString().replace(/^\uFEFF/g, /* strips BOM */''),
opt.compiler,
from
)
// take only the css
} catch (e) {
helpers.err(e)
}
if (opt.export)
return out.reduce((prev, curr) => prev + curr[opt.export], '')
else return out
/**
* Compile the source files using the riot-compiler
* @param { String } tag - tag source
* @param { Object } opt - cli options
* @param { String } url - tag file path
* @returns { String } riot-compiler output
*/
function parse (tag, opt, url) {
let out
try {
out = compiler.compile(tag, opt.compiler, url)
} catch (e) {
helpers.err(e)
}
// take only the css
if (opt.export)
return out.reduce((prev, curr) => prev + curr[opt.export], '')
else return out
}
/**
* Wrap the generated tags using a default UMD wrapper
* @param { String } from - source files array
* @param { Object } opt - cli options
* @returns { String } wrapped output
*/
encapsulate(from, opt) {
var out = !opt.compiler.modular ? from : `${START_FRAG}${from}${END_FRAG}`
return sh.ShellString(out)
}
/**
* Wrap the generated tags using a default UMD wrapper
* @param { String } from - source files array
* @param { Object } opt - cli options
* @returns { String } wrapped output
*/
function encapsulate (from, opt) {
return !opt.compiler.modular ? from : `${START_FRAG}${from}${END_FRAG}`
}
module.exports = Make
module.exports = Make
{
"name": "riot-cli",
"version": "3.0.0",
"version": "3.0.1",
"description": "Riot command line utility",

@@ -16,3 +16,4 @@ "main": "lib/index.js",

"scripts": {
"test": "make test"
"test": "make test",
"prepare": "npm i babel pug coffee-script node-sass"
},

@@ -28,7 +29,7 @@ "repository": {

"devDependencies": {
"coveralls": "^2.11.15",
"eslint": "^3.10.2",
"coveralls": "^2.13.0",
"eslint": "^3.19.0",
"expect.js": "^0.3.1",
"istanbul": "^0.4.5",
"mocha": "^3.1.2"
"mocha": "^3.2.0"
},

@@ -46,6 +47,6 @@ "license": "MIT",

"optionator": "^0.8.2",
"riot-compiler": "^3.0.0",
"rollup": "^0.36.3",
"shelljs": "^0.7.5"
"riot-compiler": "^3.2.1",
"rollup": "^0.41.6",
"shelljs": "^0.7.7"
}
}

@@ -16,3 +16,3 @@ export default {

</script>
<style scoped>
<style>
</style>

@@ -19,0 +19,0 @@ </tag>

describe('Cli Tests', function() {
global.expect = require('expect.js')
require('./specs/output.spec')
require('./specs/stdinout.spec')
require('./specs/analyzer.spec')

@@ -5,0 +6,0 @@ require('./specs/api.spec')

@@ -175,4 +175,4 @@ require('shelljs/global')

setTimeout(() => {
rm(`${TAGS_FOLDER}/component-copy.tag`)
expect(test('-e', `${TAGS_FOLDER}/component-copy.js`)).to.be(true)
rm(`${TAGS_FOLDER}/component-copy.*`)
watcher.close()

@@ -179,0 +179,0 @@ done()

@@ -48,2 +48,2 @@ require('shelljs/global')

})
})
})
require('shelljs/global')
const EXPECTED_LOGS_DIR = 'test/expected/logs',
const
EXPECTED_LOGS_DIR = 'test/expected/logs',
GENERATED_LOGS_DIR = 'test/generated/logs'
describe('output logs', () => {
it('All the cli output logs are fine', () => {
var logs = ls(EXPECTED_LOGS_DIR)
logs.forEach((log) => {
expect(cat(`${EXPECTED_LOGS_DIR}/${log}`).toString()).to.be(cat(`${GENERATED_LOGS_DIR}/${log}`).toString())
ls(EXPECTED_LOGS_DIR).forEach(log => {
it(log, () => {
expect(read(`${EXPECTED_LOGS_DIR}/${log}`).trim())
.to.be(read(`${GENERATED_LOGS_DIR}/${log}`).trim())
})
})
})
})
function read (path) {
return cat(path).toString().replace(/^\s+|\s+$/gm, '')
}

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