Skip to content

Commit

Permalink
Merge pull request #15 from hhimanshu/hhimanshu/DEV-45-npx-starter
Browse files Browse the repository at this point in the history
feat(DEV-45): Starter script updates
  • Loading branch information
hhimanshu authored Jul 30, 2021
2 parents 44274cf + b29bc0e commit 6abc253
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Pre-requisites
- Requires npm version `>= 7.2.0`. Install the latest npm using command `npm install -g npm@latest`.
### What it contains
- ReactJS support with TypeScript
- Testing support using Jest and React Testing Library
Expand Down
31 changes: 27 additions & 4 deletions bin/setup-project.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');

const runCommand = command => {
try {
execSync(`${command}`, { stdio: 'inherit' });
} catch (e) {
console.error('Failed to execute ${command}', e);
console.error(`Failed to execute ${command}`, e);
return false;
}
return true;
Expand All @@ -27,14 +28,36 @@ const COMMANDS = {

console.log(`Cloning the repository with name ${repoName}`);
const checkedOut = runCommand(COMMANDS.gitCheckoutCommand);
if (!checkedOut) process.exit(-1);
if (!checkedOut) {
console.error(`Failed to clone the repository`);
process.exit(-1);
}

console.log(`Installing dependencies for ${repoName}`);
const installedDeps = runCommand(COMMANDS.installDepsCommand);
if (!installedDeps) process.exit(-1);
if (!installedDeps) {
console.error(`Failed to install the dependencies`);
process.exit(-1);
}

const projectSetup = runCommand(COMMANDS.removeFiles);
if (!projectSetup) process.exit(-1);
if (!projectSetup) {
console.error(`Failed to prepare the newly created repository`);
process.exit(-1);
}

const updatePackageJson = () => {
const commands = `
cd ${repoName} && \
npm pkg set name=${repoName} author=" " repository.url=" "
`;
return runCommand(commands);
};
let updatedPackageJson = updatePackageJson();
if (!updatedPackageJson) {
console.error(`Failed to update package.json for your repository`);
process.exit(-1);
}

console.log(`Initializing git for ${repoName}`);
const initializedGit = runCommand(COMMANDS.initializeGit);
Expand Down

1 comment on commit 6abc253

@vercel
Copy link

@vercel vercel bot commented on 6abc253 Jul 30, 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.