"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/apm.js" (8 Mar 2017, 5752 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 child_process, fs, npm, path, semver;
    3 
    4   child_process = require('child_process');
    5 
    6   fs = require('./fs');
    7 
    8   path = require('path');
    9 
   10   npm = require('npm');
   11 
   12   semver = require('semver');
   13 
   14   module.exports = {
   15     getHomeDirectory: function() {
   16       if (process.platform === 'win32') {
   17         return process.env.USERPROFILE;
   18       } else {
   19         return process.env.HOME;
   20       }
   21     },
   22     getAtomDirectory: function() {
   23       var ref;
   24       return (ref = process.env.ATOM_HOME) != null ? ref : path.join(this.getHomeDirectory(), '.atom');
   25     },
   26     getCacheDirectory: function() {
   27       return path.join(this.getAtomDirectory(), '.apm');
   28     },
   29     getResourcePath: function(callback) {
   30       var apmFolder, appFolder, appLocation, asarPath;
   31       if (process.env.ATOM_RESOURCE_PATH) {
   32         return process.nextTick(function() {
   33           return callback(process.env.ATOM_RESOURCE_PATH);
   34         });
   35       }
   36       apmFolder = path.resolve(__dirname, '..');
   37       appFolder = path.dirname(apmFolder);
   38       if (path.basename(apmFolder) === 'apm' && path.basename(appFolder) === 'app') {
   39         asarPath = appFolder + ".asar";
   40         if (fs.existsSync(asarPath)) {
   41           return process.nextTick(function() {
   42             return callback(asarPath);
   43           });
   44         }
   45       }
   46       apmFolder = path.resolve(__dirname, '..', '..', '..');
   47       appFolder = path.dirname(apmFolder);
   48       if (path.basename(apmFolder) === 'apm' && path.basename(appFolder) === 'app') {
   49         asarPath = appFolder + ".asar";
   50         if (fs.existsSync(asarPath)) {
   51           return process.nextTick(function() {
   52             return callback(asarPath);
   53           });
   54         }
   55       }
   56       switch (process.platform) {
   57         case 'darwin':
   58           return child_process.exec('mdfind "kMDItemCFBundleIdentifier == \'com.github.atom\'"', function(error, stdout, stderr) {
   59             var appLocation;
   60             if (stdout == null) {
   61               stdout = '';
   62             }
   63             if (!error) {
   64               appLocation = stdout.split('\n')[0];
   65             }
   66             if (!appLocation) {
   67               appLocation = '/Applications/Atom.app';
   68             }
   69             return callback(appLocation + "/Contents/Resources/app.asar");
   70           });
   71         case 'linux':
   72           appLocation = '/usr/local/share/atom/resources/app.asar';
   73           if (!fs.existsSync(appLocation)) {
   74             appLocation = '/usr/share/atom/resources/app.asar';
   75           }
   76           return process.nextTick(function() {
   77             return callback(appLocation);
   78           });
   79         case 'win32':
   80           return process.nextTick(function() {
   81             var programFilesPath;
   82             programFilesPath = path.join(process.env.ProgramFiles, 'Atom', 'resources', 'app.asar');
   83             return callback(programFilesPath);
   84           });
   85       }
   86     },
   87     getReposDirectory: function() {
   88       var ref;
   89       return (ref = process.env.ATOM_REPOS_HOME) != null ? ref : path.join(this.getHomeDirectory(), 'github');
   90     },
   91     getElectronUrl: function() {
   92       var ref;
   93       return (ref = process.env.ATOM_ELECTRON_URL) != null ? ref : 'https://atom.io/download/atom-shell';
   94     },
   95     getAtomPackagesUrl: function() {
   96       var ref;
   97       return (ref = process.env.ATOM_PACKAGES_URL) != null ? ref : (this.getAtomApiUrl()) + "/packages";
   98     },
   99     getAtomApiUrl: function() {
  100       var ref;
  101       return (ref = process.env.ATOM_API_URL) != null ? ref : 'https://atom.io/api';
  102     },
  103     getElectronArch: function() {
  104       switch (process.platform) {
  105         case 'darwin':
  106           return 'x64';
  107         case 'win32':
  108           return 'ia32';
  109         default:
  110           return process.arch;
  111       }
  112     },
  113     getUserConfigPath: function() {
  114       return path.resolve(this.getAtomDirectory(), '.apmrc');
  115     },
  116     getGlobalConfigPath: function() {
  117       return path.resolve(this.getAtomDirectory(), '.apm', '.apmrc');
  118     },
  119     isWin32: function() {
  120       return process.platform === 'win32';
  121     },
  122     isWindows64Bit: function() {
  123       return fs.existsSync("C:\\Windows\\SysWow64\\Notepad.exe");
  124     },
  125     x86ProgramFilesDirectory: function() {
  126       return process.env["ProgramFiles(x86)"] || process.env["ProgramFiles"];
  127     },
  128     getInstalledVisualStudioFlag: function() {
  129       if (!this.isWin32()) {
  130         return null;
  131       }
  132       if (process.env.GYP_MSVS_VERSION) {
  133         return process.env.GYP_MSVS_VERSION;
  134       }
  135       if (this.visualStudioIsInstalled("14.0")) {
  136         return '2015';
  137       }
  138       if (this.visualStudioIsInstalled("12.0")) {
  139         return '2013';
  140       }
  141       if (this.visualStudioIsInstalled("11.0")) {
  142         return '2012';
  143       }
  144       if (this.visualStudioIsInstalled("10.0")) {
  145         return '2010';
  146       }
  147     },
  148     visualStudioIsInstalled: function(version) {
  149       return fs.existsSync(path.join(this.x86ProgramFilesDirectory(), "Microsoft Visual Studio " + version, "Common7", "IDE"));
  150     },
  151     loadNpm: function(callback) {
  152       var npmOptions;
  153       npmOptions = {
  154         userconfig: this.getUserConfigPath(),
  155         globalconfig: this.getGlobalConfigPath()
  156       };
  157       return npm.load(npmOptions, function() {
  158         return callback(null, npm);
  159       });
  160     },
  161     getSetting: function(key, callback) {
  162       return this.loadNpm(function() {
  163         return callback(npm.config.get(key));
  164       });
  165     },
  166     setupApmRcFile: function() {
  167       try {
  168         return fs.writeFileSync(this.getGlobalConfigPath(), "; This file is auto-generated and should not be edited since any\n; modifications will be lost the next time any apm command is run.\n;\n; You should instead edit your .apmrc config located in ~/.atom/.apmrc\ncache = " + (this.getCacheDirectory()) + "\n; Hide progress-bar to prevent npm from altering apm console output.\nprogress = false");
  169       } catch (undefined) {}
  170     }
  171   };
  172 
  173 }).call(this);