-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
50 lines (42 loc) · 1.31 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
const tmp = require("tmp");
const clipboardy = require("clipboardy");
const trash = require("trash");
const shell = require("shelljs");
const less = require("less");
const clipboardSuccess = "✅ CSS output copied to your clipboard!";
const opts = { silent: true };
const toCSS = (repository, { clipboard } = {}, done = () => {}) => {
const cloneDir = tmp.dirSync();
const clone = cloneDir.name;
if (shell.exec(`git clone "${repository}" "${clone}"`, opts).code !== 0) {
console.error("Error: Git clone failed");
shell.exit(1);
}
if (shell.exec(`npm install --prefix ${clone}`, opts).code !== 0) {
console.error("Error: installing Atom theme dependencies failed");
shell.exit(2);
}
less.render(
shell.cat(`${clone}/index.less`),
{ paths: [clone, `${clone}/styles`] },
(err, result) => {
if (err) {
console.error("Error: Compiling Atom theme failed: ");
console.error(err.message);
trash(clone);
shell.exit(3);
}
const css = result.css.replace(/atom-text-editor/g, ".editor");
if (clipboard) {
clipboardy.writeSync(css);
console.log(clipboardSuccess);
} else {
console.log(css);
}
trash(clone);
done();
}
);
};
toCSS.clipboardSuccess = clipboardSuccess;
module.exports = toCSS;