-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds watching for less files -- closes #10 #14
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import fs from 'fs'; | |
import less from 'less'; | ||
import mkdirp from 'mkdirp'; | ||
import path from 'path'; | ||
import chokidar from 'chokidar'; | ||
|
||
commander | ||
.version('0.0.1') | ||
|
@@ -19,10 +20,34 @@ const prefixer = new LessPluginAutoPrefix({ browsers: ['last 2 versions'] }); | |
|
||
const compilePromises = []; | ||
|
||
const PATH_TO_WATCH = path.resolve('src/less/'); | ||
|
||
if (commander.watch) { | ||
console.log(chalk.blue('Compiling less files and watch for changes...')); | ||
console.log(chalk.red('--watch not yet implemented')); | ||
process.exit(1); | ||
chokidar.watch(PATH_TO_WATCH).on('all', (event, path) => { | ||
if (event === "add" || event === "change") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would prefer a switch statement instead of a series of if statments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no double quotes, only single quotes |
||
console.log(chalk.blue(event, path)); | ||
compileLessAndWriteToCSSFile(path) | ||
.then(() => { | ||
console.log(chalk.green('Done compiling ' + path)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use template strings:
|
||
}); | ||
} | ||
if (event === "unlink") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes |
||
const cssFilename = Stylesheets.getDistCSSFileForLessFile(path); | ||
const cssMapFilename = Stylesheets.getDistCSSMapFileForLessFile(path); | ||
Promise.all([removeFile(cssFilename), removeFile(cssMapFilename)]); | ||
} | ||
if (event === "unlinkDir") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes |
||
const cssFilepath = Stylesheets.getDistCSSPathForLessPath(path); | ||
removePath(cssFilepath); | ||
} | ||
if (event === "addDir" && path !== PATH_TO_WATCH) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes |
||
createCSSDirectory(path) | ||
.catch(error => { | ||
console.error(chalk.red(error)); | ||
}); | ||
} | ||
}); | ||
} | ||
else { | ||
console.log(chalk.blue('Compiling less files...')); | ||
|
@@ -68,6 +93,22 @@ function compileLessAndWriteToCSSFile(filename) { | |
}); | ||
} | ||
|
||
/** | ||
* Creates a new directory in the css folder to match that in the less folder | ||
*/ | ||
function createCSSDirectory(pathname) { | ||
return new Promise((resolve, reject) => { | ||
const cssPathname = Stylesheets.getDistCSSPathForLessPath(pathname); | ||
mkdirp(cssPathname, error => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Takes a filename and returns a promise that is completed with a buffer containing the contents | ||
* of the file. | ||
|
@@ -106,3 +147,35 @@ function writeFile(filename, buffer) { | |
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Takes a filename to remove and returns a promise that is completed when the file has been | ||
* deleted. | ||
*/ | ||
function removeFile(filename) { | ||
return new Promise((resolve, reject) => { | ||
fs.unlink(filename, (error) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Takes a filepath to remove and returns a promise that is completed when the path has been | ||
* deleted. | ||
*/ | ||
function removePath(filepath) { | ||
return new Promise((resolve, reject) => { | ||
fs.rmdir(filepath, (error) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
@import 'node_modules/@blueprintjs/core/dist/variables'; | ||
|
||
body { | ||
background-color: @pt-app-background-color; | ||
margin: 10px 0 0 20px; | ||
} | ||
|
||
.margin-all-8 { | ||
margin: 8px; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alphabetize imports