-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commands): Add 'upgrade-packages' command
- Loading branch information
Showing
5 changed files
with
162 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,77 @@ | ||
import { GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core"; | ||
import { TemplateManager } from "../TemplateManager"; | ||
|
||
let command: { | ||
[name: string]: any, | ||
templateManager: TemplateManager, | ||
execute: (argv: any) => Promise<void>, | ||
upgrade: (argv: any) => Promise<void> | ||
}; | ||
|
||
// tslint:disable:object-literal-sort-keys | ||
command = { | ||
command: "upgrade-packages", | ||
desc: "upgrades Ignite UI Packages", | ||
templateManager: null, | ||
builder: { | ||
"skip-install": { | ||
alias: "si", | ||
default: false, | ||
describe: "Runs upgrade command without performing install", | ||
type: "boolean" | ||
} | ||
}, | ||
async execute(argv) { | ||
|
||
GoogleAnalytics.post({ | ||
t: "screenview", | ||
cd: "Upgrade packages" | ||
}); | ||
|
||
return command.upgrade(argv); | ||
}, | ||
async upgrade(argv) { | ||
const config = ProjectConfig.getConfig(); | ||
const framework = config.project.framework; | ||
const projectType = config.project.projectType; | ||
|
||
switch (framework.toLowerCase()) { | ||
case "jquery": | ||
Util.log("Upgrading packages for jQuery projects is currently not supported!"); | ||
return; | ||
case "react": | ||
Util.log("Upgrading packages for React projects is currently not supported!"); | ||
return; | ||
case "angular": | ||
if (projectType === "igx-ts") { | ||
const projectLibrary = command.templateManager.getProjectLibrary(framework, projectType); | ||
let project; | ||
if (!config.project.projectTemplate) { | ||
// in case project template is missing from the config we provide backward. | ||
project = projectLibrary.getProject(projectLibrary.projectIds[0]); | ||
} else { | ||
project = projectLibrary.getProject(config.project.projectTemplate); | ||
} | ||
const success = await project.upgradeIgniteUIPackages(process.cwd(), ""); | ||
if (success && !argv.skipInstall) { | ||
Util.execSync("npm install"); | ||
} | ||
} else { | ||
Util.log("Upgrading packages for Angular Wrappers projects is currently not supported!"); | ||
return; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
GoogleAnalytics.post({ | ||
t: "event", | ||
ec: "$ig upgrade-packages", | ||
cd1: framework, | ||
cd2: projectType | ||
}); | ||
} | ||
}; | ||
|
||
export default command; |
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
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,76 @@ | ||
import { | ||
BaseTemplateManager, Config, GoogleAnalytics, PackageManager, ProjectConfig, ProjectLibrary, ProjectTemplate, Util | ||
} from "@igniteui/cli-core"; | ||
|
||
import { default as upgradeCmd } from "../../packages/cli/lib/commands/upgrade"; | ||
|
||
describe("Unit - Upgrade command", () => { | ||
beforeAll(() => { | ||
spyOn(GoogleAnalytics, "post"); | ||
}); | ||
|
||
beforeEach(() => { | ||
spyOn(Util, "log"); | ||
spyOn(process, "chdir"); | ||
spyOn(Util, "execSync"); | ||
spyOn(PackageManager, "installPackages"); | ||
}); | ||
|
||
it("Upgrade an Ignite UI for Angular project", async done => { | ||
// tslint:disable-next-line: no-object-literal-type-assertion | ||
const config: Config = { | ||
project: { | ||
framework: "angular", | ||
projectTemplate: "test-template", | ||
projectType: "igx-ts" | ||
} | ||
} as Config; | ||
spyOn(ProjectConfig, "getConfig").and.returnValue(config); | ||
|
||
const mockProject: Partial<ProjectTemplate> = { | ||
upgradeIgniteUIPackages: () => null | ||
}; | ||
const mockProjLib: Partial<ProjectLibrary> = { getProject: () => null }; | ||
const mockTemplateManager: Partial<BaseTemplateManager> = { getProjectLibrary: () => null }; | ||
upgradeCmd.templateManager = mockTemplateManager as any; | ||
spyOn(mockTemplateManager, "getProjectLibrary").and.returnValue(mockProjLib); | ||
spyOn(mockProjLib, "getProject").and.returnValue(mockProject); | ||
const upgradeIgniteUIPackagesSpy = spyOn(mockProject, "upgradeIgniteUIPackages"); | ||
|
||
upgradeIgniteUIPackagesSpy.and.returnValue(Promise.resolve(true)); | ||
await upgradeCmd.execute({ skipInstall: true }); | ||
expect(mockTemplateManager.getProjectLibrary).toHaveBeenCalledTimes(1); | ||
expect(mockTemplateManager.getProjectLibrary) | ||
.toHaveBeenCalledWith(config.project.framework, config.project.projectType); | ||
expect(mockProjLib.getProject).toHaveBeenCalledWith(config.project.projectTemplate); | ||
expect(mockProject.upgradeIgniteUIPackages).toHaveBeenCalledTimes(1); | ||
expect(mockProject.upgradeIgniteUIPackages).toHaveBeenCalledWith(process.cwd(), ""); | ||
expect(Util.execSync).not.toHaveBeenCalled(); | ||
|
||
upgradeIgniteUIPackagesSpy.and.returnValue(Promise.resolve(false)); | ||
await upgradeCmd.execute({ skipInstall: false }); | ||
expect(mockProject.upgradeIgniteUIPackages).toHaveBeenCalledTimes(2); | ||
expect(Util.execSync).not.toHaveBeenCalled(); | ||
|
||
upgradeIgniteUIPackagesSpy.and.returnValue(Promise.resolve(true)); | ||
await upgradeCmd.execute({ skipInstall: false }); | ||
expect(mockProject.upgradeIgniteUIPackages).toHaveBeenCalledTimes(3); | ||
expect(Util.execSync).toHaveBeenCalledWith("npm install"); | ||
|
||
done(); | ||
}); | ||
|
||
it("Logs error for not supported framework", async done => { | ||
// tslint:disable-next-line: no-object-literal-type-assertion | ||
const config: Config = { | ||
project: { | ||
framework: "jquery" | ||
} | ||
} as Config; | ||
spyOn(ProjectConfig, "getConfig").and.returnValue(config); | ||
|
||
await upgradeCmd.execute({}); | ||
expect(Util.log).toHaveBeenCalledTimes(1); | ||
done(); | ||
}); | ||
}); |