From aec8c418d4e462525110d6468d5975897404fdcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=C3=A1rd=20Moldov=C3=A1n?= Date: Wed, 9 Sep 2015 14:34:08 +0200 Subject: [PATCH 01/14] Update hapi and hapi-sass --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8f7bf6c..87999dd 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ ], "license": "MIT", "dependencies": { - "hapi": "^6.0.2", - "node-sass": "^0.9.3", + "hapi": "^9.3.1", + "node-sass": "^3.3.2", "mkdirp": "^0.3.5", "hoek": "^2.3.0" }, From 9c1494a351d5de84722978548f8d8326ff9fe35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=C3=A1rd=20Moldov=C3=A1n?= Date: Sat, 12 Sep 2015 19:04:14 +0200 Subject: [PATCH 02/14] Update hapi to v10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87999dd..83e3007 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "license": "MIT", "dependencies": { - "hapi": "^9.3.1", + "hapi": "^10.0.0", "node-sass": "^3.3.2", "mkdirp": "^0.3.5", "hoek": "^2.3.0" From 37e7f23455c9cd6a56464873055b713e662be236 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Fri, 1 Aug 2014 14:21:29 -0700 Subject: [PATCH 03/14] Adding example folder: * Update dependencies * provide an example server setup --- example/sass/style.scss | 17 +++++++++++++++++ example/server.js | 35 ++++++++++++++++++++++++++++++++++ example/vendor/sass/_base.scss | 7 +++++++ 3 files changed, 59 insertions(+) create mode 100644 example/sass/style.scss create mode 100644 example/server.js create mode 100644 example/vendor/sass/_base.scss diff --git a/example/sass/style.scss b/example/sass/style.scss new file mode 100644 index 0000000..b34f69a --- /dev/null +++ b/example/sass/style.scss @@ -0,0 +1,17 @@ +@import "base"; + +nav { + ul { + margin: 0; + padding: 0; + list-style: none; + } + + li { display: inline-block; } + + a { + display: block; + padding: 6px 12px; + text-decoration: none; + } +} \ No newline at end of file diff --git a/example/server.js b/example/server.js new file mode 100644 index 0000000..e1ba23f --- /dev/null +++ b/example/server.js @@ -0,0 +1,35 @@ +/* + * hapi-sass + * https://github.com/mdarnall/hapi-sass + * + * Copyright (c) 2014 Matt Darnall + * Licensed under the MIT license. + */ + +'use strict'; + +var Hapi = require('hapi'); + +var server = new Hapi.Server('localhost', 1337); + +var options = { + src: './sass', + dest:'./css', + force: true, + debug: true, + routePath: '/css/{file}.css', + includePaths: ['./vendor/sass'], + outputStyle: 'nested', + sourceComments: 'map' +}; + +server.pack.register({ + plugin: require("../index.js"), + options: options + } + , function(err) { + if (err) throw err; + server.start(function() { + console.log("Hapi server started @ " + server.info.uri); + }); + }); \ No newline at end of file diff --git a/example/vendor/sass/_base.scss b/example/vendor/sass/_base.scss new file mode 100644 index 0000000..16b4c53 --- /dev/null +++ b/example/vendor/sass/_base.scss @@ -0,0 +1,7 @@ +$font-stack: Helvetica, sans-serif; +$primary-color: #333; + +body { + font: 100% $font-stack; + color: $primary-color; +} \ No newline at end of file From 622e831826f38cb26cbff72acb773071896dd1b5 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:05:05 -0700 Subject: [PATCH 04/14] Bumping version to 2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83e3007..5081c8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hapi-sass", - "version": "1.0.0", + "version": "2.0.0", "description": "A Hapi.js plugin for compiling and serving Sass stylesheets", "main": "index.js", "scripts": { From 36d956d729a62b197ef9d1df5e82997867b6450b Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:08:09 -0700 Subject: [PATCH 05/14] Updated node dep. - Hapi 10.0 requires node 4.0 --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 5081c8e..aa55f7d 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "sass", "node-sass" ], + "engines": { + "node": ">=4.0.0" + }, "license": "MIT", "dependencies": { "hapi": "^10.0.0", From 63139a2c9f6eecdbd68d44c70293667e653ebb84 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:56:03 -0700 Subject: [PATCH 06/14] Working example for hapi10 api --- example/server.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/example/server.js b/example/server.js index e1ba23f..397cbd7 100644 --- a/example/server.js +++ b/example/server.js @@ -9,12 +9,14 @@ 'use strict'; var Hapi = require('hapi'); +var HapiSass = require('../index') -var server = new Hapi.Server('localhost', 1337); +var server = new Hapi.Server(); +server.connection({ port: 1337 }); var options = { src: './sass', - dest:'./css', + dest: './css', force: true, debug: true, routePath: '/css/{file}.css', @@ -23,13 +25,14 @@ var options = { sourceComments: 'map' }; -server.pack.register({ - plugin: require("../index.js"), - options: options - } - , function(err) { - if (err) throw err; - server.start(function() { - console.log("Hapi server started @ " + server.info.uri); - }); - }); \ No newline at end of file +server.register({ + register: HapiSass, + options: options + } + , function (err) { + if (err) throw err; + server.start(function () { + server.log("Hapi server started @ " + server.info.uri); + }); + } +); \ No newline at end of file From 9a3ffe6b12807692b45135e4cbf9aeefac5a3001 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:56:28 -0700 Subject: [PATCH 07/14] Updated old variable naming - server instead of plugin --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 759e784..ffd1a34 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ var internals = { } }; -exports.register = function (plugin, options, next) { +exports.register = function (server, options, next) { var settings = Hoek.applyToDefaults(internals.defaults, options); // Force compilation @@ -51,7 +51,7 @@ exports.register = function (plugin, options, next) { // Default dest dir to source var dest = settings.dest ? settings.dest : src; - plugin.route({ + server.route({ method: 'GET', path: settings.routePath, handler: function (request, reply) { From 8807a5bb27854f7f8caaa2d1e9825c0532490e59 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:57:01 -0700 Subject: [PATCH 08/14] Make Hapi v10 a peer dependency - following other plugiins in Hapijs org --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index aa55f7d..9535554 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,10 @@ "node": ">=4.0.0" }, "license": "MIT", + "peerDependencies": { + "hapi": ">=10.0.0" + }, "dependencies": { - "hapi": "^10.0.0", "node-sass": "^3.3.2", "mkdirp": "^0.3.5", "hoek": "^2.3.0" From 840f5e913e11121b9ce73e3d28d39413d790251f Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Sun, 13 Sep 2015 21:57:15 -0700 Subject: [PATCH 09/14] Update tests --- package.json | 5 +++-- test/indexTest.js | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 9535554..3d5a61b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A Hapi.js plugin for compiling and serving Sass stylesheets", "main": "index.js", "scripts": { - "test": "mocha" + "test": "mocha --ui bdd", + "start": "node example/server.js" }, "author": { "name": "Matt Darnall", @@ -38,7 +39,7 @@ }, "devDependencies": { "mocha": "^1.17.1", - "chai": "^1.9.0", + "chai": "^3.2.0", "sinon": "^1.9.0" } } diff --git a/test/indexTest.js b/test/indexTest.js index 38305ac..478bda9 100644 --- a/test/indexTest.js +++ b/test/indexTest.js @@ -2,20 +2,22 @@ var HapiSass = require('../index'); var expect = require('chai').expect; var Hapi = require('hapi'); -describe('Hapi-Sass', function(){ +describe('Hapi-Sass', function () { - describe('register', function(){ + describe('register', function () { - it('creates a route for the plugin', function(done){ + it('creates a route for the plugin', function (done) { var server = new Hapi.Server(); - server.pack.register({ - plugin: HapiSass, - options: {} - }, function (err) { - var routes = server.table(); - expect(routes[0].path).to.equal('/css/{file}.css'); - done(); - } + server.connection(); + server.register({ register: HapiSass, options: {}}, function (err) { + expect(err).to.not.exist; + var tables = server.table(); + expect(tables.length).to.be.greaterThan(0); + var routes = tables[0].table; + expect(routes.length).to.be.greaterThan(0); + expect(routes[0].path).to.equal('/css/{file}.css'); + done(); + } ); }); }); From 5dfffa9835f512e2e5ce0a785c598814b8b7ee14 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Tue, 15 Sep 2015 16:22:29 -0700 Subject: [PATCH 10/14] Updates to get node-sass api working - include Boom as module, not as part of Hapi - Updated API against sass.render --- example/server.js | 6 +++--- index.js | 40 ++++++++++++++++++++-------------------- package.json | 5 +++-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/example/server.js b/example/server.js index 397cbd7..a51d17b 100644 --- a/example/server.js +++ b/example/server.js @@ -15,12 +15,12 @@ var server = new Hapi.Server(); server.connection({ port: 1337 }); var options = { - src: './sass', - dest: './css', + src: './example/sass', + dest: './example/css', force: true, debug: true, routePath: '/css/{file}.css', - includePaths: ['./vendor/sass'], + includePaths: ['./example/vendor/sass'], outputStyle: 'nested', sourceComments: 'map' }; diff --git a/index.js b/index.js index ffd1a34..51cc805 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var Error = require('hapi').error, +var Boom = require('boom'), sass = require('node-sass'), Hoek = require('hoek'), fs = require('fs'), @@ -21,10 +21,10 @@ var internals = { error: function (reply, err) { if (err.code == 'ENOENT') { - return reply(Error.notFound()); + return reply(Boom.notFound()); } else { - return reply(Error.internal(err)); + return reply(Boom.internal(err)); } }, @@ -45,7 +45,7 @@ exports.register = function (server, options, next) { // Source dir required var src = settings.src; if (!src) { - next(new Error('hapi-sass requires "src" directory')); + next(new Boom('hapi-sass requires "src" directory')); } // Default dest dir to source @@ -78,26 +78,26 @@ exports.register = function (server, options, next) { includePaths: [sassDir].concat(settings.includePaths || []), imagePath: settings.imagePath, outputStyle: settings.outputStyle, - sourceComments: settings.sourceComments, - error: function (err) { + sourceComments: settings.sourceComments + }, function(err, result){ + + if(err){ return internals.error(reply, err); - }, - success: function (css) { - if (debug) { - internals.log('render', 'compilation ok'); - } + } - mkdirp(dirname(cssPath), 0x1c0, function (err) { - if (err) { - return reply(err); - } - fs.writeFile(cssPath, css, 'utf8', function (err) { - reply(css).type('text/css'); - }); - }); + if (debug) { + internals.log('render', 'compilation ok'); } - }); + mkdirp(dirname(cssPath), 0x1c0, function (err) { + if (err) { + return reply(err); + } + fs.writeFile(cssPath, result.css, 'utf8', function (err) { + reply(result.css).type('text/css'); + }); + }); + }); }; if (force) { diff --git a/package.json b/package.json index 3d5a61b..c4cc702 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,10 @@ "hapi": ">=10.0.0" }, "dependencies": { - "node-sass": "^3.3.2", + "boom": "^2.8.0", + "hoek": "^2.3.0", "mkdirp": "^0.3.5", - "hoek": "^2.3.0" + "node-sass": "^3.3.2" }, "devDependencies": { "mocha": "^1.17.1", From a350bbbf3669dac5344e7c76b372ba41dfb63a61 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Tue, 15 Sep 2015 16:23:56 -0700 Subject: [PATCH 11/14] Updated gitignore for compiled stylesheet --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cfbee8d..963c9d6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ build .grunt node_modules +example/css From 47c9cb574de66010148117064bf99ccf7365da47 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Wed, 16 Sep 2015 16:27:10 -0700 Subject: [PATCH 12/14] Updated example in README - reflects the changes for Hapi v10 plugin api --- README.md | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3f5bcff..5e4ef34 100644 --- a/README.md +++ b/README.md @@ -16,29 +16,34 @@ $ npm install hapi-sass --save ``` ```javascript -var server = new Hapi.Server(config.host, config.port, config.server) - -server.pack.register({ - plugin: require('hapi-sass'), - options: { - debug: true, - force: true, - src: './lib/sass', - outputStyle: 'compressed', - sourceComments: 'normal', - dest: './public/css', - routePath: '/css/{file}.css' +var Hapi = require('hapi'); +var HapiSass = require('../index') + +var server = new Hapi.Server(); +server.connection({ port: 1337 }); + +var options = { + src: './example/sass', + dest: './example/css', + force: true, + debug: true, + routePath: '/css/{file}.css', + includePaths: ['./example/vendor/sass'], + outputStyle: 'nested', + sourceComments: true +}; + +server.register({ + register: HapiSass, + options: options } - }, function(err){ - if(err){ - console.log(err) - return + , function (err) { + if (err) throw err; + server.start(function () { + server.log("Hapi server started @ " + server.info.uri); + }); } - - server.route(routes) - server.start() - console.log('Running on port: ' + config.port); -}) +); ``` ### Options: From 286afd67cef04cdd87faaa5159c632f560eddbe0 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Wed, 16 Sep 2015 16:27:47 -0700 Subject: [PATCH 13/14] Updated node-sass api usage - sourceComments are now boolean types --- README.md | 2 +- example/server.js | 2 +- index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e4ef34..65b9590 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ server.register({ * `dest`: the destination directory to write compiled `.css` files. Defaults to `./public/css` * `routePath`: the route to register with hapijs. Defaults to `/css/{file}.css`. The `{file}` portion of the string is currently significant. It's used as a request parameter. * `outputStyle`: [parameter for node-sass](https://github.com/sass/node-sass#outputstyle). Defaults to `compressed` -* `sourceComments`: [parameter for node-sass](https://github.com/sass/node-sass#sourcecomments). Defaults to `none`. +* `sourceComments`: [parameter for node-sass](https://github.com/sass/node-sass#sourcecomments). Defaults to `false`. * `imagePath`: [parameter for node-sass](https://github.com/sass/node-sass#imagepath). Defaults to `undefined`. * `includePaths`: [parameter for node-sass](https://github.com/sass/node-sass#includepaths). Defaults to `[]`. diff --git a/example/server.js b/example/server.js index a51d17b..d501b0d 100644 --- a/example/server.js +++ b/example/server.js @@ -22,7 +22,7 @@ var options = { routePath: '/css/{file}.css', includePaths: ['./example/vendor/sass'], outputStyle: 'nested', - sourceComments: 'map' + sourceComments: true }; server.register({ diff --git a/index.js b/index.js index 51cc805..b975dd0 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ var internals = { dest: './public/css', routePath: '/css/{file}.css', outputStyle: 'compressed', - sourceComments: 'none' + sourceComments: false }, error: function (reply, err) { From ec3dc0dc231839c0fe3393ae79a65f8cbfb46a90 Mon Sep 17 00:00:00 2001 From: Matt Darnall Date: Wed, 16 Sep 2015 16:28:44 -0700 Subject: [PATCH 14/14] Removed the reference to imagePaths option - not part of node-sass v3.0.x --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 65b9590..e22a28f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,5 @@ server.register({ * `routePath`: the route to register with hapijs. Defaults to `/css/{file}.css`. The `{file}` portion of the string is currently significant. It's used as a request parameter. * `outputStyle`: [parameter for node-sass](https://github.com/sass/node-sass#outputstyle). Defaults to `compressed` * `sourceComments`: [parameter for node-sass](https://github.com/sass/node-sass#sourcecomments). Defaults to `false`. -* `imagePath`: [parameter for node-sass](https://github.com/sass/node-sass#imagepath). Defaults to `undefined`. * `includePaths`: [parameter for node-sass](https://github.com/sass/node-sass#includepaths). Defaults to `[]`.