Skip to content

Commit

Permalink
chore(build) Automated sass partial includes
Browse files Browse the repository at this point in the history
Sass partials (_*.scss) are now automatically included in the build.
One less thing to worry about adding manually.
  • Loading branch information
atruskie committed Dec 29, 2014
1 parent 6b89ee8 commit 46c38b6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 91 deletions.
105 changes: 70 additions & 35 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = function (grunt) {
var modRewrite = require('connect-modrewrite'),
gzipStatic = require('connect-gzip-static'),
path = require('path'),
slash = require("slash"),
_ = require('lodash');


Expand Down Expand Up @@ -108,12 +109,12 @@ module.exports = function (grunt) {
*/
meta: {
banner: '/**\n' +
' * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed <%= pkg.licenses.type %> <<%= pkg.licenses.url %>>\n' +
' */\n'
' * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed <%= pkg.licenses.type %> <<%= pkg.licenses.url %>>\n' +
' */\n'
},

/**
Expand Down Expand Up @@ -181,7 +182,7 @@ module.exports = function (grunt) {
build_app_assets: {
files: [
{
src: [ '**' ],
src: ['**'],
dest: '<%= build_dir %>/assets/',
cwd: 'src/assets',
expand: true,
Expand Down Expand Up @@ -244,7 +245,7 @@ module.exports = function (grunt) {
},
files: [
{
src: [ '<%= app_files.js %>' ],
src: ['<%= app_files.js %>'],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true,
Expand All @@ -258,7 +259,7 @@ module.exports = function (grunt) {
},
files: [
{
src: [ '<%= vendor_files.js %>' ],
src: ['<%= vendor_files.js %>'],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true,
Expand All @@ -269,7 +270,7 @@ module.exports = function (grunt) {
compile_assets: {
files: [
{
src: [ '**' ],
src: ['**'],
dest: '<%= compile_dir %>/assets',
cwd: '<%= build_dir %>/assets',
expand: true,
Expand All @@ -292,8 +293,7 @@ module.exports = function (grunt) {
banner: '<%= meta.banner %>'
},
nonull: true,
src:
[
src: [
'<%= vendor_files.css %>',
'<%= build_dir %>/assets/styles/*.css'
],
Expand All @@ -309,8 +309,8 @@ module.exports = function (grunt) {
},
nonull: true,
src: [
(function() {
return userConfig.vendor_files.js.map(function(file) {
(function () {
return userConfig.vendor_files.js.map(function (file) {
return userConfig.build_dir + "/" + file;
});
}()),
Expand All @@ -332,7 +332,7 @@ module.exports = function (grunt) {
compile: {
files: [
{
src: [ '<%= app_files.js %>' ],
src: ['<%= app_files.js %>'],
cwd: '<%= build_dir %>',
dest: '<%= build_dir %>',
expand: true
Expand Down Expand Up @@ -365,15 +365,13 @@ module.exports = function (grunt) {
* This task is run after the sass file template has been processed.
*/
sassReal: {
options: {

},
options: {},
build: {
options: {
imagePath: '<%= build_configs.current.siteDir %>assets/img',
outputStyle: 'expanded',
sourceComments: 'normal' /*'map',
sourceMap: '<%= sassDestName %>.map'*/
sourceMap: '<%= sassDestName %>.map'*/
},
src: '<%= app_files.processedSass %>',
dest: '<%= sassDest %>'
Expand Down Expand Up @@ -440,7 +438,7 @@ module.exports = function (grunt) {
options: {
base: 'src/app'
},
src: [ '<%= app_files.atpl %>' ],
src: ['<%= app_files.atpl %>'],
dest: '<%= build_dir %>/templates-app.js'
},

Expand All @@ -451,7 +449,7 @@ module.exports = function (grunt) {
options: {
base: 'src'
},
src: [ '<%= app_files.ctpl %>' ],
src: ['<%= app_files.ctpl %>'],
dest: '<%= build_dir %>/templates-common.js'
}
},
Expand Down Expand Up @@ -555,7 +553,6 @@ module.exports = function (grunt) {
'^/assets(.*) /assets$1 [L]',



// this rule matches anything without an extension
// if matched, the root (index.html) is sent back instead.
// from there, angular deals with the route information
Expand All @@ -570,7 +567,7 @@ module.exports = function (grunt) {
]),

// disable all caching
function(req, res, next) {
function (req, res, next) {
req.headers['if-none-match'] = 'no-match-for-this';
next();
},
Expand Down Expand Up @@ -606,7 +603,8 @@ module.exports = function (grunt) {
* plugin should auto-detect.
*/
options: {
livereload: true
livereload: true,
spawn: false
},

/**
Expand All @@ -615,7 +613,7 @@ module.exports = function (grunt) {
*/
gruntfile: {
files: 'Gruntfile.js',
tasks: [ 'jshint:gruntfile' ],
tasks: ['jshint:gruntfile'],
options: {
livereload: false
}
Expand All @@ -631,7 +629,7 @@ module.exports = function (grunt) {
],
// karma:unit:run is disabled because it breaks watch by stopping it
// see https://github.com/karma-runner/grunt-karma/issues/30
tasks: [ 'jshint:src', 'karma:unit:run', 'copy:build_appjs' ]
tasks: ['jshint:src', 'karma:unit:run', 'copy:build_appjs']
},

/**
Expand All @@ -642,15 +640,15 @@ module.exports = function (grunt) {
files: [
'src/assets/**/*'
],
tasks: [ 'copy:build_app_assets' ]
tasks: ['copy:build_app_assets']
},

/**
* When index.html changes, we need to compile it.
*/
html: {
files: [ '<%= app_files.html %>' ],
tasks: [ 'index:build' ]
files: ['<%= app_files.html %>'],
tasks: ['index:build']
},

/**
Expand All @@ -661,14 +659,14 @@ module.exports = function (grunt) {
'<%= app_files.atpl %>',
'<%= app_files.ctpl %>'
],
tasks: [ 'html2js' ]
tasks: ['html2js']
},

/**
* When the CSS files change, we need to compile and minify them.
*/
sass: {
files: [ 'src/**/*.scss' ],
files: ['src/**/*.scss'],
tasks: ['sass:build', 'concat:build_css']
},

Expand All @@ -680,7 +678,7 @@ module.exports = function (grunt) {
files: [
'<%= app_files.jsunit %>'
],
tasks: [ 'jshint:test', 'karma:unit:run' ],
tasks: ['jshint:test', 'karma:unit:run'],
options: {
livereload: false
}
Expand All @@ -701,12 +699,12 @@ module.exports = function (grunt) {
* before watching for changes.
*/
grunt.renameTask('watch', 'delta');
grunt.registerTask('watch', [ 'build', 'karma:unit', 'connect', 'delta' ]);
grunt.registerTask('watch', ['build', 'karma:unit', 'connect', 'delta']);

/**
* The default task is to build and compile.
*/
grunt.registerTask('default', [ 'build', 'compile' ]);
grunt.registerTask('default', ['build', 'compile']);

/**
* The `build` task gets your app ready to run for development and testing.
Expand Down Expand Up @@ -785,13 +783,50 @@ module.exports = function (grunt) {
grunt.registerTask('sassTemplate', 'Transforming sass file', function () {
var mainScss = grunt.config('app_files.sass');
var processedScss = path.join(path.dirname(mainScss), path.basename(mainScss, ".tpl.scss")) + ".scss.processed";
//debugger;
var scssPartials = grunt.file.expand("src/**/_*.scss");
scssPartials = scssPartials.map(function (value) {
return slash(path.relative(path.dirname(mainScss), value));
});

scssPartials = scssPartials.sort(function compare(a, b) {
var dottedA = a.indexOf("..") === 0,
dottedB = b.indexOf("..") === 0,
isSlashedA = a.indexOf("/") > 0,
isSlashedB = b.indexOf("/") > 0;

if (isSlashedA && isSlashedB) {
if (dottedA && dottedB) {
return a.localeCompare(b);
} else if (dottedA) {
return 1;
} else if (dottedB) {
return -1;
}



} else if(isSlashedA) {
return 1;
} else if (isSlashedB) {
return -1;
}


});

grunt.config.set('app_files.processedSass', processedScss);

grunt.log.write("Temp file: " + processedScss);

grunt.file.copy(mainScss, processedScss, {
process: function (contents, path) {
return grunt.template.process(contents, grunt.config());
return grunt.template.process(contents, {
data: {
build_configs: grunt.config("build_configs"),
partials: scssPartials
}
});
}
});
});
Expand Down
20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"connect-gzip-static": "^1.0.0",
"connect-modrewrite": "0.7.x",
"grunt": "~0.4.1",
"grunt-bump": "0.0.16",
"grunt-bump": "0.0.14",
"grunt-changelog": "~0.2.x",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-connect": "0.9.x",
"grunt-contrib-copy": "0.7.x",
"grunt-contrib-jshint": "0.10.x",
Expand All @@ -32,19 +32,15 @@
"grunt-html2js": "~0.2.3",
"grunt-karma": "0.9.x",
"grunt-ngmin": "0.0.3",
"grunt-sass": "0.16.x",
"grunt-sass": "0.17.x",
"karma-chrome-launcher": "~0.1.1",
"karma-coverage": "~0.2",
"karma-firefox-launcher": "~0.1.3",
"karma-jasmine": "~0.3.x",
"karma-jasmine": "^0.2.2",
"karma-phantomjs-launcher": "~0.1.1",
"lodash": "~2.4.1"
"lodash": "~2.4.1",
"slash": "^1.0.0"
},
"private": true,
"dependencies": {
"karma-jasmine": "^0.2.2",
"grunt-contrib-clean": "^0.5.0",
"grunt-bump": "0.0.14",
"grunt-contrib-concat": "^0.4.0"
}
"dependencies": {}
}
2 changes: 1 addition & 1 deletion src/app/annotationLibrary/_annotationLibrary.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//$loadGifPath: $IMAGE_ASSET_PATH + 'assets/img/load.gif';
$loadGifPath: image-url('load.gif');
@import "../annotationViewer/annotationViewer";

/* Library list */
.annotation-paging {
Expand Down
Loading

0 comments on commit 46c38b6

Please sign in to comment.