-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
202 lines (189 loc) · 7.51 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
module.exports = function (grunt) {
"use strict";
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: [
{ src: '<%= pkg.name %>.js', dest: 'tmp/<%= pkg.name %>.js'},
{ src: '<%= pkg.name %>.js', dest: 'dist/<%= pkg.name %>.v<%= pkg.version %>.js'},
{ src: 'dist/<%= pkg.name %>.v<%= pkg.version %>.min.js', dest: 'dist/<%= pkg.name %>.latest.min.js'},
{ src: 'dist/<%= pkg.name %>.v<%= pkg.version %>.js', dest: 'dist/<%= pkg.name %>.latest.js'}
]
}
},
uglify: {
dist: {
files: {
'dist/<%= pkg.name %>.v<%= pkg.version %>.min.js': ['<%= pkg.name %>.js']
}
}
},
connect: {
target: {
options: {
port: 3001,
keepalive: true
}
}
},
jslint: {
all: {
options: {
edition: 'latest', // specify an edition of jslint or use 'dir/mycustom-jslint.js' for own path
errorsOnly: true, // only display errors
failOnError: false, // defaults to true
checkstyle: 'tmp/lint-checkstyle.xml' // write a checkstyle-XML
},
src: [
'Gruntfile.js',
'test/**/*.spec.js',
'<%= pkg.name %>.js'
],
directives: {
browser: true,
nomen: true,
plusplus: true,
predef: [
'd3',
'dimple',
'module',
'console',
'jasmine',
'simpledimple',
'module',
'define',
'require',
'exports',
'describe',
'it',
'xdescribe',
'xit',
'beforeEach',
'afterEach'
]
}
}
},
prop: {
dist: {
src: [
'examples/templates/*.html'
]
},
options: {
exampleOutputPath: 'examples/',
d3Path: '../bower_components/d3/d3.min.js',
dimplePath: '../bower_components/dimple/dist/dimple.v<%= pkg.buildDependencies.dimple %>.min.js',
distPath: '/dist/',
version: 'v<%= pkg.version %>',
scriptTag: '{scriptDependencies}',
header: "<!----------------------------------------------------------------->\n" +
"<!-- AUTOMATICALLY GENERATED CODE - PLEASE EDIT TEMPLATE INSTEAD -->\n" +
"<!----------------------------------------------------------------->\n"
}
},
karma: {
options: {
basepath: '',
frameworks: ['jasmine', 'requirejs'],
files: [
'test/test-main.js',
{ pattern: 'bower_components/d3/d3.min.js', included: false },
{ pattern: 'bower_components/dimple/dist/dimple.latest.min.js', included: false },
{ pattern: 'lib/**/*.min.js', included: false },
{ pattern: 'tmp/*.js', included: false },
{ pattern: 'test/**/*.spec.js', included: false }
],
reporters: ['progress'],
port: 9876,
colors: true,
browsers: ['PhantomJS']
},
unit: {
singleRun: true
},
continuous: {
background: true
}
},
watch: {
src: {
files: [
'<%= pkg.name %>.js'
],
tasks: ['karma:continuous:run']
},
test: {
files: [
'test/**/*.spec.js',
'test/*.spec.js'
],
tasks: ['karma:continuous:run']
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-karma');
// Propogate version into relevant files
grunt.registerMultiTask('prop', 'Propagate Versions.', function () {
function generateScriptElements(options, indent) {
var createScriptElement = function (path) {
var scriptElement = '<script src="{path}"></script>';
return scriptElement.split("{path}").join(path);
},
d3Path = options.d3Path,
dimplePath = options.dimplePath,
distPath = options.distPath,
version = options.version,
simpledimplePath = "..{distFolder}simpledimple.{version}.js",
tab = "",
i;
// default indentation to two spaces
indent = indent || 2;
for (i = 0; i < indent; i++) {
tab += " ";
}
simpledimplePath = simpledimplePath.split("{distFolder}").join(distPath);
simpledimplePath = simpledimplePath.split("{version}").join(version);
grunt.log.writeln("\nUsing d3: " + d3Path);
grunt.log.writeln("\nUsing dimple: " + dimplePath);
grunt.log.writeln("\nUsing simpledimple: " + simpledimplePath + " with " + version + "\n");
return createScriptElement(d3Path) + "\n" + tab + createScriptElement(dimplePath) + "\n" + tab + createScriptElement(simpledimplePath);
}
var options, outPath, header, scriptTag, scripts;
options = this.options();
outPath = options.exampleOutputPath;
header = options.header;
scriptTag = options.scriptTag;
scripts = generateScriptElements(options);
this.files.forEach(function (f) {
f.src.filter(function (filepath) {
var result = true;
if (!grunt.file.exists(filepath)) {
grunt.log.warn('File "' + filepath + '" not found.');
result = false;
}
return result;
}).map(function (filepath) {
// Read file source.
var src = grunt.file.read(filepath);
// Replace the script placeholder tag with script html elements
src = src.split(scriptTag).join(scripts);
// Write the new file
grunt.log.writeln("Creating " + outPath + filepath.substring(filepath.lastIndexOf("/") + 1));
grunt.file.write(outPath + filepath.substring(filepath.lastIndexOf("/") + 1), header + src);
});
});
});
// Default tasks
grunt.registerTask('default', ['jslint', 'uglify', 'copy', 'prop', 'connect']);
grunt.registerTask('test:unit', ['karma:unit']);
grunt.registerTask('test', ['karma:continuous:start', 'watch']);
};