-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (57 loc) · 1.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/** @babel */
import postcss from 'postcss';
import rucksack from 'rucksack-css';
import postcssSafeParser from 'postcss-safe-parser';
function init() {
const editor = atom.workspace.getActiveTextEditor();
if (!editor) {
return;
}
const selectedText = editor.getSelectedText();
const text = selectedText || editor.getText();
postcss(rucksack(atom.config.get('rucksack'))).process(text, {
parser: postcssSafeParser
}).then(result => {
result.warnings().forEach(x => {
console.warn(x.toString());
atom.notifications.addWarning('rucksack', {detail: x.toString()});
});
const cursorPosition = editor.getCursorBufferPosition();
if (selectedText) {
editor.setTextInBufferRange(editor.getSelectedBufferRange(), result.css);
} else {
editor.setText(result.css);
}
editor.setCursorBufferPosition(cursorPosition);
}).catch(err => {
if (err.name === 'CssSyntaxError') {
err.message += err.showSourceCode();
}
console.error(err);
atom.notifications.addError('rucksack', {detail: err.message});
});
}
export const config = {
browsers: {
title: 'Supported browsers',
description: 'Using the [following syntax](https://github.com/ai/browserslist#queries).',
type: 'array',
default: rucksack.defaults,
items: {
type: 'string'
}
},
cascade: {
title: 'Cascade prefixes',
type: 'boolean',
default: true
},
remove: {
title: 'Remove unneeded prefixes',
type: 'boolean',
default: true
}
};
export const activate = () => {
atom.commands.add('atom-workspace', 'rucksack', init);
};