New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-contrib-symlink

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-contrib-symlink - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

.jshintrc

53

package.json
{
"name": "grunt-contrib-symlink",
"description": "Create a symlink between paths",
"version": "0.1.1",
"homepage": "https://github.com/mintbridge/grunt-contrib-symlink",
"description": "Create symbolic links.",
"version": "0.2.0",
"homepage": "https://github.com/gruntjs/grunt-contrib-symlink",
"author": {
"name": "Paul Dixon",
"email": "paul.dixon@mintbridge.co.uk"
"name": "Grunt Team",
"url": "http://gruntjs.com/"
},
"repository": {
"type": "git",
"url": "git://github.com/mintbridge/grunt-contrib-symlink.git"
"url": "git://github.com/gruntjs/grunt-contrib-symlink.git"
},
"bugs": {
"url": "https://github.com/mintbridge/grunt-contrib-symlink/issues"
"url": "https://github.com/gruntjs/grunt-contrib-symlink/issues"
},

@@ -20,8 +20,8 @@ "licenses": [

"type": "MIT",
"url": "https://github.com/mintbridge/grunt-contrib-symlink/blob/master/LICENSE-MIT"
"url": "https://github.com/gruntjs/grunt-contrib-symlink/blob/master/LICENSE-MIT"
}
],
"main": "grunt.js",
"main": "Gruntfile.js",
"engines": {
"node": "*"
"node": ">= 0.8.0"
},

@@ -31,25 +31,20 @@ "scripts": {

},
"dependencies": {
"grunt-lib-contrib": "~0.3.0",
"mkdirp": "~0.3.1",
"rimraf": "~2.0.3"
},
"devDependencies": {
"grunt": "~0.3.15",
"grunt-contrib-clean": "~0.3.0"
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-internal": "~0.4.5",
"grunt": "~0.4.1"
},
"peerDependencies": {
"grunt": "~0.4.1"
},
"keywords": [
"gruntplugin",
"symlink"
],
"contributors": [
"Paul Dixon <paul.dixon@mintbridge.co.uk>"
],
"readmeFilename": "README.md",
"gitHead": "497ad9393733117588b7cc687135227c0ff5ad0e",
"directories": {
"doc": "docs",
"test": "test"
},
"license": "BSD"
"file",
"link",
"copy",
"symlink",
"symbolic"
]
}

@@ -1,81 +0,82 @@

