diff --git a/src/commands/__tests__/createApp.test.ts b/src/commands/__tests__/createApp.test.ts index 11d1d8a..a5c706a 100644 --- a/src/commands/__tests__/createApp.test.ts +++ b/src/commands/__tests__/createApp.test.ts @@ -1,6 +1,6 @@ import { confirm } from '@inquirer/prompts'; -import { vol } from 'memfs'; -import { Mock, afterEach, test, vi } from 'vitest'; +import { fs, vol } from 'memfs'; +import { Mock, afterEach, expect, test, vi } from 'vitest'; import print from '../../util/print'; import { createApp } from '../createApp'; @@ -15,7 +15,7 @@ afterEach(() => { (print as Mock).mockReset(); }); -test("doesn't error", async () => { +test('creates app', async () => { (confirm as Mock).mockResolvedValueOnce(true); vi.spyOn(process, 'chdir').mockImplementation(() => { const json = { @@ -29,4 +29,6 @@ test("doesn't error", async () => { vol.fromJSON(json, './'); }); await createApp('MyApp', { testing: true }); + + expect(fs.readFileSync('App.tsx', 'utf8')).toMatch('expo-status-bar'); }); diff --git a/src/commands/createApp.ts b/src/commands/createApp.ts index 9265a55..f57affc 100644 --- a/src/commands/createApp.ts +++ b/src/commands/createApp.ts @@ -4,6 +4,7 @@ import ora from 'ora'; import { globals } from '../constants'; import addDependency from '../util/addDependency'; import addPackageJsonScripts from '../util/addPackageJsonScripts'; +import copyTemplateDirectory from '../util/copyTemplateDirectory'; import exec from '../util/exec'; import getUserPackageManager from '../util/getUserPackageManager'; import print from '../util/print'; @@ -30,6 +31,7 @@ export async function createApp(name: string | undefined, options: Options) { globals.interactive = interactive; globals.isTest = isTest; + globals.isCreateApp = true; const appName = name || (await getAppName()); await printIntro(); @@ -83,6 +85,8 @@ export async function createApp(name: string | undefined, options: Options) { await commit('Add jest, Testing Library'); } + await copyTemplateDirectory({ templateDir: 'createApp' }); + print(chalk.green(`\n\nšŸ‘– ${appName} successfully configured!`)); print(` diff --git a/src/constants.ts b/src/constants.ts index cf26cb0..42b6b14 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,7 @@ import { fileURLToPath } from 'url'; export const globals = { interactive: true, isTest: false, + isCreateApp: false, }; // TSUP builds files without hierarchy to dist/, so the path is ultimately diff --git a/templates/createApp/App.tsx b/templates/createApp/App.tsx new file mode 100644 index 0000000..fd4ee47 --- /dev/null +++ b/templates/createApp/App.tsx @@ -0,0 +1,28 @@ +import { StatusBar } from 'expo-status-bar'; +import { StyleSheet, Text, View } from 'react-native'; +import Providers, { Provider } from 'src/components/Providers'; + +// Add providers to this array +const providers: Provider[] = [ + // CODEGEN:BELT:PROVIDERS - do not remove +]; + +export default function App() { + return ( + + + Open up App.js to start working on your app! + + + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#fff', + alignItems: 'center', + justifyContent: 'center', + }, +}); diff --git a/templates/createApp/src/components/Providers.tsx b/templates/createApp/src/components/Providers.tsx new file mode 100644 index 0000000..8aa4f5e --- /dev/null +++ b/templates/createApp/src/components/Providers.tsx @@ -0,0 +1,16 @@ +import { ReactNode } from 'react'; + +export type Provider = (children: ReactNode) => ReactNode; + +type ProvidersProps = { + children: ReactNode; + providers: Provider[]; +}; + +export default function Providers({ children, providers }: ProvidersProps) { + // final = call last render with children + // call n-1 passing final as children + return providers.reverse().reduce((acc, current) => { + return current(acc); + }, children); +}