-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathamplify_project_creator.ts
118 lines (102 loc) · 3.88 KB
/
amplify_project_creator.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
107
108
109
110
111
112
113
114
115
116
117
118
import { EOL } from 'os';
import { LogLevel, format, printer } from '@aws-amplify/cli-core';
import { PackageManagerController } from '@aws-amplify/plugin-types';
import { ProjectRootValidator } from './project_root_validator.js';
import { GitIgnoreInitializer } from './gitignore_initializer.js';
import { InitialProjectFileGenerator } from './initial_project_file_generator.js';
const LEARN_MORE_USAGE_DATA_TRACKING_LINK =
'https://docs.amplify.aws/react/reference/telemetry';
/**
* Orchestration class that sets up a new Amplify project
*/
export class AmplifyProjectCreator {
private readonly defaultDevPackages = [
'@aws-amplify/backend',
'@aws-amplify/backend-cli',
'aws-cdk@^2',
'aws-cdk-lib@^2',
'constructs@^10.0.0',
'typescript@^5.4.0',
'tsx',
'esbuild',
];
private readonly defaultProdPackages = ['aws-amplify'];
/**
* Orchestrator for the create-amplify workflow.
* Delegates out to other classes that handle parts of the getting started experience
*/
constructor(
private readonly projectRoot: string,
private readonly packageManagerController: PackageManagerController,
private readonly projectRootValidator: ProjectRootValidator,
private readonly gitIgnoreInitializer: GitIgnoreInitializer,
private readonly initialProjectFileGenerator: InitialProjectFileGenerator
) {}
/**
* Executes the create-amplify workflow
*/
create = async (): Promise<void> => {
printer.log(
`Validating current state of target directory...`,
LogLevel.DEBUG
);
await this.projectRootValidator.validate();
await this.packageManagerController.initializeProject();
printer.printNewLine();
printer.log(format.sectionHeader(`Installing devDependencies:`));
printer.log(format.list(this.defaultDevPackages));
printer.printNewLine();
printer.log(format.sectionHeader(`Installing dependencies:`));
printer.log(format.list(this.defaultProdPackages));
printer.printNewLine();
await printer.indicateProgress('Installing devDependencies', () =>
this.packageManagerController.installDependencies(
this.defaultDevPackages,
'dev'
)
);
printer.log(`✔ DevDependencies installed`);
await printer.indicateProgress('Installing dependencies', () =>
this.packageManagerController.installDependencies(
this.defaultProdPackages,
'prod'
)
);
printer.log(`✔ Dependencies installed`);
await printer.indicateProgress('Creating template files', async () => {
await this.gitIgnoreInitializer.ensureInitialized();
await this.initialProjectFileGenerator.generateInitialProjectFiles();
});
printer.log(`✔ Template files created`);
printer.log(format.success('Successfully created a new project!'));
printer.printNewLine();
const cdPreamble =
process.cwd() === this.projectRoot
? null
: `Navigate to your project directory using ${format.command(
`cd .${this.projectRoot.replace(process.cwd(), '')}`
)} and then:`;
printer.log(format.sectionHeader(`Welcome to AWS Amplify!`));
const welcomeMessage = format.list([
`Get started by running ${format.normalizeAmpxCommand('sandbox')}.`,
`Run ${format.normalizeAmpxCommand(
'help'
)} for a list of available commands.`,
]);
const instructionSteps = [cdPreamble, welcomeMessage]
.filter(Boolean)
.join(EOL);
printer.log(instructionSteps);
printer.printNewLine();
printer.log(
format.note(
`Amplify collects anonymous telemetry data about general usage of the CLI. Participation is optional, and you may opt-out by using ${format.normalizeAmpxCommand(
'configure telemetry disable'
)}. To learn more about telemetry, visit ${format.link(
LEARN_MORE_USAGE_DATA_TRACKING_LINK
)}`
)
);
printer.printNewLine();
};
}