Sha256: 2497a074dfd2924b1b64b9184d42d386ab3c2e1d67932d3234e547144d135f03

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

var fs = require('fs');
var path = require('path');
var common = require('./common');
var os = require('os');

//@
//@ ### ln(options, source, dest)
//@ ### ln(source, dest)
//@ Available options:
//@
//@ + `s`: symlink
//@ + `f`: force
//@
//@ Examples:
//@
//@ ```javascript
//@ ln('file', 'newlink');
//@ ln('-sf', 'file', 'existing');
//@ ```
//@
//@ Links source to dest. Use -f to force the link, should dest already exist.
function _ln(options, source, dest) {
  options = common.parseOptions(options, {
    's': 'symlink',
    'f': 'force'
  });

  if (!source || !dest) {
    common.error('Missing <source> and/or <dest>');
  }

  source = path.resolve(process.cwd(), String(source));
  dest = path.resolve(process.cwd(), String(dest));

  if (!fs.existsSync(source)) {
    common.error('Source file does not exist', true);
  }

  if (fs.existsSync(dest)) {
    if (!options.force) {
      common.error('Destination file exists', true);
    }

    fs.unlinkSync(dest);
  }

  if (options.symlink) {
    fs.symlinkSync(source, dest, os.platform() === "win32" ? "junction" : null);
  } else {
    fs.linkSync(source, dest, os.platform() === "win32" ? "junction" : null);
  }
}
module.exports = _ln;

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/shelljs/src/ln.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/shelljs/src/ln.js
exercism-analysis-0.1.1 vendor/javascript/node_modules/jshint/node_modules/shelljs/src/ln.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/shelljs/src/ln.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/shelljs/src/ln.js
trans-0.5.10 template/node_modules/shelljs/src/ln.js
trans-0.5.9 template/node_modules/shelljs/src/ln.js