-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from js-spider/master
add uninstall hooks #57
- Loading branch information
Showing
4 changed files
with
3,071 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ lib-cov | |
*.out | ||
*.pid | ||
*.gz | ||
|
||
.idea/** | ||
pids | ||
logs | ||
results | ||
|
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,45 @@ | ||
#!/usr/bin/env node | ||
|
||
const { cleanRegistry } = require('./cli') | ||
|
||
function preuninstall(){ | ||
if(ifNeedClean()){ | ||
console.log('preuninstall run success : clean .nrmrc info') | ||
return cleanRegistry(); | ||
}; | ||
console.log('preuninstall run success : keep .nrmrc info') | ||
process.exit(); | ||
} | ||
|
||
function ifNeedClean(){ | ||
if(process.env.npm_config_clean){ | ||
return true | ||
}else{ | ||
const envArgv = process.env.npm_config_argv || '{"original":[]}'; | ||
const envOriginal = JSON.parse(envArgv).original; | ||
return envOriginal.includes('-C') | ||
} | ||
} | ||
|
||
function isLocalDebug(argv){ | ||
let debugTarget = null; | ||
argv.forEach(item=>{ | ||
// use node hooks.js --LocalDebugging=preuninstall | ||
if(item.startsWith('--LocalDebugging=')){ | ||
debugTarget = item.split('=')[1] | ||
} | ||
}) | ||
return debugTarget; | ||
} | ||
|
||
|
||
function run (argv) { | ||
const target = isLocalDebug(argv) || process.env.npm_lifecycle_event; | ||
switch(target){ | ||
case 'preuninstall': | ||
preuninstall(argv);break; | ||
default: process.exit(0) | ||
} | ||
} | ||
|
||
run(process.argv.slice(2)); |
Oops, something went wrong.