Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add init prompts for Gen2 #13849

Merged
merged 50 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
592abd1
feat: add warning to init
Jul 9, 2024
d0a26e0
feat: add prompt to init
Jul 10, 2024
365eab4
feat: only prompt on new project
Jul 10, 2024
631a252
feat: add guide to Gen2
Jul 10, 2024
c0c4e3e
refactor: change to use process exit
Jul 10, 2024
5d53a55
Update packages/amplify-cli/src/init-steps/preInitMigrationWarning.ts
0618 Jul 10, 2024
49a9f01
refactor: rename to gen2Recommendation
Jul 10, 2024
0d3a057
refactor: combine gen2Recommendation to preInitSetup
Jul 10, 2024
cadc06f
feat: remove goodbye message
Jul 10, 2024
39f8b34
test: fix init.test
Jul 10, 2024
e4330c3
test: add unit test for preInitSetup
Jul 10, 2024
08e896a
chore: rename to getPreInitSetup
Jul 10, 2024
22cff01
feat: change verbiage
Jul 10, 2024
85cd59a
chore: update unit test
Jul 10, 2024
f12fe7a
feat: add whyContinueWithGen1 to stack metadata
Jul 10, 2024
bad9430
fix: verify verify_versions_match
Jul 11, 2024
ad48c8d
fix: verify verify_versions_match
Jul 11, 2024
2378a19
feat: bump versions
Jul 11, 2024
ad3ab5e
feat: bump versions
Jul 12, 2024
cac0e9d
feat: bump versions
Jul 12, 2024
dfba32e
chore: rename to recommendGen2
Jul 12, 2024
aa1850c
chore: rename to recommendGen2 in test
Jul 12, 2024
fba0211
revert .sh format
Jul 15, 2024
1e8e25b
chore: rename and not export preInitSetup
Jul 15, 2024
3d1bb59
fix: export gen2Recommandation and preInitSetup for test
Jul 15, 2024
c20f939
Merge branch 'dev' into add-init-promps
Aug 5, 2024
7ecde5c
fix: set inital answer for pick
Aug 7, 2024
e67d7cc
Merge branch 'dev' into add-init-promps
Aug 8, 2024
d8fa624
Revert "fix: set inital answer for pick"
Aug 8, 2024
1d671cf
Revert "Revert "fix: set inital answer for pick""
Aug 8, 2024
6fc0979
fix: preInitSetup.test
Aug 8, 2024
71b204c
fix: e2e test by adding isCI
Aug 12, 2024
20157e7
chore: upgrade node-pty
Aug 13, 2024
203d1ca
Merge branch 'dev' into add-init-promps
Aug 14, 2024
66ae2a1
Revert "fix: e2e test by adding isCI"
Aug 14, 2024
d94ed5e
test: add prompt to e2e
Aug 14, 2024
ea7b9de
fix: set default value for whyContinueWithGen1
Aug 14, 2024
faa0859
fix: projectConfig undefined and remove default choice
Aug 17, 2024
c540b9c
fix: preInitSetup.test.ts
Aug 17, 2024
bbeec57
fix: add default choice back
Aug 17, 2024
bb73c4b
fix: remove prompts from migration test
Aug 19, 2024
13b81af
test: move new prompt from v12
Sep 2, 2024
eeb6f71
test: move new prompt from initJSProjectWithProfile
Sep 3, 2024
4e7fd0c
Revert "test: move new prompt from initJSProjectWithProfile"
Sep 3, 2024
57342e6
test: move new prompts from initJSProjectWithProfile
Sep 3, 2024
9d92f56
chore: change recommendGen2
Sep 8, 2024
7548ef8
test: fix preInitSetup unit test
Sep 8, 2024
fc21886
test: add includeGen2RecommendationPrompt
Sep 8, 2024
fd5f0d7
test: add includeGen2RecommendationPrompt to migration-2
Sep 8, 2024
808c795
test: remove prompts from initAndroidProjectWithProfileV12
Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/local_publish_helpers_codebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function checkPackageVersionsInLocalNpmRegistry {

if [[ $cli_internal_version != $cli_version ]]; then
echo "Versions did not match."
echo "Manual fix: add a proper conventional commit that touches the amplify-cli-npm package to correct its version bump. For example https://github.com/aws-amplify/amplify-cli/commit/6f14792d1db424aa428ec4836fed7d6dd5cccfd0"
echo "Manual fix: add a proper conventional commit that touches the amplify-cli-npm package to correct its version bump. For example https://github.com/aws-amplify/amplify-cli/pull/13759/commits/15dcd96feae925ff26ca51abfb4a0477890af745"
awsluja marked this conversation as resolved.
Show resolved Hide resolved
exit 1
else
echo "Versions matched."
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli-npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const install = async (): Promise<void> => {
return binary.install();
};

// force version bump to 12.12.0
// force version bump to 12.13.0
6 changes: 4 additions & 2 deletions packages/amplify-cli/src/__tests__/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { execSync } from 'child_process';
import { ensureDir, existsSync, readFileSync, readJSON, readdirSync } from 'fs-extra';
import { sync } from 'which';
import { preInitSetup } from '../../init-steps/preInitSetup';
import { getPreInitSetup } from '../../init-steps/preInitSetup';
import { analyzeProject } from '../../init-steps/s0-analyzeProject';
import { initFrontend } from '../../init-steps/s1-initFrontend';
import { scaffoldProjectHeadless } from '../../init-steps/s8-scaffoldHeadless';
Expand Down Expand Up @@ -137,7 +137,9 @@ describe('amplify init:', () => {
},
},
};
await preInitSetup(context as unknown as $TSContext);
const recommendGen2 = true;
const step = getPreInitSetup(!recommendGen2);
await step(context as unknown as $TSContext);
expect(execSync).toBeCalledWith(`git ls-remote ${appUrl}`, { stdio: 'ignore' });
expect(execSync).toBeCalledWith(`git clone ${appUrl} .`, { stdio: 'inherit' });
expect(execSync).toBeCalledWith('yarn install', { stdio: 'inherit' });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { $TSContext } from '@aws-amplify/amplify-cli-core';
import { printer, prompter } from '@aws-amplify/amplify-prompts';
import { getPreInitSetup, preInitSetup, gen2Recommendation } from '../../init-steps/preInitSetup';
import { isNewProject } from '../../init-steps/s0-analyzeProject';

