Skip to content

Commit

Permalink
refactor: update cli to use root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
yjose committed Nov 10, 2022
1 parent 6bb7b7e commit 2fe52e2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 32 deletions.
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<p align="center">
<img alt="React Native Template Obytes" src="https://user-images.githubusercontent.com/11137944/93101697-808bc580-f6a2-11ea-8ce3-482be6ca456a.png" width="200" />

</p>
<a href='https://starter.obytes.com'>
<h2 align="center">
https://starter.obytes.com
</h2>
</a>

<h1 align="center">
React Native Template Obytes
</h1>

📱 A template for your next React Native project 🚀, Made with developer experience and performance first: Expo,TypeScript,tailwindcss, Husky, Lint-Staged, react-navigation, react-query, react-hook-form, I18n.

# 😎 Overview
## 😎 Overview

This starter is based on obytes mobile tribe best practices for building react native apps and used on a daily based by our team. The starter is battle tested with multiple projects we worked on over the past four years.

Expand Down Expand Up @@ -71,11 +66,11 @@ The short answer is yes, if you are building a react native app and you want to

If you don't think using a starter is a good idea you can just take a look and get some inspiration for your project to find some good practices and solutions for common challenges react native developers are facing while building apps.

# 🧑‍💻 Stay up to date
## 🧑‍💻 Stay up to date

The starter is constantly improving and we are adding new features and fixing bugs as soon as we can. You can stay up to date by watching the repository or by hitting the start button.

# 💎 Libraries used
## 💎 Libraries used

