"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/develop.js" (8 Mar 2017, 6065 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 Command, Develop, Install, Link, _, async, config, fs, git, path, request, 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     slice = [].slice;
    6 
    7   fs = require('fs');
    8 
    9   path = require('path');
   10 
   11   _ = require('underscore-plus');
   12 
   13   async = require('async');
   14 
   15   yargs = require('yargs');
   16 
   17   config = require('./apm');
   18 
   19   Command = require('./command');
   20 
   21   Install = require('./install');
   22 
   23   git = require('./git');
   24 
   25   Link = require('./link');
   26 
   27   request = require('./request');
   28 
   29   module.exports = Develop = (function(superClass) {
   30     extend(Develop, superClass);
   31 
   32     Develop.commandNames = ['dev', 'develop'];
   33 
   34     function Develop() {
   35       this.atomDirectory = config.getAtomDirectory();
   36       this.atomDevPackagesDirectory = path.join(this.atomDirectory, 'dev', 'packages');
   37     }
   38 
   39     Develop.prototype.parseOptions = function(argv) {
   40       var options;
   41       options = yargs(argv).wrap(100);
   42       options.usage("Usage: apm develop <package_name> [<directory>]\n\nClone the given package's Git repository to the directory specified,\ninstall its dependencies, and link it for development to\n~/.atom/dev/packages/<package_name>.\n\nIf no directory is specified then the repository is cloned to\n~/github/<package_name>. The default folder to clone packages into can\nbe overridden using the ATOM_REPOS_HOME environment variable.\n\nOnce this command completes you can open a dev window from atom using\ncmd-shift-o to run the package out of the newly cloned repository.");
   43       return options.alias('h', 'help').describe('help', 'Print this usage message');
   44     };
   45 
   46     Develop.prototype.getRepositoryUrl = function(packageName, callback) {
   47       var requestSettings;
   48       requestSettings = {
   49         url: (config.getAtomPackagesUrl()) + "/" + packageName,
   50         json: true
   51       };
   52       return request.get(requestSettings, function(error, response, body) {
   53         var message, repositoryUrl;
   54         if (body == null) {
   55           body = {};
   56         }
   57         if (error != null) {
   58           return callback("Request for package information failed: " + error.message);
   59         } else if (response.statusCode === 200) {
   60           if (repositoryUrl = body.repository.url) {
   61             return callback(null, repositoryUrl);
   62           } else {
   63             return callback("No repository URL found for package: " + packageName);
   64           }
   65         } else {
   66           message = request.getErrorMessage(response, body);
   67           return callback("Request for package information failed: " + message);
   68         }
   69       });
   70     };
   71 
   72     Develop.prototype.cloneRepository = function(repoUrl, packageDirectory, options, callback) {
   73       if (callback == null) {
   74         callback = function() {};
   75       }
   76       return config.getSetting('git', (function(_this) {
   77         return function(command) {
   78           var args;
   79           if (command == null) {
   80             command = 'git';
   81           }
   82           args = ['clone', '--recursive', repoUrl, packageDirectory];
   83           if (!options.argv.json) {
   84             process.stdout.write("Cloning " + repoUrl + " ");
   85           }
   86           git.addGitToEnv(process.env);
   87           return _this.spawn(command, args, function() {
   88             var args;
   89             args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
   90             if (options.argv.json) {
   91               return _this.logCommandResultsIfFail.apply(_this, [callback].concat(slice.call(args)));
   92             } else {
   93               return _this.logCommandResults.apply(_this, [callback].concat(slice.call(args)));
   94             }
   95           });
   96         };
   97       })(this));
   98     };
   99 
  100     Develop.prototype.installDependencies = function(packageDirectory, options, callback) {
  101       var installOptions;
  102       if (callback == null) {
  103         callback = function() {};
  104       }
  105       process.chdir(packageDirectory);
  106       installOptions = _.clone(options);
  107       installOptions.callback = callback;
  108       return new Install().run(installOptions);
  109     };
  110 
  111     Develop.prototype.linkPackage = function(packageDirectory, options, callback) {
  112       var linkOptions;
  113       linkOptions = _.clone(options);
  114       if (callback) {
  115         linkOptions.callback = callback;
  116       }
  117       linkOptions.commandArgs = [packageDirectory, '--dev'];
  118       return new Link().run(linkOptions);
  119     };
  120 
  121     Develop.prototype.run = function(options) {
  122       var packageDirectory, packageName, ref;
  123       packageName = options.commandArgs.shift();
  124       if (!((packageName != null ? packageName.length : void 0) > 0)) {
  125         return options.callback("Missing required package name");
  126       }
  127       packageDirectory = (ref = options.commandArgs.shift()) != null ? ref : path.join(config.getReposDirectory(), packageName);
  128       packageDirectory = path.resolve(packageDirectory);
  129       if (fs.existsSync(packageDirectory)) {
  130         return this.linkPackage(packageDirectory, options);
  131       } else {
  132         return this.getRepositoryUrl(packageName, (function(_this) {
  133           return function(error, repoUrl) {
  134             var tasks;
  135             if (error != null) {
  136               return options.callback(error);
  137             } else {
  138               tasks = [];
  139               tasks.push(function(callback) {
  140                 return _this.cloneRepository(repoUrl, packageDirectory, options, callback);
  141               });
  142               tasks.push(function(callback) {
  143                 return _this.installDependencies(packageDirectory, options, callback);
  144               });
  145               tasks.push(function(callback) {
  146                 return _this.linkPackage(packageDirectory, options, callback);
  147               });
  148               return async.waterfall(tasks, options.callback);
  149             }
  150           };
  151         })(this));
  152       }
  153     };
  154 
  155     return Develop;
  156 
  157   })(Command);
  158 
  159 }).call(this);