-
Notifications
You must be signed in to change notification settings - Fork 818
/
index.ts
95 lines (87 loc) · 3.17 KB
/
index.ts
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
import path from 'path';
import { nspawn as spawn, getCLIPath, singleSelect, amplifyRegions, addCircleCITags, KEY_DOWN_ARROW } from 'amplify-e2e-core';
import fs from 'fs-extra';
import os from 'os';
export async function initWithoutCredentialFileAndNoNewUserSetup(projRoot) {
const settings = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-west-2',
};
delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;
delete process.env.AWS_DEFAULT_REGION;
delete process.env.AWS_REGION;
const dotAWSDirPath = path.normalize(path.join(os.homedir(), '.aws'));
const credentialsFilePath = path.join(dotAWSDirPath, 'credentials');
const configFilePath = path.join(dotAWSDirPath, 'config');
const credentialsFilePathHide = path.join(dotAWSDirPath, 'credentials.hide');
const configFilePathHide = path.join(dotAWSDirPath, 'config.hide');
try {
if (fs.existsSync(configFilePath)) {
fs.renameSync(configFilePath, configFilePathHide);
}
if (fs.existsSync(credentialsFilePath)) {
fs.renameSync(credentialsFilePath, credentialsFilePathHide);
}
await initWorkflow(projRoot, settings);
} catch (e) {
throw e;
} finally {
if (fs.existsSync(configFilePathHide)) {
fs.renameSync(configFilePathHide, configFilePath);
}
if (fs.existsSync(credentialsFilePathHide)) {
fs.renameSync(credentialsFilePathHide, credentialsFilePath);
}
}
}
async function initWorkflow(cwd: string, settings: { accessKeyId: string; secretAccessKey: string; region: string }) {
addCircleCITags(cwd);
return new Promise((resolve, reject) => {
let chain = spawn(getCLIPath(), ['init'], {
cwd,
stripColors: true,
env: {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
.wait('Enter a name for the project')
.sendCarriageReturn()
.wait('Enter a name for the environment')
.sendCarriageReturn()
.wait('Choose your default editor:')
.sendCarriageReturn()
.wait("Choose the type of app that you're building")
.sendCarriageReturn()
.wait('What javascript framework are you using')
.sendCarriageReturn()
.wait('Source Directory Path:')
.sendCarriageReturn()
.wait('Distribution Directory Path:')
.sendCarriageReturn()
.wait('Build Command:')
.sendCarriageReturn()
.wait('Start Command:')
.sendCarriageReturn()
.wait('Using default provider awscloudformation')
.wait('Select the authentication method you want to use:')
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
.pauseRecording()
.wait('accessKeyId')
.sendLine(settings.accessKeyId)
.wait('secretAccessKey')
.sendLine(settings.secretAccessKey)
.resumeRecording()
.wait('region');
singleSelect(chain, settings.region, amplifyRegions);
chain.wait('Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything').run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}