-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
277 lines (221 loc) · 9.18 KB
/
Gruntfile.js
File metadata and controls
277 lines (221 loc) · 9.18 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*jslint indent: 4, maxlen: 250, maxerr: 10, white: true, browser: true, devel: true, nomen: true, sloppy: true, unparam:true */
module.exports = function (grunt) {
'use strict';
require('time-grunt')(grunt);
var arg2, allFunc, taskRun, defaults = {}, d = new Date(),
pkg = require("./package.json"),
Config = require('./configProject/taskGrunt').Config,
path = require('path'),
fs = require('fs'),
fsx = require('fs-extra'),
caminho = path.resolve(".") + '/',
contentPath = caminho + 'content/',
conf = new Config();
grunt.template.addDelimiters('handlebars-like-delimiters', '{{', '}}');
grunt.loadTasks('./tasks');
grunt.initConfig({
pkg: pkg,
yuidoc : require('./taskGrunt/yuidoc.js'),
plato : require('./taskGrunt/plato.js'),
jshint : require('./taskGrunt/jshint.js'),
concat : require('./taskGrunt/concat.js'),
remove : require('./taskGrunt/remove.js'),
clean : require('./taskGrunt/clean.js'),
cssmin : require('./taskGrunt/cssmin.js'),
concat_css : require('./taskGrunt/concat_css.js'),
template : require('./taskGrunt/template.js'),
sass : require('./taskGrunt/sass.js'),
watch : require('./taskGrunt/watch.js'),
concurrent : require('./taskGrunt/concurrent.js'),
uglify : require('./taskGrunt/uglify.js'),
exec : require('./taskGrunt/exec_npm.js'),
sassdoc : require('./taskGrunt/sassdoc.js'),
});
Object.keys(grunt.config('pkg').devDependencies).forEach(function (dep) {
if ( /^grunt\-/i.test(dep)) {
grunt.loadNpmTasks(dep);
}
});
/**
* This method it makes one forEach in all dependencies package.json for grunt.task.loadTasks method.
*/
taskRun = function (param) {
grunt.task.run(param);
};
grunt.registerTask('help', 'info task gruntfile.', function () {
var text, colors = ['white', 'black', 'grey', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow', 'rainbow'];
//grunt.log.writeln('');
grunt.log.writeln('Help das task do projeto'['yellow'].bold);
text =
'| task: | call: | description: |\n' +
'|----------------------| ------------------------------| ---------------------------------|\n' +
'| doc, sassdoc, plato | grunt info:project | create yuidoc & plato |\n' +
'| Debug js | grunt js:project | file config defalt:debug = true |\n' +
'| create html | grunt html:project | html:project |\n' +
'| minified js | grunt js:project | file config defalt:debug = false |\n' +
'| watch task | grunt watched:project | This watch all task |\n' +
'| minified css | grunt css:project:[css||sass] | compress css or sass |\n'
grunt.log.writeln(text);
});
/**
*@description
*/
grunt.registerTask('wait', function (start) {
var project = /([!:+](\w+))/.exec(process.argv.slice(2))[2];
taskRun(['concat_css:dist', 'cssmin:target:'+conf.readConfig('build', project)+'/css/general-min-un.css','remove:temp:./temp' ]);
var done = this.async();
setTimeout(function () {
taskRun('remove:temp:./release');
done();
}, start);
});
/**
* [description]
* @param {String} project name the of project
* @param {String} name the of css used
*
*/
grunt.task.registerTask('css', 'Read a file asynchronously and write its contents out', function(project,styles) {
if(styles==="sass"){
taskRun('clean:all:./projects/'+project+"/styles/"+styles+"/*.css");
taskRun("sass:dist:"+project);
};
var array = conf.checkStyles(project,styles),
total = array.length,
cout =0, key, start;
for(key in array){
var done = this.async();
fsx.copy('./projects/'+project+'/styles/'+styles+'/'+array[key].replace(/\d+/g, ''), './release/'+array[key], function (err) {
if (!err){
cout++
start = d.getMilliseconds();
}
if(total === cout){
taskRun('wait:'+start);
done();
/* Solution disable map sass. */
taskRun('clean:all:./projects/'+project+"/styles/"+styles+"/*.map");
}
})
}
});
/**
* [description]
* @param
*
*/
grunt.task.registerTask('js', 'minified js', function(){
var project = /([!:+](\w+))/.exec(process.argv.slice(2))[2];
taskRun('jshint');
/**
* WARNING
* tests all modules before
*/
taskRun('exec');
if(conf.readConfig('debug', project)){
taskRun('debug:'+project);
}else{
taskRun('Gzipjs:'+project);
}
});
/**
* Mode debug js.
* exemple for call.
* grunt debug:site || debug:admin
*/
grunt.task.registerTask('debug', '...........', function () {
var
project = Object.values(arguments)[0], min,
PathLibs = './libs/*.js',
PathController = './projects/'+project+'/controller/*.js',
PathDest = conf.readConfig('build', project)+'js/general-min-un.js',
File = conf.CheckModule(project),
PathCore = './content/core/*.js',
PathModules = './modules/*.js',
plugins = conf.checkLibs(project),
modules = File(),
dest = arguments[1] === undefined ? PathDest : arguments[1];
taskRun('remove:temp:'+conf.readConfig('build', project)+'/js/');
for (var i=0; i < plugins.length; i++) {
taskRun('copyLibs:'+plugins[i]);
}
for (var i=0; i < modules.length; i++) {
taskRun('copyModule:'+modules[i]);
}
taskRun('concat:debug:'+dest+':'+PathCore+':'+PathModules+':'+PathController+':'+PathLibs);
taskRun('remove:temp:./modules');
taskRun('remove:temp:./libs');
});
/**
* [description]
* @param
*
*/
grunt.task.registerTask('Gzipjs', 'minified js para qualquer project criado', function (project) {
var project = /([!:+](\w+))/.exec(process.argv.slice(2))[2]
conf.extend(defaults, {
dest: './temp/general.js',
build: conf.readConfig('build', project)+'js/'
});
taskRun('jshint');
taskRun('debug:'+project+':'+defaults.dest)
taskRun('uglify:all:'+defaults.build);
taskRun('remove:temp:./temp');
});
/**
* Create plato and documentation the of project
*/
grunt.task.registerTask('info', 'Create plato and documentation the of project', function (start) {
if(start){
console.log('start...')
}
taskRun('plato');
taskRun('yuidoc');
taskRun('sassdoc');
});
/**
* [description]
* @param {[type]}
* @return {[type]}
*/
grunt.task.registerTask('copyModule', 'Read a file asynchronously and write its contents out', function(name) {
// Tell grunt this task is asynchronous.
var done = this.async();
fsx.copy('./content/modules/MODULE_'+name, './modules/MODULE_'+name, function (err) {
if (err) return console.error(err)
//console.log("success!")
done();
})
});
/**
* [description] copy all libs/plugins as jquery, soma
* @param {[type]} name) { var done [description]
* @return {[type]} [description]
*/
grunt.task.registerTask('copyLibs', 'Read a file asynchronously and write its contents out', function(name) {
// Tell grunt this task is asynchronous.
var done = this.async();
fsx.copy('./content/libs/'+name.replace(/(^[0-9]+)/g, ''), './libs/'+name, function (err) {
if (err) return console.error(err)
//console.log("success!")
done();
})
});
/**
* Create/template html.
* exemple for call.
* grunt html:Painel || grunt html:site
*/
grunt.task.registerTask('html', 'minified js para qualquer project criado', function () {
var project = /([!:+](\w+))/.exec(process.argv.slice(2))[2];
taskRun('template:dev:'+project+':'+conf.readConfig('build', project));
});
/**
* [description]
* @param name the project
*/
grunt.task.registerTask('watched', 'project should be watching', function () {
var project = /([!:+](\w+))/.exec(process.argv.slice(2))[2];
taskRun('concurrent:prod:'+project);
});
};