Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
tl;dr New build system!
Browse files Browse the repository at this point in the history
Use "grunt dev" for a local dev server.
It automagically minifes everything as it does.

Create a Gruntfile with
- uglify (to minify js)
- cssmin (to minify css)
- imagemin (" images)
- copy (to move html + fonts)

Moved all development assets to a new assets folder.
All work should be done in there.

The static folder now holds built files.

Grunt newer is used to ensure that we only build the extra files we need to every time we build.

The default task starts a production server, and the dev task starts a development server.

Removed the app-local.js file - it's no longer needed.
  • Loading branch information
ConorBobbleHat committed Sep 15, 2019
1 parent d362ce4 commit 564b495
Show file tree
Hide file tree
Showing 72 changed files with 5,552 additions and 139 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ typings/
.yarn-integrity

# dotenv environment variables file
.env

.env
94 changes: 94 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module.exports = function (grunt) {
// Project config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
ngAnnotate: {
build: {
files: [{
expand: true,
cwd: 'Website/assets/js/',
src: ['**/*.js', '!**/*.annotated.js'],
dest: 'Website/assets/js/'
//ext: '.annotated.js',
//extDot: 'last'
}]
}
},
uglify: {
build: {
src: [
'Website/assets/js/jquery.js',
'Website/assets/js/bootstrap.min.js',
'Website/assets/js/angular.min.js',
'Website/assets/js/*.js'
],
dest: 'Website/static/js/app.min.js'
}
},
cssmin: {
build: {
src: 'Website/assets/css/*.css',
dest: 'Website/static/css/app.min.css'
}
},
imagemin: {
build: {
files: [{
expand: true,
cwd: "Website/assets/images/",
src: "**/*.{jpg,png,gif}",
dest: "Website/static/images/"
}]
}
},
copy: {
html: {
expand: true,
cwd: "Website/assets/",
src: "*.html",
dest: "Website/static/"
},
fonts: {
expand: true,
cwd: "Website/assets/fonts/",
src: "**/*",
dest: "Website/static/fonts"
}
},
run: {
prod: {
cmd: 'node',
args: [
'Website/app.js',
'prod'
]
},
dev: {
cmd: 'node',
args: [
'Website/app.js',
'dev'
]
}
}
});

grunt.loadNpmTasks('grunt-ng-annotate') // angular js doesn't like minification normally
grunt.loadNpmTasks('grunt-contrib-uglify'); // js minification
grunt.loadNpmTasks('grunt-contrib-cssmin'); // css minification
grunt.loadNpmTasks('grunt-contrib-imagemin'); // image minification
grunt.loadNpmTasks('grunt-contrib-copy'); // copy over html

grunt.loadNpmTasks('grunt-newer'); // only run on new files - takes like 5 mins to run from scratch
grunt.loadNpmTasks('grunt-run'); // used to start the server

// Default task - build assets, and start a production server
grunt.registerTask('default', ['build', 'run:prod']);

// Dev task - build assets, and start a dev server
grunt.registerTask('dev', ['build', 'run:dev']);

// Build task - minimize all assets
grunt.registerTask('build', ['newer:ngAnnotate:build', 'newer:uglify:build', 'newer:cssmin:build', 'newer:imagemin:build', 'newer:copy']);

}
21 changes: 0 additions & 21 deletions Website/app-local.js

This file was deleted.

53 changes: 33 additions & 20 deletions Website/app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
// What mode are we running in?
const mode = process.argv.length == 3 ? process.argv[2] : 'prod';

// Dependencies
const express = require('express');

const compression = require('compression');
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS;
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
var content = require("./content");

const content = require("./content");
const app = express();

app.use(redirectToHTTPS());
app.use(compression());
if (mode == "prod") {
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS;
const https = require('https');

app.use(redirectToHTTPS());

// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/chain.pem', 'utf8');

// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/chain.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};

const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
}

app.use(compression());

// Get content from JSON file
app.get("/pageJSON/:page", function(req, res) {
Expand All @@ -32,16 +42,19 @@ app.get("/pagesJSON", function(req, res) {
res.json(content.pages());
});

app.use(express.static("static"));
app.use(express.static(__dirname + "/static"));

// Starting both http & https server
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);

httpServer.listen(80, () => {
console.log('HTTP Server running on port 80');
});

httpsServer.listen(443, () => {
console.log('HTTPS Server running on port 443');
});
if (mode == "prod") {
const httpsServer = https.createServer(credentials, app);

httpsServer.listen(443, () => {
console.log('HTTPS Server running on port 443');
});
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Website/assets/fonts/FontAwesome.otf
Binary file not shown.
Binary file added Website/assets/fonts/fontawesome-webfont.eot
Binary file not shown.
Loading

0 comments on commit 564b495

Please sign in to comment.