diff --git a/package.json b/package.json index 5b58ddd40..f760e1f26 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build:css": "concurrent \"npm run build:css:ipython\" \"npm run build:css:style\"", "build:css:ipython": "lessc --include-path=notebook/static notebook/static/style/ipython.less notebook/static/style/ipython.min.css", "build:css:style": "lessc --include-path=notebook/static notebook/static/style/style.less notebook/static/style/style.min.css", - "build:css:watch": "echo Not implemented yet...", + "build:css:watch": "./scripts/less-watch ./notebook/static", "build:js": "webpack", "build:js:watch": "npm run build:js -- --watch" }, diff --git a/scripts/less-watch b/scripts/less-watch new file mode 100755 index 000000000..6d2fdfb22 --- /dev/null +++ b/scripts/less-watch @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +/** + +Usage: +./scripts/less-watch [watchPath] + +Example: +./scripts/less-watch ./notebook/static/notebook/less + +**/ + +var less = require('less'); +var fs = require('fs'); +var path = require('path'); +var child_process = require('child_process'); + +function watchDir(dir) { + var rootPath = path.join(__dirname, '..'); + var watchPath = path.resolve(dir); + console.log('less-watch:', 'watching:', path.relative(rootPath, watchPath)); + fs.watch(watchPath, {recursive: true}, function(event, file) { + if (file && /.+\.less$/.test(file)) { + console.log('less-watch:', 'modified:', file); + child_process.exec('lessc --include-path=notebook/static --verbose notebook/static/style/style.less notebook/static/style/style.min.css', function(err, stdout, stderr) { + if (err) return console.log(err); + if (stdout) console.log(stdout); + if (stderr) console.log(stderr); + }); + child_process.exec('lessc --include-path=notebook/static notebook/static/style/ipython.less notebook/static/style/ipython.min.css', function(err, stdout, stderr) { + if (err) return console.log(err); + if (stdout) console.log(stdout); + if (stderr) console.log(stderr); + }); + } + }); +} + +watchDir(process.argv[2]);