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
private mapNpmCommand(command: string, packagesDevExact: string[], | |
packagesDevInexact: string[], packagesDepExact: string[], packagesDepInexact: string[], | |
packagesDepUn: string[], packagesDevUn: string[]): void { | |
const npmReduceRegex: RegExp = /npm\s+(i|un)\s+([\w\d\@\/\.-]+)\s+(-D|-S)?\s?(-E)?/gm; | |
const npmReduceMatch: RegExpExecArray | null = npmReduceRegex.exec(command); | |
const packageNameGroupId: number = 2; | |
const installCommandGroupId: number = 1; | |
const dependencyCategoryGroupId: number = 3; | |
const exactGroupId: number = 4; | |
if (npmReduceMatch) { | |
if (npmReduceMatch[dependencyCategoryGroupId] === '-S') { | |
if (npmReduceMatch[exactGroupId] === '-E') { | |
packagesDepExact.push(npmReduceMatch[packageNameGroupId]); | |
} else if (npmReduceMatch[installCommandGroupId] === 'i') { | |
packagesDepInexact.push(npmReduceMatch[packageNameGroupId]); | |
} else { | |
packagesDepUn.push(npmReduceMatch[packageNameGroupId]); | |
} | |
} else if (npmReduceMatch[dependencyCategoryGroupId] === '-D') { | |
if (npmReduceMatch[exactGroupId] === '-E') { | |
packagesDevExact.push(npmReduceMatch[packageNameGroupId]); | |
} else if (npmReduceMatch[installCommandGroupId] === 'i') { | |
packagesDevInexact.push(npmReduceMatch[packageNameGroupId]); | |
} else { | |
packagesDevUn.push(npmReduceMatch[packageNameGroupId]); | |
} | |
} | |
} | |
} | |
private reduceNpmCommand(commandsToExecute: string[], packagesDevExact: string[], | |
packagesDevInexact: string[], packagesDepExact: string[], packagesDepInexact: string[], | |
packagesDepUn: string[], packagesDevUn: string[]): void { | |
if (packagesDepExact.length > 0) { | |
commandsToExecute.push(`npm i ${packagesDepExact.join(' ')} -S -E`); | |
} | |
if (packagesDevExact.length > 0) { | |
commandsToExecute.push(`npm i ${packagesDevExact.join(' ')} -D -E`); | |
} | |
if (packagesDepInexact.length > 0) { | |
commandsToExecute.push(`npm i ${packagesDepInexact.join(' ')} -S`); | |
} | |
if (packagesDevInexact.length > 0) { | |
commandsToExecute.push(`npm i ${packagesDevInexact.join(' ')} -D`); | |
} | |
if (packagesDepUn.length > 0) { | |
commandsToExecute.push(`npm un ${packagesDepUn.join(' ')} -S`); | |
} | |
if (packagesDevUn.length > 0) { | |
commandsToExecute.push(`npm un ${packagesDevUn.join(' ')} -D`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment