-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 34eb190
Showing
8 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Commenting this out is preferred by some people, see | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
# Users Environment Variables | ||
.lock-wscript | ||
|
||
# Mac shit | ||
.DS_STORE | ||
|
||
# Logs | ||
server/logs/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 ByteMuse | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "cssnextify", | ||
"version": "1.0.0", | ||
"description": "A Browserify transform for css & cssnext", | ||
"main": "src/index.js", | ||
"directories": { | ||
"test": "./node_modules/.bin/mocha tests" | ||
}, | ||
"dependencies": { | ||
"through2": "^2.0.0", | ||
"cssnext": "^1.6.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^10.2.4", | ||
"jsdom": "^3.1.2", | ||
"mocha": "^2.2.5" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ByteMuse/cssnextify.git" | ||
}, | ||
"keywords": [ | ||
"browserify", | ||
"transform", | ||
"css", | ||
"cssnext" | ||
], | ||
"author": "ByteMuse", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ByteMuse/cssnextify/issues" | ||
}, | ||
"homepage": "https://github.com/ByteMuse/cssnextify" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var through = require('through2') | ||
var cssnext = require('cssnext') | ||
|
||
function canCompile(filename) { | ||
return /\.css$/.test(filename) | ||
} | ||
|
||
function compile(data) { | ||
function inject(css) { | ||
var style = document.createElement('style') | ||
style.type = 'text/css' | ||
if(style.styleSheet) { | ||
style.styleSheet.cssText = css | ||
} else { | ||
style.appendChild(document.createTextNode(css)) | ||
} | ||
|
||
document.getElementsByTagName('head')[0].appendChild(style) | ||
} | ||
|
||
var style = cssnext(data) | ||
return '(' + inject + ')(' + JSON.stringify(style) + ')' | ||
} | ||
|
||
module.exports = function(filename) { | ||
if(!canCompile(filename)) { | ||
return through() | ||
} | ||
|
||
var data = '' | ||
function write(chunk, enc, cb) { | ||
data += chunk | ||
cb() | ||
} | ||
|
||
function end(cb) { | ||
this.push(compile(data)) | ||
cb() | ||
} | ||
|
||
return through(write, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function() { | ||
return 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
:root { | ||
--roses: red; | ||
--violets: blue; | ||
--iNeed: #C0FFEE; | ||
} | ||
|
||
body { | ||
background-color: var(--violets); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var assert = require('assert') | ||
var cssnextify = require('../src/index') | ||
var browserify = require('browserify') | ||
var jsdom = require('jsdom') | ||
|
||
describe('#nextify', function() { | ||
it('should skip non-css files', function(done) { | ||
var b = browserify() | ||
b.add(__dirname + '/fixtures/random.js') | ||
b.transform(cssnextify) | ||
b.bundle(function(err, buf) { | ||
assert.equal(err, null) | ||
done() | ||
}) | ||
}) | ||
|
||
it('should compile css input', function(done) { | ||
var b = browserify() | ||
b.add(__dirname + '/fixtures/style.css') | ||
b.transform(cssnextify) | ||
b.bundle(function(err, buf) { | ||
assert.equal(err, null) | ||
var html = '<html><head></head><body></body><script>' + buf.toString() + '</script></html>' | ||
jsdom.env({ | ||
html: html, | ||
features : { | ||
FetchExternalResources : ['script'], | ||
ProcessExternalResources : ['script'] | ||
}, | ||
done: function(err, window) { | ||
assert.equal(err, null) | ||
var bodyStyle = window.getComputedStyle(window.document.body) | ||
assert.equal(bodyStyle.getPropertyValue('background-color'), 'blue') | ||
done() | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |