Skip to content

Commit 43cba1b

Browse files
committed
feat: add cssmodules transform
0 parents  commit 43cba1b

File tree

11 files changed

+266
-0
lines changed

11 files changed

+266
-0
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"es2015-node4",
4+
"stage-0"
5+
],
6+
"plugins": [
7+
"add-module-exports"
8+
]
9+
}

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true
4+
trim_trailing_whitespace = true
5+
indent_style = tab
6+
7+
[.*rc]
8+
indent_style = space
9+
10+
[{package.json}]
11+
indent_style = space
12+
13+
[*.font]
14+
indent_style = space

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["xo", "xo/esnext"]
3+
}

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
node_modules
28+
29+
# Optional npm cache directory
30+
.npm
31+
32+
# Optional REPL history
33+
.node_repl_history
34+
35+
# jsonlint-cli cache
36+
.tmp
37+
38+
# transpiled artifacts
39+
distribution

.jsonlintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"validate": "http://json.schemastore.org/package"
3+
}

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spin = false
2+
progress = false
3+
save-exact = true
4+
cache-min = 99999999

license.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 SinnerSchrader Deutschland GmbH and [contributors](./graphs/contributors)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+
---
24+
Copyright 2016 by [SinnerSchrader Deutschland GmbH](https://github.com/sinnerschrader) and [contributors](./graphs/contributors). Released under the [MIT license]('./license.md').

package.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"name": "patternplate-transform-cssmodules",
3+
"version": "0.0.0",
4+
"description": "patternplate transform creating css modules",
5+
"main": "distribution/index.js",
6+
"files": [
7+
"distribution"
8+
],
9+
"scripts": {
10+
"start": "npm run watch",
11+
"clean": "rm -rf distribution",
12+
"prepare": "mkdir -p distribution",
13+
"prebuild": "parallelshell 'npm run test' 'npm run clean && npm run prepare'",
14+
"build": "babel source --out-dir distribution && echo '' || notify -t $npm_package_name -m 'Build failed! 😢'",
15+
"postbuild": "npm run notify",
16+
"test": "(eslint source/**/*.js && conventional-changelog-lint --to=HEAD~1 && jsonlint-cli **/*.json) && echo '' || notify -t $npm_package_name -m 'Linting failed! 😢'",
17+
"watch": "watch 'npm run build' source",
18+
"notify": "echo 'Build ready, happy hacking! ✊' && notify -t $npm_package_name -m 'Build ready, happy hacking! ✊'",
19+
"commit": "git-cz",
20+
"commitmsg": "conventional-changelog-lint -e",
21+
"changelog": "conventional-changelog --preset angular --infile changelog.md --same-file --output-unreleased",
22+
"push": "git push && git push --tags && hub release create \"v$(cat .git/RELEASE_VERSION.tmp)\" --message=\"v$(cat .git/RELEASE_VERSION.tmp)\n$(cat .git/COMMITMSG.tmp)\" && npm publish && rm .git/RELEASE_VERSION.tmp && rm .git/COMMITMSG.tmp",
23+
"release": "npm version $(conventional-recommended-bump -p angular)",
24+
"preversion": "npm run build && npm test",
25+
"version": "npm run changelog && git add . && echo \"$(conventional-changelog -p angular)\" > .git/COMMITMSG.tmp",
26+
"postversion": "echo $(git log -1 --pretty=%B HEAD^..HEAD) > .git/RELEASE_VERSION.tmp && git tag -d v$(cat .git/RELEASE_VERSION.tmp) && git commit --amend -m \"chore(release): $(cat .git/RELEASE_VERSION.tmp)\n$(cat .git/COMMITMSG.tmp)\" && git tag -a v$(cat .git/RELEASE_VERSION.tmp) -m \"$(cat .git/COMMITMSG.tmp)\""
27+
},
28+
"repository": {
29+
"type": "git",
30+
"url": "git+https://github.com/nerdlabs/patternplate-transform-cssmodules.git"
31+
},
32+
"bugs": {
33+
"url": "https://github.com/nerdlabs/patternplate-transform-cssmodules/issues"
34+
},
35+
"homepage": "https://github.com/nerdlabs/patternplate-transform-cssmodules#readme",
36+
"keywords": [
37+
"react",
38+
"patternplate",
39+
"transform",
40+
"pattern"
41+
],
42+
"author": {
43+
"name": "Nerdlabs",
44+
"email": "nerds@nerdlabs.it"
45+
},
46+
"contributors": [
47+
{
48+
"name": "Bjoern Brauer",
49+
"email": "zaubernerd@nerdlabs.it"
50+
},
51+
{
52+
"name": "Mario Nebl",
53+
"email": "mario.nebl@sinnerschrader.com"
54+
}
55+
],
56+
"license": "MIT",
57+
"licenses": [
58+
"MIT"
59+
],
60+
"devDependencies": {
61+
"babel": "6.5.2",
62+
"babel-cli": "6.4.0",
63+
"babel-eslint": "4.1.8",
64+
"babel-plugin-add-module-exports": "0.1.2",
65+
"babel-preset-es2015-node4": "2.0.3",
66+
"babel-preset-stage-0": "6.3.13",
67+
"commitizen": "2.5.0",
68+
"conventional-changelog-cli": "1.1.1",
69+
"conventional-changelog-lint": "0.3.1",
70+
"conventional-recommended-bump": "0.1.0",
71+
"cz-conventional-changelog": "1.1.5",
72+
"eslint": "1.10.3",
73+
"eslint-config-xo": "0.9.1",
74+
"eslint-plugin-babel": "3.1.0",
75+
"husky": "0.10.2",
76+
"jsonlint-cli": "0.2.7",
77+
"node-notifier": "4.4.0",
78+
"parallelshell": "2.0.0",
79+
"watch": "0.17.1"
80+
},
81+
"dependencies": {
82+
"css-modules-loader-core": "1.0.0",
83+
"lodash": "4.5.1",
84+
"postcss": "5.0.18",
85+
"postcss-modules": "0.4.0"
86+
}
87+
}

readme.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# patternplate-transform-cssmodules
2+
[patternplate](/sinnerschrader/patternplate) transform to enable usage of [css modules](/css-modules/css-modules).
3+
4+
## Installation
5+
```shell
6+
npm install --save patternplate-transform-cssmodules
7+
```
8+
## Configuration
9+
```javascript
10+
// file: configuration/patternplate-server/patterns.js
11+
module.exports = {
12+
formats: {
13+
css: {
14+
name: 'Style',
15+
transforms: ['cssmodules']
16+
}
17+
}
18+
};
19+
20+
// file: configuration/patternplate-server/transforms.js
21+
module.exports = {
22+
cssmodules: {
23+
inFormat: 'css',
24+
outFormat: 'css'
25+
}
26+
};
27+
```

source/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {merge} from 'lodash';
2+
import postcss from 'postcss';
3+
import modules from 'postcss-modules';
4+
import createLoaderClass from './loader';
5+
6+
7+
export default () => {
8+
return async file => {
9+
const processor = postcss([
10+
modules({
11+
getJSON(_, json) {
12+
file.meta = merge({}, file.meta, {
13+
cssmodules: json
14+
});
15+
},
16+
Loader: createLoaderClass(file)
17+
})
18+
]);
19+
const source = file.buffer.toString('utf-8');
20+
const {css} = await processor.process(source, {
21+
from: file.path
22+
});
23+
file.buffer = css;
24+
return file;
25+
};
26+
};

0 commit comments

Comments
 (0)