pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
Gruntfile.js
(9745B)
1 module.exports = function(grunt) {
2 "use strict";
3
4 grunt.loadNpmTasks('grunt-contrib-jshint');
5 grunt.loadNpmTasks('grunt-contrib-concat');
6 grunt.loadNpmTasks('grunt-contrib-copy');
7 grunt.loadNpmTasks('grunt-contrib-uglify');
8 grunt.loadNpmTasks('grunt-contrib-less');
9 //grunt.loadNpmTasks('grunt-contrib-htmlmin');
10 //grunt.loadNpmTasks('grunt-contrib-jasmine');
11 grunt.loadNpmTasks('grunt-contrib-watch');
12 grunt.loadNpmTasks('grunt-contrib-clean');
13 grunt.loadNpmTasks('grunt-hash');
14
15 /**
16 * Load in our build configuration file.
17 */
18 var userConfig = require( './build.config.js' );
19 /**
20 * This is the configuration object Grunt uses to give each plugin its
21 * instructions.
22 */
23 var taskConfig = {
24 /**
25 * We read in our `package.json` file so we can access the package name and
26 * version. It's already there, so we don't repeat ourselves here.
27 */
28 pkg: grunt.file.readJSON('package.json'),
29
30 meta: {
31 artifact: "<%= pkg.name %>-<%= pkg.version %>"
32 },
33
34 jshint: {
35 options: {
36 curly: true,
37 eqeqeq: true,
38 immed: true,
39 latedef: true,
40 newcap: true,
41 noarg: true,
42 sub: true,
43 undef: true,
44 unused: true,
45 boss: true,
46 eqnull: true,
47 browser: true,
48 evil: true,
49 globals: {
50 "jQuery": false,
51 "$": false,
52 "angular": false,
53 "_": false,
54 "ko": false,
55 "App": true,
56 "google": false,
57 "Modernizr": false
58 }
59 },
60 src: [
61 '<%= app_files.js %>'
62 ],
63 test: {
64 options: {
65 globals: {
66 "jQuery": false,
67 "$": false,
68 "angular": false,
69 "_": false,
70 "ko": false,
71 "App": true,
72 "it": false,
73 "xit": false,
74 "describe": false,
75 "xdescribe": false,
76 "beforeEach": false,
77 "afterEach": false,
78 "expect": false,
79 "spyOn": false,
80 "module": false,
81 "inject": false
82 }
83 },
84 files: {
85 src: ['<%= app_files.jsspec %>']
86 }
87 },
88 gruntfile: {
89 options: {
90 globals: {
91 "module": false,
92 "require": false
93 }
94 },
95 files: {
96 src: ['Gruntfile.js']
97 }
98 }
99 },
100
101 jasmine: {
102 src: '<%= app_files.js %>',
103 options: {
104 vendor: [
105 'http://maps.googleapis.com/maps/api/js?sensor=false&language=en',
106 'bower_components/jquery/dist/jquery.js',
107 'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
108 '<%= vendor_files.js %>',
109 'bower_components/angular-mocks/angular-mocks.js'
110 ],
111 specs: '<%= app_files.jsspec %>'
112 }
113 },
114
115 less: {
116 compile: {
117 options: {
118 sourceMap: true,
119 sourceMapFilename: "<%= dirs.build %>/css/assets/app_styles.css.map",
120 sourceMapBasepath: "<%= dirs.build %>/css",
121 sourceMapRootpath: "/"
122 },
123 files: {
124 "<%= dirs.build %>/css/assets/app_styles.css": "<%= app_files.less %>"
125 }
126 },
127 compress: {
128 options: {
129 compress: true,
130 cleancss: true,
131 report: 'min'
132 },
133 files: {
134 "<%= dirs.build %>/app_styles.min.css": "<%= app_files.less %>"
135 }
136 }
137 },
138
139 htmlmin: {
140 dist: {
141 options: {
142 removeComments: true,
143 collapseWhitespace: true
144 },
145 expand: true,
146 cwd: '<%= dirs.src %>',
147 src: ['**/*.html'],
148 dest: '<%= dirs.dist %>/'
149 }
150 },
151
152 concat: {
153 /**
154 * The `vendor_css` target concatenates vendor CSS.
155 */
156 vendor_css: {
157 src: ['<%= vendor_files.css %>'],
158 dest: '<%= dirs.build %>/vendor_styles.css'
159 },
160 /**
161 * The `build_css` target concatenates compiled CSS and vendor CSS
162 * together.
163 */
164 build_css: {
165 src: [
166 '<%= dirs.build %>/app_styles.min.css',
167 '<%= dirs.build %>/vendor_styles.min.css'
168 ],
169 dest: '<%= dirs.build %>/<%= meta.artifact %>.min.css'
170 },
171 /**
172 * The `compile_js` target is the concatenation of our application source
173 * code and all specified vendor source code into a single file.
174 */
175 compile_js: {
176 /*options: {
177 separator: ';'
178 },*/
179 src: [
180 '<%= vendor_files.js %>',
181 '<%= app_files.js %>'
182 ],
183 dest: "<%= dirs.build %>/<%= meta.artifact %>.js"
184 }
185 },
186
187 uglify: {
188 options: {
189 banner: '/*! <%= pkg.name %>-<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
190 },
191 build: {
192 src: "<%= concat.compile_js.dest %>",
193 dest: "<%= dirs.build %>/<%= meta.artifact %>.min.js"
194 }
195 },
196
197 hash: {
198 options: {
199 mapping: '<%= dirs.resources %>/assets.json',
200 srcBasePath: '<%= dirs.build %>',
201 destBasePath: '<%= dirs.dist %>/assets'
202 },
203 js: {
204 src: '<%= uglify.build.dest %>',
205 dest: '<%= dirs.dist %>/assets'
206 },
207 css: {
208 src: '<%= dirs.build %>/<%= meta.artifact %>.min.css',
209 dest: '<%= dirs.dist %>/assets'
210 }
211 },
212
213 gensourceslist: {
214 sources_js: {
215 options: {
216 srcBasePath: '<%= dirs.src %>', // the base Path you want to remove from the input
217 destBasePath: '' // the base Path you want to prepend to output
218 },
219 files: [
220 {
221 src: [
222 '<%= app_files.js %>'
223 ],
224 dest: '<%= dirs.resources %>/source_scripts.txt'
225 }
226 ]
227 },
228 vendor_js: {
229 options: {
230 srcBasePath: '<%= dirs.src %>'
231 },
232 files: [
233 {
234 src: '<%= vendor_files.js %>',
235 dest: '<%= dirs.resources %>/vendor_scripts.txt'
236 }
237
238 ]
239 },
240 vendor_css: {
241 options: {
242 srcBasePath: '<%= dirs.src %>'
243 },
244 files: [
245 {
246 src: '<%= vendor_files.css %>',
247 dest: '<%= dirs.resources %>/vendor_styles.txt'
248 }
249
250 ]
251 }
252 },
253
254 copy: {
255 vendor_assets: {
256 files: [
257 {
258 src: [ '<%= vendor_files.assets %>' ],
259 dest: '<%= dirs.dist %>/',
260 cwd: '<%= dirs.src %>',
261 expand: true
262 }
263 ]
264 }
265 },
266
267 delta: {
268 /**
269 * By default, we want the Live Reload to work for all tasks; this is
270 * overridden in some tasks (like this file) where browser resources are
271 * unaffected. It runs by default on port 35729, which your browser
272 * plugin should auto-detect.
273 */
274 options: {
275 livereload: true
276 },
277
278 /**
279 * When the Gruntfile changes, we just want to lint it.
280 */
281 gruntfile: {
282 files: 'Gruntfile.js',
283 tasks: [ 'jshint:gruntfile' ]
284 },
285
286 /**
287 * When our JavaScript source files change, we want to lint them,
288 * run our unit tests, and live reload.
289 */
290 jssrc: {
291 files: [
292 '<%= app_files.js %>'
293 ],
294 tasks: ['jshint:src']
295 },
296
297 /**
298 * When a JavaScript test file changes, we only want to lint it and
299 * run the unit tests. We don't want to do any live reloading.
300 */
301 jstest: {
302 files: '<%= app_files.jsspec %>',
303 tasks: [ 'jshint:test', 'jasmine'],
304 options: {
305 livereload: false
306 }
307 },
308
309 less: {
310 files: ["<%= dirs.src %>/less/**/*.less"],
311 tasks: ["less:compile"]
312 },
313 pkg: {
314 files: 'package.json',
315 tasks: ['build']
316 }
317 },
318 clean: {
319 build: ["<%= dirs.target %>"]
320 }
321 };
322
323 // configure grunt
324 grunt.initConfig( grunt.util._.extend( taskConfig, userConfig ) );
325
326 /**
327 * The `build` task gets your app ready to run for development and testing.
328 */
329 grunt.registerTask('build', ['clean', 'gensourceslist', 'jshint', 'less:compile']);
330
331 /**
332 * The `test` task runs your tests.
333 */
334 grunt.registerTask('test', [/*'jasmine'*/]);
335
336 /**
337 * The `compress` task gets your app ready for deployment by concatenating and
338 * minifying your code.
339 */
340 grunt.registerTask('compress', [
341 'concat:compile_js', 'uglify', 'less:compress', 'concat:vendor_css', 'concat:build_css', 'hash', 'copy:vendor_assets'
342 ]);
343
344 /**
345 * The default task is to build, test, and compress.
346 */
347 grunt.registerTask('default', ['build', 'test', 'compress']);
348
349 /**
350 * In order to make it safe to just compile or copy *only* what was changed,
351 * we need to ensure we are starting from a clean, fresh build. So we rename
352 * the `watch` task to `delta` (that's why the configuration var above is
353 * `delta`) and then add a new task called `watch` that does a clean build
354 * before watching for changes.
355 */
356 grunt.renameTask('watch', 'delta');
357 grunt.registerTask('watch', ['build', 'delta']);
358
359 grunt.registerMultiTask('gensourceslist', 'Generate a list of sources.', function() {
360 var options = this.options(),
361 destBasePath = options.destBasePath || '';
362
363 this.files.forEach(function(fs) {
364 var contents = "";
365 fs.src.forEach(function(file) {
366 var out = destBasePath + file.replace(options.srcBasePath, "");
367 contents = contents + out + "\n";
368 });
369
370 grunt.file.write(fs.dest, contents);
371 grunt.log.writeln("File created: " + fs.dest);
372 });
373 });
374 };
375