-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from jGleitz/watch
Streamlined development process
- Loading branch information
Showing
11 changed files
with
376 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"rules": { | ||
"indent": [ | ||
2, | ||
"tab", { | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"quotes": [ | ||
2, | ||
"single" | ||
], | ||
"linebreak-style": [ | ||
2, | ||
"unix" | ||
], | ||
"semi": [ | ||
2, | ||
"always" | ||
], | ||
"no-mixed-spaces-and-tabs": [ | ||
2, "smart-tabs" | ||
] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"indent_size": 2, | ||
"indent_char": " ", | ||
"eol": "\n", | ||
"indent_level": 0, | ||
"indent_with_tabs": true, | ||
"preserve_newlines": true, | ||
"max_preserve_newlines": 3, | ||
"jslint_happy": false, | ||
"space_after_anon_function": false, | ||
"brace_style": "collapse", | ||
"keep_array_indentation": false, | ||
"keep_function_indentation": false, | ||
"space_before_conditional": true, | ||
"break_chained_methods": false, | ||
"eval_code": false, | ||
"unescape_strings": false, | ||
"wrap_line_length": 0, | ||
"wrap_attributes": "auto", | ||
"wrap_attributes_indent_size": 4, | ||
"end_with_newline": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* Handles SCSS rendering. | ||
*/ | ||
|
||
|
||
var sass = require('node-sass'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var q = require('q'); | ||
|
||
var basePath = path.resolve(__dirname, '..'); | ||
var resolve = path.resolve.bind(path, basePath); | ||
|
||
function returnQ(argument) { | ||
return q.bind(q, argument); | ||
} | ||
|
||
/** | ||
* Renders the given scss file. | ||
* | ||
* @param {string} filePath The path to .scss file out of the css folder. | ||
* @return {promise<string>} A promise that will be fulfilled with the path to the rendered file when it was rendered. | ||
*/ | ||
function renderFile(filePath) { | ||
var outFilePath = getOutputFilePath(filePath); | ||
return q.nfcall(sass.render, { | ||
file: filePath, | ||
outFile: outFilePath | ||
}).then(function(result) { | ||
return mkdirs(path.dirname(outFilePath)) | ||
.then(q.nbind(fs.writeFile, fs, outFilePath, result.css)); | ||
}).then(returnQ(outFilePath)); | ||
} | ||
|
||
function getOutputFilePath(filePath) { | ||
filePath = filePath.replace(/.scss$/, '.css'); | ||
return resolve('build', path.relative(resolve(''), filePath)); | ||
} | ||
|
||
/** | ||
* Remove the rendered equivalent of the provided scss file. | ||
* | ||
* @param {string} filePath The path of a scss file that was present in the css folder, but was deleted. | ||
* @return {promise<string>} A promise that will be fulfilled with the path of the rendered file when it was deleted. | ||
*/ | ||
function clean(filePath) { | ||
var rendered = getOutputFilePath(filePath); | ||
return q.nfcall(fs.unlink, rendered).then(returnQ(rendered)); | ||
} | ||
|
||
module.exports = { | ||
render: renderFile, | ||
clean: clean | ||
}; | ||
|
||
/** | ||
* @param {string} dir A directory | ||
* @return {promise<void>} A promise that will be fulfilled when all directories on the way to dir (including dir itself) exist. | ||
*/ | ||
function mkdirs(dir) { | ||
return q.nfcall(fs.stat, dir).catch(function(error) { | ||
if (error.code === 'ENOENT') { | ||
return mkdirs(path.dirname(dir)) | ||
.then(q.nbind(fs.mkdir, fs, dir)) | ||
.catch(function(error) { | ||
if (error.code !== 'EEXIST') { | ||
throw error; | ||
} | ||
}); | ||
} else { | ||
throw error; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @param {string} dir A directory | ||
* @return {promise<Array<string>>} A promise for all files in that directory, including nested files. | ||
*/ | ||
function walk(dir) { | ||
var results = []; | ||
return q.nfcall(fs.readdir, dir).then(function(list) { | ||
|
||
if (list.length === 0) { | ||
return list; | ||
} | ||
|
||
var promises = list.map(function(file) { | ||
file = path.resolve(dir, file); | ||
|
||
return q.nfcall(fs.stat, file).then(function(stat) { | ||
if (stat.isDirectory()) { | ||
return walk(file).then(function(res) { | ||
results = results.concat(res); | ||
}); | ||
} else { | ||
results.push(file); | ||
return q(); | ||
} | ||
}); | ||
}); | ||
return q.all(promises).then(function() { | ||
return results; | ||
}); | ||
}); | ||
} | ||
|
||
if (require.main === module) { | ||
walk(resolve('css')).then(function(list) { | ||
var promises = list.map(function(file) { | ||
if (path.extname(file) === '.scss') { | ||
return renderFile(file); | ||
} | ||
return q(); | ||
}); | ||
return q.all(promises); | ||
}).done(process.exit.bind(process, 0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Very simple webserver for development purposes. | ||
*/ | ||
|
||
var connect = require('connect'); | ||
var serveStatic = require('serve-static'); | ||
var path = require('path'); | ||
|
||
var baseDir = path.resolve(__dirname, '..'); | ||
|
||
function getWebserver() { | ||
var setHeaders = function(res) { | ||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); | ||
res.setHeader('Pragma', 'no-cache'); | ||
res.setHeader('Expires', '0'); | ||
}; | ||
return serveStatic(baseDir, { | ||
setHeaders: setHeaders, | ||
etag: false | ||
}); | ||
} | ||
|
||
/** | ||
* A simple web server that will default to deliver the base directory of this repository. It can be extended through #use. | ||
*/ | ||
function Server() { | ||
|
||
var server = connect(); | ||
|
||
/** | ||
* Use the provided middleware. The order of the calls defines the order in which middlewares will be queried. | ||
* | ||
* @param {Object} server A node js server middleware. | ||
* @return {void} | ||
*/ | ||
this.use = server.use.bind(server); | ||
|
||
/** | ||
* Launch the server and listen on the provided port. | ||
* | ||
* @param {number} port The port to listen on. | ||
* @return {void} | ||
*/ | ||
this.listen = function(port) { | ||
server.use(getWebserver()); | ||
server.listen(port); | ||
}; | ||
} | ||
|
||
module.exports = Server; |
Oops, something went wrong.