|
| 1 | +import path from 'path'; |
| 2 | +import fs from 'fs-extra'; |
| 3 | +import dedent from 'dedent'; |
| 4 | +import type { TemplateConfiguration } from './config'; |
| 5 | +import kleur from 'kleur'; |
| 6 | + |
| 7 | +export async function printNextSteps( |
| 8 | + local: boolean, |
| 9 | + folder: string, |
| 10 | + config: TemplateConfiguration |
| 11 | +) { |
| 12 | + if (local) { |
| 13 | + let linked; |
| 14 | + |
| 15 | + const packageManager = (await fs.pathExists( |
| 16 | + path.join(process.cwd(), 'yarn.lock') |
| 17 | + )) |
| 18 | + ? 'yarn' |
| 19 | + : 'npm'; |
| 20 | + |
| 21 | + const packageJsonPath = path.join(process.cwd(), 'package.json'); |
| 22 | + |
| 23 | + if (await fs.pathExists(packageJsonPath)) { |
| 24 | + const packageJson = await fs.readJSON(packageJsonPath); |
| 25 | + const isReactNativeProject = Boolean( |
| 26 | + packageJson.dependencies?.['react-native'] |
| 27 | + ); |
| 28 | + |
| 29 | + if (isReactNativeProject) { |
| 30 | + packageJson.dependencies = packageJson.dependencies || {}; |
| 31 | + packageJson.dependencies[config.project.slug] = |
| 32 | + packageManager === 'yarn' |
| 33 | + ? `link:./${path.relative(process.cwd(), folder)}` |
| 34 | + : `file:./${path.relative(process.cwd(), folder)}`; |
| 35 | + |
| 36 | + await fs.writeJSON(packageJsonPath, packageJson, { |
| 37 | + spaces: 2, |
| 38 | + }); |
| 39 | + |
| 40 | + linked = true; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + console.log( |
| 45 | + dedent(` |
| 46 | + ${kleur.magenta( |
| 47 | + `${kleur.bold('Get started')} with the project` |
| 48 | + )}${kleur.gray(':')} |
| 49 | +
|
| 50 | + ${ |
| 51 | + (linked |
| 52 | + ? `- Run ${kleur.blue( |
| 53 | + `${packageManager} install` |
| 54 | + )} to link the library\n` |
| 55 | + : `- Link the library at ${kleur.blue( |
| 56 | + path.relative(process.cwd(), folder) |
| 57 | + )} based on your project setup'\n`) + |
| 58 | + `- Run ${kleur.blue( |
| 59 | + 'pod install --project-directory=ios' |
| 60 | + )} to install dependencies with CocoaPods\n` + |
| 61 | + `- Run ${kleur.blue('npx react-native run-android')} or ${kleur.blue( |
| 62 | + 'npx react-native run-ios' |
| 63 | + )} to build and run the app\n` + |
| 64 | + `- Import from ${kleur.blue( |
| 65 | + config.project.slug |
| 66 | + )} and use it in your app.` |
| 67 | + } |
| 68 | +
|
| 69 | + ${kleur.yellow(`Good luck!`)} |
| 70 | + `) |
| 71 | + ); |
| 72 | + } else { |
| 73 | + const platforms = { |
| 74 | + ios: { name: 'iOS', color: 'cyan' }, |
| 75 | + android: { name: 'Android', color: 'green' }, |
| 76 | + ...(config.example === 'expo' |
| 77 | + ? ({ web: { name: 'Web', color: 'blue' } } as const) |
| 78 | + : null), |
| 79 | + } as const; |
| 80 | + |
| 81 | + console.log( |
| 82 | + dedent(` |
| 83 | + ${kleur.magenta( |
| 84 | + `${kleur.bold('Get started')} with the project` |
| 85 | + )}${kleur.gray(':')} |
| 86 | +
|
| 87 | + ${kleur.gray('$')} yarn |
| 88 | + ${Object.entries(platforms) |
| 89 | + .map( |
| 90 | + ([script, { name, color }]) => ` |
| 91 | + ${kleur[color](`Run the example app on ${kleur.bold(name)}`)}${kleur.gray( |
| 92 | + ':' |
| 93 | + )} |
| 94 | +
|
| 95 | + ${kleur.gray('$')} yarn example ${script}` |
| 96 | + ) |
| 97 | + .join('\n')} |
| 98 | +
|
| 99 | + ${kleur.yellow( |
| 100 | + `See ${kleur.bold('CONTRIBUTING.md')} for more details. Good luck!` |
| 101 | + )} |
| 102 | + `) |
| 103 | + ); |
| 104 | + } |
| 105 | +} |
0 commit comments