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

grunt-lib-contrib

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-lib-contrib - npm Package Compare versions

Comparing version 0.4.0 to 0.5.1

.jshintrc

145

lib/contrib.js

@@ -14,61 +14,4 @@ /*

// TODO: ditch this when grunt v0.4 is released
grunt.util = grunt.util || grunt.utils;
var path = require('path');
// TODO: remove if/when we officially drop node <= 0.7.9
path.sep = path.sep || path.normalize('/');
exports.buildIndividualDest = function(dest, srcFile, basePath, flatten) {
dest = path.normalize(dest);
srcFile = path.normalize(srcFile);
var newDest = path.dirname(dest);
var newName = path.basename(srcFile, path.extname(srcFile)) + path.extname(dest);
var relative = path.dirname(srcFile);
if (flatten) {
relative = '';
} else if (basePath && basePath.length >= 1) {
relative = grunt.util._(relative).strRight(basePath).trim(path.sep);
}
// make paths outside grunts working dir relative
relative = relative.replace(/\.\.(\/|\\)/g, '');
return path.join(newDest, relative, newName);
};
exports.findBasePath = function(srcFiles, basePath) {
if (basePath === false) {
return '';
}
if (grunt.util.kindOf(basePath) === 'string' && basePath.length >= 1) {
return grunt.util._(path.normalize(basePath)).trim(path.sep);
}
var foundPath;
var basePaths = [];
var dirName;
srcFiles.forEach(function(srcFile) {
srcFile = path.normalize(srcFile);
dirName = path.dirname(srcFile);
basePaths.push(dirName.split(path.sep));
});
basePaths = grunt.util._.intersection.apply([], basePaths);
foundPath = path.join.apply(path, basePaths);
if (foundPath === '.') {
foundPath = '';
}
return foundPath;
};
exports.getNamespaceDeclaration = function(ns) {

@@ -93,80 +36,2 @@ var output = [];

exports.isIndividualDest = function(dest) {
if (grunt.util._.startsWith(path.basename(dest), '*')) {
return true;
} else {
return false;
}
};
// TODO: ditch this when grunt v0.4 is released
// Temporary helper for normalizing files object
exports.normalizeMultiTaskFiles = function(data, target) {
var prop, obj;
var files = [];
if (grunt.util.kindOf(data) === 'object') {
if ('src' in data || 'dest' in data) {
obj = {};
if ('src' in data) { obj.src = data.src; }
if ('dest' in data) { obj.dest = data.dest; }
files.push(obj);
} else if (grunt.util.kindOf(data.files) === 'object') {
for (prop in data.files) {
files.push({src: data.files[prop], dest: prop});
}
} else if (Array.isArray(data.files)) {
data.files.forEach(function(obj) {
var prop;
if ('src' in obj || 'dest' in obj) {
files.push(obj);
} else {
for (prop in obj) {
files.push({src: obj[prop], dest: prop});
}
}
});
}
} else {
files.push({src: data, dest: target});
}
// Process each normalized file object as a template.
files.forEach(function(obj) {
// Process src as a template (recursively, if necessary).
if ('src' in obj) {
obj.src = grunt.util.recurse(obj.src, function(src) {
if (typeof src !== 'string') { return src; }
return grunt.template.process(src);
});
}
if ('dest' in obj) {
// Process dest as a template.
obj.dest = grunt.template.process(obj.dest);
}
});
return files;
};
// Helper for consistent options key access across contrib tasks.
exports.options = function(data, defaults) {
var global_target = data.target ? grunt.config(['options', data.name, data.target]) : null;
var global_task = grunt.config(['options', data.name]);
if (global_task || global_target) {
grunt.fail.warn('root level [options] key will be unsupported in grunt v0.4. please consider using task and target options.');
}
var target = data.target ? grunt.config([data.name, data.target, 'options']) : null;
var task = grunt.config([data.name, 'options']);
var options = grunt.util._.defaults({}, target, task, global_target, global_task, defaults);
return grunt.util.recurse(options, function(value) {
if (typeof value !== 'string') { return value; }
return grunt.template.process(value);
});
};
// Convert an object to an array of CLI arguments

@@ -217,3 +82,13 @@ exports.optsToArgs = function(options) {

// Log min and max info
function minMaxGzip(src) {
return src ? require('gzip-js').zip(src, {}) : '';
}
exports.minMaxInfo = function(min, max) {
var gzipSize = String(minMaxGzip(min).length);
grunt.log.writeln('Uncompressed size: ' + String(max.length).green + ' bytes.');
grunt.log.writeln('Compressed size: ' + gzipSize.green + ' bytes gzipped (' + String(min.length).green + ' bytes minified).');
};
return exports;
};
{
"name": "grunt-lib-contrib",
"description": "Common functionality shared across grunt-contrib tasks.",
"version": "0.4.0",
"version": "0.5.1",
"homepage": "http://github.com/gruntjs/grunt-lib-contrib",

@@ -24,3 +24,3 @@ "author": {

"engines": {
"node": ">= 0.6.0"
"node": ">= 0.8.0"
},

@@ -31,5 +31,10 @@ "scripts": {

"devDependencies": {
"grunt": "~0.3.15"
"grunt-contrib-jshint": "~0.1.1rc5",
"grunt-contrib-nodeunit": "~0.1.2rc5",
"grunt": "~0.4.0rc5"
},
"main": "lib/contrib"
"main": "lib/contrib",
"dependencies": {
"gzip-js": "~0.3.1"
}
}

@@ -13,10 +13,2 @@ # grunt-lib-contrib [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-lib-contrib.png?branch=master)](http://travis-ci.org/gruntjs/grunt-lib-contrib)

#### buildIndividualDest(dest, srcFile, basePath, flatten)
This helper is used to build a destination filepath for tasks supporting individual compiling.
#### findBasePath(srcFiles)
This helper is used to take an array of filepaths and find the common base directory.
#### getNamespaceDeclaration(ns)

@@ -26,16 +18,2 @@

#### isIndividualDest(dest)
This helper is used to detect if a destination filepath triggers individual compiling.
#### normalizeMultiTaskFiles(data, target)
This helper is a (temporary) shim to handle multi-task `files` object in the same way grunt v0.4 does.
#### options(data, defaults)
This helper is on its way out as grunt v0.4 adds an options helper to the task api. This new helper only supports task and target options (no root level options key) so you should start adjusting your tasks now to be ready for the v0.4 release.
Contrib tasks are in the process of being updated to check for the new helper first.
#### optsToArgs(options)

@@ -60,4 +38,19 @@

#### minMaxInfo(min, max)
Helper for logging compressed and uncompressed sizes of strings.
```js
var max = grunt.file.read('max.js');
var min = minify(max);
minMaxInfo(min, max);
// Will print:
// Uncompressed size: 108 bytes.
// Compressed size: 82 bytes gzipped (76 bytes minified).
```
--
*Lib submitted by [Tyler Kellen](https://goingslowly.com/).*

@@ -5,22 +5,2 @@ var grunt = require('grunt');

exports.lib = {
findBasePath: function(test) {
'use strict';
var path = require('path');
test.expect(3);
var actual = helper.findBasePath(['dir1/dir2/dir3/file.ext', 'dir1/dir2/another.ext', 'dir1/dir2/dir3/dir4/file.ext']);
var expected = path.normalize('dir1/dir2');
test.equal(expected, actual, 'should detect basePath from array of filepaths.');
actual = helper.findBasePath(['dir1/dir2/dir3/file.ext', 'dir1/dir2/another.ext', 'file.ext'], 'dir1');
expected = 'dir1';
test.equal(expected, actual, 'should default to passed basePath if valid');
actual = helper.findBasePath(['.dir1/dir2', '.dir1/dir2/another.ext', '.dir1/dir2/dir3/dir4/file.ext', 'file.ext']);
expected = '';
test.equal(expected, actual, 'should return empty string if foundPath is a single dot (helps with dotfiles)');
test.done();
},
getNamespaceDeclaration: function(test) {

@@ -81,31 +61,2 @@ 'use strict';

},
options: function(test) {
'use strict';
test.expect(5);
var options = helper.options({name: 'test_task', target: 'target'}, {required: 'default'});
var actual = options.param;
var expected = 'target';
test.equal(expected, actual, 'should allow target options key to override task');
actual = options.param2;
expected = 'task';
test.equal(expected, actual, 'should set default task options that can be overriden by target options');
actual = options.required;
expected = 'default';
test.equal(expected, actual, 'should allow task to define default values');
actual = options.template;
expected = 'source/';
test.equal(expected, actual, 'should automatically process template vars');
actual = options.data.template;
expected = 'source/';
test.equal(expected, actual, 'should process template vars recursively');
test.done();
},
optsToArgs: function(test) {

@@ -152,3 +103,28 @@ 'use strict';

test.done();
},
minMaxInfo: function(test) {
'use strict';
test.expect(1);
var max = '1234567890';
var min = '12345';
var actual = '';
var expected = [
'Uncompressed size: 10 bytes.',
'Compressed size: 25 bytes gzipped (5 bytes minified).'
].join(grunt.util.linefeed) + grunt.util.linefeed;
grunt.util.hooker.hook(grunt.log, 'writeln', {
pre: function(result) {
actual += grunt.log.uncolor(result) + grunt.util.linefeed;
return grunt.util.hooker.preempt();
}
});
helper.minMaxInfo(min, max);
grunt.util.hooker.unhook(grunt.log, 'writeln');
test.equal(expected, actual, 'should have logged min and max info.');
test.done();
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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