generated from hhimanshu/create-react-ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from hhimanshu/hhimanshu/DEV-45-npx-starter
feat(DEV-25): Create `npx` based starter command
- Loading branch information
Showing
3 changed files
with
2,149 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/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]; | ||
if (!repoName) { | ||
console.log('error: please provide name for your project'); | ||
console.log('usage: npx create-pwa-app <your-app-name>'); | ||
process.exit(-1); | ||
} | ||
|
||
const COMMANDS = { | ||
gitCheckoutCommand: `git clone --depth 1 [email protected]:hhimanshu/create-pwa-app.git ${repoName}`, | ||
installDepsCommand: `cd ${repoName} && yarn install`, | ||
initializeGit: `cd ${repoName} && rm -rf .git && git init && git add . && git commit -q -m "initial commit"`, | ||
removeFiles: `cd ${repoName} && rm -f pwa/twa-manifest.json` | ||
}; | ||
|
||
console.log(`Cloning the repository with name ${repoName}`); | ||
const checkedOut = runCommand(COMMANDS.gitCheckoutCommand); | ||
if (!checkedOut) process.exit(-1); | ||
|
||
console.log(`Installing dependencies for ${repoName}`); | ||
const installedDeps = runCommand(COMMANDS.installDepsCommand); | ||
if (!installedDeps) process.exit(-1); | ||
|
||
const projectSetup = runCommand(COMMANDS.removeFiles) | ||
if (!projectSetup) process.exit(-1); | ||
|
||
console.log(`Initializing git for ${repoName}`); | ||
const initializedGit = runCommand(COMMANDS.initializeGit); | ||
if (!initializedGit) process.exit(-1); | ||
|
||
console.log( | ||
'Congratulations! You are ready. Follow the following commands to start' | ||
); | ||
console.log(`cd ${repoName} && yarn start`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6e5e51c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: