Skip to content

Commit a522ba4

Browse files
committed
(flavor) fancy-templated-site v3.0.0
1 parent 839e7af commit a522ba4

20 files changed

+186
-3
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.min.js
2+
*.build.js

lib/extensions/browser-sync.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const ChildProcess = require('child_process');
4+
const Util = require('util');
5+
6+
module.exports = [
7+
{
8+
type: 'onPostStart',
9+
method: async (server) => {
10+
11+
if (!server.realm.pluginOptions.developmentMode) {
12+
return;
13+
}
14+
15+
const bs = server.app.bs = require('browser-sync').create();
16+
const base = server.realm.settings.files.relativeTo;
17+
const run = (cmd) => ChildProcess.spawn('npm', ['run', cmd], { stdio: 'inherit' });
18+
19+
bs.watch(`${base}/public/**/*.scss`).on('change', () => run('prebuild:css'));
20+
bs.watch([`${base}/public/**/*.js`, '!**/*.build.*']).on('change', () => run('prebuild:js'));
21+
22+
bs.watch(`${base}/templates/**/*`).on('change', bs.reload);
23+
bs.watch(`${base}/public/**/*.{build.js,css}`).on('change', bs.reload);
24+
25+
await Util.promisify(bs.init)({ proxy: server.info.uri });
26+
}
27+
},
28+
{
29+
type: 'onPreStop',
30+
method: (server) => {
31+
32+
if (!server.app.bs) {
33+
return;
34+
}
35+
36+
server.app.bs.exit();
37+
}
38+
}
39+
];

lib/path.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = __dirname;

lib/plugins/@hapi.inert.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = {};

lib/plugins/@hapi.vision.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = {};

lib/public/css/main.build.css

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/public/css/main.build.css.map

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/public/css/main.build.min.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body{background-color:#000;color:#fff}

lib/public/css/main.scss

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
color: white;
3+
background-color: black;
4+
}

lib/public/js/main.build.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/public/js/main.build.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/public/js/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log('Hello, pals!');

lib/routes/home.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = {
4+
method: 'get',
5+
path: '/',
6+
handler: {
7+
view: {
8+
template: 'home'
9+
}
10+
}
11+
};

lib/routes/public.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = {
4+
method: 'get',
5+
path: '/public/{p*}',
6+
handler: {
7+
directory: {
8+
path: 'public'
9+
}
10+
}
11+
};
File renamed without changes.

lib/templates/home.hbs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{#> layout title="Home" }}
2+
3+
{{#*inline "content"}}
4+
Hello, pals! This is the homepage.
5+
{{/inline}}
6+
7+
{{/layout}}

lib/templates/partials/layout.hbs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>{{title}}</title>
5+
6+
{{#if options.developmentMode}}
7+
<link rel="stylesheet" href="{{baseURI}}/public/css/main.build.css">
8+
{{else}}
9+
<link rel="stylesheet" href="{{baseURI}}/public/css/main.build.min.css">
10+
{{/if}}
11+
12+
{{#> head-block}}
13+
{{!-- Custom <head> content per page could be added. --}}
14+
{{/head-block}}
15+
</head>
16+
17+
<body>
18+
{{#> content}}
19+
{{!-- Content goes here. --}}
20+
{{/content}}
21+
22+
{{#if options.developmentMode}}
23+
<script src="{{baseURI}}/public/js/main.build.js"></script>
24+
{{else}}
25+
<script src="{{baseURI}}/public/js/main.build.min.js"></script>
26+
{{/if}}
27+
28+
{{#> scripts-block}}
29+
{{!-- Custom scripts per page can be added. --}}
30+
{{/scripts-block}}
31+
</body>
32+
</html>

lib/view-manager.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const Handlebars = require('handlebars');
4+
5+
module.exports = (server, options) => ({
6+
path: 'templates',
7+
partialsPath: 'templates/partials',
8+
helpersPath: 'templates/helpers',
9+
isCached: !options.developmentMode,
10+
defaultExtension: 'hbs',
11+
engines: {
12+
hbs: Handlebars
13+
},
14+
context: {
15+
options,
16+
baseURI: server.realm.modifiers.route.prefix || ''
17+
}
18+
});

package.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55
"scripts": {
66
"start": "node server",
77
"test": "lab -a @hapi/code -L",
8-
"lint": "eslint ."
8+
"lint": "eslint .",
9+
"prebuild:css": "node-sass lib/public/css/main.scss lib/public/css/main.build.css --source-map true",
10+
"build:css": "postcss lib/public/css/main.build.css -o lib/public/css/main.build.min.css --use cssnano --no-map",
11+
"prebuild:js": "browserify lib/public/js/main.js -o lib/public/js/main.build.js -d -t [ babelify --presets [ @babel/preset-env ] ]",
12+
"build:js": "uglifyjs lib/public/js/main.build.js -o lib/public/js/main.build.min.js",
13+
"build": "npm run build:css && npm run build:js"
914
},
1015
"dependencies": {
1116
"@hapi/boom": "9.x.x",
17+
"@hapi/inert": "6.x.x",
18+
"@hapi/vision": "6.x.x",
1219
"@hapipal/haute-couture": "4.x.x",
20+
"handlebars": "4.x.x",
1321
"joi": "17.x.x"
1422
},
1523
"devDependencies": {
24+
"@babel/preset-env": "7.x.x",
25+
"@babel/core": "7.x.x",
1626
"@hapi/code": "8.x.x",
1727
"@hapi/eslint-config-hapi": "13.x.x",
1828
"@hapi/eslint-plugin-hapi": "4.x.x",
@@ -24,8 +34,16 @@
2434
"@hapipal/hpal-debug": "2.x.x",
2535
"@hapipal/toys": "3.x.x",
2636
"babel-eslint": "10.x.x",
37+
"babelify": "10.x.x",
38+
"browser-sync": "2.x.x",
39+
"browserify": "17.x.x",
40+
"cssnano": "5.x.x",
2741
"dotenv": "8.x.x",
2842
"eslint": "7.x.x",
29-
"exiting": "6.x.x"
43+
"exiting": "6.x.x",
44+
"node-sass": "5.x.x",
45+
"postcss": "8.x.x",
46+
"postcss-cli": "8.x.x",
47+
"uglify-js": "3.x.x"
3048
}
3149
}

server/manifest.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ module.exports = new Confidence.Store({
3131
plugins: [
3232
{
3333
plugin: '../lib', // Main plugin
34-
options: {}
34+
options: {
35+
developmentMode: {
36+
$filter: { $env: 'NODE_ENV' },
37+
$default: true,
38+
production: false
39+
}
40+
}
3541
},
3642
{
3743
plugin: {

0 commit comments

Comments
 (0)