Skip to content

Commit

Permalink
(flavor) fancy-templated-site v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Apr 12, 2021
1 parent 839e7af commit a522ba4
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.min.js
*.build.js
39 changes: 39 additions & 0 deletions lib/extensions/browser-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const ChildProcess = require('child_process');
const Util = require('util');

module.exports = [
{
type: 'onPostStart',
method: async (server) => {

if (!server.realm.pluginOptions.developmentMode) {
return;
}

const bs = server.app.bs = require('browser-sync').create();
const base = server.realm.settings.files.relativeTo;
const run = (cmd) => ChildProcess.spawn('npm', ['run', cmd], { stdio: 'inherit' });

bs.watch(`${base}/public/**/*.scss`).on('change', () => run('prebuild:css'));
bs.watch([`${base}/public/**/*.js`, '!**/*.build.*']).on('change', () => run('prebuild:js'));

bs.watch(`${base}/templates/**/*`).on('change', bs.reload);
bs.watch(`${base}/public/**/*.{build.js,css}`).on('change', bs.reload);

await Util.promisify(bs.init)({ proxy: server.info.uri });
}
},
{
type: 'onPreStop',
method: (server) => {

if (!server.app.bs) {
return;
}

server.app.bs.exit();
}
}
];
3 changes: 3 additions & 0 deletions lib/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = __dirname;
3 changes: 3 additions & 0 deletions lib/plugins/@hapi.inert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
3 changes: 3 additions & 0 deletions lib/plugins/@hapi.vision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
5 changes: 5 additions & 0 deletions lib/public/css/main.build.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/public/css/main.build.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/public/css/main.build.min.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{background-color:#000;color:#fff}
4 changes: 4 additions & 0 deletions lib/public/css/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
color: white;
background-color: black;
}
7 changes: 7 additions & 0 deletions lib/public/js/main.build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/public/js/main.build.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/public/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('Hello, pals!');
11 changes: 11 additions & 0 deletions lib/routes/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
method: 'get',
path: '/',
handler: {
view: {
template: 'home'
}
}
};
11 changes: 11 additions & 0 deletions lib/routes/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = {
method: 'get',
path: '/public/{p*}',
handler: {
directory: {
path: 'public'
}
}
};
File renamed without changes.
7 changes: 7 additions & 0 deletions lib/templates/home.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#> layout title="Home" }}

{{#*inline "content"}}
Hello, pals! This is the homepage.
{{/inline}}

{{/layout}}
32 changes: 32 additions & 0 deletions lib/templates/partials/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<title>{{title}}</title>

{{#if options.developmentMode}}
<link rel="stylesheet" href="{{baseURI}}/public/css/main.build.css">
{{else}}
<link rel="stylesheet" href="{{baseURI}}/public/css/main.build.min.css">
{{/if}}

{{#> head-block}}
{{!-- Custom <head> content per page could be added. --}}
{{/head-block}}
</head>

<body>
{{#> content}}
{{!-- Content goes here. --}}
{{/content}}

{{#if options.developmentMode}}
<script src="{{baseURI}}/public/js/main.build.js"></script>
{{else}}
<script src="{{baseURI}}/public/js/main.build.min.js"></script>
{{/if}}

{{#> scripts-block}}
{{!-- Custom scripts per page can be added. --}}
{{/scripts-block}}
</body>
</html>
18 changes: 18 additions & 0 deletions lib/view-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const Handlebars = require('handlebars');

module.exports = (server, options) => ({
path: 'templates',
partialsPath: 'templates/partials',
helpersPath: 'templates/helpers',
isCached: !options.developmentMode,
defaultExtension: 'hbs',
engines: {
hbs: Handlebars
},
context: {
options,
baseURI: server.realm.modifiers.route.prefix || ''
}
});
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
"scripts": {
"start": "node server",
"test": "lab -a @hapi/code -L",
"lint": "eslint ."
"lint": "eslint .",
"prebuild:css": "node-sass lib/public/css/main.scss lib/public/css/main.build.css --source-map true",
"build:css": "postcss lib/public/css/main.build.css -o lib/public/css/main.build.min.css --use cssnano --no-map",
"prebuild:js": "browserify lib/public/js/main.js -o lib/public/js/main.build.js -d -t [ babelify --presets [ @babel/preset-env ] ]",
"build:js": "uglifyjs lib/public/js/main.build.js -o lib/public/js/main.build.min.js",
"build": "npm run build:css && npm run build:js"
},
"dependencies": {
"@hapi/boom": "9.x.x",
"@hapi/inert": "6.x.x",
"@hapi/vision": "6.x.x",
"@hapipal/haute-couture": "4.x.x",
"handlebars": "4.x.x",
"joi": "17.x.x"
},
"devDependencies": {
"@babel/preset-env": "7.x.x",
"@babel/core": "7.x.x",
"@hapi/code": "8.x.x",
"@hapi/eslint-config-hapi": "13.x.x",
"@hapi/eslint-plugin-hapi": "4.x.x",
Expand All @@ -24,8 +34,16 @@
"@hapipal/hpal-debug": "2.x.x",
"@hapipal/toys": "3.x.x",
"babel-eslint": "10.x.x",
"babelify": "10.x.x",
"browser-sync": "2.x.x",
"browserify": "17.x.x",
"cssnano": "5.x.x",
"dotenv": "8.x.x",
"eslint": "7.x.x",
"exiting": "6.x.x"
"exiting": "6.x.x",
"node-sass": "5.x.x",
"postcss": "8.x.x",
"postcss-cli": "8.x.x",
"uglify-js": "3.x.x"
}
}
8 changes: 7 additions & 1 deletion server/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ module.exports = new Confidence.Store({
plugins: [
{
plugin: '../lib', // Main plugin
options: {}
options: {
developmentMode: {
$filter: { $env: 'NODE_ENV' },
$default: true,
production: false
}
}
},
{
plugin: {
Expand Down

0 comments on commit a522ba4

Please sign in to comment.