From 6769500b5b950f447a99633d672b4e1cd9f9de95 Mon Sep 17 00:00:00 2001 From: hhimanshu Date: Thu, 29 Jul 2021 18:04:39 -0700 Subject: [PATCH 1/2] feat(DEV-45): work in progress --- bin/setup-project.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/bin/setup-project.js b/bin/setup-project.js index cfc1ab3..36f5445 100755 --- a/bin/setup-project.js +++ b/bin/setup-project.js @@ -1,5 +1,6 @@ #!/usr/bin/env node const { execSync } = require('child_process'); +const fs = require('fs'); const runCommand = command => { try { @@ -27,14 +28,34 @@ 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} && \ + npx -y npm@latest pkg set name=${repoName} && \ + npx -y npm@latest pkg delete author && \ + npx -y npm@latest pkg delete repository.url + `; + runCommand(commands); +}; +updatePackageJson(); console.log(`Initializing git for ${repoName}`); const initializedGit = runCommand(COMMANDS.initializeGit); From b29bc0e418053c1487f9116ccf178fedcc1ce2a5 Mon Sep 17 00:00:00 2001 From: hhimanshu Date: Fri, 30 Jul 2021 12:30:53 -0700 Subject: [PATCH 2/2] feat(DEV-45): update package.json. add requirement for npm version --- README.md | 2 ++ bin/setup-project.js | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a0702f0..76d4851 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/setup-project.js b/bin/setup-project.js index 36f5445..98a81b4 100755 --- a/bin/setup-project.js +++ b/bin/setup-project.js @@ -6,7 +6,7 @@ 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; @@ -49,13 +49,15 @@ if (!projectSetup) { const updatePackageJson = () => { const commands = ` cd ${repoName} && \ - npx -y npm@latest pkg set name=${repoName} && \ - npx -y npm@latest pkg delete author && \ - npx -y npm@latest pkg delete repository.url + npm pkg set name=${repoName} author=" " repository.url=" " `; - runCommand(commands); + return runCommand(commands); }; -updatePackageJson(); +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);