Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
feat: add skip flag
Browse files Browse the repository at this point in the history
  • Loading branch information
arantespp committed Jun 14, 2021
1 parent 4fd8b40 commit 215dba1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import AWS from 'aws-sdk';
import * as faker from 'faker';

import { cloudFormation } from './deploy/cloudFormation.core';

const region = 'us-east-1';

const optionsFromConfigFiles = {
Expand Down Expand Up @@ -58,6 +60,7 @@ test('set AWS region', async () => {
const argv = await parse(`print-args --region=${region}`, {});
expect(argv.region).toEqual(region);
expect(AWS.config.region).toEqual(region);
expect(await cloudFormation().config.region()).toEqual(region);
});

describe('environment type', () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
readObjectFile,
} from './utils';

const coerce = (env: EnvironmentVariables) => (value: any) => {
const coerceSetEnvVar = (env: EnvironmentVariables) => (value: any) => {
if (value) {
setEnvVar(env, value);
}
Expand All @@ -28,7 +28,7 @@ const coerce = (env: EnvironmentVariables) => (value: any) => {

export const options = {
branch: {
coerce: coerce('BRANCH'),
coerce: coerceSetEnvVar('BRANCH'),
require: false,
type: 'string',
},
Expand All @@ -41,17 +41,18 @@ export const options = {
},
environment: {
alias: ['e', 'env'],
coerce: coerce('ENVIRONMENT'),
coerce: coerceSetEnvVar('ENVIRONMENT'),
type: 'string',
},
environments: {},
project: {
coerce: coerce('PROJECT'),
coerce: coerceSetEnvVar('PROJECT'),
require: false,
type: 'string',
},
region: {
alias: 'r',
coerce: coerceSetEnvVar('REGION'),
default: AWS_DEFAULT_REGION,
describe: 'AWS region.',
type: 'string',
Expand Down
31 changes: 31 additions & 0 deletions packages/cli/src/deploy/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ const parse = (command: string, options: any = {}) =>
});
});

describe('testing skip-deploy flag', () => {
const mockExit = jest
.spyOn(process, 'exit')
.mockImplementation(() => null as never);

afterAll(() => {
mockExit.mockRestore();
});

beforeEach(() => {
mockExit.mockReset();
});

test('should skip deploy', async () => {
await parse('deploy', { skipDeploy: true });
expect(mockExit).toHaveBeenCalled();
});

test('should not skip deploy', async () => {
await parse('deploy', {
skipDeploy: false,
environments: {
Production: {
skipDeploy: true,
},
},
});
expect(mockExit).not.toHaveBeenCalled();
});
});

describe('stack name and cache', () => {
beforeEach(() => {
setPreDefinedStackName('');
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/deploy/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export const options = {
'A list of parameters that will be passed to CloudFormation Parameters when deploying. The format is the same as parameters from cloudformation create-stack CLI command.',
type: 'array',
},
'skip-deploy': {
alias: 'skip',
default: false,
describe: 'Skip deploy.',
type: 'boolean',
},
'stack-name': {
describe: 'CloudFormation Stack name.',
type: 'string',
Expand Down Expand Up @@ -176,6 +182,15 @@ export const deployCommand: CommandModule<
}
},
)
.middleware(({ skipDeploy }) => {
if (skipDeploy) {
log.error(
logPrefix,
'Skip deploy flag is true, then the deploy command was stopped.',
);
process.exit();
}
})
.command(deployLambdaLayerCommand)
.command(describeDeployCommand)
.command(deployBaseStackCommand)
Expand Down
12 changes: 12 additions & 0 deletions packages/website/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ function Feature({ imageUrl, title, description }) {
function Home() {
const context = useDocusaurusContext();
const { siteConfig = {} } = context;

const redirectTo = useBaseUrl('/docs');

React.useEffect(() => {
window.location.href = redirectTo;
}, [redirectTo]);

if (redirectTo) {
return null;
}

return (
<Layout
title={`Hello from ${siteConfig.title}`}
Expand All @@ -72,6 +83,7 @@ function Home() {
'button button--outline button--secondary button--lg',
styles.getStarted,
)}
// eslint-disable-next-line react-hooks/rules-of-hooks
to={useBaseUrl('docs/')}
>
Get Started
Expand Down

0 comments on commit 215dba1

Please sign in to comment.