Skip to content

Commit

Permalink
i did it
Browse files Browse the repository at this point in the history
  • Loading branch information
the-sides committed Jan 28, 2020
0 parents commit 5e30c48
Show file tree
Hide file tree
Showing 18 changed files with 8,839 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
.DS_Store
2 changes: 2 additions & 0 deletions README.md
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.
91 changes: 91 additions & 0 deletions bin/www
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);
}
90 changes: 90 additions & 0 deletions gulpfile.js
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}
Loading

0 comments on commit 5e30c48

Please sign in to comment.