-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathindex.js
49 lines (40 loc) · 1.17 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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const scssSyntax = require('postcss-scss')
const concise = require('../src/index')
const command = {
name: process.argv[2],
input: process.argv[3],
output: process.argv[4]
}
const build = (input, output) => {
concise.process(fs.readFileSync(input, 'utf8'), { from: input, parser: scssSyntax }).then(css => {
// Create all the parent directories if required
fs.mkdirSync(path.dirname(output), { recursive: true })
// Write the 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
}