Comparing version 3.0.4 to 4.0.0
@@ -9,6 +9,53 @@ 'use strict' | ||
co = require('co'), | ||
sh = require('shelljs') | ||
fs = require('fs') | ||
module.exports = { | ||
/** | ||
* Simple/cheap debounce implementation | ||
* @param {function} fn - callback | ||
* @param {number} delay - delay in seconds | ||
* @returns {function} debounced function | ||
*/ | ||
debounce(fn, delay) { | ||
let t | ||
return function () { | ||
clearTimeout(t) | ||
t = setTimeout(fn, delay) | ||
} | ||
}, | ||
/** | ||
* Make a directory recursively | ||
* @param {String} fullPath - path to directory | ||
* @returns {String} the path passed as argument | ||
*/ | ||
mkdir(fullPath) { | ||
return fullPath | ||
.split(path.sep) | ||
.reduce((acc, folder) => { | ||
const currentPath = path.join(acc, folder, path.sep) | ||
if (!this.doesPathExist(currentPath)) fs.mkdirSync(currentPath) | ||
return currentPath | ||
}, '') | ||
}, | ||
/** | ||
* Output the file content as string | ||
* @param {String} path - path to the file | ||
* @returns {String} file content | ||
*/ | ||
cat(path) { | ||
return fs.readFileSync(path, 'utf8') | ||
}, | ||
/** | ||
* True if the path exists | ||
* @param {String} path - path to verify | ||
* @returns {Boolean} | ||
*/ | ||
doesPathExist(path) { | ||
return fs.existsSync(path) | ||
}, | ||
/** | ||
* Read from Stdin | ||
@@ -31,2 +78,33 @@ * @returns { String } captured lines from stdin | ||
/** | ||
* Walk a directory recursively finding all the files contained in it | ||
* @param {String} dir - directory path | ||
* @returns {Array} path of all the files found | ||
*/ | ||
walkDir(dir) { | ||
const files = fs.readdirSync(dir) | ||
const filelist = [] | ||
files.forEach(file => { | ||
const fullPath = path.join(dir, file) | ||
const stat = fs.statSync(fullPath) | ||
if (stat.isDirectory()) { | ||
this.walkDir(fullPath).forEach((f) => filelist.push(f)) | ||
} else if (stat.isFile()) { | ||
filelist.push(fullPath) | ||
} | ||
}) | ||
return filelist | ||
}, | ||
/** | ||
* Write a file | ||
* @param {String} content - file content | ||
* @param {String} path - path to the file | ||
*/ | ||
writeFile(content, path) { | ||
fs.writeFileSync(path, content, 'utf8') | ||
}, | ||
/** | ||
* Read from a file | ||
@@ -37,3 +115,3 @@ * @param { String } from - file path | ||
readFile(from) { | ||
return sh.cat(from).toString().replace(/^\uFEFF/g, /* strips BOM */'') | ||
return this.cat(from).replace(/^\uFEFF/g, /* strips BOM */'') | ||
}, | ||
@@ -48,4 +126,4 @@ | ||
find(extRegex, from) { | ||
return sh | ||
.find(from) | ||
return this | ||
.walkDir(from) | ||
.filter((f) => extRegex.test(f) && TEMP_FILE_NAME.test(f)) | ||
@@ -76,3 +154,3 @@ }, | ||
toRelative(path) { | ||
return path.replace(sh.pwd().toString() + '/', '') | ||
return path.replace(process.cwd().toString() + '/', '') | ||
}, | ||
@@ -79,0 +157,0 @@ |
@@ -34,3 +34,3 @@ #!/usr/bin/env node | ||
helpers.log(h) | ||
return h | ||
return Promise.resolve(h) | ||
}, | ||
@@ -40,3 +40,3 @@ version() { | ||
helpers.log(v) | ||
return v | ||
return Promise.resolve(v) | ||
}, | ||
@@ -66,2 +66,5 @@ new(opt) { return new New(opt) }, | ||
// avoid unhandled rejections | ||
process.on('unhandledRejection', r => {throw r}) | ||
// Translate args into options hash | ||
@@ -79,2 +82,3 @@ // extending args with the options loaded via config file | ||
exclude: args.exclude, | ||
sourcemap: args.sourcemap ? 'inline' : false, | ||
expr: args.expr, | ||
@@ -81,0 +85,0 @@ modular: args.modular, |
@@ -84,2 +84,7 @@ 'use strict' | ||
{ | ||
option: 'sourcemap', | ||
type: 'Boolean', | ||
description: 'Add inline sourcemaps to the generated files' | ||
}, | ||
{ | ||
option: 'check', | ||
@@ -86,0 +91,0 @@ type: 'Boolean', |
@@ -6,3 +6,2 @@ 'use strict' | ||
path = require('path'), | ||
sh = require('shelljs'), | ||
compiler = global.compiler || require('riot-compiler'), | ||
@@ -20,3 +19,3 @@ constants = require('./const'), | ||
/* istanbul ignore next */ | ||
if (this.called) return | ||
if (this.called) return Promise.resolve() | ||
this.called = true | ||
@@ -39,3 +38,3 @@ | ||
const err = this.validate(opt.compiler, opt.parsers) | ||
if (err) return this.handleError(err, opt.isCli) | ||
if (err) return Promise.reject(this.handleError(err, opt.isCli)) | ||
} else { | ||
@@ -55,3 +54,3 @@ // make sure to set always the compiler options | ||
// Check if the path exsists | ||
if (!sh.test('-e', opt.from)) return this.handleError(NO_FILE_FOUND, opt.isCli) | ||
if (!helpers.doesPathExist(opt.from)) return Promise.reject(this.handleError(NO_FILE_FOUND, opt.isCli)) | ||
} | ||
@@ -93,4 +92,3 @@ | ||
// each run method could return different stuff | ||
return this.run(opt) | ||
return Promise.resolve(this.run(opt)) | ||
} | ||
@@ -97,0 +95,0 @@ |
@@ -5,7 +5,6 @@ 'use strict' | ||
analyzer = require('../analyzer'), | ||
sh = require('shelljs'), | ||
helpers = require('../helpers'), | ||
chalk = require('chalk'), | ||
log = helpers.log, | ||
find = helpers.find, | ||
find = helpers.find.bind(helpers), | ||
toRelative = helpers.toRelative | ||
@@ -22,3 +21,3 @@ | ||
// get the content of the tag file analysing it | ||
var results = analyzer(sh.cat(file).toString().replace(/^\uFEFF/g, /* strips BOM */'')) | ||
var results = analyzer(helpers.readFile(file)) | ||
return { | ||
@@ -48,3 +47,2 @@ file: toRelative(file), | ||
return results | ||
} | ||
@@ -51,0 +49,0 @@ } |
@@ -9,3 +9,2 @@ 'use strict' | ||
path = require('path'), | ||
sh = require('shelljs'), | ||
co = require('co'), | ||
@@ -38,3 +37,3 @@ constants = require('./../const'), | ||
// Create any necessary dirs | ||
if (!isStdout) to.forEach(f => sh.mkdir('-p', path.dirname(f))) | ||
if (!isStdout) to.forEach(f => helpers.mkdir(path.dirname(f))) | ||
@@ -45,10 +44,2 @@ // extend the compiler parsers | ||
// Process files | ||
if (isStdout) | ||
this.toStdout(from, opt) | ||
else if (isOutputFile) | ||
this.toFile(from, to, opt) | ||
else | ||
this.toDir(from, to, opt) | ||
/** | ||
@@ -69,3 +60,9 @@ * Print what's been done (unless --silent) | ||
return true | ||
// Process files | ||
if (isStdout) | ||
return this.toStdout(from, opt) | ||
else if (isOutputFile) | ||
return this.toFile(from, to, opt) | ||
else | ||
return this.toDir(from, to, opt) | ||
} | ||
@@ -81,10 +78,5 @@ | ||
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) | ||
}) | ||
process.stdout.write(yield this.generateOutput(from, opt)) | ||
}.bind(this)) | ||
} | ||
@@ -101,9 +93,20 @@ | ||
return co(function* () { | ||
// Save to a file | ||
helpers.writeFile(yield this.generateOutput(from, opt), to[0]) | ||
}.bind(this)) | ||
} | ||
/** | ||
* Generate the output files | ||
* @param {Array} from - source files | ||
* @param {Object} opt - cli options | ||
* @returns {Promise<string>} | ||
*/ | ||
generateOutput(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) | ||
// Save to a file | ||
sh.ShellString(wrapped).to(to[0]) | ||
return encapsulate(compiled, opt) | ||
}) | ||
@@ -122,4 +125,6 @@ } | ||
const wrapped = encapsulate(compiled, opt) | ||
sh.ShellString(wrapped).to(to[i]) | ||
helpers.writeFile(wrapped, to[i]) | ||
}) | ||
return Promise.resolve() // to make it consistent with the toFile and to toStdout methods | ||
} | ||
@@ -126,0 +131,0 @@ } |
@@ -7,3 +7,2 @@ 'use strict' | ||
path = require('path'), | ||
sh = require('shelljs'), | ||
constants = require('./../const'), | ||
@@ -22,7 +21,5 @@ TAG_TEMPLATE = constants.TAG_TEMPLATE, | ||
sh.mkdir('-p', path.dirname(opt.new)) | ||
helpers.mkdir(path.dirname(opt.new)) | ||
sh | ||
.echo(TAG_TEMPLATE(tagName)) | ||
.to(out) | ||
helpers.writeFile(TAG_TEMPLATE(tagName), out) | ||
@@ -32,3 +29,2 @@ helpers.log(chalk.green(TAG_CREATED_CORRECTLY(out))) | ||
return true | ||
} |
@@ -47,3 +47,3 @@ 'use strict' | ||
}) | ||
.on('all', () => new Make(opt)) | ||
.on('all', helpers.debounce(() => new Make(opt), 100)) | ||
@@ -50,0 +50,0 @@ return watcher |
{ | ||
"name": "riot-cli", | ||
"version": "3.0.4", | ||
"version": "4.0.0", | ||
"description": "Riot command line utility", | ||
@@ -17,3 +17,3 @@ "main": "lib/index.js", | ||
"test": "make test", | ||
"prepare": "npm i babel pug coffee-script node-sass --no-save" | ||
"prepare": "npm i babel pug coffeescript node-sass --no-save" | ||
}, | ||
@@ -33,8 +33,10 @@ "repository": { | ||
"devDependencies": { | ||
"coveralls": "^2.13.1", | ||
"eslint": "^4.6.1", | ||
"co-mocha": "^1.2.1", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.13.1", | ||
"eslint-config-riot": "^1.0.0", | ||
"expect.js": "^0.3.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.5.0" | ||
"mocha": "^4.0.1", | ||
"shelljs": "^0.7.8" | ||
}, | ||
@@ -48,10 +50,9 @@ "license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.1.0", | ||
"chalk": "^2.3.0", | ||
"chokidar": "^1.7.0", | ||
"co": "^4.6.0", | ||
"optionator": "^0.8.2", | ||
"riot-compiler": "^3.2.4", | ||
"rollup": "^0.51.2", | ||
"shelljs": "^0.7.8" | ||
"riot-compiler": "^3.4.0", | ||
"rollup": "^0.52.1" | ||
} | ||
} |
@@ -35,3 +35,3 @@ # Riot cli | ||
[codeclimate-image]:https://img.shields.io/codeclimate/github/riot/cli.svg?style=flat-square | ||
[codeclimate-image]:https://api.codeclimate.com/v1/badges/1409ace7dbefdb5da35a/maintainability | ||
[codeclimate-url]:https://codeclimate.com/github/riot/cli |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
34686
6
14
1017
8
3
+ Addedrollup@0.52.3(transitive)
- Removedshelljs@^0.7.8
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinterpret@1.4.0(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedrechoir@0.6.2(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrollup@0.51.8(transitive)
- Removedshelljs@0.7.8(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedchalk@^2.3.0
Updatedriot-compiler@^3.4.0
Updatedrollup@^0.52.1