-
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.
- Loading branch information
0 parents
commit 5e30c48
Showing
18 changed files
with
8,839 additions
and
0 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,3 @@ | ||
dist | ||
node_modules | ||
.DS_Store |
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,2 @@ | ||
# web-template | ||
The template I'm always copying to develop node sites. |
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,91 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../server'); | ||
var debug = require('debug')('nodulus:server'); | ||
var http = require('http'); | ||
|
||
/** | ||
* Get port from environment and store in Express. | ||
*/ | ||
|
||
var port = normalizePort(process.env.PORT || '3000'); | ||
app.set('port', port); | ||
|
||
/** | ||
* Create HTTP server. | ||
*/ | ||
|
||
var server = http.createServer(app); | ||
|
||
/** | ||
* Listen on provided port, on all network interfaces. | ||
*/ | ||
|
||
server.listen(port); | ||
console.log("Listening on port", port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
/** | ||
* Normalize a port into a number, string, or false. | ||
*/ | ||
|
||
function normalizePort(val) { | ||
var port = parseInt(val, 10); | ||
|
||
if (isNaN(port)) { | ||
// named pipe | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
// port number | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "error" event. | ||
*/ | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
var bind = typeof port === 'string' | ||
? 'Pipe ' + port | ||
: 'Port ' + port; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
console.error(bind + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error(bind + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
/** | ||
* Event listener for HTTP server "listening" event. | ||
*/ | ||
|
||
function onListening() { | ||
var addr = server.address(); | ||
var bind = typeof addr === 'string' | ||
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} |
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,90 @@ | ||
const {src, dest, series, parallel} = require('gulp') | ||
const watch = require('glob-watcher') | ||
const webpack = require('webpack-stream') | ||
const browserSync = require('browser-sync').create(); | ||
const nodemon = require('gulp-nodemon'); | ||
const del = require('del') | ||
const named = require('vinyl-named') | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const sass = require('gulp-sass'); | ||
|
||
function clean(){ | ||
return del([ | ||
'./dist/scripts/**', | ||
'./dist/styles/**' | ||
]) | ||
} | ||
|
||
async function bsTask(){ | ||
console.log('this is bs'); | ||
return browserSync.init({ | ||
proxy: "localhost:3000", | ||
port: 3001 | ||
}) | ||
} | ||
async function nodemonTask(cb) { | ||
return nodemon( { | ||
script: './bin/www', | ||
ext: 'js html', | ||
env: { 'NODE_ENV': 'development' }, | ||
port: 3000, | ||
done: cb() | ||
})//.once('start', cb); | ||
|
||
}; | ||
|
||
|
||
function scripts(){ | ||
return src(['./src/scripts/**.js', | ||
]) | ||
.pipe(sourcemaps.init()) | ||
.pipe(named()) | ||
.pipe(webpack({ | ||
mode: 'development' | ||
})) | ||
.pipe(sourcemaps.write()) | ||
.pipe(dest('dist/scripts/')); | ||
} | ||
|
||
function styles(){ | ||
return src('./src/styles/**/*.scss') | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(dest('dist/styles/')) | ||
.pipe(browserSync.stream()) | ||
} | ||
|
||
function vendors(){ | ||
return src(['']) | ||
.pipe(dest('dist/vendors/')) | ||
} | ||
|
||
function images(){ | ||
return src(['./src/images/**/**']) | ||
.pipe(dest('dist/images/')) | ||
} | ||
|
||
const dev = series( | ||
clean, | ||
//vendors, | ||
scripts, | ||
parallel( | ||
styles, | ||
images | ||
) | ||
) | ||
|
||
async function watcher(){ | ||
watch(['./src/styles/**/*.scss'], styles ) | ||
watch( [ `./src/scripts/**/**`, `./src/views/**/*.pug`], ()=>{ | ||
series( | ||
dev(), | ||
setTimeout(browserSync.reload,2000) | ||
) | ||
|
||
}); | ||
} | ||
|
||
|
||
const run = series(dev, watcher, nodemonTask, bsTask); | ||
|
||
module.exports = {dev, watcher, run} |
Oops, something went wrong.