Skip to content

Commit acd14a8

Browse files
UnleashedMindyuth
authored andcommitted
feat: headless Init and configure (#371)
* init headless * add headless for javascript frontend * setup headless for android frontend * move publish ignore to a file inside hosting folder * move publish ignore out of amplifyrc file
1 parent 34704fb commit acd14a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1139
-679
lines changed

packages/amplify-category-auth/provider-utils/awscloudformation/service-walkthroughs/auth-questions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function serviceWalkthrough(
1212
const { inputs } = serviceMetadata;
1313
const { amplify } = context;
1414
const { parseInputs } = require(`${__dirname}/../question-factories/core-questions.js`);
15-
const projectType = Object.keys(amplify.getProjectConfig().frontendHandler)[0];
15+
const projectType = amplify.getProjectConfig().frontend;
1616

1717

1818
let coreAnswers = {};

packages/amplify-category-auth/provider-utils/supported-services.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
"operator": "includes"
143143
},
144144
{
145-
"key": "frontendHandler",
145+
"key": "frontend",
146146
"value": "ios",
147147
"operator": "configMatch"
148148
}
@@ -160,7 +160,7 @@
160160
"operator": "includes"
161161
},
162162
{
163-
"key": "frontendHandler",
163+
"key": "frontend",
164164
"value": "android",
165165
"operator": "configMatch"
166166
}

packages/amplify-category-hosting/lib/S3AndCloudFront/helpers/cloudfront-manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ async function invalidate(context) {
4848
}
4949

5050
async function getCloudFrontClient(context) {
51-
const { projectConfig } = context.exeInfo;
52-
const provider = require(projectConfig.providers[providerName]);
51+
const providerPlugins = context.amplify.getProviderPlugins(context);
52+
const provider = require(providerPlugins[providerName]);
5353
const aws = await provider.getConfiguredAWSClient(context);
5454
return new aws.CloudFront();
5555
}

packages/amplify-category-hosting/lib/S3AndCloudFront/helpers/configure-Publish.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ const inquirer = require('inquirer');
33
const minimatch = require('minimatch');
44
const fs = require('fs-extra');
55

6-
const { PublishIgnoreRCLabel } = require('../../constants');
6+
const PublishIgnoreFileName = 'amplifyPublishIgnore.json';
77

