Skip to content

Commit b977aae

Browse files
committed
Only clean bin directory when executing npm publish
1 parent 40813b5 commit b977aae

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"build": "scripts/preinstall && scripts/build",
3232
"install": "prebuild-install --download https://github.com/NodeOS/nodeos-cross-toolchain/releases/download/v{version}/{platform}-{arch}.tar.gz || npm run build",
3333
"postinstall": "scripts/postinstall",
34-
"prepublish": "rm -rf bin/*-nodeos-linux-musl-* && truncate --size 0 bin/*",
34+
"prepublish": "scripts/prepublish",
3535
"test": "scripts/test",
3636
"unbuild": "scripts/unbuild"
3737
},

scripts/prepublish

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
5+
6+
const DIR = 'bin'
7+
8+
const bins = Object.keys(require('../package.json').bin)
9+
10+
11+
// http://stackoverflow.com/a/34597104/586382
12+
// NPM will run prepublish script after `npm install` (https://docs.npmjs.com/misc/scripts)
13+
// This ensures that when script is executed using `npm *` it is run only when the command is `npm publish`.
14+
const npm_config_argv = process.env.npm_config_argv
15+
if(npm_config_argv && JSON.parse(npm_config_argv).original[0] === 'publish')
16+
fs.readdir(DIR, function(err, files)
17+
{
18+
if(err) throw err
19+
20+
// Delete all files in the `bin` folder
21+
files.forEach(function(file)
22+
{
23+
fs.unlinkSync(DIR+'/'+file)
24+
})
25+
26+
// Re-create the symlinks stubs
27+
bins.forEach(function(file)
28+
{
29+
fs.writeFileSync(DIR+'/'+file, '')
30+
})
31+
})

0 commit comments

Comments
 (0)