-
-
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
- Loading branch information
Stephen Hanson
committed
Oct 29, 2023
1 parent
1a458e3
commit 8fb926a
Showing
13 changed files
with
292 additions
and
138 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
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,47 @@ | ||
import { input } from '@inquirer/prompts'; | ||
import { execSync, spawnSync } from 'child_process'; | ||
import createScaffold from './createScaffold'; | ||
import addEslint from './eslint'; | ||
import addTypescript from './typescript'; | ||
|
||
export async function createApp(name: string | undefined) { | ||
const appName = name || (await getAppName()); | ||
|
||
spawnSync('npx', ['--yes', 'create-expo-app@latest', appName], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
process.chdir(`./${appName}`); | ||
|
||
execSync('git init'); | ||
execSync('git add .'); | ||
execSync('git commit -m "Initial commit"'); | ||
|
||
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); | ||
} |
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 { log } from 'console'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { URL, fileURLToPath } from 'url'; | ||
|
||
const dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
export default async function createScaffold() { | ||
console.log(chalk.bold('👖 Creating directory structure')); | ||
console.log(` | ||
src/ | ||
components/ | ||
util/ | ||
hooks/ | ||
test/ | ||
`); | ||
fs.copySync(path.join(dirname, 'templates', 'scaffold', 'src'), './src'); | ||
log('✅ Created directories'); | ||
} |
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
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
Oops, something went wrong.