-
Notifications
You must be signed in to change notification settings - Fork 478
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 #9 from kylejrp/master
Add Sass build tools and theming
- Loading branch information
Showing
19 changed files
with
3,173 additions
and
199 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,84 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ |
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,75 @@ | ||
const express = require('express') | ||
const app = express() | ||
const http = require('http').Server(app) | ||
const io = require('socket.io')(http) | ||
const fs = require('fs-extra') | ||
const chokidar = require('chokidar') | ||
const sass = require('node-sass') | ||
|
||
const script = ` | ||
const socket = io() | ||
socket.on('reload', () => location.reload()) | ||
` | ||
|
||
app.get('/', async (req, res) => { | ||
console.log('> Serving index') | ||
const html = await fs.readFile('index.html') | ||
const injected = html.toString().replace('</body>', `<script src='/socket.io/socket.io.js'></script><script>${script}</script></body>`) | ||
res.send(injected) | ||
}) | ||
|
||
app.get('/script.js', async (req, res) => { | ||
console.log('> Serving script') | ||
const script = await fs.readFile('script.js') | ||
res.contentType('javascript') | ||
res.send(script) | ||
}) | ||
|
||
app.use('/dist', (req, res, next) => { | ||
console.log('> Serving a stylesheet') | ||
next() | ||
}, express.static('dist')) | ||
|
||
function reload() { | ||
console.log('> Reloading') | ||
io.emit('reload') | ||
} | ||
|
||
chokidar.watch('index.html', { ignoreInitial: true }).on('all', () => { | ||
console.log('> Index changed') | ||
reload() | ||
}) | ||
|
||
chokidar.watch('script.js', { ignoreInitial: true }).on('all', () => { | ||
console.log('> Script changed') | ||
reload() | ||
}) | ||
|
||
function buildSass(file) { | ||
sass.render({ file, outputStyle: 'compressed' }, async (errors, result) => { | ||
if (errors) { | ||
console.log('> Sass errors!') | ||
console.log(errors) | ||
return | ||
} | ||
const outFile = file.replace('src', 'dist').replace('.scss', '.css') | ||
await fs.outputFile(outFile, result.css) | ||
reload() | ||
}) | ||
} | ||
|
||
chokidar.watch('src/*.scss', { ignoreInitial: true }).on('all', (event, file) => { | ||
console.log('> Stylesheet changed') | ||
buildSass(file) | ||
}) | ||
|
||
chokidar.watch('src/parts/*.scss', { ignoreInitial: true }).on('all', async () => { | ||
console.log('> Stylesheet part changed') | ||
const src = await fs.readdir('src') | ||
const files = src.filter(file => file !== 'parts').map(file => `src/${file}`) | ||
for (let file of files) { | ||
buildSass(file) | ||
} | ||
}) | ||
|
||
http.listen(3000, () => console.log('> Ready at http://localhost:3000/')) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.