-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-initializer.ts
53 lines (46 loc) · 1.82 KB
/
angular-initializer.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
import { resolve, basename } from 'path';
import { Answers } from '../../@types/common/answers';
import ora from 'ora';
import Logger from '../../utils/logger';
import CommandExecutorInterface from '../../@types/utils/command-executor';
import FileSystemInterface from '../../@types/utils/file-system';
const USE_COLORS = true;
const logger = new Logger(USE_COLORS);
export async function createAngularProject(
projectDir: string,
commandExecutor: CommandExecutorInterface,
fileSystem: FileSystemInterface
): Promise<void> {
const absoluteProjectDir = resolve(projectDir);
const projectName = basename(projectDir);
try {
if (fileSystem.mkdir) {
await fileSystem.mkdir(absoluteProjectDir, { recursive: true });
}
process.chdir(absoluteProjectDir);
const command = `npx @angular/cli new ${projectName} --strict`;
await commandExecutor.execute(command, { cwd: absoluteProjectDir });
} finally {
process.chdir(absoluteProjectDir);
}
}
export async function runAngularCLI(
answers: Answers,
commandExecutor: CommandExecutorInterface
): Promise<void> {
const { projectName, destination } = answers;
const projectDir = `${destination}/${projectName}`;
const spinner = ora('Initializing Angular project...').start();
try {
spinner.stop();
const command = `npx @angular/cli new ${projectName} --strict`;
await commandExecutor.execute(command, { stdio: 'inherit', cwd: destination });
spinner.succeed(`Angular project created successfully at ${projectDir}`);
logger.log('Application created successfully, happy hacking! 🚀');
process.exit(0);
} catch (error: any) {
spinner.fail('Error initializing Angular project');
logger.error(error.message);
throw error;
}
}