Skip to content

Instantly share code, notes, and snippets.

@hhimanshu
Created June 30, 2021 22:54
Show Gist options
  • Save hhimanshu/f33b8d6eb8799b4924bb179a32300dc1 to your computer and use it in GitHub Desktop.
Save hhimanshu/f33b8d6eb8799b4924bb179a32300dc1 to your computer and use it in GitHub Desktop.
Create NPX based React Starter App
#!/usr/bin/env node
const {execSync} = require('child_process');
const runCommand = command => {
try {
execSync(`${command}`, {stdio: 'inherit'});
} catch (e) {
console.error(`Failed to execute ${command}`, e);
return false;
}
return true;
}
const repoName = process.argv[2];
const gitCheckoutCommand = `git clone --depth 1 https://github.com/hhimanshu/react-ts-starter ${repoName}`;
const installDepsCommand = `cd ${repoName} && npm install`;
console.log(`Cloning the repository with name ${repoName}`);
const checkedOut = runCommand(gitCheckoutCommand);
if(!checkedOut) process.exit(-1);
console.log(`Installing dependencies for ${repoName}`);
const installedDeps = runCommand(installDepsCommand);
if(!installedDeps) process.exit(-1);
console.log("Congratulations! You are ready. Follow the following commands to start");
console.log(`cd ${repoName} && npm start`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment