forked from rowanmanning/frag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJakefile
More file actions
123 lines (98 loc) · 2.83 KB
/
Jakefile
File metadata and controls
123 lines (98 loc) · 2.83 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
// Dependencies
var exec = require('child_process').exec;
var colors = require('colors');
var fs = require('fs');
var hogan = require('hogan.js');
var path = require('path');
// Configurations
var config = {
paths: {
npmbin: './node_modules/.bin',
sass: './lib/frag.sass',
less: './lib/frag.less',
dist: './dist/frag.css',
distMin: './dist/frag.min.css'
},
pkg: JSON.parse(fs.readFileSync('./component.json', 'utf8'))
};
config.pkg.year = (new Date()).getFullYear();
var headTemplate = hogan.compile(fs.readFileSync('./config/head.txt', 'utf8'));
// Pre-task message
log("\n----------------------------------------".blue);
log("Frag Build Tool".blue.underline);
// Tasks
// Compile
desc('Compile the Sass source into CSS');
task('compile', ['compile:sass'], null, {async: true});
namespace('compile', function () {
var compileSassDesc = 'Compile the Sass source into CSS';
desc(compileSassDesc);
task('sass', function () {
log(compileSassDesc, 'task');
compileSass(config.paths.sass, config.paths.dist);
}, {async: true});
var compileLessDesc = 'Compile the LESS source into CSS';
desc(compileLessDesc);
task('less', function () {
log(compileLessDesc, 'task');
compileLess(config.paths.less, config.paths.dist);
}, {async: true});
});
// Default
task('default', ['compile'], null, {async: true});
// Post-task cleanup
jake.addListener('complete', function () {
log("\n----------------------------------------\n".blue);
process.exit();
});
// Functions
function renderHead () {
return headTemplate.render(config.pkg);
}
function compileSass (inPath, outPath) {
cmd([getCompileSassCommand(inPath, outPath)], 'Compiled successfully', null, {printStderr: true, breakOnError: true});
}
function getCompileSassCommand (inPath, outPath) {
return 'echo "' + renderHead() + '`sass ' + inPath + '`" > ' + outPath;
}
function compileLess (inPath, outPath) {
cmd([getCompileLessCommand(inPath, outPath)], 'Compiled successfully', null, {printStderr: true, breakOnError: true});
}
function getCompileLessCommand (inPath, outPath) {
return 'echo "' + renderHead() + '`' + config.paths.npmbin + '/lessc ' + inPath + '`" > ' + outPath;
}
// Utilities
// Execute command
function cmd (commands, successMsg, callback, options) {
jake.exec(commands, function () {
if (successMsg) {
log(successMsg, 'success');
}
if (typeof callback === 'function') {
callback();
}
complete();
}, options);
}
// Logging
function log (message, level) {
var out = null;
switch (level) {
case 'task':
out = '\n' + message.cyan;
break;
case 'success':
out = message.green;
break;
case 'notice':
out = message.yellow;
break;
case 'error':
out = message.red;
break;
default:
out = message;
break;
}
console.log(out);
}