-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
140 lines (125 loc) · 3.96 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var neat = require('node-neat');
module.exports = function(grunt) {
var aws;
try {
aws = grunt.file.readJSON('.aws.json');
} catch (e) {
aws = {};
}
// load 3rd party grunt plugins
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-s3');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
aws: aws,
clean: ['compiled/'],
copy: {
main: {
files: [
{
dest: 'compiled/',
cwd: 'src',
src: '*.html',
expand: true
},
{
dest: 'compiled/css/mocha.css',
src: 'src/css/mocha.css'
},
{
dest: 'compiled/js/',
cwd: 'src/js/',
src: '**',
expand: true
}
]
}
},
handlebars: {
compile: {
options: {
namespace: 'templates',
amd: true,
processName: function (filePath) {
var templateDir = grunt.config('pkg.templateDir'),
filename = filePath.split(templateDir + '/')[1],
templateName = filename.split('.hbs')[0];
return templateName;
}
},
files: [
{
dest: 'compiled/js/templates.js',
src: '<%= pkg.templateDir %>/*.hbs'
}
]
}
},
sass: {
dist: {
options: {
loadPath: neat.includePaths
},
files: {
'compiled/css/style.css': 'src/css/base.scss'
}
}
},
s3: {
options: {
key: '<%= aws.key %>',
secret: '<%= aws.secret %>',
bucket: '<%= pkg.devBucket %>',
deploy: {
upload: [
{
src: 'compiled/**',
rel: 'compiled',
access: 'public-read'
}
]
}
}
},
watch: {
copy: {
files: ['src/*.html', 'src/**/*.js'],
tasks: ['copy']
},
handlebars: {
files: ['<%= pkg.templateDir %>/*.hbs'],
tasks: ['handlebars']
},
sass: {
files: ['src/css/**/*.scss'],
tasks: ['sass']
}
}
});
// set target bucket for javascript
grunt.registerTask('bucket',
'Generate bucket target file',
function (bucket) {
grunt.file.write('src/js/bucket.coffee',
'define(function() { return "' + bucket + '"; });');
}
);
// set bucket, compile and push, then set bucket back to dev
grunt.registerTask('deploy',
'Push to an s3 bucket',
function (bucket) {
devBucket = grunt.config('pkg.devBucket');
grunt.config('s3.deploy.bucket', bucket);
grunt.task.run([
'bucket:' + bucket, 'compile', 's3', 'bucket:' + devBucket
]);
}
);
// compile all files from src/ folder to compiled/
grunt.registerTask('compile', ['clean', 'copy', 'handlebars', 'sass']);
grunt.registerTask('default', ['compile', 'watch']);
};