Skip to content

Commit 4876593

Browse files
dannyhwdanstepanov
authored andcommitted
feat: exit on no install eas
1 parent 4cf1007 commit 4876593

File tree

4 files changed

+68
-59
lines changed

4 files changed

+68
-59
lines changed

.changeset/plenty-toys-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-expo-stack': patch
3+
---
4+
5+
exits when eas and no install are chosen together since its not possible

cli/src/utilities/printOutput.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,7 @@ import { AvailablePackages, CliResults } from '../types';
55
import { copyBaseAssets } from './copyBaseAssets';
66
import { outro, spinner } from '@clack/prompts';
77
import { easConfigure } from './runEasConfigure';
8-
9-
type STDIO = 'inherit' | 'ignore' | 'pipe' | 'overlapped';
10-
11-
const onlyErrors = ['ignore', 'ignore', 'inherit'] as const;
12-
13-
async function runSystemCommand({
14-
command,
15-
errorMessage,
16-
stdio,
17-
toolbox
18-
}: {
19-
command: string;
20-
toolbox: Toolbox;
21-
stdio: readonly [STDIO, STDIO, STDIO] | STDIO | undefined;
22-
errorMessage: string;
23-
}) {
24-
const {
25-
print: { error },
26-
system
27-
} = toolbox;
28-
29-
const result = await system.spawn(command, {
30-
shell: true,
31-
stdio
32-
});
33-
34-
if (result.error || result.status !== 0) {
35-
error(`${errorMessage}: ${JSON.stringify(result)}`);
36-
37-
error(`failed to run command: ${command}`);
38-
39-
return process.exit(1);
40-
}
41-
}
8+
import { ONLY_ERRORS, runSystemCommand } from './systemCommand';
429

4310
export async function printOutput(
4411
cliResults: CliResults,
@@ -78,7 +45,7 @@ export async function printOutput(
7845
await runSystemCommand({
7946
toolbox,
8047
command: `cd ${projectName} && ${packageManager} install --silent`,
81-
stdio: packageManager === 'npm' ? undefined : onlyErrors,
48+
stdio: packageManager === 'npm' ? undefined : ONLY_ERRORS,
8249
errorMessage: 'Error installing dependencies'
8350
});
8451

@@ -91,7 +58,7 @@ export async function printOutput(
9158
await runSystemCommand({
9259
toolbox,
9360
command: `cd ${projectName} && ${packageManager} ${installCommand} --silent expo@latest`,
94-
stdio: isNpm ? undefined : onlyErrors,
61+
stdio: isNpm ? undefined : ONLY_ERRORS,
9562
errorMessage: 'Error updating expo'
9663
});
9764

@@ -129,7 +96,7 @@ export async function printOutput(
12996
toolbox,
13097
command: `${runnerType} prettier "${projectName}/**/*.{json,js,jsx,ts,tsx}" --no-config --write`,
13198
errorMessage: 'Error formatting code',
132-
stdio: onlyErrors
99+
stdio: ONLY_ERRORS
133100
});
134101

135102
s.stop('Project files formatted!');

cli/src/utilities/runEasConfigure.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { Toolbox } from 'gluegun/build/types/domain/toolbox';
22
import { cancel, confirm, isCancel, select } from '@clack/prompts';
33
import { CliResults, PackageManager } from '../types';
4+
import { runSystemCommand } from './systemCommand';
45

56
export async function easConfigure(
67
cliResults: CliResults,
78
packageManager: PackageManager,
89
toolbox: Toolbox
910
): Promise<void> {
1011
const {
11-
print: { info, success, error, warning },
12+
print: { info, success, warning, error },
1213
system
1314
} = toolbox;
1415

16+
if (cliResults.flags.noInstall) {
17+
error('Eas configuration requires installing dependencies, please remove the --no-install flag and try again.');
18+
19+
process.exit(1);
20+
}
21+
1522
const { projectName } = cliResults;
1623

1724
info('Configuring EAS...');
@@ -55,38 +62,33 @@ export async function easConfigure(
5562

5663
info(`We'll use ${packageManagerToUse} install -g eas-cli`);
5764
info(``);
58-
const result = await system.spawn(`${packageManagerToUse} install -g eas-cli`);
5965

60-
if (result.error) {
61-
error('Error installing EAS CLI');
62-
return process.exit(1);
63-
}
66+
await runSystemCommand({
67+
command: `${packageManagerToUse} install -g eas-cli`,
68+
toolbox,
69+
errorMessage: 'Error installing EAS CLI',
70+
stdio: undefined
71+
});
6472
}
6573
}
6674

67-
const result = await system.spawn(`cd ${projectName} && eas build:configure -p all`, {
68-
shell: true,
69-
stdio: 'inherit'
75+
await runSystemCommand({
76+
command: `cd ${projectName} && eas build:configure -p all`,
77+
errorMessage: 'Error configuring EAS',
78+
stdio: 'inherit',
79+
toolbox
7080
});
7181

72-
if (result.error || result.status !== 0) {
73-
error('Error configuring EAS');
74-
return process.exit(1);
75-
}
76-
7782
success('EAS configured!');
7883

7984
info(`Now we'll generate the native code for your project`);
8085

81-
const preBuildResult = await system.spawn(`cd ${projectName} && ${packageManager} run prebuild`, {
82-
shell: true,
83-
stdio: 'inherit'
86+
await runSystemCommand({
87+
command: `cd ${projectName} && ${packageManager} run prebuild`,
88+
errorMessage: 'Error generating native code',
89+
stdio: 'inherit',
90+
toolbox
8491
});
8592

86-
if (preBuildResult.error || preBuildResult.status !== 0) {
87-
error('Error generating native code');
88-
return process.exit(1);
89-
}
90-
9193
success('Native code generated!');
9294
}

cli/src/utilities/systemCommand.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Toolbox } from 'gluegun/build/types/domain/toolbox';
2+
3+
type STDIO = 'inherit' | 'ignore' | 'pipe' | 'overlapped';
4+
5+
export const ONLY_ERRORS = ['ignore', 'ignore', 'inherit'] as const;
6+
7+
export async function runSystemCommand({
8+
command,
9+
errorMessage,
10+
stdio,
11+
toolbox
12+
}: {
13+
command: string;
14+
toolbox: Toolbox;
15+
stdio: readonly [STDIO, STDIO, STDIO] | STDIO | undefined;
16+
errorMessage: string;
17+
}) {
18+
const {
19+
print: { error },
20+
system
21+
} = toolbox;
22+
23+
const result = await system.spawn(command, {
24+
shell: true,
25+
stdio
26+
});
27+
28+
if (result.error || result.status !== 0) {
29+
error(`${errorMessage}: ${JSON.stringify(result)}`);
30+
31+
error(`failed to run command: ${command}`);
32+
33+
return process.exit(1);
34+
}
35+
}

0 commit comments

Comments
 (0)