Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Close #25 PR: Add SCSS support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ducksoupdev authored and sindresorhus committed Jan 29, 2016
1 parent 6c144c3 commit fc02483
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @babel */
import path from 'path';
import postcss from 'postcss';
import autoprefixer from 'autoprefixer';
import postcssSafeParser from 'postcss-safe-parser';
import postcssScssParser from 'postcss-scss';

function init() {
const editor = atom.workspace.getActiveTextEditor();
Expand All @@ -12,13 +14,21 @@ function init() {

const selectedText = editor.getSelectedText();
const text = selectedText || editor.getText();
const filePath = editor.getPath();
let postcssParser = postcssScssParser;

if (filePath && path.extname(filePath).toLowerCase() === '.css') {
postcssParser = postcssSafeParser;
}

postcss(autoprefixer(atom.config.get('autoprefixer'))).process(text, {
parser: postcssSafeParser
parser: postcssParser
}).then(result => {
result.warnings().forEach(x => {
console.warn(x.toString());
atom.notifications.addWarning('Autoprefixer', {detail: x.toString()});
atom.notifications.addWarning('Autoprefixer', {
detail: x.toString()
});
});

const cursorPosition = editor.getCursorBufferPosition();
Expand All @@ -36,7 +46,9 @@ function init() {
}

console.error(err);
atom.notifications.addError('Autoprefixer', {detail: err.message});
atom.notifications.addError('Autoprefixer', {
detail: err.message
});
});
}

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"prefixer"
],
"dependencies": {
"autoprefixer": "^6.0.0",
"postcss": "^5.0.4",
"postcss-safe-parser": "^1.0.1"
"autoprefixer": "^6.3.1",
"postcss": "^5.0.14",
"postcss-safe-parser": "^1.0.4",
"postcss-scss": "^0.1.3"
},
"devDependencies": {
"xo": "*"
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# autoprefixer

> Prefix CSS with [Autoprefixer](https://github.com/ai/autoprefixer)
> Prefix CSS or SCSS with [Autoprefixer](https://github.com/ai/autoprefixer)

## Install
Expand Down
5 changes: 5 additions & 0 deletions test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div {
&:hover {
display: flex;
}
}

0 comments on commit fc02483

Please sign in to comment.