This repository was archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
116 lines (104 loc) · 4.26 KB
/
Gruntfile.js
File metadata and controls
116 lines (104 loc) · 4.26 KB
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
/*global module:false*/
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Resources/Private/Templates/Source/js/**/*.js'],
options: {
jshintrc: 'node_modules/PortableCGL/jshint/.jshintrc'
}
},
uglify: {
dynamic_mappings: {
files: [
{
expand: true,
cwd: 'Resources/Private/Templates/Source/js/',
src: ['**/*.js'],
dest: 'Resources/Private/Templates/Build/js/',
ext: '.min.js'
}
]
}
},
compile: {
source: 'Resources/Private/Templates/Source/html/**/*.html'
},
copy: {
main: {
files: [
{
src: ['**'],
dest: 'Resources/Private/Templates/Build/test/qunit/',
cwd: 'Resources/Private/Templates/Source/test/qunit/',
expand: true
},
{
src: ['**'],
dest: 'Resources/Private/Templates/Build/test/images/',
cwd: 'Resources/Private/Templates/Source/test/images/',
expand: true
}
]
}
},
jade: {
compile: {
options: {
pretty: true
},
files: {
'Resources/Private/Templates/Build/test/imgQuery.test.normal.html': 'Resources/Private/Templates/Source/test/imgQuery.test.normal.jade',
'Resources/Private/Templates/Build/test/imgQuery.test.small.html': 'Resources/Private/Templates/Source/test/imgQuery.test.small.jade',
'Resources/Private/Templates/Build/test/imgQuery.test.large.html': 'Resources/Private/Templates/Source/test/imgQuery.test.large.jade',
'Resources/Private/Templates/Build/test/imgQuery.test.cache.html': 'Resources/Private/Templates/Source/test/imgQuery.test.cache.jade'
}
}
},
qunit: {
all: ['Resources/Private/Templates/Build/test/*.html']
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-jade');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerMultiTask('compile', 'Compile imgQuery HTML Templates.', function () {
var _ = grunt.util._,
files = grunt.file.expand(this.data),
jsFile,
destination,
content,
script;
files.forEach(function (f) {
if (!grunt.file.exists(f)) {
grunt.log.warn('Source file "' + f + '" not found.');
}
destination = f.replace('/Source/html/', '/Build/html/');
jsFile = f.replace('/Source/html/', '/Build/js/').replace(/\.html?$/i, '.min.js');
if (!grunt.file.exists(jsFile)) {
grunt.log.warn('Source file "' + jsFile + '" not found.');
}
script = grunt.file.read(jsFile)
.replace(/imagesIn/gi, '###IMAGES###')
.replace(/breakpointsIn/gi, '###BREAKPOINTS###')
.replace(/ratiosIn/gi, '###RATIOS###')
.replace(/cacheKeyIn/gi, '\'###CACHE_KEY###\'');
content = grunt.file.read(f)
.replace(/###SCRIPT###/gi, script);
grunt.file.write(
f.replace('/Source/html/', '/Build/html/'),
content
);
if (!grunt.file.exists(jsFile)) {
grunt.log.warn('Target file "' + destination + '" was not compiled.');
}
});
grunt.log.ok(files.length + ' file' + (files.length === 1 ? '' : 's') + ' compiled.');
});
grunt.registerTask('build', ['jshint', 'uglify', 'compile', 'copy', 'jade']);
grunt.registerTask('test', ['qunit']);
grunt.registerTask('default', ['build', 'test']);
};