-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
66 lines (48 loc) · 1.48 KB
/
cli.js
File metadata and controls
66 lines (48 loc) · 1.48 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
/*
* datauri - A simple Data URI scheme generator
* https://github.com/heldr/datauri
*
* Copyright (c) 2012 Helder Santana
* Licensed under the MIT license.
* https://raw.github.com/heldr/datauri/master/MIT-LICENSE.txt
*/
(function (args) {
"use strict";
var fs = require('fs'),
path = require('path'),
DataURI = require('./datauri');
function writeNewCssFile(file, content, action) {
fs.writeFile(file, content, 'utf-8', function (err) {
if (err) {
throw err;
}
console.log('File ' + action + ': ' + file);
});
}
function outputCSS(file, content) {
if (fs.existsSync(file)) {
if (path.extname(file).match(/(css|sass|less)/)) {
fs.readFile(file, 'utf-8', function (err, cssContent) {
cssContent += content;
writeNewCssFile(file, cssContent, 'updated');
});
} else {
console.log('Must be a CSS file');
}
} else {
writeNewCssFile(file, content, 'created');
}
}
if (args.length > 2) {
var cls = args[4] || '',
uri = new DataURI(args[2]),
content;
if (args.length < 4) {
content = uri.content;
console.log(content);
} else {
content = uri.getCss(cls);
outputCSS(args[3], content);
}
}
}(process.argv));