Skip to content

Commit

Permalink
fix: parameters file path and updates cloud backend with build (aws-a…
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu authored and Sachin Panemangalore committed Nov 10, 2021
1 parent fbe6a0f commit d1a835d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class AmplifyAuthTransform extends AmplifyCategoryTransform {
const backendDir = pathManager.getBackendDirPath();
const overrideDir = path.join(backendDir, this._category, this.resourceName);
const isBuild = await buildOverrideDir(backendDir, overrideDir).catch(error => {
printer.warn(`Skipping build as ${error.message}`);
printer.debug(`Skipping build as ${error.message}`);
return false;
});
if (isBuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class AmplifyUserPoolGroupTransform extends AmplifyCategoryTransform {
const backendDir = pathManager.getBackendDirPath();
const overrideDir = path.join(backendDir, this._category, this._resourceName);
const isBuild = await buildOverrideDir(backendDir, overrideDir).catch(error => {
printer.warn(`Skipping build as ${error.message}`);
printer.debug(`Skipping build as ${error.message}`);
return false;
});
if (isBuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ async function updateConfigOnEnvInit(context, category, service) {

const providerPlugin = context.amplify.getPluginInstance(context, provider);
// previously selected answers
const currentAuthName = await getAuthResourceName(context);
const cliState = new AuthInputState(currentAuthName);
const resourceParams = await cliState.loadResourceParameters(context, cliState.getCLIInputPayload());
const resourceParams = providerPlugin.loadResourceParameters(context, 'auth', service);
// ask only env specific questions
let currentEnvSpecificValues = context.amplify.loadEnvResourceParameters(context, category, service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class DDBStackTransform {
const overrideFilePath = pathManager.getResourceDirectoryPath(undefined, 'storage', this._resourceName);

const isBuild = await buildOverrideDir(backendDir, overrideFilePath).catch(error => {
printer.warn(`Skipping build as ${error.message}`);
printer.debug(`Skipping build as ${error.message}`);
return false;
});
// skip if packageManager or override.ts not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class AmplifyS3ResourceStackTransform {
const backendDir = pathManager.getBackendDirPath();
const overrideFilePath = pathManager.getResourceDirectoryPath(undefined, AmplifyCategories.STORAGE, this.resourceName);
const isBuild = await buildOverrideDir(backendDir, overrideFilePath).catch(error => {
printer.warn(`Skipping build as ${error.message}`);
printer.debug(`Skipping build as ${error.message}`);
return false;
});
//Skip if packageManager or override.ts not found
Expand Down
50 changes: 30 additions & 20 deletions packages/amplify-cli-core/src/state-manager/pathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const PathConstants = {
CurrentCloudBackendDirName: '#current-cloud-backend',
HooksDirName: 'hooks',

// resource level
BuildDirName: 'build',
// 2nd Level
OverrideDirName: 'overrides',
ProviderName: 'awscloudformation',
Expand All @@ -41,7 +43,6 @@ export const PathConstants = {
HooksShellSampleFileName: 'post-push.sh.sample',
HooksJsSampleFileName: 'pre-push.js.sample',
HooksReadmeFileName: 'hooks-readme.md',
OverrideFileName: 'override.ts',

LocalEnvFileName: 'local-env-info.json',
LocalAWSInfoFileName: 'local-aws-info.json',
Expand All @@ -52,10 +53,11 @@ export const PathConstants = {
CLIJSONFileNameGlob: 'cli*.json',
CLIJsonWithEnvironmentFileName: (env: string) => `cli.${env}.json`,

CLIInputsJsonFileName: 'cli-inputs.json',

CfnFileName: (resourceName: string) => `${resourceName}-awscloudformation-template.json`,

CustomPoliciesFilename: 'custom-policies.json',
cliInputsFileName: 'cli-inputs.json',
};

export class PathManager {
Expand Down Expand Up @@ -92,16 +94,6 @@ export class PathManager {
getBackendDirPath = (projectPath?: string): string =>
this.constructPath(projectPath, [PathConstants.AmplifyDirName, PathConstants.BackendDirName]);

getCliInputsPath = (projectPath: string, category: string, resourceName: string): string => {
return this.constructPath(projectPath, [
PathConstants.AmplifyDirName,
PathConstants.BackendDirName,
category,
resourceName,
PathConstants.cliInputsFileName,
]);
};

getCurrentCloudBackendDirPath = (projectPath?: string): string =>
this.constructPath(projectPath, [PathConstants.AmplifyDirName, PathConstants.CurrentCloudBackendDirName]);

Expand Down Expand Up @@ -142,11 +134,29 @@ export class PathManager {
getResourceDirectoryPath = (projectPath: string | undefined, category: string, resourceName: string): string =>
this.constructPath(projectPath, [PathConstants.AmplifyDirName, PathConstants.BackendDirName, category, resourceName]);

getResourceParametersFilePath = (projectPath: string | undefined, category: string, resourceName: string): string =>
path.join(this.getResourceDirectoryPath(projectPath, category, resourceName), 'build', PathConstants.ParametersJsonFileName);
getResourceInputsJsonFilePath = (projectPath: string | undefined, category: string, resourceName: string): string =>
path.join(this.getResourceDirectoryPath(projectPath, category, resourceName), PathConstants.CLIInputsJsonFileName);

getResourceParametersFilePath = (projectPath: string | undefined, category: string, resourceName: string): string => {
let isBuildParametersjson: boolean = false;
const resourceDirPath = this.getResourceDirectoryPath(projectPath, category, resourceName);
if (!fs.existsSync(path.join(resourceDirPath, PathConstants.ParametersJsonFileName))) {
isBuildParametersjson = true;
}
const basePath = isBuildParametersjson ? path.join(resourceDirPath, PathConstants.BuildDirName) : resourceDirPath;
return path.join(basePath, PathConstants.ParametersJsonFileName);
};

getResourceCfnTemplatePath = (projectPath: string | undefined, category: string, resourceName: string): string =>
path.join(this.getResourceDirectoryPath(projectPath, category, resourceName), 'build', PathConstants.CfnFileName(resourceName));
getResourceCfnTemplatePath = (
projectPath: string | undefined,
category: string,
resourceName: string,
buildDirectory = false,
): string => {
const resourceDirPath = this.getResourceDirectoryPath(projectPath, category, resourceName);
const basePath = buildDirectory ? path.join(resourceDirPath, PathConstants.BuildDirName) : resourceDirPath;
return path.join(basePath, PathConstants.CfnFileName(resourceName));
};

getReadMeFilePath = (projectPath?: string): string =>
this.constructPath(projectPath, [PathConstants.AmplifyDirName, PathConstants.ReadMeFileName]);
Expand All @@ -167,8 +177,8 @@ export class PathManager {

getDotAWSDirPath = (): string => path.normalize(path.join(homedir(), PathConstants.DotAWSDirName));

getCustomPoliciesPath = (category: string, resourceName: string): string =>
path.join(this.getResourceDirectoryPath(undefined, category, resourceName), PathConstants.CustomPoliciesFilename);
getCustomPoliciesPath = (category: string, resourceName: string): string =>
path.join(this.getResourceDirectoryPath(undefined, category, resourceName), PathConstants.CustomPoliciesFilename);

getAWSCredentialsFilePath = (): string => path.normalize(path.join(this.getDotAWSDirPath(), PathConstants.AWSCredentials));

Expand Down Expand Up @@ -214,7 +224,7 @@ export class PathManager {
PathConstants.AmplifyDirName,
PathConstants.BackendDirName,
PathConstants.ProviderName,
PathConstants.CfnStacksBuildDirName,
PathConstants.BuildDirName,
]);
};

Expand All @@ -223,7 +233,7 @@ export class PathManager {
PathConstants.AmplifyDirName,
PathConstants.CurrentCloudBackendDirName,
PathConstants.ProviderName,
PathConstants.CfnStacksBuildDirName,
PathConstants.BuildDirName,
]);
};

Expand Down
23 changes: 22 additions & 1 deletion packages/amplify-cli-core/src/state-manager/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import _ from 'lodash';
import { PathConstants, pathManager } from './pathManager';
import { $TSMeta, $TSTeamProviderInfo, $TSAny, DeploymentSecrets, HooksConfig } from '..';
import { $TSMeta, $TSTeamProviderInfo, $TSAny, DeploymentSecrets, HooksConfig, $TSObject } from '..';
import { JSONUtilities } from '../jsonUtilities';
import { SecretFileMode } from '../cliConstants';
import { HydrateTags, ReadTags, Tag } from '../tags';
Expand Down Expand Up @@ -147,6 +147,21 @@ export class StateManager {
return this.getData<$TSAny>(filePath, mergedOptions);
};

getResourceInputsJson = (
projectPath: string | undefined,
category: string,
resourceName: string,
options?: GetOptions<$TSAny>,
): $TSAny => {
const filePath = pathManager.getResourceInputsJsonFilePath(projectPath, category, resourceName);
const mergedOptions = {
throwIfNotExist: true,
...options,
};

return this.getData<$TSAny>(filePath, mergedOptions);
};

getCurrentResourceParametersJson = (
projectPath: string | undefined,
category: string,
Expand Down Expand Up @@ -271,6 +286,12 @@ export class StateManager {
JSONUtilities.writeJson(filePath, parameters);
};

setResourceInputsJson = (projectPath: string | undefined, category: string, resourceName: string, inputs: $TSObject): void => {
const filePath = pathManager.getResourceInputsJsonFilePath(projectPath, category, resourceName);

JSONUtilities.writeJson(filePath, inputs);
};

cliJSONFileExists = (projectPath: string, env?: string): boolean => {
try {
return fs.existsSync(pathManager.getCLIJSONFilePath(projectPath, env));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class AmplifyRootStackTransform {
const backendDir = pathManager.getBackendDirPath();
const overrideFilePath = path.join(backendDir, this._resourceName);
const isBuild = await buildOverrideDir(backendDir, overrideFilePath).catch(error => {
amplifyPrinter.printer.warn(`Skipping build as ${error.message}`);
amplifyPrinter.printer.debug(`Skipping build as ${error.message}`);
return false;
});
// skip if packageManager or override.ts not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function run(folder, zipFilePath, ignorePattern = DEFAULT_IGNORE_PATTERN, extraF
cwd: folder,
dot: true,
});
zip.glob('storage/*/build/**', {
cwd: folder,
dot: true,
});
zip.glob('auth/*/build/**', {
cwd: folder,
dot: true,
});
zip.glob('**', {
cwd: folder,
ignore: ignorePattern,
Expand Down

0 comments on commit d1a835d

Please sign in to comment.