Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-css-rebase

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-css-rebase - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

95

index.js

@@ -9,44 +9,75 @@ 'use strict';

var fs = require('fs');
var merge = require('merge');
var md5 = require('md5');
var fileExists = require('file-exists');
module.exports = function(filePath, publicPrefix){
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
return;
}
module.exports = function (opt) {
var options = merge({
output: null,
exclude: [],
overwrite: false
}, opt);
if (file.isStream()){
return this.emit('error', PluginError('gulp-css-rebase', 'Streaming not supported'));
}
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
return;
}
var adjusted = adjust(file);
file.contents = new Buffer(adjusted);
if (file.isStream()) {
return this.emit('error', PluginError('gulp-css-rebase', 'Streaming not supported'));
}
cb(null, file);
});
var adjusted = adjust(file);
file.contents = new Buffer(adjusted);
function adjust(file){
var css = file.contents.toString();
cb(null, file);
});
return rework(css)
.use(url(function(url) {
if(!/^(data|\/|\w+:\/\/)/.test(url)){
var assetPath = path.join(path.dirname(file.path), url);
var assetFolder = path.basename(path.dirname(assetPath))
var newPath = path.join(filePath, assetFolder, path.basename(assetPath)).replace(/[\#|\?].*$/, '');
function adjust(file) {
var css = file.contents.toString();
mkpath(path.dirname(newPath), function(err) {
if (err) {
throw err;
}
return rework(css)
.use(url(function (url) {
if (!/^(data|\/|\w+:\/\/)/.test(url)) {
var assetPath = path.join(path.dirname(file.path), url);
var assetFolder = md5(path.relative(process.cwd(), path.dirname(assetPath)));
var IsExclude = false;
fs.createReadStream(assetPath.replace(/[\#|\?].*$/, '')).pipe(fs.createWriteStream(newPath));
});
for (var index in options.exclude) {
if (options.exclude[index] === assetPath.substr(0, options.exclude[index].length)) {
IsExclude = true;
break;
}
}
url = path.normalize(path.join(publicPrefix, assetFolder, path.basename(assetPath))).replace(/\\/g, '/');
}
var newPath = !IsExclude
? path.normalize(path.join(options.output, assetFolder, path.basename(assetPath)))
: path.normalize(assetPath)
;
return url;
}))
.toString();
}
if (
(!IsExclude && !fileExists(newPath))
||
(!IsExclude && options.overwrite)
) {
mkpath(path.dirname(newPath), function (err) {
if (err) {
throw err;
}
fs
.createReadStream(assetPath.replace(/[\#|\?].*$/, ''))
.pipe(fs.createWriteStream(newPath.replace(/[\#|\?].*$/, '')))
;
});
}
url = path.relative(options.output, newPath);
}
return url;
}))
.toString();
}
};
{
"name": "gulp-css-rebase",
"version": "1.0.0",
"description": "",
"version": "2.0.0",
"description": "Rewrite url references in CSS and copyed CSS assets",
"main": "index.js",
"dependencies": {
"file-exists": "^2.0.0",
"fs": "0.0.1-security",
"md5": "^2.2.1",
"merge": "^1.2.0",
"mkpath": "^1.0.0",

@@ -31,6 +34,8 @@ "path": "^0.12.7",

"gulp",
"gulpplugin",
"css",
"url",
"rebase"
"rebase",
"rewrite"
]
}
# gulp-css-rebase
A [gulp](http://gulpjs.com/) plugin that allows rewriting url references in CSS
## Install

@@ -15,7 +17,13 @@

var webPath = '.', outputPath = 'dest';
var outputPath = 'dest';
gulp.task('default', () =>
gulp.src('src/*.css')
.pipe(rebase(outputPath, webPath))
.pipe(rebase({
output: outputPath,
exclude: [
'path/to/web/dir'
],
overwrite: false
}))
.pipe(gulp.dest(outputPath))

@@ -25,1 +33,5 @@ );

### Options
- `output` - The target directory for the processed CSS. Paths are rewritten relatively to that directory.
- `exclude` - Paths are rewritten relatively to original path.
- `overwrite` - Overwrite files
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc