New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

watch-less-do-more

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watch-less-do-more - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

browserslist

15

package.json
{
"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

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