This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (81 loc) · 2.69 KB
/
index.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
'use strict';
const callsite = require('callsite');
const path = require('path');
const {
arrange, listen, read, translate, minify, write
} = require('./lib');
class Tasky {
/**
* A simple JS and LESS/SCSS/CSS compiler and minifier.
*/
constructor() {
this.arrange = arrange;
this.listen = listen;
this.read = read;
this.translate = translate;
this.minify = minify;
this.write = write;
}
/**
* Arrange, Listen, Read, Translate, Minify and Write LESS/SCSS/CSS or TS/JS input files to a unique output file.
*
* TS not avaiable.
*
* @param {String} output
* @param {Array<String>} input
* @param {Object=} options
* @param {String} mode CSS or JS
*/
async run(output, input, options, mode) {
const self = this;
// Sanitize falsy args
output = output || [];
input = input || [];
options = options || {};
// Execute
console.log('Tasky > ' + mode + ' > Arrange...');
self.arrange(output, input, options, self.dirname).then(function (arrangeResult) {
console.log('Tasky > ' + mode + ' > Listen...');
self.listen(arrangeResult, function (listenResult) {
console.log('Tasky > ' + mode + ' > Read...');
return self.read(listenResult).then(function (readResult) {
console.log('Tasky > ' + mode + ' > Translate...');
return self.translate(readResult).then(function (translateResult) {
console.log('Tasky > ' + mode + ' > Minify...');
return self.minify(translateResult).then(function (minifyResult) {
console.log('Tasky > ' + mode + ' > Write...');
self.write(minifyResult, function () {
console.log('Tasky > ' + mode + ' > OK!');
});
})
});
});
});
});
}
/**
* Arrange, Listen, Read, Translate, Minify and Write LESS/SCSS/CSS input files to a unique output file.
*
* @param {String} output
* @param {Array<String>} input
* @param {Object=} options https://www.npmjs.com/package/node-sass#options and http://lesscss.org/usage/#less-options
*/
watchCSS(output, input, options) {
this.dirname = path.dirname(callsite()[1].getFileName());
this.run(output, input, options, 'CSS');
}
/**
* Arrange, Listen, Read, Translate, Minify and Write JS input files to a unique output file.
*
* TypeScript not avaiable.
*
* @param {String} output
* @param {Array<String>} input
* @param {Object=} options https://www.npmjs.com/package/uglify-es#minify-options
*/
watchJS(output, input, options) {
this.dirname = path.dirname(callsite()[1].getFileName());
this.run(output, input, options, 'JS');
}
}
module.exports = new Tasky();