Skip to content

Commit d96f646

Browse files
committed
No babel
1 parent 8cf2079 commit d96f646

16 files changed

+154
-238
lines changed

.eslintrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ rules:
2929
use-isnan: 2
3030
valid-typeof: 2
3131
no-unexpected-multiline: 2
32-
no-cond-assign: 2
3332
no-constant-condition: 2
3433
no-control-regex: 2
3534
no-debugger: 2
3635
# code style
3736
consistent-return: 0
38-
curly: 2
37+
curly: [2, "multi-line"]
3938
default-case: 2
4039
dot-notation: 2
4140
dot-location: [2, "property"]
@@ -76,7 +75,6 @@ rules:
7675
quote-props: [2, "as-needed"]
7776
quotes: [2, "single", "avoid-escape"]
7877
semi: [2, "never"]
79-
space-after-keywords: 2
78+
keyword-spacing: 2
8079
space-before-blocks: 2
8180
space-infix-ops: 2
82-
space-return-throw-case: 2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.DS_Store
33
npm-debug.log
44
build/
5-
/coverage/
5+
coverage/
6+
.nyc_output/

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
npm-debug.log
2+
changelog.md
3+
coverage/
4+
example/
5+
test/
6+
.*

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# postcss-custom-url
22
[![version](https://img.shields.io/npm/v/postcss-custom-url.svg)](https://www.npmjs.org/package/postcss-custom-url)
3-
[![status](https://travis-ci.org/zoubin/postcss-custom-url.svg?branch=master)](https://travis-ci.org/zoubin/postcss-custom-url)
4-
[![coverage](https://img.shields.io/coveralls/zoubin/postcss-custom-url.svg)](https://coveralls.io/github/zoubin/postcss-custom-url)
5-
[![dependencies](https://david-dm.org/zoubin/postcss-custom-url.svg)](https://david-dm.org/zoubin/postcss-custom-url)
6-
[![devDependencies](https://david-dm.org/zoubin/postcss-custom-url/dev-status.svg)](https://david-dm.org/zoubin/postcss-custom-url#info=devDependencies)
3+
[![status](https://travis-ci.org/reducejs/postcss-custom-url.svg?branch=master)](https://travis-ci.org/reducejs/postcss-custom-url)
4+
[![dependencies](https://david-dm.org/reducejs/postcss-custom-url.svg)](https://david-dm.org/reducejs/postcss-custom-url)
5+
[![devDependencies](https://david-dm.org/reducejs/postcss-custom-url/dev-status.svg)](https://david-dm.org/reducejs/postcss-custom-url#info=devDependencies)
6+
[![license](https://img.shields.io/npm/l/postcss-custom-url.svg)](https://www.npmjs.org/package/postcss-custom-url)
7+
[![node](https://img.shields.io/node/v/postcss-custom-url.svg)](https://www.npmjs.org/package/postcss-custom-url)
78

89
Transform `url()` in css.
910

gulpfile.babel.js

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

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
require('babel-core/register')()
2-
module.exports = require('./lib/main')
1+
'use strict'
32

3+
const postcss = require('postcss')
4+
const custom = require('./lib/custom')
5+
const util = require('./lib/util')
6+
7+
module.exports = postcss.plugin(
8+
'postcss-custom-url',
9+
function (customTransforms) {
10+
customTransforms = customTransforms || [ util.rebase ]
11+
if (!Array.isArray(customTransforms)) {
12+
customTransforms = [ customTransforms ]
13+
}
14+
return custom(customTransforms)
15+
}
16+
)
17+
18+
module.exports.util = util

lib/asset.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import fs from 'fs'
2-
import mime from 'mime'
3-
import shasum from 'shasum'
4-
import promisify from 'node-promisify'
1+
'use strict'
52

6-
var fsStat = promisify(fs.stat)
7-
var fsRead = promisify(fs.readFile)
3+
const fs = require('fs')
4+
const mime = require('mime')
5+
const shasum = require('shasum')
6+
const promisify = require('node-promisify')
87

9-
export default class Asset {
8+
const fsStat = promisify(fs.stat)
9+
const fsRead = promisify(fs.readFile)
10+
11+
class Asset {
1012
constructor(file) {
1113
this.file = file
1214
}
@@ -21,10 +23,7 @@ export default class Asset {
2123

2224
size() {
2325
if (!this._size) {
24-
this._size = fsStat(this.file)
25-
.then(function (stats) {
26-
return stats.size
27-
})
26+
this._size = fsStat(this.file).then(stats => stats.size)
2827
}
2928
return this._size
3029
}
@@ -45,9 +44,7 @@ export default class Asset {
4544

4645
base64() {
4746
if (!this._base64) {
48-
this._base64 = this.data().then(function (data) {
49-
return data.toString('base64')
50-
})
47+
this._base64 = this.data().then(data => data.toString('base64'))
5148
}
5249
return this._base64
5350
}
@@ -57,7 +54,7 @@ export default class Asset {
5754
return this._dataUrl
5855
}
5956
if (this.mimeType) {
60-
this._dataUrl = this.base64().then( (base64) => {
57+
this._dataUrl = this.base64().then( base64 => {
6158
return 'data:' + this.mimeType + ';base64,' + base64
6259
} )
6360
} else {
@@ -83,3 +80,5 @@ export default class Asset {
8380
*/
8481

8582
}
83+
84+
module.exports = Asset

lib/custom.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import eachUrlDecl from './eachUrlDecl'
2-
import Result from './result'
3-
import mix from 'util-mix'
4-
import getp from 'getp'
1+
'use strict'
52

6-
export default function (customTransforms) {
3+
const eachUrlDecl = require('./eachUrlDecl')
4+
const Result = require('./result')
5+
const mix = require('util-mix')
6+
const getp = require('getp')
7+
8+
module.exports = function (customTransforms) {
79
return function (root, result) {
810
let postcssOpts = result.opts
911
if (!postcssOpts.from) {
@@ -19,17 +21,21 @@ export default function (customTransforms) {
1921
if (i % 2 === 0) {
2022
return Promise.resolve(value)
2123
}
22-
let urlResult = new Result(value, mix({}, postcssOpts, { from: getp(decl, 'source', 'input', 'from') || postcssOpts.from }))
24+
let urlResult = new Result(value, mix(
25+
{},
26+
postcssOpts,
27+
{
28+
from: getp(decl, 'source', 'input', 'from') || postcssOpts.from,
29+
}
30+
))
2331
if (!urlResult.url) {
2432
result.warn(
2533
'postcss-custom-url empty `url()` in ' + postcssOpts.from
2634
)
2735
return Promise.resolve('url()')
2836
}
2937
return urlResult.transform(customTransforms)
30-
.then(function () {
31-
return 'url(' + urlResult.url + ')'
32-
})
38+
.then(() => 'url(' + urlResult.url + ')')
3339
})
3440
)
3541
.then(function (transformedParts) {

lib/eachUrlDecl.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { map as asyncMap } from 'async-array-methods'
1+
'use strict'
22

3-
export default function (root, next) {
3+
const asyncMap = require('async-array-methods').map
4+
5+
module.exports = function (root, next) {
46
let urlDecls = []
57
root.walkDecls(function (decl) {
68
if (decl.value && /\burl\(/.test(decl.value)) {

lib/main.js

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

lib/result.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import Url from 'url'
2-
import path from 'path'
3-
import Asset from './asset'
1+
'use strict'
42

5-
export default class Result {
3+
const Url = require('url')
4+
const path = require('path')
5+
const Asset = require('./asset')
6+
7+
class Result {
68
constructor(url, opts) {
79
this.url = url
810
this.opts = opts
@@ -33,7 +35,7 @@ export default class Result {
3335
transform(customTransforms) {
3436
let trs = []
3537
customTransforms = customTransforms || []
36-
customTransforms.forEach((tr) => {
38+
customTransforms.forEach(tr => {
3739
if (Array.isArray(tr)) {
3840
tr = tr.slice()
3941
tr.splice(1, 0, this)
@@ -74,3 +76,5 @@ export default class Result {
7476
function trim(s) {
7577
return typeof s === 'string' && s.replace(/['"]/g, '').trim()
7678
}
79+
80+
module.exports = Result

lib/util.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import path from 'path'
2-
import fs from 'fs'
3-
import promisify from 'node-promisify'
1+
'use strict'
42

5-
var fsWrite = promisify(fs.writeFile)
6-
var mkdirp = promisify(require('mkdirp'))
3+
const path = require('path')
4+
const fs = require('fs')
5+
const promisify = require('node-promisify')
76

8-
export function rebase(result) {
7+
const fsWrite = promisify(fs.writeFile)
8+
const mkdirp = promisify(require('mkdirp'))
9+
10+
exports.rebase = function (result) {
911
if (result.isRelative()) {
1012
result.url = path.relative(
1113
path.dirname(result.to), result.file
1214
)
1315
}
1416
}
1517

16-
export function inline(result, opts = {}) {
18+
exports.inline = function (result, opts) {
19+
opts = opts || {}
1720
let asset = result.asset
1821
if (!result.isRelative() || !asset.mimeType) {
1922
return
@@ -24,21 +27,19 @@ export function inline(result, opts = {}) {
2427

2528
return asset.size()
2629
.then(function (size) {
27-
if (size >= maxSize) {
28-
return
29-
}
30+
if (size >= maxSize) return
31+
3032
return asset.dataUrl()
3133
.then(function (dataUrl) {
3234
result.url = dataUrl
3335
})
3436
})
3537
}
3638

37-
export function copy(result, opts = {}) {
38-
if (!result.isRelative()) {
39-
return
40-
}
39+
exports.copy = function (result, opts) {
40+
if (!result.isRelative()) return
4141

42+
opts = opts || {}
4243
let assetFolder = opts.assetOutFolder
4344
if (typeof assetFolder === 'function') {
4445
assetFolder = assetFolder(result.file, result.opts)

0 commit comments

Comments
 (0)