-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbin.js
40 lines (29 loc) · 826 Bytes
/
bin.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
#!/usr/bin/env node
const UserAgents = require('user-agents');
const css = require('./src/css.js');
const fetch = require('./src/fetch-success.js');
const [,,cssUrl] = process.argv;
const readStdin = async () => {
const result = [];
for await (const chunk of process.stdin) {
result.push(chunk);
}
return Buffer.concat(result);
};
const readUrl = async () => {
const userAgent = new UserAgents(/Chrome/);
const { body } = await fetch(cssUrl, {
'user-agent': userAgent
});
return body.toString();
};
(async () => {
const text = cssUrl ? await readUrl() : await readStdin();
const result = await css(text.toString());
// eslint-disable-next-line no-console
console.log(result);
})().catch(e => {
// eslint-disable-next-line no-console
console.error(e);
process.exitCode = 1;
});