-
Notifications
You must be signed in to change notification settings - Fork 32
/
Gruntfile.js
162 lines (145 loc) · 4.76 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
module.exports = function(grunt) {
var path = require('path');
// Load plugins
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-strip-code');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-stripcomments');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
strip_code: {
portfolio_allocation_gs: {
options: {
blocks: [
{ start_block: "/* Start Not to be used as is in Google Sheets */",
end_block: "/* End Not to be used as is in Google Sheets */"
}
]
},
files: [
{ src: ['dist/portfolio_allocation.dist.js'], dest: 'dist/gs/portfolio_allocation.gs'}
]
},
portfolio_allocation_dist: {
options: {
blocks: [
{ start_block: "/* Start Wrapper private methods - Unit tests usage only */",
end_block: "/* End Wrapper private methods - Unit tests usage only */"
}
]
},
files: [
{ src: ['dist/portfolio_allocation.dev.js'], dest: 'dist/portfolio_allocation.dist.js'}
]
},
},
comments: {
portfolio_allocation_gs: {
options: {
singleline: true,
multiline: true,
keepSpecialComments: false
},
src: [ 'dist/gs/portfolio_allocation.gs']
},
},
replace: {
portfolio_allocation_gs: {
options: {
preserveOrder: true,
patterns: [
{
match: /self\.(\w+)\s=\sfunction/g,
replacement: 'function $1'
},
{
match: /self\./g,
replacement: ''
}
]
},
files: [
{ src: ['dist/gs/portfolio_allocation.gs'], dest: 'dist/gs/portfolio_allocation.gs'}
]
},
portfolio_allocation : {
options: {
preserveOrder: true,
patterns: [
{
match: /NONE\((.+?)\);/g,
replacement: "NONE($1);"
}
]
},
files: [
{ src: ['dist/portfolio_allocation.dev.js'], dest: 'dist/portfolio_allocation.dev.js'}
]
}
},
concat: {
portfolio_allocation: {
src: ['lib/header.js', 'lib/matrix/*.js', 'lib/stats/*.js', 'lib/allocation/*.js', 'lib/footer.js'],
dest: 'dist/portfolio_allocation.dev.js',
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> (<%= pkg.date %>), <%= pkg.author %> */'
},
portfolio_allocation_dev: {
files: {
'dist/portfolio_allocation.dev.min.js': ['dist/portfolio_allocation.dev.js']
}
},
portfolio_allocation_dist: {
files: {
'dist/portfolio_allocation.dist.min.js': ['dist/portfolio_allocation.dist.js']
}
}
},
qunit: {
dev: ['test/index_optimisation.html', 'test/index_bitset.html', 'test/index_matrix.html', 'test/index_simplex.html', 'test/index_vector.html', 'test/index_stats.html', 'test/index_combinatorics.html', 'test/index_covmatrix_dev.html', 'test/index_allocation_dev.html', 'test/index_computational_geometry_dev.html'],
dist: ['test/index_allocation_dist.html', 'test/index_covmatrix_dist.html', 'test/index_meanvector.html']
}
});
//
grunt.registerTask('deliver-dev', 'Builds the app into a distributable dev package.', function() {
// Build the app in dev mode, and run all dev unit tests,
// which are a superset of dist unit tests
grunt.task.run('concat:portfolio_allocation');
grunt.task.run('replace:portfolio_allocation')
grunt.task.run('uglify:portfolio_allocation_dev');
grunt.task.run('qunit:dev');
});
//
grunt.registerTask('test-dev', 'Tests the app in dev mode.', function() {
// Run all dev unit tests, which are a superset of dist unit tests
grunt.task.run('qunit:dev');
});
//
grunt.registerTask('deliver-dist', 'Builds the app into a distributable dist package.', function() {
// Build the app in dist mode
grunt.task.run('concat:portfolio_allocation');
grunt.task.run('replace:portfolio_allocation')
grunt.task.run('strip_code:portfolio_allocation_dist');
grunt.task.run('uglify:portfolio_allocation_dist');
// Run the non-dev unit tests
grunt.task.run('qunit:dist');
});
//
grunt.registerTask('test-dist', 'Tests the app in dist mode.', function() {
// Run all dist unit tests
grunt.task.run('qunit:dist');
});
//
grunt.registerTask('deliver-gs', 'Builds the app into a distributable package for Google Sheets.', function() {
// Remove header/footer, and remove comments
grunt.task.run('strip_code:portfolio_allocation_gs');
grunt.task.run('comments:portfolio_allocation_gs');
// Then change function definitions
grunt.task.run('replace:portfolio_allocation_gs')
});
};