"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/link.js" (7 Feb 2017, 2814 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var CSON, Command, Link, config, fs, path, yargs,
    3     extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    4     hasProp = {}.hasOwnProperty;
    5 
    6   path = require('path');
    7 
    8   CSON = require('season');
    9 
   10   yargs = require('yargs');
   11 
   12   Command = require('./command');
   13 
   14   config = require('./apm');
   15 
   16   fs = require('./fs');
   17 
   18   module.exports = Link = (function(superClass) {
   19     extend(Link, superClass);
   20 
   21     function Link() {
   22       return Link.__super__.constructor.apply(this, arguments);
   23     }
   24 
   25     Link.commandNames = ['link', 'ln'];
   26 
   27     Link.prototype.parseOptions = function(argv) {
   28       var options;
   29       options = yargs(argv).wrap(100);
   30       options.usage("\nUsage: apm link [<package_path>]\n\nCreate a symlink for the package in ~/.atom/packages. The package in the\ncurrent working directory is linked if no path is given.\n\nRun `apm links` to view all the currently linked packages.");
   31       options.alias('h', 'help').describe('help', 'Print this usage message');
   32       return options.alias('d', 'dev').boolean('dev').describe('dev', 'Link to ~/.atom/dev/packages');
   33     };
   34 
   35     Link.prototype.run = function(options) {
   36       var callback, error, error1, linkPath, packageName, packagePath, ref, ref1, targetPath;
   37       callback = options.callback;
   38       options = this.parseOptions(options.commandArgs);
   39       packagePath = (ref = (ref1 = options.argv._[0]) != null ? ref1.toString() : void 0) != null ? ref : '.';
   40       linkPath = path.resolve(process.cwd(), packagePath);
   41       try {
   42         packageName = CSON.readFileSync(CSON.resolve(path.join(linkPath, 'package'))).name;
   43       } catch (undefined) {}
   44       if (!packageName) {
   45         packageName = path.basename(linkPath);
   46       }
   47       if (options.argv.dev) {
   48         targetPath = path.join(config.getAtomDirectory(), 'dev', 'packages', packageName);
   49       } else {
   50         targetPath = path.join(config.getAtomDirectory(), 'packages', packageName);
   51       }
   52       if (!fs.existsSync(linkPath)) {
   53         callback("Package directory does not exist: " + linkPath);
   54         return;
   55       }
   56       try {
   57         if (fs.isSymbolicLinkSync(targetPath)) {
   58           fs.unlinkSync(targetPath);
   59         }
   60         fs.makeTreeSync(path.dirname(targetPath));
   61         fs.symlinkSync(linkPath, targetPath, 'junction');
   62         console.log(targetPath + " -> " + linkPath);
   63         return callback();
   64       } catch (error1) {
   65         error = error1;
   66         return callback("Linking " + targetPath + " to " + linkPath + " failed: " + error.message);
   67       }
   68     };
   69 
   70     return Link;
   71 
   72   })(Command);
   73 
   74 }).call(this);