-
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.
Merge pull request #4 from tomyitav/deploy-command
Deploy command
- Loading branch information
Showing
7 changed files
with
122 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 +1,8 @@ | ||
import { AbstractCommand } from './abstract-command' | ||
import { Init } from './init' | ||
import { Resolver } from './resolver/resolver' | ||
import { Deploy } from './deploy' | ||
|
||
const allCommands: AbstractCommand[] = [new Init(), new Resolver()] | ||
const allCommands: AbstractCommand[] = [new Init(), new Resolver(), new Deploy()] | ||
|
||
export default allCommands |
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,43 @@ | ||
import { AbstractCommand } from './abstract-command' | ||
import { shell } from '../utils/shell' | ||
import { fileExists } from '../utils/file-operations' | ||
import * as path from 'path' | ||
|
||
export class Deploy extends AbstractCommand { | ||
public getName(): string { | ||
return 'deploy [project-path]' | ||
} | ||
|
||
public getDescription(): string { | ||
return 'Deploy project to production' | ||
} | ||
|
||
public getAlias(): string { | ||
return 'd' | ||
} | ||
|
||
public getAction(): (...args: any[]) => void { | ||
return async (projectPath: string) => { | ||
try { | ||
const pathToAppend = projectPath ? projectPath : '' | ||
const pkgJsonFileExist = await fileExists(path.join(pathToAppend, 'package.json')) | ||
if (!pkgJsonFileExist) { | ||
console.error('No package.json file found, exiting...') | ||
return | ||
} | ||
console.log('Deploying server to production...') | ||
if (pathToAppend !== '') { | ||
process.chdir(pathToAppend) | ||
} | ||
await shell(this.getDeployCommand()) | ||
console.log('Project successfully deployed!') | ||
} catch (err) { | ||
console.error('Got error in deploy command- ', err) | ||
} | ||
} | ||
} | ||
|
||
private getDeployCommand(): string { | ||
return `npm run deploy` | ||
} | ||
} |
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,44 @@ | ||
import { AbstractCommand } from '../../../src/commands/abstract-command' | ||
import { Deploy } from '../../../src/commands/deploy' | ||
import * as path from 'path' | ||
|
||
describe('test for deploy command', () => { | ||
let deploy: AbstractCommand | ||
const pathToProjectDir = './test/commands/deploy/inner-dir' | ||
const pathToProjectNoPackage = './test/commands/deploy/inner-dir-no-package' | ||
const absoluteProcessDir = path.join(process.cwd(), pathToProjectDir) | ||
const absoluteProcessDirNoPackage = path.join(process.cwd(), pathToProjectNoPackage) | ||
|
||
beforeAll(() => { | ||
deploy = new Deploy() | ||
}) | ||
|
||
it('works if action returns a function', () => { | ||
const act = deploy.getAction() | ||
expect(act).toBeInstanceOf(Function) | ||
}) | ||
|
||
it('works if deploy command is executed in directory', async () => { | ||
const act = deploy.getAction() | ||
const spy = jest.spyOn(deploy as any, 'getDeployCommand') | ||
await act(undefined) | ||
expect(spy).toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
|
||
it('works if deploy command is executed with directory path', async () => { | ||
const act = deploy.getAction() | ||
const spy = jest.spyOn(deploy as any, 'getDeployCommand') | ||
await act(absoluteProcessDir) | ||
expect(spy).toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
|
||
it('works if deploy command is not executed when no package.json', async () => { | ||
const act = deploy.getAction() | ||
const spy = jest.spyOn(deploy as any, 'getDeployCommand') | ||
await act(absoluteProcessDirNoPackage) | ||
expect(spy).not.toHaveBeenCalled() | ||
spy.mockRestore() | ||
}) | ||
}) |
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,12 @@ | ||
{ | ||
"name": "packag-json-example", | ||
"version": "1.0.0", | ||
"description": "simple package json example", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"deploy": "echo \"Deploy command will be executed\" " | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,12 @@ | ||
{ | ||
"name": "packag-json-example", | ||
"version": "1.0.0", | ||
"description": "simple package json example", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"deploy": "echo \"Deploy command will be executed\" " | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |