-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default 'create' command to create new app (#16)
* Add default 'create' command to create new app * Print welcome messages, start test
- Loading branch information
Stephen Hanson
authored
Nov 3, 2023
1 parent
1a458e3
commit 6f539ce
Showing
22 changed files
with
379 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { vi } from 'vitest'; | ||
|
||
export const spawnSync = vi.fn(); | ||
export const execSync = vi.fn(); | ||
export const exec = vi.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
chdir: vi.fn(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { confirm } from '@inquirer/prompts'; | ||
import { vol } from 'memfs'; | ||
import { Mock, afterEach, test, vi } from 'vitest'; | ||
import print from '../../util/print'; | ||
import { createApp } from '../createApp'; | ||
|
||
vi.mock('@inquirer/prompts', () => ({ | ||
confirm: vi.fn(), | ||
})); | ||
vi.mock('../../util/addDependency'); | ||
vi.mock('../../util/print', () => ({ default: vi.fn() })); | ||
|
||
afterEach(() => { | ||
vol.reset(); | ||
(print as Mock).mockReset(); | ||
}); | ||
|
||
test("doesn't error", async () => { | ||
(confirm as Mock).mockResolvedValueOnce(true); | ||
vi.spyOn(process, 'chdir').mockImplementation(() => { | ||
const json = { | ||
'package.json': '{ "dependencies": {}, "devDependencies": {} }', | ||
}; | ||
vol.fromJSON(json, './'); | ||
}); | ||
await createApp('MyApp'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { confirm, input } from '@inquirer/prompts'; | ||
import { execSync, spawnSync } from 'child_process'; | ||
import print from '../util/print'; | ||
import addEslint from './eslint'; | ||
import createScaffold from './scaffold'; | ||
import addTypescript from './typescript'; | ||
|
||
export async function createApp(name: string | undefined) { | ||
const appName = name || (await getAppName()); | ||
await printIntro(); | ||
|
||
spawnSync('npx', ['--yes', 'create-expo-app@latest', appName], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
process.chdir(`./${appName}`); | ||
|
||
await addTypescript(); | ||
execSync('git add .'); | ||
execSync('git commit -m "Add TypeScript"'); | ||
|
||
await addEslint(); | ||
execSync('git add .'); | ||
execSync('git commit -m "Configure ESLint"'); | ||
|
||
await createScaffold(); | ||
execSync('git add .'); | ||
execSync('git commit -m "Add app scaffold"'); | ||
} | ||
|
||
async function getAppName() { | ||
return input({ message: 'What is the name of your app?' }); | ||
} | ||
|
||
/** | ||
* Commander requires this signature to be ...args: unknown[] | ||
* Actual args are: | ||
* ([<appName>, <Options hash>, <Command>]) | ||
* or ([<Options hash>, <Command>]) if <appName> not passed) | ||
*/ | ||
export default function createAppAction(...args: unknown[]) { | ||
// if argument ommitted, args[0] is options | ||
const appNameArg = (args[0] as string[])[0]; | ||
return createApp(appNameArg); | ||
} | ||
|
||
async function printIntro() { | ||
print('👖 Let’s get started!'); | ||
print(`\nWe will now perform the following tasks: | ||
- Create a new app using the latest create-expo-app | ||
- Add and configure TypeScript | ||
- Add and configure ESLint | ||
- Add and configure Prettier | ||
- Create the project directory structure | ||
`); | ||
|
||
if (!(await confirm({ message: 'Ready to proceed?' }))) { | ||
process.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import chalk from 'chalk'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { URL, fileURLToPath } from 'url'; | ||
import print from '../util/print'; | ||
|
||
const dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
export default async function createScaffold() { | ||
print(chalk.bold('👖 Creating directory structure')); | ||
print(` | ||
src/ | ||
components/ | ||
util/ | ||
hooks/ | ||
test/ | ||
`); | ||
fs.copySync(path.join(dirname, 'templates', 'scaffold', 'src'), './src'); | ||
print('✅ Created directories'); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/commands/templates/scaffold/src/components/buttons/PrimaryButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
StyleSheet, | ||
TouchableOpacity, | ||
TouchableOpacityProps, | ||
} from 'react-native'; | ||
|
||
type ButtonProps = TouchableOpacityProps; | ||
|
||
export default function PrimaryButton({ | ||
style, | ||
text, | ||
textStyle, | ||
children, | ||
...props | ||
}: ButtonProps) { | ||
return ( | ||
<TouchableOpacity | ||
activeOpacity={0.6} | ||
style={[styles.button, style]} | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
paddingVertical: 16, | ||
paddingHorizontal: 14, | ||
backgroundColor: '#08f', | ||
borderRadius: 12, | ||
justifyContent: 'center', | ||
}, | ||
}); |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { exec } from 'child_process'; | ||
import { execSync } from 'child_process'; | ||
|
||
export default async function formatFile(filePath: string) { | ||
exec(`npx prettier --write '${filePath}'`); | ||
execSync(`npx prettier --write '${filePath}'`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { test, vi } from 'vitest'; | ||
import printWelcome from '../printWelcome'; | ||
|
||
vi.mock('../../print', () => ({ default: vi.fn() })); | ||
|
||
test('doesnt error', () => { | ||
printWelcome(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import chalk from 'chalk'; | ||
import print from '../print'; | ||
|
||
export default function printWelcome() { | ||
print(chalk.bold('\n\n\t👖 thoughtbelt 👖\n')); | ||
print( | ||
'Perform project setup and redundant tasks\n without your pants falling down!\n\n', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { vi } from 'vitest'; | ||
|
||
vi.mock('child_process'); | ||
vi.mock('fs-extra'); |
Oops, something went wrong.