|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -// Reset the generic bin symlinks before publishing to npm sothey point to the |
4 | | -// native platform libraries |
| 3 | +/** |
| 4 | + * Reset the generic bin symlinks before publishing to npm so they point to the |
| 5 | + * native platform libraries |
| 6 | + */ |
5 | 7 |
|
6 | 8 | const fs = require('fs') |
7 | 9 |
|
8 | 10 |
|
9 | | -const DIR = 'bin' |
10 | | -const bins = Object.keys(require('../package.json').bin) |
11 | | -const bypass = fs.readFileSync('bypass.js') |
12 | | - |
13 | | - |
14 | 11 | // http://stackoverflow.com/a/34597104/586382 |
15 | 12 | // By design, NPM will run prepublish script after `npm install` (see |
16 | 13 | // [npm docs](https://docs.npmjs.com/misc/scripts)) |
17 | 14 | // This trick ensures that when script is executed using `npm <whatever>` it is |
18 | 15 | // run only when the command is `npm publish`. |
19 | 16 | const npm_config_argv = process.env.npm_config_argv |
20 | | -if(npm_config_argv && JSON.parse(npm_config_argv).original[0] === 'publish') |
| 17 | +if(npm_config_argv && JSON.parse(npm_config_argv).original[0] === 'publish' |
| 18 | +|| process.argv[2] === '--force') |
| 19 | +{ |
| 20 | + const DIR = 'bin' |
| 21 | + |
21 | 22 | fs.mkdir(DIR, function(err) |
22 | 23 | { |
23 | 24 | if(err && err.code !== 'EEXIST') throw err |
24 | 25 |
|
25 | | - // Re-create the symlinks stubs |
26 | | - bins.forEach(function(file) |
| 26 | + fs.readFile('bypass.js', function(err, bypass) |
27 | 27 | { |
28 | | - fs.writeFileSync(DIR+'/'+file, bypass, {mode: 0o755}) |
| 28 | + if(err) throw err |
| 29 | + |
| 30 | + // Re-create the symlinks stubs |
| 31 | + Object.keys(require('../package.json').bin).forEach(function(file) |
| 32 | + { |
| 33 | + fs.writeFileSync(DIR+'/'+file, bypass, {mode: 0o755}) |
| 34 | + }) |
29 | 35 | }) |
30 | 36 | }) |
| 37 | +} |
0 commit comments