// Mock dependencies
jest.mock('@aws-amplify/amplify-cli-core', () => ({
...(jest.requireActual('@aws-amplify/amplify-cli-core') as {}),
FeatureFlags: {
getBoolean: jest.fn(),
getNumber: jest.fn(),
isInitialized: jest.fn().mockReturnValue(true),
ensureDefaultFeatureFlags: jest.fn(),
},
getPackageManager: jest.fn(),
}));

jest.mock('@aws-amplify/amplify-prompts', () => ({
printer: {
warn: jest.fn(),
},
prompter: {
confirmContinue: jest.fn(),
pick: jest.fn(),
},
}));

jest.mock('../../init-steps/s0-analyzeProject', () => ({
isNewProject: jest.fn(),
}));

describe('preInitSetup', () => {
it('should return preInitSetupBasic when isHeadless is true', () => {
const result = getPreInitSetup(true);
expect(result).toBe(preInitSetup);
});

it('should return a function when isHeadless is false', () => {
const result = getPreInitSetup(false);
expect(typeof result).toBe('function');
});
});

describe('gen2Recommendation', () => {
let context;

beforeEach(() => {
context = { exeInfo: {} } as $TSContext;
});

afterEach(() => {
jest.clearAllMocks();
});

it('should recommend using Gen 2 for new projects', async () => {
const isNewProjectMock = jest.mocked(isNewProject);
isNewProjectMock.mockReturnValue(true);

const confirmContinueMock = jest.mocked(prompter.confirmContinue);
confirmContinueMock.mockResolvedValue(true);

const pickMock = jest.mocked(prompter.pick);
pickMock.mockResolvedValue('I am a current Gen 1 user');

await gen2Recommendation(context);

expect(require('@aws-amplify/amplify-prompts').printer.warn).toHaveBeenCalledWith(
'For new projects, we recommend starting with AWS Amplify Gen 2, our new code-first developer experience. Get started at https://docs.amplify.aws/react/start/quickstart/',
);
expect(confirmContinueMock).toHaveBeenCalledWith('Do you want to continue with Amplify Gen 1?');
expect(pickMock).toHaveBeenCalledWith(
'Why would you like to use Amplify Gen 1?',
[
'I am a current Gen 1 user',
'Gen 2 is missing features I need from Gen 1',
'I find the Gen 1 CLI easier to use',
'Prefer not to answer',
],
{ initial: 3 },
);
expect(context.exeInfo.projectConfig).toEqual({ whyContinueWithGen1: 'I am a current Gen 1 user' });
});

it('should return the context for existing projects', async () => {
const isNewProjectMock = jest.mocked(isNewProject);
isNewProjectMock.mockReturnValue(false);

const result = await gen2Recommendation(context);

expect(result).toEqual(context);
expect(printer.warn).not.toHaveBeenCalled();
expect(prompter.confirmContinue).not.toHaveBeenCalled();
expect(prompter.pick).not.toHaveBeenCalled();
});
});
7 changes: 4 additions & 3 deletions packages/amplify-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { constructInputParams } from '../amplify-service-helper';
import { Context } from '../domain/context';
import { raisePostEnvAddEvent } from '../execution-manager';
import { postInitSetup } from '../init-steps/postInitSetup';
import { preInitSetup } from '../init-steps/preInitSetup';
import { getPreInitSetup } from '../init-steps/preInitSetup';
import { analyzeProject, analyzeProjectHeadless } from '../init-steps/s0-analyzeProject';
import { initFrontend } from '../init-steps/s1-initFrontend';
import { initProviders } from '../init-steps/s2-initProviders';
Expand All @@ -18,11 +18,12 @@ const constructExeInfo = (context: $TSContext): void => {
};
};

