-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent_cauldron
executable file
·79 lines (61 loc) · 1.8 KB
/
component_cauldron
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
component_dir="lib/components/"
core_styles_dir="lib/styles/"
core_scss="core.scss"
core_js="lib/core.js"
echo "Running React Component Cauldron..."
if [[ -z "$1" ]]; then
echo "No component name provided" >&2
exit 1
fi
echo "Creating UI component $1" >&2
if [[ -r ./.uirc ]]; then
echo ".uirc file found..." >&2
. ./.uirc
fi
componentName="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
dest="$(pwd)/$component_dir/$componentName"
if [[ ! -d $(pwd)/$core_styles_dir ]]; then
mkdir -p $(pwd)/$core_styles_dir
fi
coreSass=$(pwd)/$core_styles_dir/$core_scss
`touch $coreSass`
echo "@import \"../components/$componentName/$componentName.scss\";" >> $coreSass
if [[ ! -f $(pwd)/$core_js ]]; then
`touch $(pwd)/core_js`
echo "import './styles/$core_scss';
export * from './components';" > $(pwd)/$core_js
fi
echo "Beginning scaffolding component $1 in dir $dest" >&2
mkdir -p $dest && cd $dest
if [[ -f ./$componentName.js || -f ./$componentName.scss ]]; then
echo "Files for $componentName component already exists; Exiting program" >&2
exit 1
fi
#Create file for sass and js, populate js file with basic react component tempalte
$(touch $componentName.scss)
$(touch $componentName.js)
echo "Templating JS file..." >&2
echo "import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default class $componentName extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
</div>
);
}
}
$componentName.propTypes = {
}
" > $componentName.js
#Add files to the core files for exporting as library
cd ..
`touch index.js`
echo "Exporting component through index.js..." >&2
echo "export { default as $componentName } from './$componentName/$componentName';" >> index.js
echo "Done! React component created!" >&2
exit 0