forked from obytes/react-native-template-obytes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclone-repo.js
executable file
·35 lines (31 loc) · 1.15 KB
/
clone-repo.js
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
const { runCommand, TEMPLATE_REPOSITORY } = require('./utils.js');
const { consola } = require('consola');
const getLatestRelease = async () => {
try {
const repoData = await fetch(
`https://api.github.com/repos/${TEMPLATE_REPOSITORY}/releases/latest`
);
const releaseData = await repoData.json();
return releaseData.tag_name || 'master';
} catch (error) {
console.warn(
'Failed to retrieve the latest release; will use the master branch instead'
);
return 'master';
}
};
const cloneLatestTemplateRelease = async (projectName) => {
consola.start('Extracting last release number 👀');
const latest_release = await getLatestRelease();
consola.info(`Using Rootstrap's Template ${latest_release}`);
// create a new project based on Rootstrap template
const cloneStarter = `git clone -b ${latest_release} --depth=1 https://github.com/${TEMPLATE_REPOSITORY}.git ${projectName}`;
await runCommand(cloneStarter, {
loading: 'Extracting the template...',
success: 'Template extracted successfully',
error: 'Failed to download and extract template',
});
};
module.exports = {
cloneLatestTemplateRelease,
};