-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathprintOutput.ts
More file actions
304 lines (259 loc) · 10.5 KB
/
Copy pathprintOutput.ts
File metadata and controls
304 lines (259 loc) · 10.5 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import { outro, spinner } from '@clack/prompts';
import { Toolbox } from 'gluegun/build/types/domain/toolbox';
import os from 'os';
import { AvailablePackages, CliResults } from '../types';
import { copyBaseAssets } from './copyBaseAssets';
import { generateNWUI } from './generateNWUI';
import { getPackageManager, getPackageManagerRunnerX } from './getPackageManager';
import { easConfigure } from './runEasConfigure';
import { ONLY_ERRORS, quoteShellArg, runSystemCommand } from './systemCommand';
import { appendFile, writeFile } from 'fs/promises';
const yarnRcFixes = `
enableGlobalCache: false
nodeLinker: node-modules`;
export async function printOutput(
cliResults: CliResults,
formattedFiles: any[],
toolbox: Toolbox,
stylingPackage: AvailablePackages
): Promise<void> {
const {
parameters: { options },
print: { info, success, highlight, warning }
} = toolbox;
const { projectName, flags } = cliResults;
const projectDir = quoteShellArg(projectName);
const projectCwd = projectName;
const s = spinner();
// Output the results to the user
s.start('Initializing your project...');
await Promise.all(formattedFiles);
s.stop('Project initialized!');
s.start('Copying base assets...');
await copyBaseAssets(projectName, toolbox);
s.stop('Base assets copied!');
// check if npm option is set, otherwise set based on what the system is configure to use
const packageManager = cliResults.flags.packageManager || getPackageManager(toolbox, cliResults);
const isNpm = packageManager === 'npm';
// seems like all package managers actually support the run command
const runCommand = `${packageManager} run`;
const runnerType = getPackageManagerRunnerX(toolbox, cliResults);
const expoCommand =
packageManager === 'pnpm'
? 'pnpm exec expo'
: packageManager === 'yarn'
? 'yarn expo'
: packageManager === 'bun'
? 'bunx expo'
: 'npx expo@latest';
const pnpmInstallEnv = packageManager === 'pnpm' ? { PNPM_CONFIG_STRICT_DEP_BUILDS: 'false' } : undefined;
if (!options.noInstall && !flags.noInstall) {
s.start(`Installing dependencies using ${packageManager}...`);
// attempt to improve npm install speeds by disabling audit and progress
const additionalFlags = isNpm
? '--silent --no-audit --progress=false --legacy-peer-deps'
: packageManager === 'pnpm'
? '--config.strict-dep-builds=false'
: '';
const installCommand = `${packageManager} install${additionalFlags ? ` ${additionalFlags}` : ''}`;
if (packageManager === 'yarn') {
// create empty yarn.lock to stop yarn from complaining
await writeFile(`${projectName}/yarn.lock`, '');
// apply fixes to .yarnrc.yml to stop issues with PnP and caching
await appendFile(`${projectName}/.yarnrc.yml`, yarnRcFixes);
await runSystemCommand({
toolbox,
command: 'yarn set version stable',
stdio: ONLY_ERRORS,
errorMessage: 'Error setting yarn version',
cwd: projectCwd
});
}
await runSystemCommand({
toolbox,
command: installCommand,
stdio: isNpm ? undefined : ONLY_ERRORS,
errorMessage: 'Error installing dependencies',
env: pnpmInstallEnv,
cwd: projectCwd
});
s.stop('Dependencies installed!');
s.start('Updating packages to expo compatible versions...');
const expoInstallFixCommand =
packageManager === 'pnpm'
? 'pnpm exec expo install --fix'
: packageManager === 'yarn'
? 'yarn expo install --fix'
: packageManager === 'bun'
? 'bunx expo install --fix'
: `npx expo@latest install --fix ${isNpm ? `-- ${additionalFlags}` : ``}`;
await runSystemCommand({
toolbox,
command: expoInstallFixCommand,
errorMessage: 'Error updating packages',
stdio: undefined,
env: pnpmInstallEnv,
cwd: projectCwd
});
s.stop('Packages updated!');
await generateNWUI(cliResults, toolbox);
s.start(`Cleaning up your project...`);
// format the files with prettier and eslint using installed packages.
await runSystemCommand({
toolbox,
command: `${runCommand} format`,
errorMessage: 'Error formatting code',
stdio: ONLY_ERRORS,
env: pnpmInstallEnv,
cwd: projectCwd
});
s.stop('Project files formatted!');
} else {
await generateNWUI(cliResults, toolbox);
s.start(`formatting your project using ${runnerType} prettier...`);
// Running prettier using global runners against the template.
// Use --no-config to prevent using project's config (that may have plugins/dependencies)
await runSystemCommand({
toolbox,
command: `${runnerType} prettier "${projectName}/**/*.{json,js,jsx,ts,tsx}" --no-config --write`,
errorMessage: 'Error formatting code',
stdio: ONLY_ERRORS
});
s.stop('Project files formatted!');
}
if (!options.noGit && !flags.noGit && process.env.NODE_ENV !== 'test') {
s.start(`Initializing git...`);
// initialize git repo and add first commit
// get create expo stack version
const cesVersion: string = require('../../package.json').version || '2.0.0';
const generatedByMessage = quoteShellArg(`Generated by create-expo-stack ${cesVersion}`);
await runSystemCommand({
toolbox,
command: `git init --quiet && git add . && git commit --no-verify --no-gpg-sign -m "Initial commit" -m ${generatedByMessage} --quiet`,
errorMessage: 'Error initializing git',
stdio: ONLY_ERRORS,
env: {
GIT_TERMINAL_PROMPT: '0',
GIT_EDITOR: 'true',
GCM_INTERACTIVE: 'Never'
},
cwd: projectCwd
});
s.stop(`Git initialized!`);
}
if (cliResults.flags.eas) {
await easConfigure(cliResults, packageManager, toolbox);
}
if (stylingPackage?.name === 'unistyles' && os.type() === 'Darwin') {
try {
const xcodeVersion = await runSystemCommand({
command: `xcodebuild -version | head -n 1 | awk '{print $2}'`,
errorMessage: 'failed to check xcode version',
stdio: 'pipe',
toolbox,
failOnError: false
});
const xcodeVersionString = String(xcodeVersion).trim();
if (xcodeVersionString === '16.2') {
warning(
'\nUnistyles is currently not compatible with xcode 16.2 due to an xcode bug, downgrade to 16.1 or lower to use Unistyles \nhttps://github.com/jpudysz/react-native-unistyles/issues/507'
);
}
} catch (_e: unknown) {
// ignore this error
}
}
const printVexoSteps = () => {
info(``);
highlight('Head over to https://vexo.co to create a new Vexo project.');
info(``);
highlight(`Get the API key:`);
info(`1. Create a new app in your vexo dashboard:`);
highlight(`https://vexo.co/apps`);
info(`2. Find your API key on your app settings page.`);
info(`3. Copy the key and paste it into your .env file.`);
info(`4. Optionally, follow the docs to get started with Vexo:`);
highlight(`https://docs.vexo.co/`);
info(``);
};
// check if packages includes package with name "supabase"
if (cliResults.packages.some((pkg) => pkg.name === 'supabase')) {
success(`\nSuccess! 🎉 Now, here's what's next:`);
info(``);
highlight('Head over to https://database.new to create a new Supabase project.');
info(``);
highlight(`Get the Project URL and anon key from the API settings:`);
info(`1. Go to the API settings page in the Dashboard.`);
info(`2. Find your Project URL, anon, and service_role keys on this page.`);
info(`3. Copy these keys and paste them into your .env file.`);
info(`4. Optionally, follow one of these guides to get started with Supabase:`);
highlight(`https://docs.expo.dev/guides/using-supabase/#next-steps`);
if (cliResults.packages.some((pkg) => pkg.name === 'vexo-analytics')) {
printVexoSteps();
}
success(`Once you're done, run the following to get started: `);
info(``);
} else if (cliResults.packages.some((pkg) => pkg.name === 'firebase')) {
success(`\nSuccess! 🎉 Now, here's what's next:`);
info(``);
highlight('Head over to https://console.firebase.google.com/ to create a new Firebase project.');
info(``);
highlight(`Get the API key and other unique identifiers:`);
info(`1. Register a web app in your Firebase project:`);
highlight(`https://firebase.google.com/docs/web/setup#register-app`);
info(`2. Find your API key and other identifiers.`);
info(`3. Copy these keys and paste them into your .env file.`);
info(`4. Optionally, follow one of these guides to get started with Firebase:`);
highlight(`https://docs.expo.dev/guides/using-firebase/#next-steps`);
if (cliResults.packages.some((pkg) => pkg.name === 'vexo-analytics')) {
printVexoSteps();
}
success(`Once you're done, run the following to get started: `);
info(``);
} else {
if (cliResults.packages.some((pkg) => pkg.name === 'vexo-analytics')) {
success(`Success! 🎉 Now, here's what's next:`);
printVexoSteps();
success(`Once you're done, run the following to get started: `);
} else {
success('\nSuccess! 🎉 Now, just run the following to get started: ');
}
info(``);
}
let step = 1;
if (flags.eas) {
info(`To build for development:`);
info(``);
highlight(`${step}. cd ${projectDir}`);
if (flags.noInstall) highlight(`${++step}. ${packageManager} install`);
highlight(`${++step}. eas build --profile=development`);
highlight(`${++step}. ${runCommand} start`);
info(``);
step = 1;
info(`To create a build to share with others:`);
info(``);
highlight(`${step}. cd ${projectDir}`);
if (flags.noInstall) highlight(`${++step}. ${packageManager} install`);
highlight(`${++step}. eas build --profile=preview`);
info(``);
info('To add additional ios users:');
info(``);
highlight(`eas device:create `);
} else {
highlight(`${step}. cd ${projectDir}`);
if (flags.noInstall) highlight(`${++step}. ${packageManager} install`);
if (stylingPackage.name === 'unistyles' || stylingPackage.name === 'nativewindui') {
highlight(`${++step}. ${expoCommand} prebuild --clean`);
}
highlight(`${++step}. ${runCommand} ios`);
}
info(``);
if (!flags.publish) {
info('To create a GitHub repository for this project, run:');
highlight('npx rn-new --publish');
info(``);
}
outro(
`If you're looking to move even faster, the team at Ronin can help you build it:\n- https://ronindevs.com/?utm_source=rn_new&utm_medium=cli`
);
}