Add and run removeNPMAbsolutePaths
This commit is contained in:
parent
a76042ab4a
commit
256c63a715
712 changed files with 13722 additions and 18895 deletions
51
node_modules/removeNPMAbsolutePaths/src/cli.js
generated
vendored
Normal file
51
node_modules/removeNPMAbsolutePaths/src/cli.js
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
const defaultOpts = {
|
||||
force: false,
|
||||
};
|
||||
|
||||
function parseArguments(args) {
|
||||
if (args.length < 1) {
|
||||
throw new Error('Missing path.\nThe first argument should be the path to a directory or a package.json file.');
|
||||
}
|
||||
|
||||
const path = args[0];
|
||||
const opts = { ...defaultOpts };
|
||||
|
||||
const ignored = [];
|
||||
|
||||
for (let i = 1; i < args.length; i += 1) {
|
||||
const arg = args[i];
|
||||
switch (arg) {
|
||||
case '--force':
|
||||
opts.force = true;
|
||||
break;
|
||||
case '--fields':
|
||||
if (opts.fields) {
|
||||
throw new Error('Duplicated argument: --fields.\nThe --fields flag has been detected twice.');
|
||||
}
|
||||
|
||||
opts.fields = [];
|
||||
while (args[i + 1] && args[i + 1].slice(0, 2) !== '--') {
|
||||
opts.fields.push(args[i += 1]);
|
||||
}
|
||||
|
||||
if (opts.fields && opts.fields.length === 0) {
|
||||
throw new Error('Invalid argument usage: --fields.\nThe --fields flag should be followed by the specific fields that should be removed but none was found.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ignored.push(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
path,
|
||||
opts,
|
||||
ignored,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.defaultOpts = defaultOpts;
|
||||
module.exports.parseArguments = parseArguments;
|
||||
Loading…
Add table
Add a link
Reference in a new issue