Skip to content

Commit 71d10aa

Browse files
committed
added exitGracefully function
1 parent 83ace21 commit 71d10aa

30 files changed

Lines changed: 88 additions & 66 deletions

src/angular/angular-utilities.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { getPath } from '../utilities';
1111
const mockConstants: MockConstants = getMockConstants('angular-utilities');
1212

1313
let npmInstallMock: jest.SpiedFunction<typeof NpmUtilities.install>;
14-
let cpExecSyncMock: jest.SpiedFunction<typeof CPUtilities.execSync>;
14+
let cpExecSyncMock: jest.SpiedFunction<typeof CPUtilities.exec>;
1515

1616
describe('AngularUtilities', () => {
1717
beforeEach(async () => {
@@ -26,7 +26,7 @@ describe('AngularUtilities', () => {
2626
]
2727
);
2828
npmInstallMock = jest.spyOn(NpmUtilities, 'install').mockImplementation(async () => {});
29-
cpExecSyncMock = jest.spyOn(CPUtilities, 'execSync').mockImplementation(() => {});
29+
cpExecSyncMock = jest.spyOn(CPUtilities, 'exec').mockImplementation(async () => {});
3030
});
3131

3232
test('addComponentImports', async () => {

src/angular/angular.utilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ export abstract class AngularUtilities {
513513
* @param command - The command to run.
514514
* @param options - Options for running the command.
515515
*/
516-
static runCommand(directory: Path, command: AngularCliCommands, options: AngularCliOptions<typeof command>): void {
517-
CPUtilities.execSync(`cd ${directory} && npx @angular/cli@${this.CLI_VERSION} ${command} ${optionsToCliString(options)}`);
516+
static async runCommand(directory: Path, command: AngularCliCommands, options: AngularCliOptions<typeof command>): Promise<void> {
517+
await CPUtilities.exec(`cd ${directory} && npx @angular/cli@${this.CLI_VERSION} ${command} ${optionsToCliString(options)}`);
518518
}
519519

520520
/**
@@ -530,7 +530,7 @@ export abstract class AngularUtilities {
530530
navElement: AddNavElementConfig | undefined,
531531
domain: string | undefined
532532
): Promise<void> {
533-
this.runCommand(root, `generate component pages/${pageName}`, { '--skip-tests': true, '--inline-style': true });
533+
await this.runCommand(root, `generate component pages/${pageName}`, { '--skip-tests': true, '--inline-style': true });
534534

535535
if (navElement) {
536536
await this.addNavElement(root, navElement);
@@ -805,7 +805,7 @@ export abstract class AngularUtilities {
805805
{ provide: 'HTTP_INTERCEPTORS', useClass: 'OfflineRequestInterceptor' as any, multi: true },
806806
[{ defaultImport: false, element: 'OfflineRequestInterceptor', path: NpmPackage.NGX_PWA }]
807807
);
808-
this.runCommand(root, `add @angular/pwa@${this.CLI_VERSION}`, { '--skip-confirmation': true });
808+
await this.runCommand(root, `add @angular/pwa@${this.CLI_VERSION}`, { '--skip-confirmation': true });
809809
await NpmUtilities.install(name, [NpmPackage.NGX_PWA]);
810810
await FsUtilities.updateFile(
811811
getPath(root, 'src', 'app', 'app.component.html'),

src/commands/add/add-angular-library/add-angular-library.command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,22 @@ export class AddAngularLibraryCommand extends BaseAddCommand<AddAngularLibraryCo
9191
private async createProject(config: AddAngularLibraryConfiguration): Promise<CreateResult> {
9292
// eslint-disable-next-line no-console
9393
console.log('Creates a temporary angular workspace');
94-
AngularUtilities.runCommand(
94+
await AngularUtilities.runCommand(
9595
getPath(LIBS_DIRECTORY_NAME),
9696
`new ${config.name}`,
9797
{ '--no-create-application': true }
9898
);
9999
// eslint-disable-next-line no-console
100100
console.log('Creates the base library');
101-
AngularUtilities.runCommand(
101+
await AngularUtilities.runCommand(
102102
getPath(LIBS_DIRECTORY_NAME, config.name),
103103
`generate library ${config.name}`,
104104
{}
105105
);
106106

107107
// eslint-disable-next-line no-console
108108
console.log('Sets up the storybook');
109-
StorybookUtilities.setup(getPath(LIBS_DIRECTORY_NAME, config.name));
109+
await StorybookUtilities.setup(getPath(LIBS_DIRECTORY_NAME, config.name));
110110

111111
const oldPackageJson: PackageJson = await FsUtilities.parseFileAs(
112112
getPath(LIBS_DIRECTORY_NAME, config.name, 'projects', config.name, PACKAGE_JSON_FILE_NAME)

src/commands/add/add-angular-website/add-angular-website.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class AddAngularWebsiteCommand extends BaseAddCommand<AddAngularWebsiteCo
233233
private async createProject(config: AddAngularWebsiteConfiguration): Promise<Path> {
234234
// eslint-disable-next-line no-console
235235
console.log('Creates the base website');
236-
AngularUtilities.runCommand(
236+
await AngularUtilities.runCommand(
237237
getPath(APPS_DIRECTORY_NAME),
238238
`new ${config.name}`,
239239
{ '--skip-git': true, '--style': 'css', '--inline-style': true, '--ssr': true }

src/commands/add/add-angular/add-angular.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class AddAngularCommand extends BaseAddCommand<AddAngularConfiguration> {
213213

214214
private async createProject(config: AddAngularConfiguration): Promise<Path> {
215215
console.log('Creates the base app');
216-
AngularUtilities.runCommand(
216+
await AngularUtilities.runCommand(
217217
getPath(APPS_DIRECTORY_NAME),
218218
`new ${config.name}`,
219219
{ '--skip-git': true, '--style': 'css', '--inline-style': true, '--ssr': true }

src/commands/add/add-nest/add-nest.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class AddNestCommand extends BaseAddCommand<AddNestConfiguration> {
220220
private async createProject(config: AddNestConfiguration): Promise<Path> {
221221
// eslint-disable-next-line no-console
222222
console.log('Creates the base app');
223-
NestUtilities.runCommand(
223+
await NestUtilities.runCommand(
224224
getPath(APPS_DIRECTORY_NAME),
225225
`new ${config.name}`,
226226
{

src/commands/add/add-ts-library/add-ts-library.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class AddTsLibraryCommand extends BaseAddCommand<TsLibraryConfiguration>
7777
private async createProject(config: TsLibraryConfiguration): Promise<string> {
7878
// eslint-disable-next-line no-console
7979
console.log('Creates the library');
80-
CPUtilities.execSync(`cd ${LIBS_DIRECTORY_NAME} && npm create vite@${this.VITE_VERSION} ${config.name} -- --template vanilla-ts`);
80+
await CPUtilities.exec(`cd ${LIBS_DIRECTORY_NAME} && npm create vite@${this.VITE_VERSION} ${config.name} -- --template vanilla-ts`);
8181
const libraryPath: string = getPath(LIBS_DIRECTORY_NAME, config.name);
8282
await FsUtilities.createFile(getPath(libraryPath, 'vite.config.ts'), [
8383
'import { defineConfig, PluginOption } from \'vite\';',

src/commands/base-command.model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export abstract class BaseCommand<Input extends object = {}> {
4747
* @param args - The cli args.
4848
*/
4949
protected async validate(args: string[]): Promise<void> {
50-
this.validateMaxLength(args);
50+
await this.validateMaxLength(args);
5151
await this.validateInsideWorkspace();
5252
}
5353

@@ -61,20 +61,20 @@ export abstract class BaseCommand<Input extends object = {}> {
6161
const config: WorkspaceConfig | undefined = await WorkspaceUtilities.getConfig();
6262
// eslint-disable-next-line typescript/strict-boolean-expressions
6363
if (!config?.isWorkspace) {
64-
exitWithError('This command can only be run inside a workspace');
64+
await exitWithError('This command can only be run inside a workspace');
6565
}
6666
}
6767

6868
/**
6969
* Validates that the provided args are not bigger than the maxLength.
7070
* @param args - The cli args.
7171
*/
72-
protected validateMaxLength(args: string[]): void {
72+
protected async validateMaxLength(args: string[]): Promise<void> {
7373
if (this.maxLength == undefined) {
7474
return;
7575
}
7676
if (args.length > this.maxLength) {
77-
exitWithError(TOO_MANY_ARGUMENTS_ERROR_MESSAGE);
77+
await exitWithError(TOO_MANY_ARGUMENTS_ERROR_MESSAGE);
7878
}
7979
}
8080
}

src/commands/down/down.command.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export class DownCommand extends BaseCommand<DownConfiguration> {
1313
protected override readonly insideWorkspace: boolean = true;
1414
protected override readonly maxLength: number = 2;
1515

16-
protected override run(input: DownConfiguration): Promise<void> | void {
16+
protected override async run(input: DownConfiguration): Promise<void> {
1717
for (const filePath of input.dockerFilePaths) {
18-
CPUtilities.execSync(`docker compose -f ${filePath} -p ${input.projectName} stop`);
18+
await CPUtilities.exec(`docker compose -f ${filePath} -p ${input.projectName} stop`);
1919
}
2020
}
2121

2222
protected override async validate(args: string[]): Promise<void> {
23-
this.validateMaxLength(args);
23+
await this.validateMaxLength(args);
2424
if (args.length === 1) {
2525
await this.validateInsideWorkspace();
2626
}
@@ -36,7 +36,7 @@ export class DownCommand extends BaseCommand<DownConfiguration> {
3636
.filter(d => d != undefined);
3737

3838
if (!dockerFilePaths.length) {
39-
exitWithError(`Error: Could not find any running docker services for "${projectName}"`);
39+
await exitWithError(`Error: Could not find any running docker services for "${projectName}"`);
4040
}
4141

4242
return {

src/commands/init/init.command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class InitCommand extends BaseCommand<InitConfiguration> {
1717
protected override async run(config: InitConfiguration): Promise<void> {
1818
await NpmUtilities.init('root', false);
1919

20-
NpmUtilities.installInRoot([
20+
await NpmUtilities.installInRoot([
2121
NpmPackage.ESLINT_CONFIG_SERVICE_SOFT,
2222
NpmPackage.ESLINT,
2323
NpmPackage.TAILWIND,
@@ -40,7 +40,7 @@ export class InitCommand extends BaseCommand<InitConfiguration> {
4040
this.addNpmWorkspaces()
4141
]);
4242

43-
CPUtilities.execSync('git init');
43+
await CPUtilities.exec('git init');
4444
if (config.setupGithubActions) {
4545
await GithubUtilities.createWorkflow({
4646
name: 'main',
@@ -69,7 +69,7 @@ export class InitCommand extends BaseCommand<InitConfiguration> {
6969
await super.validate(args);
7070
const config: WorkspaceConfig | undefined = await WorkspaceUtilities.getConfig();
7171
if (config?.isWorkspace === true) {
72-
exitWithError('Error: The current directory is already a monorepo workspace');
72+
await exitWithError('Error: The current directory is already a monorepo workspace');
7373
}
7474
}
7575

0 commit comments

Comments
 (0)