-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZETA-6456: Get package name and version. (#6)
- Loading branch information
1 parent
6d7fc33
commit 7eb65ad
Showing
7 changed files
with
74 additions
and
34 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { getFirstWordOfCommand } from "../utils/word-search"; | ||
import { getFirstWordOfCommand } from "../utils/command-search/command-search"; | ||
import { npmCommandMorph } from "../npm/npm-command-morph"; | ||
import { CommandMorph } from "./command-morph.interface"; | ||
|
||
export function morphCommand(commandText: string): any { | ||
export async function morphCommand(commandText: string): any { | ||
const commandTool = getFirstWordOfCommand(commandText); | ||
switch(commandTool) { | ||
case CommandMorph.npm: | ||
return npmCommandMorph(commandText); | ||
return await npmCommandMorph(commandText); | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { morphCommand } from "../../command-morph/command-morph"; | ||
|
||
describe('npmInstall', () => { | ||
it('should return npm install with needed codemod', () => { | ||
const npmInstallCommandText = 'npm install test'; | ||
const result = morphCommand(npmInstallCommandText); | ||
const expected = 'npm install test'; | ||
it('should return npm install with needed codemod', async() => { | ||
const npmInstallCommandText = 'npm install apollo-angular'; | ||
const result = await morphCommand(npmInstallCommandText); | ||
const expected = 'npm install apollo-angular'; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
// import axios from 'axios'; | ||
import { extractPackageName } from "../../utils/command-search/command-search"; | ||
import { getNameAndVersion } from "../../utils/version/version"; | ||
|
||
export function npmInstallCodemorph(commandText: string): string { | ||
export async function npmInstallCodemorph(commandText: string, stringToUpdate: string): Promise<string> { | ||
const packageName = extractPackageName(commandText); | ||
const {name, version} = await getNameAndVersion(packageName); | ||
console.log('name'); | ||
console.log(name); | ||
console.log('version'); | ||
console.log(version); | ||
return commandText; | ||
} |
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,42 @@ | ||
import { extractPackageName, getFirstWordOfCommand, getSecondWordOfCommand } from "./command-search"; | ||
|
||
describe('WordSearch', () => { | ||
describe('getFirstWordOfCommand', () => { | ||
it('should get the first word of the command tool', () => { | ||
const commandText = 'npm install text'; | ||
const result = getFirstWordOfCommand(commandText); | ||
const expected = 'npm'; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('getSecondWordOfCommand', () => { | ||
it('should get the second word of the command tool', () => { | ||
const commandText = 'npm install text'; | ||
const result = getSecondWordOfCommand(commandText); | ||
const expected = 'install'; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('extractPackageName', () => { | ||
it('should extract the package name from a command', () => { | ||
const sampleCommand = 'npm install apollo-angular'; | ||
const result = extractPackageName(sampleCommand); | ||
expect(result).toEqual('apollo-angular'); | ||
}); | ||
|
||
it('should extract the package name from a command if has semicolon in front of it', () => { | ||
const sampleCommand = 'npm install apollo-angular;'; | ||
const result = extractPackageName(sampleCommand); | ||
expect(result).toEqual('apollo-angular'); | ||
}); | ||
|
||
it('should extract the package name from a command if has version and keep version in tact', () => { | ||
const sampleCommand = 'npm install apollo-angular@^3.0.1;'; | ||
const result = extractPackageName(sampleCommand); | ||
expect(result).toEqual('apollo-angular@^3.0.1'); | ||
}); | ||
}) | ||
|
||
}); |
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 was deleted.
Oops, something went wrong.