Skip to content

Commit

Permalink
Merge pull request #14 from hhimanshu/hhimanshu/DEV-45-npx-starter
Browse files Browse the repository at this point in the history
feat(DEV-25): Create `npx` based starter command
  • Loading branch information
hhimanshu authored Jul 29, 2021
2 parents debfabb + 21a8d1c commit 6e5e51c
Show file tree
Hide file tree
Showing 3 changed files with 2,149 additions and 63 deletions.
46 changes: 46 additions & 0 deletions bin/setup-project.js
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`);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@bonsaiilabs/create-pwa-app",
"version": "0.0.0-development",
"description": "A React Starter to develop Progressive Web Applications (PWA) and deploy to Google Play Store",
"private": true,
"bin": "./bin/setup-project.js",
"scripts": {
"test": "jest --config jest.config.ts",
"test:watch": "jest --watchAll --config jest.config.ts",
Expand Down
Loading

1 comment on commit 6e5e51c

@vercel
Copy link

@vercel vercel bot commented on 6e5e51c Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.