# grunt-contrib-symlink [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-symlink.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-symlink)
# grunt-contrib-symlink
Create symlinks between files/directories
> Create symbolic links.
## Overview
This task can be used to create symlinks between files/directories in your project. It is a multitask and so can
be used to create multiple links.
### Getting Started
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-contrib-symlink`
## Getting Started
This plugin requires Grunt `~0.4.1`
Then add this line to your project's `grunt.js` gruntfile:
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```javascript
grunt.loadNpmTasks('grunt-contrib-symlink');
```shell
npm install grunt-contrib-symlink --save-dev
```
### Usage
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
Inside your `grunt.js` file add a section named `symlink`. This section specifies the target and link path, and optionally any options you want to use. Once the section has been added you can run the task with `grunt symlink`.
```js
grunt.loadNpmTasks('grunt-contrib-symlink');
```
### Parameters
#### target ```string```
Path to the file/directory you want to link to. Paths will be relative to the grunt.js file unless an absolute path is used.
#### link ```string```
## Symlink task
_Run this task with the `grunt symlink` command._
Path to the new file/directory link location. Paths will be relative to the grunt.js file unless an absolute path is used.
Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. Pay special attention to the [Building the files object dynamically](http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically) section, which explains how to create many src-dest file mappings all at once.
#### type ```string```
Note that the symlink mode (file, dir) is determined automatically based on the src file type.
#### options ```object```
### Usage Examples
A hash of options to configure the symlink and tasks behaviour
##### overwrite ```boolean```
Choose whether or not to overwrite existing symlink/files, default is false.
##### force ```boolean```
Force can be used to create the directory structure for the link path if it has not previously been
created, default is false
##### type ```boolean```
To specifically set the type of symlink to be created, default type will be inferred from
the target type. Values can be 'dir', 'file', or 'junction'. see [node.js - fs][node_symlink] for more info
#### Usage Examples
```javascript
```js
symlink: {
docroot: {
target: 'path/to/target',
link: path/to/link
// The "build/target.txt" symlink will be created and linked to
// "source/target.txt". It should appear like this in a file listing:
// build/target.txt -> ../source/target.txt
explicit: {
src: 'source/target.txt',
dest: 'build/target.txt'
},
another: {
target: 'path/to/target',
link: path/to/link,
options: {
overwrite: true,
force: true
}
}
// These examples using "expand" to generate src-dest file mappings:
// http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
expanded: {
files: [
// All child files and directories in "source", starting with "foo-" will
// be symlinked into the "build" directory, with the leading "source"
// stripped off.
{
expand: true,
cwd: 'source',
src: ['foo-*'],
dest: 'build'
},
// All child directories in "source" will be symlinked into the "build"
// directory, with the leading "source" stripped off.
{
expand: true,
cwd: 'source',
src: ['*'],
dest: 'build',
filter: 'isDirectory'
}
]
},
}
```
## Release History
* 2012-12-20   v0.1.0   Initial Release
--
*Task submitted by [Paul Dixon](http://www.mintbridge.co.uk/).*
* 2013-07-26   v0.2.0   Initial release as rewritten, officially-maintained, contrib plugin.
* 2012-12-21   v0.1.1   Unofficial release.
* 2012-12-20   v0.1.0   Unofficial release.
[grunt]: https://github.com/gruntjs/grunt
[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md
[node_symlink]: http://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback
---
Task submitted by ["Cowboy" Ben Alman](http://benalman.com/)
*This file was generated on Mon Jul 29 2013 12:12:23.*
/*
* grunt-contrib-symlink
* http://gruntjs.com/
* https://github.com/gruntjs/grunt-contrib-symlink
*
* Copyright (c) 2012 Paul Dixon, contributors
* Copyright (c) 2013 Grunt Team
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
'use strict';
// TODO: ditch this when grunt v0.4 is released
grunt.util = grunt.util || grunt.utils;
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
grunt.registerMultiTask('symlink', 'Create a symlink between paths', function() {
var helpers = require('grunt-lib-contrib').init(grunt);
var options = helpers.options(this, {
overwrite: false,
force: false,
type: 'file'
});
var target;
var link;
var linkDir;
var type;
var relative;
var depth;
grunt.verbose.writeflags(options, 'Options');
// TODO: ditch this when grunt v0.4 is released
this.files = helpers.normalizeMultiTaskFiles(this.data, this.target);
target = path.normalize(this.data.target);
link = path.normalize(this.data.link);
linkDir = path.dirname(link);
if (target.length === 0) {
grunt.fail.warn('Unable to compile; no valid target was found.');
}
// does the src exist?
if (fs.existsSync(target)) {
type = fs.statSync(target).isFile() ? 'file' : 'dir';
}
// does the destination already exist?
if (fs.existsSync(link)) {
// replace it?
if ( ! options.overwrite) {
grunt.fail.warn('A file or directory already exists at ' + link);
grunt.registerMultiTask('symlink', 'Create symbolic links.', function() {
var nowrite = grunt.option('no-write');
var linkCount = 0;
this.files.forEach(function(f) {
var srcpath = f.src[0];
var destpath = f.dest;
if (!grunt.file.exists(srcpath)) {
grunt.log.warn('Source file "' + srcpath + '" not found.');
return;
} else if (grunt.file.exists(destpath)) {
grunt.log.warn('Destination ' + destpath + ' already exists.');
return;
}
else {
// delete the current file
require("rimraf").sync(link);
// Strip any trailing slashes.
destpath = destpath.replace(/[\\\/]$/, '');
// The destdir is the location in which the symlink will be created.
var destdir = path.join(destpath, '..');
// If the dest path is relative, create a proper relative symlink path.
if (!grunt.file.isPathAbsolute(srcpath)) {
srcpath = path.relative(destdir, srcpath);
}
}
// does the parent diectory exist?
if ( ! fs.existsSync(linkDir)) {
// create it?
if ( ! options.force) {
grunt.fail.warn('The destination directory ' + link + ' does not exist');
// Create any necessary interim directories.
grunt.file.mkdir(destdir);
// The symlink mode is determined automatically.
var mode = grunt.file.isDir(f.src[0]) ? 'dir' : 'file';
grunt.verbose.write((nowrite ? 'Not actually linking ' : 'Linking ') + '(' + mode + ') ' + destpath + ' -> ' + srcpath + '...');
try {
if (!nowrite) {
fs.symlinkSync(srcpath, destpath, mode);
}
grunt.verbose.ok();
} catch(e) {
grunt.verbose.error();
}
else {
grunt.verbose.or.write('Creating directory ' + linkDir.cyan + '...');
mkdirp.sync(linkDir);
grunt.verbose.or.ok();
}
}
grunt.verbose.or.write('Creating symlink to ' + target.cyan + ' at ' + link.cyan + '...');
fs.symlinkSync(target, link, type);
grunt.verbose.or.ok();
linkCount++;
});
grunt.log.ok('Created ' + linkCount + ' symbolic links.');
});
};

@@ -0,71 +1,59 @@

'use strict';
var grunt = require('grunt');
var fs = require('fs');
exports.symlink = {
single: function(test) {
'use strict';
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
test.expect(1);
Test methods:
test.expect(numAssertions)
test.done()
Test assertions:
test.ok(value, [message])
test.equal(actual, expected, [message])
test.notEqual(actual, expected, [message])
test.deepEqual(actual, expected, [message])
test.notDeepEqual(actual, expected, [message])
test.strictEqual(actual, expected, [message])
test.notStrictEqual(actual, expected, [message])
test.throws(block, [error], [message])
test.doesNotThrow(block, [error], [message])
test.ifError(value)
*/
var actual = grunt.file.read('single.js');
var expected = grunt.file.read('test/fixtures/single.js');
test.equal(expected, actual, 'should allow for a single file symlink to be created');
test.done();
},
singleOverwrite: function(test) {
'use strict';
exports.symlink = {
explicit: function(test) {
test.expect(1);
var actual = grunt.file.read('single2.js');
var expected = grunt.file.read('test/fixtures/single2.js');
test.equal(expected, actual, 'should allow for a single file symlink to be overwriten');
test.equal(grunt.file.read('tmp/baz.txt'), 'baz!', 'should be the fixture file.');
test.done();
},
directory: function(test) {
'use strict';
dirs: function(test) {
test.expect(2);
test.expect(1);
test.equal(grunt.file.read('tmp/dirs/test/fixtures/foo/file.txt'), 'foo!', 'should be the fixture file.');
test.equal(grunt.file.read('tmp/dirs/test/fixtures/bar/file.txt'), 'bar!', 'should be the fixture file.');
var actual = fs.readdirSync('folder_one').sort();
var expected = fs.readdirSync('test/fixtures/folder_one').sort();
test.deepEqual(expected, actual, 'should allow for a directory symlink to be created');
test.done();
},
directoryOverwrite: function(test) {
'use strict';
files: function(test) {
test.expect(2);
test.expect(1);
test.equal(grunt.file.read('tmp/files/test/fixtures/baz.txt'), 'baz!', 'should be the fixture file.');
test.equal(grunt.file.read('tmp/files/test/fixtures/qux.txt'), 'qux!', 'should be the fixture file.');
var actual = fs.readdirSync('folder_two').sort();
var expected = fs.readdirSync('test/fixtures/folder_two').sort();
test.deepEqual(expected, actual, 'should allow for a directory symlink to be overwriten');
test.done();
},
singleInNewDirectory: function(test) {
'use strict';
cwd: function(test) {
test.expect(4);
test.expect(1);
test.equal(grunt.file.read('tmp/cwd/foo/file.txt'), 'foo!', 'should be the fixture file.');
test.equal(grunt.file.read('tmp/cwd/bar/file.txt'), 'bar!', 'should be the fixture file.');
test.equal(grunt.file.read('tmp/cwd/baz.txt'), 'baz!', 'should be the fixture file.');
test.equal(grunt.file.read('tmp/cwd/qux.txt'), 'qux!', 'should be the fixture file.');
var actual = grunt.file.read('tmp/single.js');
var expected = grunt.file.read('test/fixtures/single.js');
test.equal(expected, actual, 'should allow for a single file symlink to be created in a new directory');
test.done();
},
directoryInNewDirectory: function(test) {
'use strict';
test.expect(1);
var actual = fs.readdirSync('tmp/test/folder_one').sort();
var expected = fs.readdirSync('test/fixtures/folder_one').sort();
test.deepEqual(expected, actual, 'should allow for a directory symlink to be created');
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

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