const recommendGen2 = true;
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const runStrategy = (quickstart: boolean) =>
quickstart
? [preInitSetup, analyzeProjectHeadless, scaffoldProjectHeadless, onHeadlessSuccess]
: [preInitSetup, analyzeProject, initFrontend, initProviders, onSuccess, postInitSetup];
? [getPreInitSetup(recommendGen2), analyzeProjectHeadless, scaffoldProjectHeadless, onHeadlessSuccess]
: [getPreInitSetup(!recommendGen2), analyzeProject, initFrontend, initProviders, onSuccess, postInitSetup];

/**
* entry point for the init command
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,4 @@ export const executeAmplifyCommand = async (context: Context): Promise<void> =>
}
};

// bump version to 12.12.0
//
// bump version to 12.13.0
49 changes: 49 additions & 0 deletions packages/amplify-cli/src/init-steps/preInitSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { execSync } from 'child_process';
import * as fs from 'fs-extra';
import * as url from 'url';
import { generateLocalEnvInfoFile } from './s9-onSuccess';
import { printer, prompter } from '@aws-amplify/amplify-prompts';
import { isNewProject } from './s0-analyzeProject';

export const getPreInitSetup = (recommendGen2: boolean) => {
if (recommendGen2) {
return preInitSetup;
} else {
return async (context) => {
await gen2Recommendation(context);
await preInitSetup(context);
};
}
awsluja marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Executes before init
Expand All @@ -22,6 +35,42 @@ export const preInitSetup = async (context: $TSContext): Promise<$TSContext> =>
return context;
};

/**
* recommend using Gen 2 or continue with Gen 1.
* ask for why they are using Gen 1 and store the answer in project-config
*/
export const gen2Recommendation = async (context: $TSContext): Promise<$TSContext> => {
awsluja marked this conversation as resolved.
Show resolved Hide resolved
if (!isNewProject(context)) {
return context;
}
printer.warn(
'For new projects, we recommend starting with AWS Amplify Gen 2, our new code-first developer experience. Get started at https://docs.amplify.aws/react/start/quickstart/',
);

const continueWithGen1 = await prompter.confirmContinue('Do you want to continue with Amplify Gen 1?');

if (!continueWithGen1) {
process.exit(0);
}

const whyContinueWithGen1 = await prompter.pick(
'Why would you like to use Amplify Gen 1?',
[
'I am a current Gen 1 user',
'Gen 2 is missing features I need from Gen 1',
'I find the Gen 1 CLI easier to use',
'Prefer not to answer',
],
{ initial: 3 },
);

context.exeInfo.projectConfig = {
awsluja marked this conversation as resolved.
Show resolved Hide resolved
whyContinueWithGen1,
};

return context;
};

