forked from flaviait/ng2-jspm-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
101 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
var sass = require("node-sass"); | ||
var autoprefixer = require("autoprefixer"); | ||
var cssnano = require("cssnano"); | ||
var postcss = require("postcss"); | ||
var program = require("commander"); | ||
var fs = require("fs"); | ||
var _ = require("lodash"); | ||
|
||
var AUTOPREFIXER_OPTIONS = { | ||
browsers: ["last 2 versions"] | ||
}; | ||
var CSSNANO_OPTIONS = { | ||
zindex: false | ||
}; | ||
|
||
program | ||
.usage('[options] <entry> <output>') | ||
.option("-w, --watch <glob>", "Watch the styles") | ||
.option("-m, --minify", "Minify the styles") | ||
.parse(process.argv); | ||
|
||
program.entry = program.args[0]; | ||
program.output = program.args[1]; | ||
|
||
var preprocess = file => new Promise((resolve, reject) => | ||
sass.render({ | ||
sourceMapEmbed: true, | ||
sourceMapContents: true, | ||
file: file | ||
}, (error, result) => { | ||
if (error) { | ||
console.error(`${error.line}:${error.column} ${error.message}`); | ||
reject(error); | ||
} else { | ||
resolve(result); | ||
} | ||
}) | ||
); | ||
|
||
var postprocess = input => new Promise((resolve, reject) => { | ||
var processors = [autoprefixer(AUTOPREFIXER_OPTIONS)]; | ||
if (program.minify) { | ||
processors.push(cssnano(CSSNANO_OPTIONS)); | ||
} | ||
postcss(processors) | ||
.process(input.css, {map: {inline: false}, to: program.output}) | ||
.then( | ||
result => resolve(result), | ||
reject | ||
); | ||
}); | ||
|
||
var writeFile = (target, content) => | ||
new Promise((resolve, reject) => | ||
fs.writeFile(target, content, err => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}) | ||
); | ||
|
||
var writeStyles = result => | ||
Promise.all([ | ||
writeFile(program.output, result.css), | ||
writeFile(`${program.output}.map`, result.map) | ||
]); | ||
|
||
var processStyles = () => preprocess(program.entry) | ||
.then(postprocess) | ||
.then(writeStyles); | ||
|
||
processStyles() | ||
.catch(err => { | ||
console.error("Error processing styles:", err); | ||
process.exit(1); | ||
}); | ||
|
||
if (program.watch) { | ||
var chokidar = require("chokidar"); | ||
console.log(`Watching for changes in ${program.watch}`); | ||
chokidar.watch(program.watch) | ||
.on("change", _.debounce(file => { | ||
console.log(`${file} changed. Reprocessing styles ...`); | ||
processStyles() | ||
.then( | ||
() => console.log(`Styles written to ${program.output}`), | ||
err => console.error("Error processing styles:", err) | ||
); | ||
}, 100)); | ||
} |
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 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 |
---|---|---|
@@ -1,23 +1,19 @@ | ||
var express = require("express"); | ||
var path = require("path"); | ||
var processStyles = require("./dev/process-styles"); | ||
var config = require("./config.json"); | ||
|
||
var app = express(); | ||
|
||
require("./dev/hmr")(); | ||
require("./dev/watch")(); | ||
|
||
config.appRoutes.forEach(route => | ||
app.get(route, (req, res) => | ||
res.sendFile(path.resolve("src/dev/index.dev.html")))); | ||
app.get("/ports", (req, res) => res.send(require("./config.json").port)); | ||
app.get("/main.css", (req, res) => | ||
processStyles(path.resolve("src/main.scss")).then( | ||
css => res.set("Content-Type", "text/css").end(css), | ||
err => res.status(500).send(err) | ||
)); | ||
|
||
app.use(require("./proxy")); | ||
app.use(express.static(".")); | ||
app.get("*", (req, res) => | ||
res.sendFile(path.resolve("src/dev/index.dev.html"))); | ||
app.use(express.static(".tmp")); | ||
|
||
app.listen(config.port.dev, () => console.log(`Listening on http://localhost:${config.port.dev}...`)); |
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 |
---|---|---|
|
@@ -7,5 +7,4 @@ html { | |
|
||
body { | ||
background: #eee; | ||
z-index: 60; | ||
} |