This repository has been archived by the owner on Mar 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGruntfile.js
100 lines (81 loc) · 2.93 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*global module:false*/
module.exports = function(grunt) {
/**
* Check if config.json exists
*/
if (!grunt.file.exists('config.json') || !grunt.file.exists('package.json')) {
grunt.log.error("Wow, wow, wow! Some json files are missing!")
process.exit(1)
}
/**
* Load configuration
* @param {string} path folder
* @return {object}
*/
function loadConfig(path) {
var glob = require('glob')
, object = {}
, key
glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'')
object[key] = require(path + option)
})
return object
}
/**
* Import modules
*/
require('load-grunt-tasks')(grunt)
/**
* Define base configuration
*/
var gruntConfig = {
pkg: grunt.file.readJSON("package.json"),
config: grunt.file.readJSON("config.json"),
timestamp: new Date().getTime(),
cachebuster: '.<%= timestamp %>'
}
/**
* Merge configurations
*/
grunt.util._.extend(gruntConfig, loadConfig('./grunt_tasks/options/'))
/**
* Init grunt
*/
grunt.initConfig(gruntConfig)
/**
* Tasks
*/
// Default
grunt.registerTask('default', ['dev', 'connect:server', 'open:localhost', 'watch'])
// Public
grunt.registerTask('dist', ['main:dist', 'replace:dist', 'copy:cachebuster', 'notify:complete'])
grunt.registerTask('dev', ['main:dev', 'replace:dev', 'notify:complete'])
// Private
grunt.registerTask('start', ['config:check', 'clean:all', 'copy:assets', 'glyphicons:compile'])
grunt.registerTask('main:dist', ['newer:jshint:dist', 'start', 'concurrent:minify', 'clean:compiled-images', 'concurrent:images-dist'])
grunt.registerTask('main:dev', ['newer:jshint:dev', 'start', 'concurrent:concat', 'clean:compiled-images'])
grunt.registerTask('styles:dist', ['sass:dist'])
grunt.registerTask('styles:dev', ['sass:dev'])
grunt.registerTask('scripts:dist', ['handlebars:compile', 'uglify:compile', 'clean:handlebars'])
grunt.registerTask('scripts:dev', ['handlebars:compile', 'concat:compile', 'clean:handlebars'])
grunt.registerTask('glyphicons:compile',['shell:fontcustom'])
grunt.registerTask('copy:cachebuster', ['copy:cachebuster-css', 'copy:cachebuster-css-map', 'copy:cachebuster-js', 'clean:no-cachebuster'])
// Custom tasks
grunt.registerTask("config:check", 'Check if all embedded files are here.', function() {
var isError = false
grunt.util._.each(grunt.config.data.config.scripts, function(collection) {
grunt.util._.each(collection, function(item) {
if(!/\*|\!/.test(item)) {
if(!('src/templates/templates.js' === item) && !grunt.file.exists(item)) {
grunt.log.error('Dead file: ' + item)
isError = true
}
}
})
})
if(isError) {
grunt.fail.warn('Please, check your `config.json, some files are dead.')
}
})
}