watch-less-do-more
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "watch-less-do-more", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Watch less files and their dependency tree for changes & automatically recompile", | ||
@@ -9,2 +9,3 @@ "main": "src/index.js", | ||
"start": "http-server examples/ -c-0 -o", | ||
"watch": "src/cli.js -u autoprefixer -i examples/src/index.less -o examples/build/index.css", | ||
"test": "eslint src/" | ||
@@ -32,11 +33,14 @@ }, | ||
"devDependencies": { | ||
"autoprefixer": "6.7.6", | ||
"bootstrap": "3.3.7", | ||
"eslint-config-jakesidsmith": "git+https://github.com/jakesidsmith/eslint-config-jakesidsmith.git", | ||
"http-server": "0.9.0" | ||
"http-server": "0.9.0", | ||
"less": "2.7.2", | ||
"postcss": "5.2.16" | ||
}, | ||
"dependencies": { | ||
"chokidar": "1.6.1", | ||
"less": "2.7.2", | ||
"lodash.foreach": "4.5.0", | ||
"lodash.map": "4.6.0", | ||
"mkdirp": "0.5.1", | ||
"underscore": "1.8.3", | ||
"yargs": "6.6.0" | ||
@@ -46,3 +50,6 @@ }, | ||
"less": "2.x" | ||
}, | ||
"optionalDependencies": { | ||
"postcss": "5.x" | ||
} | ||
} |
@@ -38,8 +38,16 @@ # watch-less-do-more [![CircleCI](https://circleci.com/gh/JakeSidSmith/watch-less-do-more.svg?style=svg)](https://circleci.com/gh/JakeSidSmith/watch-less-do-more) | ||
Install watch-less-do-more and less. Currently supports less `2.x.x`. | ||
Install watch-less-do-more. You'll also need to install less. | ||
Currently supports less `2.x.x`. | ||
```shell | ||
npm install less watch-less-do-more --save | ||
npm install watch-less-do-more less --save | ||
``` | ||
Optionally install postcss if you want to use postcss modules. | ||
Currently supports postcss `5.x.x`. | ||
```shell | ||
npm install postcss --save | ||
``` | ||
## Usage | ||
@@ -67,8 +75,21 @@ | ||
### PostCSS | ||
You can use PostCSS modules with watch-less-do-more incredibly easily. | ||
Just install the modules you want, and tell watch-less-do-more to use them in the same way you would with PostCSS. | ||
```json | ||
{ | ||
"watch-less": "watch-less-do-more -u autoprefixer -i source.less -o output.css" | ||
} | ||
``` | ||
### Options | ||
If installed globally run the following to display a full list of options | ||
```shell | ||
watch-less-do-more --help | ||
--input, -i Path to input LESS file [string] [required] | ||
--output, -o Path to output CSS file [string] [required] | ||
--use, -u PostCSS module to use [string] | ||
--help Show help [boolean] | ||
--version Show version number [boolean] | ||
``` |
@@ -7,3 +7,3 @@ #! /usr/bin/env node | ||
var _ = require('underscore'); | ||
var forEach = require('lodash.foreach'); | ||
var yargs = require('yargs'); | ||
@@ -26,2 +26,7 @@ | ||
type: 'string' | ||
}, | ||
'use': { | ||
alias: 'u', | ||
description: 'PostCSS module to use', | ||
type: 'string' | ||
} | ||
@@ -34,7 +39,6 @@ }) | ||
// console.log(argv); | ||
var inputs = typeof argv.input !== 'undefined' ? [].concat(argv.input) : []; | ||
var outputs = typeof argv.output !== 'undefined' ? [].concat(argv.output) : []; | ||
var use = typeof argv.use !== 'undefined' ? [].concat(argv.use) : []; | ||
var inputs = [].concat(argv.input); | ||
var outputs = [].concat(argv.output); | ||
if (inputs.length !== outputs.length) { | ||
@@ -49,6 +53,7 @@ console.error( | ||
} else if (inputs.length > 1) { | ||
_.each(inputs, function (input, index) { | ||
forEach(inputs, function (input, index) { | ||
watchLessDoMore({ | ||
input: input, | ||
output: outputs[index] | ||
output: outputs[index], | ||
use: use | ||
}); | ||
@@ -59,3 +64,4 @@ }); | ||
input: inputs[0], | ||
output: outputs[0] | ||
output: outputs[0], | ||
use: use | ||
}); | ||
@@ -62,0 +68,0 @@ } |
@@ -8,12 +8,13 @@ 'use strict'; | ||
var _ = require('underscore'); | ||
var map = require('lodash.map'); | ||
var chokidar = require('chokidar'); | ||
var mkdirp = require('mkdirp'); | ||
var less = require('less'); | ||
var postcss; | ||
var UTF8 = 'utf8'; | ||
// var CWD = process.cwd(); | ||
function watchLessDoMore (options) { | ||
var libs, processor; | ||
var initialized = false; | ||
@@ -26,2 +27,23 @@ var parseFileAndWatchImports; | ||
if (options.use.length) { | ||
try { | ||
postcss = require('postcss'); | ||
} catch (error) { | ||
console.error('Optional dependency \'postcss\' is required to use postcss modules'); | ||
console.error(error.message); | ||
process.exit(1); | ||
} | ||
try { | ||
libs = map(options.use, function (lib) { | ||
return require(lib); | ||
}); | ||
processor = postcss(libs); | ||
} catch (error) { | ||
console.error(error.message); | ||
process.exit(1); | ||
} | ||
} | ||
var watcher = chokidar.watch(inputFilePath, {persistent: true}); | ||
@@ -33,2 +55,20 @@ | ||
function postProcess (css, callback) { | ||
if (!processor) { | ||
callback(css); | ||
} else { | ||
processor | ||
.process(css) | ||
.then(function (result) { | ||
callback(result.css); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
if (!initialized) { | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
} | ||
function readFile (filePath, callback) { | ||
@@ -71,2 +111,4 @@ fs.readFile(filePath, UTF8, function (error, result) { | ||
}); | ||
initialized = true; | ||
} | ||
@@ -76,19 +118,20 @@ }); | ||
parseFileAndWatchImports = _.debounce(function () { | ||
readFile(inputFilePath, function (result) { | ||
parseLess(result, function (output) { | ||
watcher.unwatch(watchedPaths); | ||
function parseFileAndWatchImports (eventType) { | ||
if (eventType !== 'add') { | ||
readFile(inputFilePath, function (result) { | ||
parseLess(result, function (output) { | ||
watcher.unwatch(watchedPaths); | ||
outputCSS(output.css); | ||
initialized = true; | ||
postProcess(output.css, outputCSS); | ||
watchedPaths = output.imports; | ||
watcher.add(watchedPaths); | ||
watchedPaths = output.imports; | ||
watcher.add(watchedPaths); | ||
}); | ||
}); | ||
}); | ||
}, 2000, true); | ||
} | ||
} | ||
watcher.on('all', parseFileAndWatchImports); | ||
parseFileAndWatchImports(); | ||
parseFileAndWatchImports('init'); | ||
} | ||
@@ -95,0 +138,0 @@ |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
33175
12
176
94
7
6
2
+ Addedlodash.foreach@4.5.0
+ Addedlodash.map@4.6.0
+ Addedajv@4.11.8(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedassert-plus@0.2.0(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedform-data@2.1.4(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhar-schema@1.0.5(transitive)
+ Addedhar-validator@4.2.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-flag@1.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjs-base64@2.6.4(transitive)
+ Addedjson-stable-stringify@1.2.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedless@2.7.3(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.map@4.6.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedperformance-now@0.2.0(transitive)
+ Addedpostcss@5.2.18(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.4.1(transitive)
+ Addedrequest@2.81.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedsupports-color@2.0.03.2.3(transitive)
+ Addedtough-cookie@2.3.4(transitive)
- Removedless@2.7.2
- Removedunderscore@1.8.3
- Removedajv@6.12.6(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedform-data@2.3.3(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedless@2.7.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedunderscore@1.8.3(transitive)
- Removeduri-js@4.4.1(transitive)