-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
index.js
64 lines (57 loc) · 2.12 KB
/
index.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
'use strict';
const inquirer = require('@serverless/utils/inquirer');
const { StepHistory } = require('@serverless/utils/telemetry');
const log = require('@serverless/utils/log').log.get('onboarding');
const { resolveInitialContext } = require('./utils');
const steps = {
service: require('./service'),
consoleLogin: require('./console-login'),
dashboardLogin: require('./dashboard-login'),
dashboardSetOrg: require('./dashboard-set-org'),
awsCredentials: require('./aws-credentials'),
deploy: require('./deploy'),
};
module.exports = async (context) => {
const stepsDetails = new Map(
Object.entries(steps).map(([stepName, step]) => {
return [stepName, { configuredQuestions: step.configuredQuestions }];
})
);
const { commandUsage, options } = context;
const history = new Map();
context = { ...context, inquirer, history };
commandUsage.stepsHistory = history;
commandUsage.stepsHistory.toJSON = () => {
return Array.from(stepsDetails.entries()).map(([step, stepDetails]) => {
const stepHistory = history.get(step);
return {
name: step,
...stepDetails,
history: stepHistory ? stepHistory.toJSON() : [],
};
});
};
const initialContext = resolveInitialContext(context);
commandUsage.initialContext = initialContext;
context.initial = initialContext;
context.isConsole = Boolean(options.console);
for (const [stepName, step] of Object.entries(steps)) {
delete context.stepHistory;
delete context.inapplicabilityReasonCode;
const stepData = await step.isApplicable(context);
if (stepData) log.debug('%s: applicable: %o', stepName, stepData);
else log.debug('%s: not applicable: %s', stepName, context.inapplicabilityReasonCode);
Object.assign(stepsDetails.get(stepName), {
isApplicable: Boolean(stepData),
inapplicabilityReasonCode: context.inapplicabilityReasonCode,
timestamp: Date.now(),
});
if (stepData) {
log.notice();
context.stepHistory = new StepHistory();
context.history.set(stepName, context.stepHistory);
await step.run(context, stepData);
}
}
return context;
};