]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/opener/opener.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / opener / opener.js
1 #!/usr/bin/env node
2
3 "use strict";
4
5 var childProcess = require("child_process");
6
7 function opener(args, options, callback) {
8     // http://stackoverflow.com/q/1480971/3191, but see below for Windows.
9     var command = process.platform === "win32" ? "cmd" :
10                   process.platform === "darwin" ? "open" :
11                   "xdg-open";
12
13     if (typeof args === "string") {
14         args = [args];
15     }
16
17     if (typeof options === "function") {
18         callback = options;
19         options = {};
20     }
21
22     if (options && typeof options === "object" && options.command) {
23         if (process.platform === "win32") {
24             // *always* use cmd on windows
25             args = [options.command].concat(args);
26         } else {
27             command = options.command;
28         }
29     }
30
31     if (process.platform === "win32") {
32         // On Windows, we really want to use the "start" command. But, the rules regarding arguments with spaces, and
33         // escaping them with quotes, can get really arcane. So the easiest way to deal with this is to pass off the
34         // responsibility to "cmd /c", which has that logic built in.
35         //
36         // Furthermore, if "cmd /c" double-quoted the first parameter, then "start" will interpret it as a window title,
37         // so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191
38         //
39         // Additionally, on Windows ampersand needs to be escaped when passed to "start"
40         args = args.map(function(value) {
41             return value.replace(/&/g, '^&');
42         });
43         args = ["/c", "start", '""'].concat(args);
44     }
45
46     return childProcess.execFile(command, args, options, callback);
47 }
48
49 // Export `opener` for programmatic access.
50 // You might use this to e.g. open a website: `opener("http://google.com")`
51 module.exports = opener;
52
53 // If we're being called from the command line, just execute, using the command-line arguments.
54 if (require.main && require.main.id === module.id) {
55     opener(process.argv.slice(2), function (error) {
56         if (error) {
57             throw error;
58         }
59     });
60 }