-
Notifications
You must be signed in to change notification settings - Fork 13
/
Gruntfile.js
228 lines (202 loc) · 7.53 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
'use strict';
module.exports = function(grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
pkg: grunt.file.readJSON('./package.json'),
clean: ['dist', '.tmp'],
// Watches files for changes and runs tasks based on the changed files
watch: {
options: {
livereload: true,
spawn: false
},
app: {
files: ['Gruntfile.js', 'dist/<%= pkg.name %>.js'],
tasks: ['newer:jshint:all']
},
styles: {
files: ['src/styles/{,*/}*.scss'],
tasks: ['sass:dev']
},
livereload: {
files: ['index.html', 'src/scripts/**/*.js'],
tasks: ['newer:jshint:all']
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function(connect) {
return [
connect.static('.tmp'),
connect.static('src'),
connect.static('dist')
];
}
}
},
test: {
options: {
port: 9001,
middleware: function(connect) {
return [
connect.static('test'),
connect.static('src'),
connect().use(
'/bower_components',
connect.static('./bower_components')
)
];
}
}
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'src/scripts/**/*.js'
]
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
}
},
sass: {
dev: {
files: {
'.tmp/styles/main.css': 'src/styles/main.scss'
}
},
dist: {
files: {
'dist/styles/main.css': 'src/styles/main.scss'
}
}
},
watchify: {
compile: {
src: './src/scripts/**/*.js',
dest: '.tmp/<%= pkg.name %>.js'
}
},
// Test settings
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
},
copy: {
dist: {
src: '.tmp/<%= pkg.name %>.js', // Actual pattern(s) to match.
dest: 'dist/<%= pkg.name %>.js' // Destination path prefix.
}
},
uglify: {
dist: {
options: {
banner: '/* <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n /* Version: <%= pkg.version %> */\n'
},
files: {
'dist/<%= pkg.name %>.min.js': ['.tmp/<%= pkg.name %>.js']
}
},
distNG: {
options: {
banner: '/* <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n /* Version: <%= pkg.version %> */\n angular.module("ngBloqs", []).constant("bloqs", null).config(["$provide",function ($provide) {',
footer: ' }]);'
},
files: {
'dist/ng-<%= pkg.name %>.min.js': ['dist/<%= pkg.name %>.js']
}
}
},
release: {
/* For more options: https://github.com/geddski/grunt-release#options */
options: {
additionalFiles: ['bower.json'],
indentation: '\t', //default: ' ' (two spaces)
commitMessage: 'Release v<%= version %>', //default: 'release <%= version %>'
tagMessage: 'v<%= version %>', //default: 'Version <%= version %>',
tagName: 'v<%= version %>'
}
},
jsonGenerator: {
all: {
options: {
cwd: 'src/scripts/bloqs/', // Src matches are relative to this path.
src: '**/*.js', // Actual pattern(s) to match.
dest: 'dist/json/', // Destination path prefix.
ext: '.json',
filter: 'isFile'
}
}
}
});
grunt.registerMultiTask('jsonGenerator', 'Generate bloqs code into JSON format', function() {
var opts = this.options();
if (!this.files.length && ('cwd' in opts) && ('src' in opts) && ('dest' in opts)) {
this.files = grunt.file.expandMapping(opts.src, opts.dest, opts);
}
var generate = function(source, destination) {
var tmpObj = require('./' + source),
obj = {};
try {
obj = JSON.parse(JSON.stringify(tmpObj));
} catch (e) {
grunt.log.error(e);
grunt.fail.warn('Error parsing json the data.', 3);
}
var content = JSON.stringify(obj, null, 2);
// Write joined contents to destination filepath.
grunt.file.write(destination, content);
grunt.log.writeln('File "' + destination + '" created.');
return content;
};
var resume = [];
var script = 'db.bitbloq_Bloqs.remove({});\n';
var content = null;
this.files.forEach(function(file) {
if (typeof(file.src) !== 'string') {
file.src.forEach(function(source) {
content = generate(source, file.dest);
script += 'db.bitbloq_Bloqs.insert(' + content + ');\n';
});
} else {
content = generate(file.src, file.dest);
script += 'db.bitbloq_Bloqs.insert(' + content + ');\n';
}
resume.push(file.dest);
});
grunt.file.write('dist/resume.json', JSON.stringify(resume));
grunt.log.writeln('Bloqs Resume Write in ' + 'dist/resume.json').ok();
grunt.file.write('dist/script.json', script);
grunt.log.writeln('Bloqs script Write in ' + 'dist/script.json').ok();
});
grunt.registerTask('bloqDist', ['jsonGenerator']);
grunt.registerTask('server', ['clean', 'jshint:all', 'watchify', 'sass:dev', 'connect:livereload', 'watch']);
grunt.registerTask('dist', ['clean', 'jshint:all', 'jsonGenerator', 'watchify', 'copy:dist', 'uglify', 'sass:dist']);
grunt.registerTask('test', ['clean', 'jshint:all', 'watchify', 'karma']);
grunt.registerTask('default', ['dist']);
};