@@ -0,0 +1,46 @@
1+#!/usr/bin/env node
2+
3+var child_process = require('child_process');
4+var path = require('path');
5+var fs = require('fs');
6+
7+
8+// Some npm users enable --ignore-scripts (a good security measure)
9+// They do not run the post-install hook, so install.js does not run.
10+//
11+// On Mac and Linux, we download the elm executable into the exact same
12+// location as this file. Since npm uses symlinks on these platforms,
13+// that means that the first run will invoke this file and subsequent
14+// runs will call the elm binary directly.
15+//
16+// On Windows, we must download a file named elm.exe for it to run properly.
17+// Instead of symlinks, they create two files:
18+//
19+// - node_modules/.bin/elm (a bash file)
20+// - node_modules/.bin/elm.cmd (a batch file)
21+//
22+// Both files specifically invoke `node` to run the file listed at package.bin,
23+// so there is no way around instantiating node for no reason on Windows. So
24+// the existsSync check is needed so that it is not downloaded more than once.
25+
26+
27+// figure out where to put the binary (calls path.resolve() to get path separators right on Windows)
28+//
29+var binaryPath = path.resolve(__dirname, package.bin) + (process.platform === 'win32' ? '.exe' : '');
30+
31+// Run the command directly if possible, otherwise download and then run.
32+// This check is important for Windows where this file will be run all the time.
33+//
34+fs.existsSync(binaryPath)
35+ ? runCommand()
36+ : require('../download.js')(runCommand);
37+
38+
39+function runCommand()
40+{
41+ // Need double quotes and { shell: true } when there are spaces in the path on windows:
42+ // https://github.com/nodejs/node/issues/7367#issuecomment-229721296
43+ child_process
44+ .spawn('"' + binaryPath + '"', process.argv.slice(2), { stdio: 'inherit', shell: true })
45+ .on('exit', process.exit);
46+}