Skip to content

Commit 688805d

Browse files
committed
hold
1 parent c6e8cdf commit 688805d

File tree

8 files changed

+310
-1
lines changed

8 files changed

+310
-1
lines changed

.eslintrc

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
ecmaFeatures:
3+
modules: true
4+
5+
env:
6+
browser: true
7+
node: true
8+
es6: true
9+
10+
rules:
11+
comma-dangle: [2, "always-multiline"]
12+
no-dupe-args: 2
13+
no-dupe-keys: 2
14+
no-duplicate-case: 2
15+
no-empty-character-class: 2
16+
no-ex-assign: 2
17+
no-extra-boolean-cast: 2
18+
no-extra-parens: 2
19+
no-extra-semi: 2
20+
no-func-assign: 2
21+
no-inner-declarations: 2
22+
no-invalid-regexp: 2
23+
no-irregular-whitespace: 2
24+
no-negated-in-lhs: 2
25+
no-obj-calls: 2
26+
no-regex-spaces: 2
27+
no-sparse-arrays: 2
28+
no-unreachable: 2
29+
use-isnan: 2
30+
valid-typeof: 2
31+
no-unexpected-multiline: 2
32+
no-cond-assign: 2
33+
no-constant-condition: 2
34+
no-control-regex: 2
35+
no-debugger: 2
36+
# code style
37+
consistent-return: 0
38+
curly: 2
39+
default-case: 2
40+
dot-notation: 2
41+
dot-location: [2, "property"]
42+
eqeqeq: [2, "allow-null"]
43+
no-else-return: 2
44+
no-lone-blocks: 2
45+
no-loop-func: 2
46+
no-multi-spaces: 2
47+
no-multi-str: 2
48+
no-proto: 2
49+
no-redeclare: 2
50+
no-return-assign: 2
51+
no-sequences: 2
52+
no-throw-literal: 2
53+
no-unused-expressions: 2
54+
no-void: 2
55+
no-warning-comments: [2, { "terms": ["todo", "fixme", "xxx"], "location": "start" }]
56+
no-with: 2
57+
radix: 2
58+
no-delete-var: 2
59+
no-shadow-restricted-names: 2
60+
no-shadow: 2
61+
no-undef: 2
62+
no-unused-vars: 2
63+
brace-style: [2, "1tbs", { "allowSingleLine": true }]
64+
comma-spacing: 2
65+
comma-style: 2
66+
indent: [2, 2]
67+
key-spacing: 2
68+
max-nested-callbacks: [2, 5]
69+
no-lonely-if: 2
70+
no-mixed-spaces-and-tabs: 2
71+
no-nested-ternary: 2
72+
no-spaced-func: 2
73+
no-trailing-spaces: 2
74+
one-var: [2, "never"]
75+
operator-linebreak: 2
76+
quote-props: [2, "as-needed"]
77+
quotes: [2, "single", "avoid-escape"]
78+
semi: [2, "never"]
79+
space-after-keywords: 2
80+
space-before-blocks: 2
81+
space-infix-ops: 2
82+
space-return-throw-case: 2

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules/
2+
.DS_Store
3+
npm-debug.log
4+
/build/
5+
/coverage/

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "4"
4+
- "0.12"
5+
- "0.11"
6+
- "iojs"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# reduce-postcss
2-
Pack postcss modules
2+
Plugin for [reduce-css](https://github.com/zoubin/reduce-css) to pack postcss modules.

gulpfile.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var gulp = require('gulp')
2+
3+
gulp.task('clean', function () {
4+
var del = require('del')
5+
return del('build')
6+
})
7+
8+
gulp.task('scripts', ['clean'], function () {
9+
return gulp.src(['lib/*.js', 'bin/*.js', 'index.js'], { base: process.cwd() })
10+
.pipe(gulp.dest('build'))
11+
})
12+
13+
gulp.task('docs', ['clean'], function () {
14+
return gulp.src(['README.md', 'LICENSE', 'package.json'])
15+
.pipe(gulp.dest('build'))
16+
})
17+
18+
gulp.task('build', ['scripts', 'docs'])
19+
20+
gulp.task('lint', function () {
21+
var eslint = require('gulp-eslint')
22+
return gulp.src(['*.js', 'bin/*.js', 'lib/*.js', 'test/*.js'])
23+
.pipe(eslint())
24+
.pipe(eslint.format())
25+
.pipe(eslint.failAfterError())
26+
})
27+
28+
gulp.task('test', ['lint'], test)
29+
gulp.task('coverage',
30+
require('callback-sequence')(instrument, test, report)
31+
)
32+
gulp.task('default', ['lint', 'coverage'])
33+
gulp.task('upload-coverage', ['coverage'], function (cb) {
34+
var handleReport = require('coveralls/lib/handleInput')
35+
var fs = require('fs')
36+
fs.readFile('./coverage/lcov.info', 'utf8', function (err, data) {
37+
if (err) {
38+
return cb(err)
39+
}
40+
handleReport(data, cb)
41+
})
42+
})
43+
44+
function instrument() {
45+
var istanbul = require('gulp-istanbul')
46+
return gulp.src(['lib/*.js', 'index.js'])
47+
.pipe(istanbul({ includeUntested: true }))
48+
.pipe(istanbul.hookRequire())
49+
}
50+
51+
function test() {
52+
require('task-tape')
53+
var tape = require('gulp-tape')
54+
var reporter = require('tap-spec')
55+
return gulp.src('test/*.js')
56+
.pipe(tape({
57+
reporter: reporter(),
58+
}))
59+
}
60+
61+
function report() {
62+
var istanbul = require('gulp-istanbul')
63+
return gulp.src('test/*.js', { read: false })
64+
.pipe(istanbul.writeReports())
65+
.pipe(istanbul.enforceThresholds({
66+
thresholds: {
67+
global: {
68+
statements: 90,
69+
functions: 90,
70+
branches: 80,
71+
lines: 90,
72+
},
73+
},
74+
}))
75+
}
76+

index.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var Pipeline = require('postcss-processor-splicer')
2+
var CacheHandler = require('deps-cache')
3+
var postcss = require('postcss')
4+
var mix = require('util-mix')
5+
6+
var PROCESSORS = [
7+
require('postcss-simple-import'),
8+
require('postcss-custom-url'),
9+
require('postcss-advanced-variables'),
10+
require('postcss-mixins'), // should come before postcss-nested
11+
require('postcss-nested'),
12+
require('postcss-extend'),
13+
require('autoprefixer'),
14+
]
15+
16+
module.exports = function (b, opts) {
17+
opts = opts || {}
18+
19+
var pipeline = Pipeline(PROCESSORS)
20+
21+
if (typeof opts.processorFilter === 'function') {
22+
opts.processorFilter(pipeline)
23+
} else if (Array.isArray(opts.processorFilter)) {
24+
pipeline.push.apply(pipeline, opts.processorFilter)
25+
}
26+
27+
var i = pipeline.indexOf('postcss-simple-import')
28+
if (i !== -1) {
29+
pipeline.splice(i, 1,
30+
rebuildAtImport(b, pipeline.get(i))
31+
)
32+
}
33+
34+
var postcssProcessor = postcss(pipeline.build())
35+
b.processor(function (result) {
36+
// b.emit('file', result.from)
37+
var postcssOpts = {
38+
from: result.from,
39+
to: result.from,
40+
entry: result, // for atImport
41+
}
42+
return postcssProcessor
43+
.process(result.css, postcssOpts)
44+
.then(function (res) {
45+
result.css = res.css
46+
})
47+
})
48+
49+
}
50+
51+
function rebuildAtImport(b, atImport) {
52+
var opts
53+
if (Array.isArray(atImport)) {
54+
opts = atImport[1]
55+
atImport = atImport[0]
56+
}
57+
opts = mix({ cache: {} }, opts)
58+
59+
var onImport = opts.onImport
60+
opts.onImport = function (from, imports, postcssOpts) {
61+
cacheHandler.add(from, imports)
62+
63+
var result = postcssOpts.entry
64+
imports.forEach(function (dep) {
65+
// watchify reports file rather than `dep`,
66+
// so emit dep and make watchify report it
67+
b.emit('file', dep)
68+
// watch dep
69+
result.emit('file', dep)
70+
})
71+
72+
if (onImport) {
73+
onImport(from, imports, postcssOpts)
74+
}
75+
}
76+
77+
var cacheHandler = new CacheHandler(opts.cache)
78+
// watchify emit `update` whenever file changes detected
79+
b.on('update', function (files) {
80+
cacheHandler.invalidate(files)
81+
})
82+
83+
return [atImport, opts]
84+
}
85+

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "reduce-css-postcss",
3+
"version": "1.0.0",
4+
"description": "Plugin for reduce-css to pack postcss modules",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "gulp"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/zoubin/reduce-css-postcss.git"
12+
},
13+
"keywords": [
14+
"postcss",
15+
"css",
16+
"reduce"
17+
],
18+
"author": "zoubin",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/zoubin/reduce-css-postcss/issues"
22+
},
23+
"homepage": "https://github.com/zoubin/reduce-css-postcss#readme",
24+
"dependencies": {
25+
"autoprefixer": "^6.0.3",
26+
"deps-cache": "^1.0.0",
27+
"postcss": "^5.0.10",
28+
"postcss-advanced-variables": "^1.2.2",
29+
"postcss-custom-url": "^3.0.0",
30+
"postcss-extend": "^1.0.1",
31+
"postcss-mixins": "^2.1.1",
32+
"postcss-nested": "^1.0.0",
33+
"postcss-simple-import": "^2.0.1",
34+
"util-mix": "^3.0.2"
35+
},
36+
"devDependencies": {
37+
"callback-sequence": "^1.2.1",
38+
"coveralls": "^2.11.4",
39+
"del": "^2.0.2",
40+
"gulp": "^3.9.0",
41+
"gulp-eslint": "^1.0.0",
42+
"gulp-istanbul": "^0.10.1",
43+
"gulp-tape": "0.0.4",
44+
"tap-spec": "^4.1.0",
45+
"tape": "^4.2.0",
46+
"task-tape": "^1.0.0"
47+
}
48+
}

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var test = require('tape')
2+
var depsify = require('depsify')
3+
var postcss = require('..')
4+
5+
test('postcss', function(t) {
6+
return depsify
7+
})

0 commit comments

Comments
 (0)