Skip to content

Commit

Permalink
feat(cli): use our repository as template
Browse files Browse the repository at this point in the history
  • Loading branch information
asdolo committed Aug 5, 2024
1 parent af7be68 commit a58b597
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT }}
-Dsonar.sonar.sourceEncoding=UTF-8
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.coverage.exclusions=**/storage/**,**/**.config.js,**/*.test.tsx,**/icons/**,**/docs/**,**/cli/**,**/__mocks__/**,**/android/**,**/ios/**
-Dsonar.coverage.exclusions=**/storage/**,**/**.config.js,**/*.test.tsx,**/icons/**,**/docs/**,**/cli/**,**/__mocks__/**,**/android/**,**/ios/**,env.js
14 changes: 8 additions & 6 deletions cli/clone-repo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { runCommand } = require('./utils.js');
const { consola } = require('consola');

const repository = "rootstrap/react-native-template";

const getLatestRelease = async () => {
try {
const repoData = await fetch(
'https://api.github.com/repos/obytes/react-native-template-obytes/releases/latest'
`https://api.github.com/repos/${repository}/releases/latest`
);
const releaseData = await repoData.json();
return releaseData.tag_name || 'master';
Expand All @@ -19,13 +21,13 @@ const getLatestRelease = async () => {
const cloneLastTemplateRelease = async (projectName) => {
consola.start('Extracting last release number 👀');
const latest_release = await getLatestRelease();
consola.info(`Using Obytes starter ${latest_release}`);
consola.info(`Using Rootstrap's Template ${latest_release}`);

// create a new project based on obytes template
const cloneStarter = `git clone -b ${latest_release} --depth=1 https://github.com/obytes/react-native-template-obytes.git ${projectName}`;
// create a new project based on Rootstrap template
const cloneStarter = `git clone -b ${latest_release} --depth=1 https://github.com/${repository}.git ${projectName}`;
await runCommand(cloneStarter, {
loading: 'Extracting the starter template...',
success: 'Starter extracted successfully',
loading: 'Extracting the template...',
success: 'Template extracted successfully',
error: 'Failed to download and extract template',
});
};
Expand Down
10 changes: 6 additions & 4 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ const { consola } = require('consola');
const { showMoreDetails } = require('./utils.js');
const { cloneLastTemplateRelease } = require('./clone-repo.js');
const { setupProject, installDeps } = require('./setup-project.js');
const pkg = require('./package.json');

const createObytesApp = async () => {
consola.box('Obytes Starter\nPerfect React Native App Kickstart 🚀!');
const { name: packageName } = pkg;
const createRootstrapApp = async () => {
consola.box("Rootstrap's React Native Template\nPerfect React Native App Kickstart 🚀!");
// get project name from command line
const projectName = process.argv[2];
// check if project name is provided
if (!projectName) {
consola.error(
'Please provide a name for your project: `npx create-rootstrap-rn-app@latest <project-name>`'
`Please provide a name for your project: \`npx ${packageName}@latest <project-name>\``
);
process.exit(1);
}
Expand All @@ -29,4 +31,4 @@ const createObytesApp = async () => {
showMoreDetails(projectName);
};

createObytesApp();
createRootstrapApp();
8 changes: 4 additions & 4 deletions cli/setup-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const initGit = async (projectName) => {

const installDeps = async (projectName) => {
await runCommand(`cd ${projectName} && pnpm install`, {
loading: 'Installing project dependencies',
loading: 'Installing project dependencies',
success: 'Dependencies installed',
error: 'Failed to install dependencies, Make sure you have pnpm installed',
});
Expand Down Expand Up @@ -55,9 +55,9 @@ const updateProjectConfig = async (projectName) => {
encoding: 'utf-8',
});
const replaced = contents
.replace(/ObytesApp/gi, projectName)
.replace(/com.obytes/gi, `com.${projectName.toLowerCase()}`)
.replace(/obytes/gi, 'expo-owner');
.replace(/RootstrapApp/gi, projectName)
.replace(/com.rootstrap/gi, `com.${projectName.toLowerCase()}`)
.replace(/rootstrap/gi, 'expo-owner');

fs.writeFileSync(configPath, replaced, { spaces: 2 });
const readmeFilePath = path.join(
Expand Down
4 changes: 2 additions & 2 deletions cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const showMoreDetails = (projectName) => {
'Your project is ready to go! \n\n\n',
'🚀 To get started, run the following commands: \n\n',
` \`cd ${projectName}\` \n`,
' IOS : `pnpm ios` \n',
' iOS : `pnpm ios` \n',
' Android : `pnpm android` \n\n',
'📚 Starter Documentation: https://starter.obytes.com'
'📚 Template Documentation: https://rootstrap.github.io/react-native-template'
);
};

Expand Down
12 changes: 6 additions & 6 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ require('dotenv').config({
* Such as: bundle id, package name, app name.
*
* You can add them to the .env file but we think it's better to keep them here as as we use prefix to generate this values based on the APP_ENV
* for example: if the APP_ENV is staging, the bundle id will be com.obytes.staging
* for example: if the APP_ENV is staging, the bundle id will be com.rootstrap.staging
*/

// TODO: Replace these values with your own

const BUNDLE_ID = 'com.rs.mobile'; // ios bundle id
const PACKAGE = 'com.rs.mobile'; // android package name
const NAME = 'react-native-template'; // app name
const EXPO_ACCOUNT_OWNER = 'rsdevs'; // expo account owner
const BUNDLE_ID = 'com.rootstrap'; // ios bundle id
const PACKAGE = 'com.rootstrap'; // android package name
const NAME = 'RootstrapApp'; // app name
const EXPO_ACCOUNT_OWNER = 'rootstrap'; // expo account owner
const EAS_PROJECT_ID = 'c3e1075b-6fe7-4686-aa49-35b46a229044'; // eas project id
const SCHEME = 'react-native-template'; // app scheme
const SCHEME = 'rootstrapApp'; // app scheme

/**
* We declare a function withEnvSuffix that will add a suffix to the variable name based on the APP_ENV
Expand Down

0 comments on commit a58b597

Please sign in to comment.