forked from fkling/JSNetworkX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
214 lines (200 loc) · 6.5 KB
/
Gruntfile.js
File metadata and controls
214 lines (200 loc) · 6.5 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
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
203
204
205
206
207
208
209
210
211
212
213
214
/*jshint node:true*/
/*global grunt*/
var path = require('path');
var namespaces = {};
namespaces.base = ['jsnx'];
namespaces.node = namespaces.base.concat('jsnx.algorithms', 'jsnx.generators');
namespaces.all = namespaces.node.concat('jsnx.drawing');
module.exports = function(grunt) {
"use strict";
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
dist: 'dist/',
wrapper: "(function(global, factory) { function extractNS(){ var g = {}; return factory.call(g, global),g.jsnx;} if(typeof define === 'function' && define.amd){ /*AMD*/ define(extractNS); } else if (typeof module !== 'undefined' && module.exports){ /*node*/ module.exports = extractNS(); } else { factory.call(global, global); } }(this, function(window) {%output%}));",
roots: ['jsnx/', 'vendor/closure-library/'],
paths: {
compiler: 'vendor/closure-compiler/compiler.jar',
library: 'vendor/closure-library/'
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: ['Gruntfile.js', 'jsnx/**/*.js']
},
jasmine: {
options: {
specs: 'jsnx/**/tests/test_*.js',
vendor: '<%= meta.paths.library %>closure/goog/base.js',
helpers: ['deps.js', 'jasmine/BaseTestClass.js', 'jasmine/*Matcher.js']
},
normal: {
src: ['jsnx/jsnx.js', 'jsnx/algorithms/algorithms.js', 'jsnx/generators/generators.js']
},
compiled: {
src: ['<%= pkg.name %>-test.js'],
options: {
outfile: '_SpecRunner_compiled.html',
helpers: ['jasmine/gcc_deps.js', 'jasmine/BaseTestClass.js', 'jasmine/*Matcher.js']
}
}
},
compile: {
options: {
closureLibraryPath: '<%= meta.paths.library %>',
compilerFile: '<%= meta.paths.compiler %>',
compile: true,
namespaces: [],
compilerOpts: {
output_wrapper: '<%= meta.wrapper %>',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
generate_exports: null,
define: ['goog.DEBUG=false', 'jsnx.TESTING=false'],
externs: ['jsnx/externs/*'],
warning_level: 'VERBOSE',
jscomp_warning: ['strictModuleDepCheck'],
jscomp_error: ['checkDebuggerStatement', 'const', 'constantProperty', 'accessControls', 'visibility']
}
},
test: {
options: {
namespaces: namespaces.all,
compilerOpts: {
output_wrapper: '<%= meta.wrapper %>',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
generate_exports: null,
define: ["'goog.DEBUG=true'", "'jsnx.TESTING=true'"],
externs: ['jsnx/externs/*'],
warning_level: 'VERBOSE',
jscomp_warning: ['strictModuleDepCheck'],
jscomp_error: ['checkDebuggerStatement', 'const', 'constantProperty', 'accessControls', 'visibility']
}
},
src: '<%= meta.roots %>',
dest: '<%= pkg.name%>-test.js'
},
base: {
options: {
namespaces: namespaces.base
},
src: '<%= meta.roots %>',
dest: '<%= meta.dist %><%= pkg.name%>-base.js'
},
node: {
options: {
namespaces: namespaces.node
},
src: '<%= meta.roots %>',
dest: '<%= meta.dist %><%= pkg.name%>-node.js'
},
all: {
options: {
namespaces: namespaces.all
},
src: '<%= meta.roots %>',
dest: '<%= pkg.name%>.js'
},
drawing: {
options: {
namespaces: namespaces.base.concat('jsnx.drawing')
},
src: '<%= meta.roots %>',
dest: '<%= meta.dist %><%= pkg.name%>-drawing.js'
},
custom: {
options: {},
src: '<%= meta.roots %>',
dest: '<%= pkg.name%>-custom.js'
}
},
deps: {
options: {
closureLibraryPath: '<%= meta.paths.library %>',
root_with_prefix: '"jsnx ../../../../jsnx"'
},
'default': {
dest: './deps.js'
}
},
connect: {
server: {
options: {
keepalive: true
}
}
}
});
// Create required repositories
grunt.file.mkdir(grunt.config.get('meta.dist'));
// Get custom namespaces from the command line if set
var custom_ns = grunt.option('ns');
if (custom_ns) {
custom_ns = custom_ns.split(',');
var ns = custom_ns.map(function(ns) {
return ns.indexOf('jsnx') === 0 ? ns : 'jsnx.' + ns;
});
ns.push('jsnx');
grunt.config.set('compile.custom.options.namespaces', ns);
}
// Check whether compiler and library exist
grunt.registerTask('check', 'Checks whether dependencies exist', function() {
var ok = true;
var library_path = grunt.config('meta.paths.library');
if (!grunt.file.exists(library_path)) {
grunt.log.error('Cannot find closure library at ' + library_path);
grunt.log.error(
'You can download the library using SVN with `svn checkout http://closure-library.googlecode.com/svn/trunk/ ' + library_path + '`'
);
ok = false;
}
else {
grunt.verbose.ok('Found closure library.');
}
var compiler_path = grunt.config('meta.paths.compiler');
if (!grunt.file.exists(compiler_path)) {
grunt.log.error('Cannot find closure compiler at ' + compiler_path);
grunt.log.error(
'Please download the compiler at https://code.google.com/p/closure-compiler/ and extract it to ' + path.dirname(compiler_path)
);
ok = false;
}
else {
grunt.verbose.ok('Found closure compiler');
}
return ok;
});
grunt.registerTask('cleanup', 'Remove test stuff', function() {
grunt.file['delete'](grunt.config.get('compile.test.dest'));
grunt.file['delete'](grunt.config.get('deps.default.dest'));
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-closure-tools');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.renameTask('closureBuilder', 'compile');
grunt.renameTask('closureDepsWriter', 'deps');
grunt.registerTask('test', ['check', 'deps', 'compile:test', 'jasmine', 'cleanup']);
grunt.registerTask('buildtest', [
'check',
'deps',
'jasmine:normal:build',
'compile:test',
'jasmine:compiled:build',
'connect:server',
'cleanup'
]);
grunt.registerTask('buildall', [
'check',
'jshint',
'compile:test',
'jasmine:compiled',
'compile:base',
'compile:node',
'compile:drawing',
'compile:all',
'cleanup'
]);
};