This repository has been archived by the owner on Dec 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGruntfile.js
186 lines (171 loc) · 5.26 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
module.exports = function(grunt){
//grunt plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-angular-templates');
grunt.loadNpmTasks('grunt-clear');
grunt.loadNpmTasks('grunt-htmlrefs');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-clear');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-ngmin');
//config
grunt.initConfig({
//tool for cutting new releases of this project
release: {options: {npm: false}},
//for tests that run in browsers
karma: {
//start karma server (the watch task will run the tests when files change)
unit: {
configFile: 'config/karma.conf.js',
background: true
},
//continuous integration mode for the build: run tests once in PhantomJS browser.
continuous: {
configFile: 'config/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
}
},
//for tests that run in Node
simplemocha: {
options: {
require: 'should',
timeout: 3000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'dot'
},
all: { src: 'test/node/**/*.js' }
},
//stylus css
stylus: {
compile: {
//specify each "combined" file. Each file can then use @import() to bring in its dependencies
files: {
'app/styles/app.css': 'app/styles/app.styl'
}
}
},
//delete the previous build and generated directories
clean: {
build: 'build',
generated: 'build/generated'
},
//copy images to the build
copy: {
img: {
src: ['app/img/**'],
dest: 'build/img'
}
},
//inline all Angular templates as Strings into a JS file that can be concatted in the build
ngtemplates: {
options: {base: 'app'},
app: {
src: ['app/templates/**/*.html'],
dest: 'build/generated/ngtemplates.js'
}
},
//replace all the script tags in the HTML file with the single built script
htmlrefs: {
options: {
file: {
buildNumber: 47878 //todo generate unique from contents of file for each file
}
},
build: {
src: 'app/index.html',
dest: 'build/'
}
},
//convert our Angular files that use simple injects to their build-safe versions
ngmin: {
app: {
expand: true,
cwd: 'app/js',
src: ['**/*.js', '!lib/**'],
dest: 'build/generated'
}
},
//minify the HTML file (index.html)
htmlmin: {
index: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
'build/index.html': 'build/index.html'
}
}
},
//combine all JS into one file, all CSS into one file
concat: {
js: {
src: [
'app/js/lib/angular/angular.js',
'app/js/lib/angular/angular-resource.js',
'build/generated/**/*.js' //all our angular components, including templates
],
dest: 'build/app.js'
},
styles: {
src: ['app/styles/**/*.css'],
dest: 'build/styles/app.css'
}
},
//minify the JS file to be as small as possible
uglify: {
app: {
src: ['build/app.js'],
dest: 'build/app.js'
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['app/js/**/*.js', 'app/**/*.html'],
tasks: ['clear', 'karma:unit:run']
},
templates: {
files: ['app/**/*.html'],
tasks: ['clear', 'karma:unit:run']
},
tests: {
files: ['test/browser/**/*.js'],
tasks: ['clear', 'karma:unit:run']
},
styles: {
files: ['app/styles/**/*.styl'],
tasks: ['clear', 'stylus']
}
}
});
grunt.registerTask('test', ['karma:continuous']);
/**
* build task explanation
* 1. delete the existing "build" directory.
* 2. compile stylus into CSS.
* 3. copy images into the build.
* 4. generate a JS file containing all our Angular templates.
* 5. generate build-safe versions of our Angular controllers, services, directives, filters, etc.
* 6. combine all our scripts, including generated versions, into a single JS file. Also combine all CSS into one file.
* 7. compress the single JS file.
* 8. replace all our <script> tags in our index.html file with a single <script> tag pointing to the combined/compressed JS file.
* 9. compress the index.html file.
* 10. delete the generated directory
*/
grunt.registerTask('build', ['clean:build', 'stylus', 'copy', 'ngtemplates', 'ngmin', 'concat', 'uglify', 'htmlrefs', 'htmlmin', 'clean:generated']);
// 'dev' task calls 'watch' which indirectly calls 'karma:unit:run'. This expects to connect to a karma server on port 9100.
// therefore, be sure to run the karma:unit task in a separate console when running the dev task.
grunt.registerTask('dev', ['karma:unit', 'watch']);
};