Skip to content

Commit 4226b73

Browse files
Sworzen1Bartłomiej SworzeńMateuszRostkowski
authored
Scripts/bootstrap (#28)
* create bootsrap script/ add utils delete code from file/ add pull request and readme templates * add script into readme --------- Co-authored-by: Bartłomiej Sworzeń <bartlomiej.sworzen@binarapps.com> Co-authored-by: Mateusz Rostkowski <mateusz.rostkowsky995@gmail.com>
1 parent 82e76d3 commit 4226b73

5 files changed

Lines changed: 254 additions & 1 deletion

File tree

app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const APP_CONFIG = {
3737
iosBundleIdentifier: 'your.ios.bundle.identifier', // CONFIG: Add your ios bundle identifier here
3838
isDev: process.env.IS_DEV === '1',
3939
isExpoGo: process.env.IS_EXPO_GO === '1',
40-
scheme: 'your_url_scheme', //CONFIG: Add your url scheme to link to your app
40+
scheme: 'your_url_scheme', // CONFIG: Add your url scheme to link to your app
4141
} as const
4242

4343
const runtimeVersion = { policy: APP_CONFIG.isDev ? 'sdkVersion' : 'appVersion' } as const

scripts/bootstrap.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const fs = require('fs')
3+
const prompt = require('prompt-sync')()
4+
5+
const { addBefore, deleteText, logger } = require('./utils')
6+
7+
const paths = {
8+
appConfig: './app.config.ts',
9+
readme: './README.md',
10+
readmeTemplate: './scripts/templates/readme_template.md',
11+
pullRequestTemplate: './.github/pull_request_template.md',
12+
newPullReuestTemplate: './scripts/templates/pull_request_template.md',
13+
}
14+
15+
// 1.
16+
const replaceReadme = (appName) => {
17+
let contents = fs.readFileSync(paths.readmeTemplate, 'utf8')
18+
contents = contents.replaceAll('_NAME_', appName)
19+
20+
fs.writeFileSync(paths.readme, contents)
21+
}
22+
23+
// 2.
24+
const setUpAppConfig = (appName, bundleId, androidPackageName, scheme, easId) => {
25+
let contents = fs.readFileSync(paths.appConfig, 'utf8')
26+
contents = deleteText(contents, "'your_android_package_name',")
27+
contents = deleteText(contents, "'your.ios.bundle.identifier',")
28+
contents = deleteText(contents, "'ac562c27-4a4e-4532-869f-fe6f9447bee6',")
29+
contents = deleteText(contents, "'Template',")
30+
contents = deleteText(contents, "'your_url_scheme',")
31+
32+
contents = addBefore(
33+
contents,
34+
'// CONFIG: Add your android package name',
35+
`'${androidPackageName}',`
36+
)
37+
contents = addBefore(contents, '// CONFIG: Add your app name', `'${appName}',`)
38+
contents = addBefore(contents, '// CONFIG: Add your eas project ID', `'${easId}',`)
39+
contents = addBefore(contents, '// CONFIG: Add your ios bundle identifier', `'${bundleId}',`)
40+
contents = addBefore(contents, '// CONFIG: Add your url scheme', `'${scheme}',`)
41+
fs.writeFileSync(paths.appConfig, contents)
42+
}
43+
44+
// 3.
45+
const replatePullRequestTemplate = () => {
46+
const contents = fs.readFileSync(paths.newPullReuestTemplate, 'utf8')
47+
48+
fs.writeFileSync(paths.pullRequestTemplate, contents)
49+
}
50+
51+
const setUpProject = (appName, bundleId, androidPackageName, scheme, easId) => {
52+
// START
53+
logger.success('Start ...')
54+
55+
logger.info('Generating new readme file')
56+
// 1. Delete readme -> and create new, with new app name etc.
57+
replaceReadme(appName)
58+
59+
logger.info('Change project variables in app.config.ts file')
60+
// 2. Replace appName, bundleId, androidPackageName,scheme and easProjectId in app.config.ts file
61+
setUpAppConfig(appName, bundleId, androidPackageName, scheme, easId)
62+
63+
logger.info('Generating new pull request template file')
64+
// 3. Delete exist pull request template -> generate the new
65+
replatePullRequestTemplate()
66+
67+
//Finish
68+
logger.success(`Config your project has been success`)
69+
}
70+
71+
const bootstrap = () => {
72+
const appName = prompt('Write your app name: ')
73+
if (!appName) {
74+
return logger.error('Please write correct app name')
75+
}
76+
77+
const bundleId = prompt('Write your bundle ID: ')
78+
if (!bundleId) {
79+
return logger.error('Please write correct bundle ID')
80+
}
81+
82+
const androidPackageName = prompt('Write your android package name: ')
83+
if (!androidPackageName) {
84+
return logger.error('Please write correct android package name')
85+
}
86+
87+
const scheme = prompt('Write your scheme: ')
88+
if (!scheme) {
89+
return logger.error('Please write correct scheme')
90+
}
91+
92+
const easId = prompt('Write your eas project ID: ')
93+
if (!easId) {
94+
return logger.error('Please write correct eas project ID')
95+
}
96+
// 1. Setup project -> set ( appName, bundleId, androidPackageName, appScheme, easProjectId )
97+
setUpProject(appName, bundleId, androidPackageName, scheme, easId)
98+
}
99+
100+
bootstrap()
101+
102+
// INSTRUCTION:
103+
// 1. Delete readme and write the new one
104+
// 2. Setup app.config.ts file
105+
// 3. Setup pull_request_template.md
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Describe your changes
2+
3+
# Issue ticket number or link
4+
5+
# Checklist before requesting a review
6+
7+
- [ ] I did self-review of my code.
8+
- [ ] Do the tests work ?
9+
- [ ] Does lint work ?, it doesn't find any bugs or problems.
10+
11+
# Do any blockers exist ? if yes, describe it below.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# @binarapps/_NAME_
2+
3+
This is a template to be used with expo. It includes all the necessary stuff to start working with expo framework. It has the most popular packages included so it's easier to start coding the app itself without all the necessary boilerplate setup. It has:
4+
5+
Version in the `package.json` is one to one the latest expo on which the template was tested.
6+
7+
## Scripts
8+
9+
#### 1. Bootstrap - At start you should trigger script
10+
11+
```
12+
node ./scripts/bootstrap.js
13+
```
14+
15+
The script gives you opportunity to setup the essentialest variables for your project like app name, bundle ID or android package name
16+
17+
#### 2. Generate new screen
18+
19+
```
20+
node ./scripts/create_new_screen.js
21+
```
22+
23+
You can use this script for generate new common screen, tabs screen or new bottom tab, from screen template. You have possiblity to change screen template for your own.
24+
25+
#### 3. Generate new component
26+
27+
```
28+
node ./scripts/create_new_component.js
29+
```
30+
31+
You can use this script for generate new common component (atom, molecule, organism, common) from component template. You have possiblity to change component template for your own.
32+
33+
## Run Locally
34+
35+
1. Clone the project
36+
37+
```bash
38+
git clone git@github.com:binarapps/_NAME_.git
39+
```
40+
41+
2. Go to the project directory
42+
43+
```bash
44+
cd _NAME_
45+
```
46+
47+
3. Install dependencies
48+
49+
```bash
50+
yarn
51+
```
52+
53+
4. Setup environment variables (right now not needed because we are using only mocked values)
54+
55+
- We are using doppler in our project, and almost everything is happening automatically
56+
- While doing the setup for the first time you need to follow this [instructions](./scripts/README.md) - "1. `generate_dotenv.sh`"
57+
58+
5. Start the expo server
59+
60+
```bash
61+
yarn start
62+
```
63+
64+
## Icons
65+
66+
This template uses [Remix icon set](https://remixicon.com/)
67+
68+
It is added to the app as a font generated by [icomoon app](https://icomoon.io/app/#/select).
69+
70+
## Adding new icons
71+
72+
1. Find `assets/icomoon/selection.json` file in your machine
73+
2. Import this file to this [page (icomoon app)](https://icomoon.io/app/#/select):
74+
75+
- Make sure there are no other icons imported there
76+
77+
3. Download icon which need to be added to the app as svg file.
78+
4. Make sure new icon name is unique (already not used).
79+
5. Add svg file to icomoon app.
80+
6. Go to generate font tab - icomoon app.
81+
82+
- Make sure that all icons that you have added have correct names
83+
84+
7. Download font - icomoon app
85+
8. Replace old files with downloaded ones
86+
87+
- ./selection.json => assets/icomoon/selection.json
88+
- ./fonts/icomoon.ttf => assets/icomoon/icomoon.ttf
89+
90+
9. Generate new types for icons
91+
92+
- run script generating icon types `yarn generate:icon:types`
93+
94+
## Sync up with template:
95+
96+
1. Add template remote
97+
98+
```bash
99+
git remote add template git@github.com:binarapps/expo-ts-template.git
100+
```
101+
102+
2. Go to new branch (for safety reason)
103+
104+
```bash
105+
git checkout -b "sync_with_template/1"
106+
```
107+
108+
3. Fetch template remote
109+
110+
```bash
111+
git fetch template
112+
```
113+
114+
4. Merge with template
115+
116+
```bash
117+
git merge -X theirs template/main --allow-unrelated-histories --no-commit
118+
```
119+
120+
5. Review changes
121+
122+
- There can be some issues with files that you were also working, make sure merge doesnt remove your logic
123+
124+
6. Adjust and commit changes
125+
126+
```bash
127+
git commit -m "chore: sync up with template code"
128+
```
129+
130+
## Working with designer in your project
131+
132+
Expo template, you are going to use - bundles native-base ui lib out of the box.
133+
To have the best starting experience in your project - write a dm to your designer that they should use [NativeBase Figma Design Kit](https://www.figma.com/community/file/1050753649783931446)

scripts/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ exports.addAfter = (content, searchText, textToAdd) => {
4747
exports.addBefore = (content, searchText, textToAdd) => {
4848
return content.replace(searchText, textToAdd + searchText)
4949
}
50+
51+
exports.deleteText = (content, searchText) => {
52+
return content.replace(searchText, '')
53+
}

0 commit comments

Comments
 (0)