-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathindex.js
44 lines (36 loc) · 976 Bytes
/
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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const compile = require('../src/index')
const command = {
name: process.argv[2],
input: process.argv[3],
output: process.argv[4]
}
const build = (input, output) => {
compile(fs.readFileSync(input, 'utf8')).then(css => {
fs.writeFile(output, css, err => {
if (err) throw err
console.log(`File written: ${output}\nFrom: ${input}`);
})
});
};
const watch = path => {
console.log(`Currently watching for changes in: ${path}`);
fs.watch(path, {recursive: true}, (eventType, filename) => {
console.log(`${eventType.charAt(0).toUpperCase() + eventType.slice(1)} in: ${filename}`);
build();
});
};
switch (command.name) {
case 'compile':
build(command.input, command.output);
break
case 'watch':
build(command.input, command.output);
watch(path.dirname(command.input));
break
default:
console.log('Unknown command')
break
}