Skip to content

Commit

Permalink
feat(generators): add mixin method for symlinking files within `this.…
Browse files Browse the repository at this point in the history
…destinationRoot()`
  • Loading branch information
cueedee committed Aug 26, 2016
1 parent d974ed4 commit 07b4afa
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

'use strict';

var _ = require( 'lodash' );
var _ = require( 'lodash' )
, fsCore = require( 'fs' )
, path = require( 'path' )
;

module.exports =
{
Expand Down Expand Up @@ -124,5 +127,45 @@ module.exports =
method.apply( fs, args );
}
}

,
/**
* Make a symbolic link within `#destinationRoot()`.
*
* @method _symLink
*
* @param {String} src The path relative to `#destinationRoot()` that should become the target of the symbolic link.
* @param {String} dst The path relative to `#destinationRoot()` that should become the symbolic link.
*
*/

_symLink: function ( src, dst )
{
src = this.destinationPath( src );
dst = this.destinationPath( dst );

this.conflicter.checkForCollision(

dst
, this.read( src )
, function ( err, status ) {

if ( 'identical' === status ) return;

// The symlink may exist, but may link to a nonexistent file in which case `status` will be `'create'`, so try unlinking it anyway.
//
try
{
fsCore.unlinkSync( dst );
}
catch ( error )
{
if ( 'ENOENT' !== error.code ) throw error;
}

fsCore.symlinkSync( path.relative( path.dirname( dst ), src ), dst );
}
);
}
}
;

0 comments on commit 07b4afa

Please sign in to comment.