- [Expo](https://docs.expo.io/)
- [React Navigation](https://reactnavigation.org/)
Expand All @@ -90,16 +85,16 @@ The starter is constantly improving and we are adding new features and fixing bu
- [React Native Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler/docs/)
- [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/)
- [React Naive Svg](https://github.com/software-mansion/react-native-svg)
- [ React Error Boundaries](https://github.com/bvaughn/react-error-boundary)
- [React Error Boundaries](https://github.com/bvaughn/react-error-boundary)
- [React Native fast image](https://github.com/DylanVann/react-native-fast-image)

# 🥷 Contributors
## 🥷 Contributors

This starter is maintained by [Obytes mobile tribe team](https://www.obytes.com/team) and we are happy to welcome new contributors to the project.

We are also open to work on your project and help you build your app. You can contact us on [obytes.com/contact](https://www.obytes.com/contact).

# 🔥 How to contribute ?
## 🔥 How to contribute ?

First of all, thank you for your interest in contributing to this project. We are happy to have you here and here is how you can help us improve this project:

Expand All @@ -111,6 +106,6 @@ First of all, thank you for your interest in contributing to this project. We ar

4. If you found a bug while using the starter or a typo in the documentation, feel free to open an issue or even better, open a pull request with the fix.

# 🔖 License
## 🔖 License

This project is MIT licensed.
24 changes: 13 additions & 11 deletions cli/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#!/usr/bin/env node

const chalk = require("chalk");
const { runCommand, cleanUpFolder } = require("./utils.js");
const chalk = require('chalk');
const { runCommand, cleanUpFolder, showMoreDetails } = require('./utils.js');

const createObytesApp = async () => {
// get project name from command line
const projectName = process.argv[2];
// check if project name is provided
if (!projectName) {
console.log(chalk.red("Please provide a project name"));
console.log(chalk.red('Please provide a project name'));
process.exit(1);
}

// create a new project based on obytes template
const createRNProjectCommand = `npx -y react-native init ${projectName} --template https://github.com/obytes/react-native-template-obytes --skip-install`;
const cloneStarter = `git clone --depth=1 -b new_structure https://github.com/obytes/react-native-template-obytes.git ${projectName}`;

// run init command and clean up project folder
await runCommand(createRNProjectCommand, {
loading: "Download and extract template",
success: "Template downloaded and extracted",
error: "Failed to download and extract template",
await runCommand(cloneStarter, {
loading: 'Download and extract template',
success: 'Template downloaded and extracted',
error: 'Failed to download and extract template',
});

await cleanUpFolder(projectName);

// install dependencies
await runCommand(`cd ${projectName} && yarn`, {
loading: "Installing dependencies",
success: "Dependencies installed",
error: "Failed to install dependencies",
loading: 'Installing dependencies',
success: 'Dependencies installed',
error: 'Failed to install dependencies',
});

showMoreDetails();
};

createObytesApp();
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-obytes-app",
"version": "1.1.0",
"version": "1.2.0",
"description": "Obytes expo starter",
"homepage": "https://github.com/obytes/react-native-template-obytes",
"repository": {
Expand Down
54 changes: 48 additions & 6 deletions cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,54 @@ const initGit = async (projectName) => {
await execShellCommand(`cd ${projectName} && git init && cd ..`);
};

// add husky script to package.json
const addPostInstallScript = async (projectName) => {
// Update package.json infos, name and set version to 0.0.1
const updatePackageInfos = async (projectName) => {
const packageJsonPath = path.join(
process.cwd(),
`${projectName}/package.json`
);
const packageJson = fs.readJsonSync(packageJsonPath);
packageJson.scripts.postinstall = 'husky install';
packageJson.version = '0.0.1';
packageJson.name = projectName?.toLowerCase();
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
};

// remove ios and android folders
const updateConfig = async (projectName) => {
const configPath = path.join(
process.cwd(),
`${projectName}/config/config.js`
);
const contents = fs.readFileSync(configPath, {
encoding: 'utf-8',
});
const replaced = contents
.replace(/ObytesApp/gi, projectName)
.replace(/com.obytes/gi, `com.${projectName.toLowerCase()}`);

fs.writeFileSync(configPath, replaced, { spaces: 2 });
const readmeFilePath = path.join(
process.cwd(),
`${projectName}/README-project.md`
);
fs.renameSync(
readmeFilePath,
path.join(process.cwd(), `${projectName}/README.md`)
);
};

// remove ios and android folders and update project config
const cleanUpFolder = async (projectName) => {
const spinner = createSpinner(`Clean and Setup project folder`).start();
const spinner = createSpinner(`Clean and Setup project folder`).start();
try {
fs.removeSync(path.join(process.cwd(), `${projectName}/.git`));
fs.removeSync(path.join(process.cwd(), `${projectName}/README.md`));
fs.removeSync(path.join(process.cwd(), `${projectName}/ios`));
fs.removeSync(path.join(process.cwd(), `${projectName}/android`));
fs.removeSync(path.join(process.cwd(), `${projectName}/docs`));
fs.removeSync(path.join(process.cwd(), `${projectName}/cli`));
await initGit(projectName);
addPostInstallScript(projectName);
updatePackageInfos(projectName);
updateConfig(projectName);
spinner.success({ text: 'Clean and Setup project folder' });
} catch (error) {
spinner.error({ text: error });
Expand All @@ -62,7 +91,20 @@ const cleanUpFolder = async (projectName) => {
}
};

// show more details message using chalk
const showMoreDetails = () => {
console.log(
'\n\n\n',
chalk('🔥 Your project is ready to go! \n\n'),
chalk('📱 Run your project: \n\n'),
chalk(' IOS : yarn ios \n'),
chalk(' Android : yarn android \n\n'),
chalk.bold('📚 Starter Documentation: https://starter.obytes.com \n')
);
};

module.exports = {
runCommand,
cleanUpFolder,
showMoreDetails,
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build:production:android": "APP_ENV=production eas build --profile development --platform android ",
"web": "expo start --web",
"postinstall": "husky install",
"np": "np --no-publish",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"type-check": "tsc --noemit",
"lint:translations": "eslint ./src/translations/ --fix --ext .json ",
Expand Down Expand Up @@ -95,6 +96,7 @@
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.1",
"np": "^7.5.0",
"jest": "^29.2.2",
"jest-coverage-badges": "^1.1.2",
"jest-environment-jsdom": "^29.2.2",
Expand All @@ -109,6 +111,6 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/username/your-repo.git"
"url": "git+https://github.com/obytes/react-native-template-obytes.git"
}
}

0 comments on commit 2fe52e2

Please sign in to comment.