-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the
postinstall
script during packaging
- Loading branch information
1 parent
49752ed
commit 0c0c045
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var fsExtra = require('fs-extra'); | ||
var path = require('path'); | ||
|
||
var cachePath = path.join(__dirname, 'pack-cache.txt'); | ||
var packageJsonPath = path.join(__dirname, '../package.json'); | ||
|
||
var packageJson = fsExtra.readJsonSync(packageJsonPath); | ||
|
||
//store the script and remove it from package.json | ||
if (process.argv.includes('--pre')) { | ||
fsExtra.outputFileSync(cachePath, packageJson.scripts.postinstall); | ||
delete packageJson.scripts.postinstall; | ||
|
||
//restore the script | ||
} else if (process.argv.includes('--post')) { | ||
packageJson.scripts.postinstall = fsExtra.readFileSync(cachePath, packageJson.scripts.postinstall).toString(); | ||
fsExtra.removeSync(cachePath); | ||
} | ||
|
||
fsExtra.outputJsonSync(packageJsonPath, packageJson, { spaces: 4 }); |