-
Notifications
You must be signed in to change notification settings - Fork 818
/
pullProject.ts
106 lines (103 loc) · 3.42 KB
/
pullProject.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
96
97
98
99
100
101
102
103
104
105
106
import * as util from '../util';
import { nspawn as spawn, getSocialProviders } from 'amplify-e2e-core';
const defaultSettings = {
name: '\r',
editor: '\r',
appType: '\r',
framework: '\r',
srcDir: '\r',
distDir: '\r',
buildCmd: '\r',
startCmd: '\r',
useProfile: '\r',
profileName: '\r',
};
export type FrontendConfig = {
frontend: string;
framework: string;
config: {
SourceDir: string;
DistributionDir: string;
BuildCommand: string;
StartCommand: string;
};
};
export function headlessPull(
projectRootDirPath: string,
amplifyParam: Object,
providersParam: Object,
categoryConfig?: Object,
frontendConfig?: FrontendConfig,
): Promise<void> {
const pullCommand: string[] = [
'pull',
'--amplify',
JSON.stringify(amplifyParam),
'--providers',
JSON.stringify(providersParam),
'--no-override',
'--yes',
];
if (categoryConfig) pullCommand.push(...['--categories', JSON.stringify(categoryConfig)]);
if (frontendConfig) pullCommand.push('--frontend', JSON.stringify(frontendConfig));
return new Promise((resolve, reject) => {
spawn(util.getCLIPath(), pullCommand, { cwd: projectRootDirPath, stripColors: true }).run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}
export function authConfigPull(projectRootDirPath: string, params: { appId: string; envName: string }, settings: Object = {}) {
const pullCommand: string[] = ['pull'];
Object.keys(params).forEach(key => {
if (params[key]) pullCommand.push(...[`--${key}`, JSON.stringify(params[key])]);
});
const s = { ...defaultSettings, ...settings };
const { FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, GOOGLE_APP_ID, GOOGLE_APP_SECRET, AMAZON_APP_ID, AMAZON_APP_SECRET } = getSocialProviders();
return new Promise((resolve, reject) => {
spawn(util.getCLIPath(), pullCommand, { cwd: projectRootDirPath, stripColors: true })
.wait('Select the authentication method you want to use:')
.sendCarriageReturn()
.wait('Please choose the profile you want to use')
.sendLine(s.profileName)
.wait('Choose your default editor:')
.sendLine(s.editor)
.wait("Choose the type of app that you're building")
.sendLine(s.appType)
.wait('What javascript framework are you using')
.sendLine(s.framework)
.wait('Source Directory Path:')
.sendLine(s.srcDir)
.wait('Distribution Directory Path:')
.sendLine(s.distDir)
.wait('Build Command:')
.sendLine(s.buildCmd)
.wait('Start Command:')
.sendLine(s.startCmd)
.wait('Do you plan on modifying this backend?')
.sendLine('y')
.wait('Enter your Facebook App ID for your OAuth flow:')
.sendLine(FACEBOOK_APP_ID)
.wait('Enter your Facebook App Secret for your OAuth flow:')
.sendLine(FACEBOOK_APP_SECRET)
.wait('Enter your Google Web Client ID for your OAuth flow:')
.sendLine(GOOGLE_APP_ID)
.wait('Enter your Google Web Client Secret for your OAuth flow:')
.sendLine(GOOGLE_APP_SECRET)
.wait('Enter your Amazon App ID for your OAuth flow:')
.sendLine(AMAZON_APP_ID)
.wait('Enter your Amazon App Secret for your OAuth flow:')
.sendLine(AMAZON_APP_SECRET)
.wait('Successfully pulled backend environment dev from the cloud.')
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}