/
deploy.js
96 lines (84 loc) · 2.79 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const Serverless = require('../../serverless');
const { writeText, style, log } = require('@serverless/utils/log');
const promptWithHistory = require('@serverless/utils/inquirer/prompt-with-history');
const { doesServiceInstanceHaveLinkedProvider } = require('./utils');
const _ = require('lodash');
const AWS = require('aws-sdk');
const isAuthenticated = require('@serverless/dashboard-plugin/lib/is-authenticated');
const printMessage = () => {
writeText(
null,
style.aside('What next?'),
'Run these commands in the project directory:',
null,
`serverless deploy ${style.aside('Deploy changes')}`,
`serverless info ${style.aside('View deployed endpoints and resources')}`,
`serverless invoke ${style.aside('Invoke deployed functions')}`,
`serverless --help ${style.aside('Discover more commands')}`
);
};
module.exports = {
async isApplicable(context) {
const { configuration, serviceDir, options, initial } = context;
if (!serviceDir) {
context.inapplicabilityReasonCode = 'NOT_IN_SERVICE_DIRECTORY';
return false;
}
if (options.console && initial.isInServiceContext) {
context.inapplicabilityReasonCode = 'CONSOLE_INTEGRATION';
return false;
}
if (
_.get(configuration, 'provider') !== 'aws' &&
_.get(configuration, 'provider.name') !== 'aws'
) {
context.inapplicabilityReasonCode = 'NON_AWS_PROVIDER';
return false;
}
// We want to proceed if the service instance has a linked provider
if (
configuration.org &&
configuration.app &&
isAuthenticated() &&
(await doesServiceInstanceHaveLinkedProvider({ configuration, options }))
) {
return true;
}
// We want to proceed if local credentials are available
if (new AWS.Config().credentials) return true;
context.inapplicabilityReasonCode = 'NO_CREDENTIALS_CONFIGURED';
return false;
},
async run(context) {
const { configuration, configurationFilename, serviceDir, stepHistory, history } = context;
if (configuration.org && !history.has('dashboardSetOrg')) {
log.notice(
'Your service is configured with Serverless Dashboard and is ready to be deployed.'
);
log.notice();
}
const shouldDeploy = await promptWithHistory({
name: 'shouldDeploy',
message: 'Do you want to deploy now?',
stepHistory,
type: 'confirm',
});
if (!shouldDeploy) {
printMessage();
return;
}
const serverless = new Serverless({
configuration,
serviceDir,
configurationFilename,
commands: ['deploy'],
options: {},
});
await serverless.init();
await serverless.run();
context.serverless = serverless;
printMessage();
},
configuredQuestions: ['shouldDeploy'],
};