"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/unlink.js" (8 Mar 2017, 4906 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, Unlink, 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 = Unlink = (function(superClass) {
   19     extend(Unlink, superClass);
   20 
   21     Unlink.commandNames = ['unlink'];
   22 
   23     function Unlink() {
   24       this.devPackagesPath = path.join(config.getAtomDirectory(), 'dev', 'packages');
   25       this.packagesPath = path.join(config.getAtomDirectory(), 'packages');
   26     }
   27 
   28     Unlink.prototype.parseOptions = function(argv) {
   29       var options;
   30       options = yargs(argv).wrap(100);
   31       options.usage("\nUsage: apm unlink [<package_path>]\n\nDelete the symlink in ~/.atom/packages for the package. The package in the\ncurrent working directory is unlinked if no path is given.\n\nRun `apm links` to view all the currently linked packages.");
   32       options.alias('h', 'help').describe('help', 'Print this usage message');
   33       options.alias('d', 'dev').boolean('dev').describe('dev', 'Unlink package from ~/.atom/dev/packages');
   34       options.boolean('hard').describe('hard', 'Unlink package from ~/.atom/packages and ~/.atom/dev/packages');
   35       return options.alias('a', 'all').boolean('all').describe('all', 'Unlink all packages in ~/.atom/packages and ~/.atom/dev/packages');
   36     };
   37 
   38     Unlink.prototype.getDevPackagePath = function(packageName) {
   39       return path.join(this.devPackagesPath, packageName);
   40     };
   41 
   42     Unlink.prototype.getPackagePath = function(packageName) {
   43       return path.join(this.packagesPath, packageName);
   44     };
   45 
   46     Unlink.prototype.unlinkPath = function(pathToUnlink) {
   47       var error, error1;
   48       try {
   49         process.stdout.write("Unlinking " + pathToUnlink + " ");
   50         if (fs.isSymbolicLinkSync(pathToUnlink)) {
   51           fs.unlinkSync(pathToUnlink);
   52         }
   53         return this.logSuccess();
   54       } catch (error1) {
   55         error = error1;
   56         this.logFailure();
   57         throw error;
   58       }
   59     };
   60 
   61     Unlink.prototype.unlinkAll = function(options, callback) {
   62       var child, error, error1, i, j, len, len1, packagePath, ref, ref1;
   63       try {
   64         ref = fs.list(this.devPackagesPath);
   65         for (i = 0, len = ref.length; i < len; i++) {
   66           child = ref[i];
   67           packagePath = path.join(this.devPackagesPath, child);
   68           if (fs.isSymbolicLinkSync(packagePath)) {
   69             this.unlinkPath(packagePath);
   70           }
   71         }
   72         if (!options.argv.dev) {
   73           ref1 = fs.list(this.packagesPath);
   74           for (j = 0, len1 = ref1.length; j < len1; j++) {
   75             child = ref1[j];
   76             packagePath = path.join(this.packagesPath, child);
   77             if (fs.isSymbolicLinkSync(packagePath)) {
   78               this.unlinkPath(packagePath);
   79             }
   80           }
   81         }
   82         return callback();
   83       } catch (error1) {
   84         error = error1;
   85         return callback(error);
   86       }
   87     };
   88 
   89     Unlink.prototype.unlinkPackage = function(options, callback) {
   90       var error, error1, error2, linkPath, packageName, packagePath, ref, ref1, targetPath;
   91       packagePath = (ref = (ref1 = options.argv._[0]) != null ? ref1.toString() : void 0) != null ? ref : '.';
   92       linkPath = path.resolve(process.cwd(), packagePath);
   93       try {
   94         packageName = CSON.readFileSync(CSON.resolve(path.join(linkPath, 'package'))).name;
   95       } catch (undefined) {}
   96       if (!packageName) {
   97         packageName = path.basename(linkPath);
   98       }
   99       if (options.argv.hard) {
  100         try {
  101           this.unlinkPath(this.getDevPackagePath(packageName));
  102           this.unlinkPath(this.getPackagePath(packageName));
  103           return callback();
  104         } catch (error1) {
  105           error = error1;
  106           return callback(error);
  107         }
  108       } else {
  109         if (options.argv.dev) {
  110           targetPath = this.getDevPackagePath(packageName);
  111         } else {
  112           targetPath = this.getPackagePath(packageName);
  113         }
  114         try {
  115           this.unlinkPath(targetPath);
  116           return callback();
  117         } catch (error2) {
  118           error = error2;
  119           return callback(error);
  120         }
  121       }
  122     };
  123 
  124     Unlink.prototype.run = function(options) {
  125       var callback;
  126       callback = options.callback;
  127       options = this.parseOptions(options.commandArgs);
  128       if (options.argv.all) {
  129         return this.unlinkAll(options, callback);
  130       } else {
  131         return this.unlinkPackage(options, callback);
  132       }
  133     };
  134 
  135     return Unlink;
  136 
  137   })(Command);
  138 
  139 }).call(this);