-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtransport.js
100 lines (84 loc) · 2.48 KB
/
transport.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
/*
* grunt-cmd-transport
* https://github.com/spmjs/grunt-cmd-transport
*
* Copyright (c) 2013 Hsiaoming Yang
* Licensed under the MIT license.
*/
module.exports = function(grunt) {
var path = require('path');
var text = require('./lib/text').init(grunt);
var script = require('./lib/script').init(grunt);
var style = require('./lib/style').init(grunt);
var template = require('./lib/template').init(grunt);
var handlebars = require('./lib/handlebars').init(grunt);
var json = require('./lib/json').init(grunt);
grunt.registerMultiTask('transport', 'Transport everything into cmd.', function() {
var options = this.options({
paths: ['sea-modules'],
idleading: '',
alias: {},
// create a debug file or not
debug: true,
// create a file with hash
hash: false,
// process a template or not
process: false,
// define parsers
parsers: {
'.js': [script.jsParser],
'.css': [style.cssParser],
'.html': [text.htmlParser],
'.json': [json.jsonParser],
'.tpl': [template.tplParser],
'.handlebars': [handlebars.handlebarsParser]
},
// for handlebars
handlebars: {
id: 'gallery/handlebars/1.0.2/runtime',
knownHelpers: [],
knownHelpersOnly: false
},
// output beautifier
uglify: {
beautify: true,
comments: true
},
// https://github.com/aliceui/aliceui.org/issues/9
styleBox: false
});
if (options.process === true) {
options.process = {};
}
var count = 0;
this.files.forEach(function(fileObj) {
// cwd shouldn't exist after normalize path
if (fileObj.cwd) {
grunt.fail.warn('should specify expand when use cwd');
}
var src = fileObj.src[0], dest = fileObj.dest;
var extname = path.extname(src);
var fileparsers = options.parsers[extname];
if (!fileparsers || fileparsers.length === 0) {
grunt.file.copy(src, dest);
return;
}
if (!Array.isArray(fileparsers)) {
fileparsers = [fileparsers];
}
var srcData = grunt.file.read(src);
if (options.process) {
srcData = grunt.template.process(srcData, options.process);
}
fileparsers.forEach(function(fn) {
fn({
src: src,
srcData: srcData,
name: path.relative(fileObj.orig.cwd || '', src),
dest: dest
}, options);
});
count++;
});
});
};