Skip to content

Commit 3d2c6d0

Browse files
committed
better tooling
ignored generated files moved stuff into folders added eslint added travis added coveralls
1 parent 866162a commit 3d2c6d0

File tree

7 files changed

+82
-94
lines changed

7 files changed

+82
-94
lines changed

.eslintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"node": true
5+
},
6+
"ecmaFeatures": {
7+
"arrowFunctions": true,
8+
"blockBindings": true,
9+
"classes": true,
10+
"defaultParams": true,
11+
"destructuring": true,
12+
"forOf": true,
13+
"modules": true,
14+
"objectLiteralComputedProperties": true,
15+
"objectLiteralShorthandMethods": true,
16+
"objectLiteralShorthandProperties": true,
17+
"spread": true,
18+
"superInFunctions": true,
19+
"templateStrings": true,
20+
"unicodeCodePointEscapes": true,
21+
"jsx": true
22+
},
23+
"rules": {
24+
"quotes": "single"
25+
}
26+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
node_modules
2+
coverage
3+
lib
4+
test

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "0.10"
5+
- "0.12"
6+
- "iojs"
7+
script: npm run travis
8+
9+
before_install:
10+
- '[ "${TRAVIS_NODE_VERSION}" != "0.10" ] || npm install -g npm'
11+
12+
after_success: cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose && rm -rf ./coverage

index.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

package.json

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,49 @@
22
"name": "postcss-modules-extract-imports",
33
"version": "0.0.1",
44
"description": "A CSS Modules transform to extract local aliases for inline imports",
5-
"main": "index.js",
5+
"main": "lib/index.js",
66
"scripts": {
7-
"watch": "chokidar index.src.js -c 'npm run build'",
8-
"build": "babel -o index.js index.src.js",
9-
"test": "mocha --compilers js:babel/register",
10-
"autotest": "chokidar index.src.js test.js -c 'npm test'"
7+
"lint": "eslint src",
8+
"build": "babel --out-dir lib src",
9+
"watch": "chokidar src -c 'npm run build'",
10+
"build-test": "babel --out-dir test test-src",
11+
"pretest": "npm run lint && npm run build && npm run build-test",
12+
"test": "mocha",
13+
"autotest": "chokidar src test-src -c 'npm test'",
14+
"precover": "npm run lint && npm run build && npm run build-test",
15+
"cover": "istanbul cover node_modules/mocha/bin/_mocha",
16+
"travis": "npm run cover -- --report lcovonly",
17+
"prepublish": "npm run build"
1118
},
1219
"repository": {
1320
"type": "git",
14-
"url": "https://github.com/geelen/postcss-modules-extract-imports.git"
21+
"url": "https://github.com/css-modules/postcss-modules-extract-imports.git"
1522
},
1623
"keywords": [
1724
"css-modules",
1825
"postcss",
1926
"plugin"
2027
],
28+
"files": [
29+
"lib"
30+
],
2131
"author": "Glen Maddern",
2232
"license": "ISC",
2333
"bugs": {
24-
"url": "https://github.com/geelen/postcss-modules-extract-imports/issues"
34+
"url": "https://github.com/css-modules/postcss-modules-extract-imports/issues"
2535
},
26-
"homepage": "https://github.com/geelen/postcss-modules-extract-imports",
36+
"homepage": "https://github.com/css-modules/postcss-modules-extract-imports",
2737
"dependencies": {
2838
"postcss": "^4.1.11"
2939
},
3040
"devDependencies": {
3141
"babel": "^5.4.7",
42+
"babel-eslint": "^3.1.9",
3243
"babelify": "^6.1.2",
3344
"chokidar-cli": "^0.2.1",
45+
"coveralls": "^2.11.2",
46+
"eslint": "^0.21.2",
47+
"istanbul": "^0.3.14",
3448
"mocha": "^2.2.5"
3549
}
3650
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import postcss from 'postcss'
1+
import postcss from 'postcss';
22

33
const declWhitelist = ['extends'],
44
declFilter = new RegExp(`^(${declWhitelist.join('|')})$`),
5-
matchImports = /^([\w ]+) from ("([^"]+)"|'([^']+)')$/
5+
matchImports = /^([\w ]+) from (?:"([^"]+)"|'([^']+)')$/;
66

7-
const processor = (css, result) => {
8-
let imports = {}
7+
const processor = (css) => {
8+
let imports = {};
99

1010
// Find any declaration that supports imports
1111
css.eachDecl(declFilter, (decl) => {
12-
let matches = decl.value.match(matchImports)
12+
let matches = decl.value.match(matchImports);
1313
if (matches) {
14-
let [_, symbols, _, doubleQuotePath, singleQuotePath] = matches,
15-
path = doubleQuotePath || singleQuotePath
16-
imports[path] = imports[path] || {}
14+
let [/*match*/, symbols, doubleQuotePath, singleQuotePath] = matches;
15+
let path = doubleQuotePath || singleQuotePath;
16+
imports[path] = imports[path] || {};
1717
let tmpSymbols = symbols.split(' ')
18-
.map(s => imports[path][s] = `__tmp_${s}_${processor.getRandomStr()}`)
19-
decl.value = tmpSymbols.join(' ')
18+
.map(s => imports[path][s] = `__tmp_${s}_${processor.getRandomStr()}`);
19+
decl.value = tmpSymbols.join(' ');
2020
}
21-
})
21+
});
2222

2323
// If we've found any imports, insert :import rules
2424
Object.keys(imports).forEach(path => {
25-
let pathImports = imports[path]
25+
let pathImports = imports[path];
2626
css.prepend(postcss.rule({
2727
selector: `:import("${path}")`,
2828
before: "\n",
@@ -31,11 +31,11 @@ const processor = (css, result) => {
3131
value: pathImports[importedSymbol],
3232
before: "\n "
3333
}))
34-
}))
35-
})
36-
}
34+
}));
35+
});
36+
};
3737

38-
processor.defaultRandomStr = () => Math.random().toString(36).substr(2, 8)
39-
processor.getRandomStr = processor.defaultRandomStr // Easy to be mocked out
38+
processor.defaultRandomStr = () => Math.random().toString(36).substr(2, 8);
39+
processor.getRandomStr = processor.defaultRandomStr; // Easy to be mocked out
4040

41-
export default processor
41+
export default processor;

test.js renamed to test-src/basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert"
22
import postcss from "postcss"
3-
import processor from "./index.src.js"
3+
import processor from "../"
44

55
let pipeline = postcss([processor]),
66
check = (desc, input, expected, randomStrs) => {

0 commit comments

Comments
 (0)