Skip to content

Instantly share code, notes, and snippets.

@pachun
Last active July 20, 2021 21:16
Show Gist options
  • Save pachun/665b46ac83698fbbb286cfcfaf6e647e to your computer and use it in GitHub Desktop.
Save pachun/665b46ac83698fbbb286cfcfaf6e647e to your computer and use it in GitHub Desktop.
Create new react native components quickly
#!/usr/bin/env ruby
require "fileutils"
def component_template(component_name)
<<~COMPONENT_TEMPLATE
import React from "react"
import { View } from "react-native"
import styles from "./styles"
const #{component_name} = (): React.ReactElement => {
return <View style={styles.container}></View>
}
export default #{component_name}
COMPONENT_TEMPLATE
end
def styles_template
<<~STYLES_TEMPLATE
import { StyleSheet } from "react-native"
const styles = StyleSheet.create({
container: {},
})
export default styles
STYLES_TEMPLATE
end
path = ARGV[0]
component_name = path.split("/").last
directory_path = "./#{path}"
index_tsx_path = "./#{path}/index.tsx"
styles_ts_path = "./#{path}/styles.ts"
FileUtils.mkdir_p(directory_path)
File.write(
index_tsx_path,
component_template(component_name),
)
File.write(
styles_ts_path,
styles_template,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment