grunt-symlink
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -5,5 +5,7 @@ module.exports = function(grunt) { | ||
symlink: { | ||
links: [ | ||
{ link: 'test/symlinks/images', to: '../images', type: 'dir' } | ||
] | ||
images: { | ||
dest: 'test/symlinks/images', | ||
relativeSrc: '../images', | ||
options: {type: 'dir'} | ||
} | ||
}, | ||
@@ -31,3 +33,3 @@ | ||
grunt.loadTasks('tasks'); | ||
grunt.registerTask('test', ['mocha']); | ||
grunt.registerTask('test', ['symlink', 'mocha']); | ||
}; |
{ | ||
"name": "grunt-symlink", | ||
"description": "Create symlinks", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/geddesign/grunt-symlink", | ||
@@ -33,3 +33,3 @@ "author": { | ||
"devDependencies": { | ||
"grunt": "~0.4.0a" | ||
"grunt": "0.4.x" | ||
}, | ||
@@ -36,0 +36,0 @@ "keywords": [ |
@@ -23,18 +23,22 @@ # grunt-symlink | ||
symlink: { | ||
links: [ | ||
{ link: 'path/to/new/symlink', to: '../path/to/original', type: 'dir'} | ||
] | ||
images: { | ||
dest: 'path/to/new/symlink', | ||
relativeSrc: '../path/to/original', | ||
options: {type: 'dir'} // 'file' by default | ||
} | ||
} | ||
``` | ||
**Important**: `link` is relative to your project's root directory, but `to` is relative to `link`. For example: | ||
**Important**: `dest` is relative to your project's root directory, but `relativeSrc` is relative to `dest`. For example: | ||
```js | ||
symlinks: { | ||
links: [ | ||
{ link: 'frontend-build/videos', to '../videos'} | ||
] | ||
symlink: { | ||
images: { | ||
dest: 'frontend-build/videos', | ||
relativeSrc: '../videos', | ||
options: {type: 'dir'} | ||
} | ||
} | ||
``` | ||
So in this case `grunt-symlink` will create a new symlink at `myproject/frontend-build/videos` that points to `myproject/videos`, because `to` in this case is relative to the `frontend-build` directory. | ||
So in this case `grunt-symlink` will create a new symlink at `myproject/frontend-build/videos` that points to `myproject/videos`, because `relativeSrc` in this case is relative to the `frontend-build` directory. | ||
@@ -41,0 +45,0 @@ `type` can either be `dir`, `file` (default), or `junction`. See [Node docs on symlinks](http://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback). |
@@ -9,21 +9,26 @@ /* | ||
var fs = require('fs'); | ||
var fs = require('fs'); | ||
module.exports = function(grunt) { | ||
grunt.registerTask('symlink', 'Create symlinks.', function() { | ||
var links = grunt.config.get("symlink.links"); | ||
links.forEach(function(link){ | ||
try{ | ||
fs.symlinkSync(link.to, link.link, link.type || 'file'); | ||
var rel = link.link.substr(0, link.link.lastIndexOf('/') + 1); | ||
grunt.log.ok('created symlink at ' + link.link + | ||
' that points to ' + link.to + | ||
' (relative to ' + rel +')' | ||
); | ||
grunt.registerMultiTask('symlink', 'Create symlinks.', function() { | ||
var options = this.options(); | ||
var src = this.file.relativeSrc; | ||
var dest = this.file.dest; | ||
try{ | ||
console.log('dest', dest); | ||
console.log('src', src); | ||
fs.symlinkSync(src, dest, options.type || 'file'); | ||
var rel = dest.substr(0, dest.lastIndexOf('/') + 1); | ||
grunt.log.ok('created symlink at ' + dest + | ||
' that points to ' + src + | ||
' (relative to ' + rel +')' | ||
); | ||
} | ||
catch(e){ | ||
if (e.code === 'EEXIST'){ | ||
return grunt.log.error(dest + ' already exists, skipping'); | ||
} | ||
catch(e){ | ||
if (e.code === 'EEXIST') grunt.log.error(link.link + ' already exists, skipping'); | ||
} | ||
}); | ||
grunt.fail.warn(e); | ||
} | ||
}); | ||
}; |
@@ -12,3 +12,8 @@ /* | ||
after(function(){ | ||
fs.unlinkSync(linkPath); | ||
}); | ||
it('creates symlinks based on links config', function(){ | ||
fs.existsSync(linkPath).should.be.true; | ||
fs.lstatSync(linkPath).isSymbolicLink().should.be.true; | ||
@@ -19,8 +24,3 @@ }); | ||
fs.existsSync(linkPath + '/cat.jpeg').should.be.true; | ||
}); | ||
afterEach(function(){ | ||
try{ fs.unlinkSync(linkPath); } | ||
catch(e){} | ||
}); | ||
}); |
24971
78
52