Skip to content

Commit 9a8c98b

Browse files
committed
feat(cli): clean up cli and improve messages
1 parent 7f487b9 commit 9a8c98b

File tree

6 files changed

+163
-557
lines changed

6 files changed

+163
-557
lines changed

cli/clone-repo.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const { runCommand } = require('./utils.js');
2+
const { consola } = require('consola');
3+
4+
const getLatestRelease = async () => {
5+
try {
6+
const repoData = await fetch(
7+
'https://api.github.com/repos/obytes/react-native-template-obytes/releases/latest'
8+
);
9+
const releaseData = await repoData.json();
10+
return releaseData.tag_name || 'master';
11+
} catch (error) {
12+
console.warn(
13+
'Failed to retrieve the latest release; will use the master branch instead'
14+
);
15+
return 'master';
16+
}
17+
};
18+
19+
const cloneLastTemplateRelease = async (projectName) => {
20+
consola.start('Extracting last release number 👀');
21+
const latest_release = await getLatestRelease();
22+
consola.info(`Using Obytes starter ${latest_release}`);
23+
24+
// create a new project based on obytes template
25+
const cloneStarter = `git clone -b ${latest_release} --depth=1 https://github.com/obytes/react-native-template-obytes.git ${projectName}`;
26+
await runCommand(cloneStarter, {
27+
loading: 'Extracting the starter template...',
28+
success: 'Starter extracted successfully',
29+
error: 'Failed to download and extract template',
30+
});
31+
};
32+
33+
module.exports = {
34+
cloneLastTemplateRelease,
35+
};

cli/index.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
#!/usr/bin/env node
22

3-
const chalk = require('chalk');
4-
const { runCommand, cleanUpFolder, showMoreDetails } = require('./utils.js');
3+
const { consola } = require('consola');
4+
const { showMoreDetails } = require('./utils.js');
5+
const { cloneLastTemplateRelease } = require('./clone-repo.js');
6+
const { setupProject, installDeps } = require('./setup-project.js');
57

68
const createObytesApp = async () => {
9+
consola.box('Obytes Starter\nPerfect React Native App Kickstart 🚀!');
710
// get project name from command line
811
const projectName = process.argv[2];
912
// check if project name is provided
1013
if (!projectName) {
11-
console.log(chalk.red('Please provide a project name'));
14+
consola.error(
15+
'Please provide a name for your project: `npx create-obytes-app@latest <project-name>`'
16+
);
1217
process.exit(1);
1318
}
19+
// clone the last release of the template from github
20+
await cloneLastTemplateRelease(projectName);
1421

15-
// create a new project based on obytes template
16-
const cloneStarter = `git clone --depth=1 https://github.com/obytes/react-native-template-obytes.git ${projectName}`;
22+
// setup the project: remove unnecessary files, update package.json infos, name and set version to 0.0.1 + add initial version to osMetadata
23+
await setupProject(projectName);
1724

18-
// run init command and clean up project folder
19-
await runCommand(cloneStarter, {
20-
loading: 'Download and extract template',
21-
success: 'Template downloaded and extracted',
22-
error: 'Failed to download and extract template',
23-
});
25+
// install project dependencies using pnpm
26+
await installDeps(projectName);
2427

25-
await cleanUpFolder(projectName);
26-
27-
// install dependencies
28-
await runCommand(`cd ${projectName} && pnpm install`, {
29-
loading: 'Installing dependencies',
30-
success: 'Dependencies installed',
31-
error: 'Failed to install dependencies, Make sure you have pnpm installed',
32-
});
33-
34-
showMoreDetails();
28+
// show instructions to run the project + link to the documentation
29+
showMoreDetails(projectName);
3530
};
3631

3732
createObytesApp();

cli/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-obytes-app",
3-
"version": "1.6.4",
3+
"version": "1.7.0",
44
"description": "Obytes expo starter cli",
55
"homepage": "https://github.com/obytes/react-native-template-obytes",
66
"repository": {
@@ -17,10 +17,8 @@
1717
"utils.js"
1818
],
1919
"dependencies": {
20-
"chalk": "^4.1.2",
21-
"chalk-animation": "^1.6.0",
22-
"fs-extra": "^10.1.0",
23-
"nanospinner": "^1.0.0"
20+
"consola": "^3.2.3",
21+
"fs-extra": "^10.1.0"
2422
},
2523
"keywords": [
2624
"react-native",

0 commit comments

Comments
 (0)