Permalink
Browse files

cleanups and adds no-shadow eslint rule

  • Loading branch information...
Simone Lusenti
Simone Lusenti committed Mar 3, 2017
1 parent 9c9d3f5 commit 80d5b2d44d01e4cc7e648c0ce0aacd4774265e54
Showing with 129 additions and 91 deletions.
  1. +2 −1 .eslintrc
  2. +69 −53 src/commands/deploy.js
  3. +3 −3 src/commands/log.js
  4. +4 −4 src/commands/proxy.js
  5. +51 −30 src/libs/createBundle.js
View
@@ -6,6 +6,7 @@
],
"rules": {
"no-template-curly-in-string": 0,
"object-curly-spacing": [1, "always"]
"object-curly-spacing": [1, "always"],
"no-shadow": 2
}
}
View
@@ -58,85 +58,101 @@ async function taskRestoreStackPolicy ({ dangerDeleteResources, stackName }) {
}
}
export async function deploy ({
appStage,
dangerDeleteResources = false,
skipAcmCertificate = false,
verbose = false,
skipChmod = false,
skipCloudformation = false
}) {
const {
API_DEFINITIONS,
SETTINGS,
APP_NAME,
PROJECT_ROOT,
getCloudFrontSettings,
getHostedZoneId
} = loadConfig();
const cloudfrontStagesMap = SETTINGS.cloudfront;
const root = SETTINGS.root || 'api';
if (dangerDeleteResources) {
export async function deploy (args) {
if (args.dangerDeleteResources) {
danger(stripIndent`
DANGER: You have used the '--danger-delete-resources' so, as part of this stack update
your DynamoDB Tables and/or S3 Buckets may be deleted, including all of its content.`);
\n
DANGER: You have used the '--danger-delete-resources' flag so, as part of this stack update
your DynamoDB Tables and/or S3 Buckets may be deleted, including all of its content.
\n
`);
}
const tasks = new Listr([
{
title: 'running pre-deploy hook',
skip: () => !SETTINGS['pre-deploy'],
task: () => execa.shell(SETTINGS['pre-deploy'])
},
{
title: 'validating configuration',
task: ctx => {
const {
API_DEFINITIONS,
APP_NAME,
getCloudFrontSettings,
getHostedZoneId,
PROJECT_ROOT,
SETTINGS
} = loadConfig();
const {
appStage,
dangerDeleteResources = false,
skipAcmCertificate = false,
skipChmod = false,
skipCloudformation = false
} = args;
const assetsDir = typeof SETTINGS.assetsDir === 'undefined' ? 'assets' : SETTINGS.assetsDir;
const cloudfrontSettings = getCloudFrontSettings({ appStage });
const cloudfrontStagesMap = SETTINGS.cloudfront;
const deploymentUid = `${Date.now()}${Math.floor(Math.random() * 1000)}`;
const hooks = {
preDeploy: SETTINGS['pre-deploy'],
postDeploy: SETTINGS['post-deploy']
};
const hostedZoneId = getHostedZoneId({ appStage });
const root = SETTINGS.root || 'api';
const stackName = templateStackName({ appName: APP_NAME, stage: appStage });
Object.assign(ctx, {
API_DEFINITIONS,
cloudfrontSettings: getCloudFrontSettings({ appStage }),
dangerDeleteResources,
skipAcmCertificate,
hostedZoneId: getHostedZoneId({ appStage }),
stackName: templateStackName({ appName: APP_NAME, stage: appStage }),
stageName: 'prod',
appName: APP_NAME,
appStage,
root: root,
ignore: SETTINGS.ignore,
assetsDir,
cloudfrontConfigMap: cloudfrontStagesMap,
appName: APP_NAME,
skipChmod,
deploymentUid: `${Date.now()}${Math.floor(Math.random() * 1000)}`,
cloudfrontSettings,
dangerDeleteResources,
deploymentUid,
hooks,
hostedZoneId,
ignore: SETTINGS.ignore,
root: root,
rootDir: PROJECT_ROOT,
assetsDir: typeof SETTINGS.assetsDir === 'undefined' ? 'assets' : SETTINGS.assetsDir
skipAcmCertificate,
skipChmod,
skipCloudformation,
stackName,
stageName: 'prod'
});
}
},
{
title: 'running pre-deploy hook',
skip: ctx => !ctx.hooks.preDeploy,
task: ctx => execa.shell(ctx.hooks.preDeploy)
},
{
title: 'checking prerequisites',
task: (ctx) => {
return new Listr([
{
title: 'validating ACM SSL/TLS Certificate',
skip: ({ cloudfrontSettings, skipAcmCertificate }) => (typeof cloudfrontSettings !== 'string' || skipAcmCertificate === true),
task: async (ctx) => {
const { acmCertificateArn } = await taskRequestACMCert(ctx);
Object.assign(ctx, { acmCertificateArn });
task: async (prereqCtx) => {
const { acmCertificateArn } = await taskRequestACMCert(prereqCtx);
Object.assign(prereqCtx, { acmCertificateArn });
}
},
{
title: 'updating support stack',
task: async (ctx) => {
const { supportBucketName } = await updateSupportStack(ctx);
Object.assign(ctx, { supportBucketName });
task: async (prereqCtx) => {
const { supportBucketName } = await updateSupportStack(prereqCtx);
Object.assign(prereqCtx, { supportBucketName });
}
}
], { concurrent: true });
}
},
{
title: 'creating bundle',
skip: () => skipCloudformation,
skip: ctx => ctx.skipCloudformation,
task: ctx => {
return taskUploadZip({
...ctx
@@ -162,15 +178,15 @@ export async function deploy ({
},
{
title: 'removing stack policy',
skip: ctx => skipCloudformation || !ctx.dangerDeleteResources,
skip: ctx => ctx.skipCloudformation || !ctx.dangerDeleteResources,
task: async (ctx) => {
const { dangerDeleteResources, stackName } = ctx;
await taskRemoveStackPolicy({ dangerDeleteResources, stackName });
}
},
{
title: 'requesting changeset',
skip: () => skipCloudformation,
skip: ctx => ctx.skipCloudformation,
task: async (ctx) => {
const { stackName, cfParams } = ctx;
const updateRequest = await taskRequestStackUpdate({ stackName, cfParams });
@@ -179,24 +195,24 @@ export async function deploy ({
},
{
title: 'waiting for stack update to complete',
skip: ctx => skipCloudformation || ctx.stackChangesetEmpty === true,
skip: ctx => ctx.skipCloudformation || ctx.stackChangesetEmpty === true,
task: ctx => {
const { stackName } = ctx;
return observerForUpdateCompleted({ stackName });
}
},
{
title: 'setting stack policy',
skip: ctx => skipCloudformation || !ctx.dangerDeleteResources,
skip: ctx => ctx.skipCloudformation || !ctx.dangerDeleteResources,
task: async (ctx) => {
const { dangerDeleteResources, stackName } = ctx;
await taskRestoreStackPolicy({ dangerDeleteResources, stackName });
}
},
{
title: 'running post-deploy hook',
skip: () => !SETTINGS['post-deploy'],
task: () => execa.shell(SETTINGS['post-deploy'])
skip: ctx => !ctx.hooks.postDeploy,
task: ctx => execa.shell(ctx.hooks.postDeploy)
},
{
title: 'uploading assets',
@@ -212,7 +228,7 @@ export async function deploy ({
}
}
], {
renderer: verbose ? verboseRenderer : undefined
renderer: args.verbose ? verboseRenderer : undefined
});
return tasks.run()
View
@@ -61,7 +61,7 @@ export function filterAndPrint (
let msgToPrint;
if (/^\d\d\d\d-\d\d-\d\dT/.test(message)) {
const requestId = message.substr(25, 36);
const messageRequestId = message.substr(25, 36);
const restMessage = message.substr(62);
let restMessageColorized;
try {
@@ -71,10 +71,10 @@ export function filterAndPrint (
dashColor: 'white',
stringColor: 'white'
});
} catch (e) {
} catch (jsonParseError) {
restMessageColorized = restMessage;
}
msgToPrint = `\n ${requestId.bold.cyan}\n${indentString(
msgToPrint = `\n ${messageRequestId.bold.cyan}\n${indentString(
restMessageColorized,
4
)}`;
View
@@ -474,8 +474,8 @@ function handleIncomingSQSMessage (
const receiptHandle = message.ReceiptHandle;
const event = JSON.parse(body);
runDockerContainer({ stage, runner, event, outputs, resources, PROJECT_ROOT }, (
runner,
error,
_runner,
_error,
result
) => {
log(`* Event handling by dev server is completed`.dim);
@@ -651,8 +651,8 @@ export function run (argv) {
cacheControl: false,
root: pathModule.join(PROJECT_ROOT, assetsPath)
})
.on('error', error => {
res.writeHead(error.status || 500);
.on('error', (sendError) => {
res.writeHead(sendError.status || 500);
const message = `Resource not found (root: ${pathModule.join(
PROJECT_ROOT,
assetsPath
Oops, something went wrong.

0 comments on commit 80d5b2d

Please sign in to comment.