/**
* Checks whether a url is a valid remote github repository
*
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-cli/src/init-steps/s0-analyzeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const analyzeProject = async (context: $TSContext): Promise<$TSContext> =
const setProjectConfig = (context: $TSContext, projectName: string): void => {
context.exeInfo.isNewProject = isNewProject(context);
context.exeInfo.projectConfig = {
...context.exeInfo.projectConfig,
awsluja marked this conversation as resolved.
Show resolved Hide resolved
projectName,
version: amplifyCLIConstants.CURRENT_PROJECT_CONFIG_VERSION,
};
Expand Down Expand Up @@ -325,7 +326,7 @@ const isNewEnv = (envName: string): boolean => {
return !allEnvs.includes(envName);
};

const isNewProject = (context: $TSContext): boolean => {
export const isNewProject = (context: $TSContext): boolean => {
let newProject = true;
const projectPath = process.cwd();
const projectConfigFilePath = context.amplify.pathManager.getProjectConfigFilePath(projectPath);
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"jest-environment-node": "^26.6.2",
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"node-pty": "beta",
"node-pty": "^1.0.0",
"retimer": "2.0.0",
"rimraf": "^3.0.0",
"semver": "^7.5.4",
Expand Down
24 changes: 24 additions & 0 deletions packages/amplify-e2e-core/src/init/initProjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof
env,
disableCIDetection: s.disableCIDetection,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -115,6 +119,10 @@ export function initAndroidProjectWithProfile(cwd: string, settings: Partial<typ
stripColors: true,
env,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -171,6 +179,10 @@ export function initIosProjectWithProfile(cwd: string, settings: Record<string,
stripColors: true,
env,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -205,6 +217,10 @@ export function initIosProjectWithXcode(cwd: string): Promise<void> {
cwd,
stripColors: true,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendCarriageReturn()
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -237,6 +253,10 @@ export function initFlutterProjectWithProfile(cwd: string, settings: Record<stri

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), ['init'], { cwd, stripColors: true })
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -286,6 +306,10 @@ export function initProjectWithAccessKey(
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify-e2e-core/src/utils/pinpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export function initProjectForPinpoint(cwd: string): Promise<void> {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(settings.name)
.wait('Initialize the project with the above configuration?')
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lodash": "^4.17.21",
"moment": "^2.24.0",
"node-fetch": "^2.6.7",
"node-pty": "beta",
"node-pty": "^1.0.0",
"rimraf": "^3.0.0",
"title-case": "^3.0.3",
"upper-case": "^2.0.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify-e2e-tests/src/init-special-cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ async function initWorkflow(cwd: string, settings: { accessKeyId: string; secret
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendCarriageReturn()
.wait('Initialize the project with the above configuration?')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function initJSProjectWithProfileV12(cwd: string, settings?: Partial<type
env,
disableCIDetection: s.disableCIDetection,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -102,6 +106,10 @@ export function initIosProjectWithProfileV12(cwd: string, settings: Record<strin
stripColors: true,
env,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -139,6 +147,10 @@ export function initAndroidProjectWithProfileV12(cwd: string, settings: Partial<
stripColors: true,
env,
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function getDefaultTemplateDescription(context: $TSContext, category: str
createdBy: deploymentTypeDescription,
createdWith: cliVersion,
stackType: stackTypeDescription,
metadata: {},
metadata: { whyContinueWithGen1: context?.exeInfo?.projectConfig?.whyContinueWithGen1 || '' },
};

return JSON.stringify(descriptionJson);
Expand Down
Loading
Loading