This repository was archived by the owner on Feb 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (84 loc) · 2.62 KB
/
index.js
File metadata and controls
91 lines (84 loc) · 2.62 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
'use strict';
var util = require('util');
var smushcss = require('./lib/css');
var smushjs = require('./lib/javascript');
var defaults = {
extension: '.tmpl',
jade: {
extension: '.jade',
comment: '//- This is a generated file. Make your changes to the .tmpl file instead.\n\n',
css: {
pattern: /link\(rel=\"stylesheet\", href=\"(.*)\.css\"/,
replacePattern: '<PLACEHOLDERFORMINIFIEDFILE>',
extension: '.css',
source: 'public',
target: 'public/css/min/'
},
js: {
pattern: /script\(src\=\"(.*)\.js\"/,
replacePattern: '<PLACEHOLDERFORMINIFIEDFILE>',
extension: '.js',
source: 'public',
target: 'public/js/min/'
}
}
};
var smush = {
css: function (options, cb) {
if (!options.template) {
return cb(new Error('no template set'));
}
var smushOptions = {
template: options.template,
extension: options.extension || defaults.extension,
jade: {
extension: options.jadeExtension || defaults.jade.extension,
comment: options.comment || defaults.jade.comment,
css: {
pattern: options.pattern || defaults.jade.css.pattern,
replacePattern: options.replacePattern || defaults.jade.css.replacePattern,
extension: options.cssExtension || defaults.jade.css.extension,
source: options.source || defaults.jade.css.source,
target: options.target || defaults.jade.css.target
}
}
};
smushcss.smush(smushOptions, cb);
},
js: function (options, cb) {
if (!options.template) {
return cb(new Error('no template set'));
}
var smushOptions = {
template: options.template,
extension: options.extension || defaults.extension,
jade: {
extension: options.jadeExtension || defaults.jade.extension,
comment: options.comment || defaults.jade.comment,
js: {
pattern: options.pattern || defaults.jade.js.pattern,
replacePattern: options.replacePattern || defaults.jade.js.replacePattern,
extension: options.jsExtension || defaults.jade.js.extension,
source: options.source || defaults.jade.js.source,
target: options.target || defaults.jade.js.target
}
}
};
smushjs.smush(smushOptions, cb);
}
};
function errHandler(e) {
util.log('Minfication failed, aborting deployment');
util.log(e.stack);
process.exit(1);
}
process.on('uncaughtException', errHandler);
module.exports = smush;
if (require.main === module) {
(function () {
var test = require('./test');
test.init(function (err, res) {
console.log(err || res);
});
})();
}