88
async function configure(context) {
9-
const amplifyRCFilePath = context.amplify.pathManager.getAmplifyRcFilePath();
10-
let amplifyRC;
11-
let publishIgnore;
9+
const publishIgnoreFilePath = getPublishIgnoreFilePath(context);
10+
let publishIgnore = [];
1211

13-
if (fs.existsSync(amplifyRCFilePath)) {
14-
amplifyRC = JSON.parse(fs.readFileSync(amplifyRCFilePath, 'utf8'));
15-
publishIgnore = amplifyRC[PublishIgnoreRCLabel];
12+
if (fs.existsSync(publishIgnoreFilePath)) {
13+
try {
14+
publishIgnore = require(publishIgnoreFilePath);
15+
} catch (e) {
16+
publishIgnore = [];
17+
}
1618
}
1719

18-
amplifyRC = amplifyRC || {};
19-
publishIgnore = publishIgnore || [];
20-
2120
publishIgnore = publishIgnore
2221
.map(ignore => ignore.trim())
2322
.filter(ignore => ignore.length > 0)
@@ -27,12 +26,20 @@ async function configure(context) {
2726
context.print.info('Use glob patterns as in the .gitignore file.');
2827

2928
publishIgnore = await configurePublishIgnore(context, publishIgnore);
30-
amplifyRC[PublishIgnoreRCLabel] = publishIgnore;
3129

32-
const jsonString = JSON.stringify(amplifyRC, null, 4);
33-
fs.writeFileSync(amplifyRCFilePath, jsonString, 'utf8');
30+
const jsonString = JSON.stringify(publishIgnore, null, 4);
31+
fs.writeFileSync(publishIgnoreFilePath, jsonString, 'utf8');
3432
}
3533

34+
function getPublishIgnoreFilePath(context) {
35+
const projectPath = context.amplify.pathManager.searchProjectRootPath();
36+
if (projectPath || fs.existsSync(projectPath)) {
37+
return path.join(projectPath, PublishIgnoreFileName);
38+
}
39+
throw new Error('You are not working inside a valid amplify project.\nUse \'amplify init\' in the root of your app directory to initialize your project with Amplify');
40+
}
41+
42+
3643
async function configurePublishIgnore(context, publishIgnore) {
3744
const DONE = "I'm done.";
3845
const configActions = ['list', 'add', 'remove', 'remove all', DONE];
@@ -115,13 +122,18 @@ async function removeIgnore(context, publishIgnore) {
115122
}
116123

117124
function getIgnore(context) {
118-
let result;
119-
const amplifyRCFilePath = context.amplify.pathManager.getAmplifyRcFilePath();
120-
if (fs.existsSync(amplifyRCFilePath)) {
121-
const amplifyRC = JSON.parse(fs.readFileSync(amplifyRCFilePath, 'utf8'));
122-
result = amplifyRC[PublishIgnoreRCLabel];
125+
let publishIgnore;
126+
const publishIgnoreFilePath = getPublishIgnoreFilePath(context);
127+
if (fs.existsSync(publishIgnoreFilePath)) {
128+
try {
129+
publishIgnore = require(publishIgnoreFilePath);
130+
} catch (e) {
131+
publishIgnore = [];
132+
}
133+
} else {
134+
publishIgnore = [];
123135
}
124-
return result;
136+
return publishIgnore;
125137
}
126138

127139
function isIgnored(filePath, publishIgnore, ignoreRoot) {

packages/amplify-category-hosting/lib/S3AndCloudFront/helpers/file-uploader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ async function run(context, distributionDirPath) {
2626
}
2727

2828
async function getS3Client(context) {
29-
const { projectConfig } = context.exeInfo;
30-
const provider = require(projectConfig.providers[providerName]);
29+
const providerPlugins = context.amplify.getProviderPlugins(context);
30+
const provider = require(providerPlugins[providerName]);
3131
const aws = await provider.getConfiguredAWSClient(context);
3232
return new aws.S3();
3333
}

packages/amplify-category-hosting/lib/category-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function getAvailableServices(context) {
77
const availableServices = [];
88
const projectConfig = context.amplify.getProjectConfig();
99
Object.keys(supportedServices).forEach((service) => {
10-
if (Object.keys(projectConfig.providers).includes(supportedServices[service].provider)) {
10+
if (projectConfig.providers.includes(supportedServices[service].provider)) {
1111
availableServices.push(service);
1212
}
1313
});
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
module.exports = {
22
CategoryName: 'hosting',
3-
PublishIgnoreRCLabel: 'publish-ignore',
43
};

packages/amplify-category-notifications/lib/auth-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ async function checkAuth(context) {
7979
}
8080

8181
async function getIamClient(context) {
82-
const { projectConfig } = context.exeInfo;
83-
const provider = require(projectConfig.providers[providerName]);
82+
const providerPlugins = context.amplify.getProviderPlugins(context);
83+
const provider = require(providerPlugins[providerName]);
8484
const aws = await provider.getConfiguredAWSClient(context);
8585
return new aws.IAM();
8686
}

packages/amplify-category-notifications/lib/pinpoint-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ function console(context) {
214214
}
215215

216216
async function getPinpointClient(context) {
217-
const { projectConfig } = context.exeInfo;
218-
const provider = require(projectConfig.providers[providerName]);
217+
const providerPlugins = context.amplify.getProviderPlugins(context);
218+
const provider = require(providerPlugins[providerName]);
219219
const aws = await provider.getConfiguredAWSClient(context);
220220
aws.config.update({ region: 'us-east-1' });
221221
return new aws.Pinpoint();

packages/amplify-cli/src/commands/configure.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const analyzeProject = require('../lib/config-steps/c0-analyzeProject');
2-
const configFrontendHandler = require('../lib/config-steps/c1-configFrontendHandler');
2+
const configFrontendHandler = require('../lib/config-steps/c1-configFrontend');
33
const configProviders = require('../lib/config-steps/c2-configProviders');
44
const configureNewUser = require('../lib/configure-new-user');
55
const onFailure = require('../lib/config-steps/c9-onFailure');
66
const onSuccess = require('../lib/config-steps/c9-onSuccess');
7+
const { normalizeInputParams } = require('../lib/input-params-manager');
78

89
module.exports = {
910
name: 'configure',
@@ -13,6 +14,7 @@ module.exports = {
1314
}
1415

1516
if (context.parameters.first === 'project') {
17+
constructExeInfo(context);
1618
return analyzeProject.run(context)
1719
.then(configFrontendHandler.run)
1820
.then(configProviders.run)
@@ -22,3 +24,9 @@ module.exports = {
2224
},
2325
};
2426

27+
function constructExeInfo(context) {
28+
context.exeInfo = {
29+
inputParams: normalizeInputParams(context),
30+
};
31+
}
32+

0 commit comments

Comments
 (0)