forked from smorcuend/bloqs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
181 lines (163 loc) · 5.86 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
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: '\n\n'
},
dist: {
src: [
'src/scripts/bloqs-languages.js',
'src/scripts/bloqs-utils.js',
'src/scripts/bloqs-tooltip.js',
'src/scripts/python-generation.js',
'src/scripts/arduino-generation.js',
'src/scripts/bloqs-suggested.js',
'src/scripts/bloqs-dotsMatrix.js',
'src/scripts/bloqs.js'
],
dest: 'dist/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'dist/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.min.js'
}
},
buildBloqs: {
all: {
options: {
cwd: 'src/scripts/bloqs/', // Src matches are relative to this path.
src: ['**/*.js', '!build-utils.js'], // Actual pattern(s) to match.
dest: 'dist/bloqs/', // Destination path prefix.
ext: '.json',
filter: 'isFile'
}
}
},
sass: {
options: {
sourceMap: false
},
dist: {
files: {
'dist/bloqs.css': 'src/styles/main.scss'
}
}
},
clean: {
dist: ['dist'],
i18n: ['i18n']
},
watch: {
scripts: {
files: ['src/styles/**/*.scss', 'src/scripts/**/*.*'],
tasks: ['default'],
options: {
spawn: false,
livereload: {
host: 'localhost',
port: 9000
}
}
}
},
jsdoc: {
dist: {
src: ['src/scripts/bloqs/**/*.js'],
options: {
destination: 'docs'
}
}
}
});
require('load-grunt-tasks')(grunt);
grunt.loadTasks('tasks');
grunt.registerMultiTask('buildBloqs', '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 bloqsList = [],
bloqsMap = {};
var generate = function(source, destination) {
var tmpObj = require('./' + source),
obj = {};
try {
obj = JSON.parse(JSON.stringify(tmpObj));
bloqsMap[tmpObj.name] = tmpObj;
bloqsList.push(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.file.write('dist/list.json', JSON.stringify(bloqsList));
grunt.log.writeln('Bloqs JSON list Write in ' + 'dist/list.json').ok();
grunt.file.write('dist/bloqsmap.json', JSON.stringify(bloqsMap));
grunt.log.writeln('Bloqs JSON MAP Write in ' + 'dist/bloqsmap.json').ok();
});
grunt.registerTask('bloqDist', ['buildBloqs']);
grunt.registerTask('i18n', 'get all file of i18n', function() {
grunt.task.run([
'clean:i18n',
'getpoeditorfiles:42730',
'poeditor2bloqs'
]);
});
grunt.registerTask('default', [
//'i18n',
'clean:dist',
'concat:dist',
'bloqDist',
'uglify',
'sass'
]);
grunt.registerTask('prepareversion', function(version) {
if (version) {
var bowerFile = grunt.file.readJSON('bower.json');
bowerFile.version = version;
grunt.file.write('bower.json', JSON.stringify(bowerFile, null, 4));
console.log('Bower version changed');
var packageFile = grunt.file.readJSON('package.json');
packageFile.version = version;
grunt.file.write('package.json', JSON.stringify(packageFile, null, 4));
console.log('Package version changed');
grunt.task.run([
'default'
]);
} else {
grunt.log.error('Tienes que indicar la version, grunt prepareversion:v2.1.0');
}
});
};