diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae3a0b..23b080b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.0] - 2020-06-01 + +### ✏️ Shell Option + +### Added + +- Check if directory exists before executing install commands +- Use `shell` option for `spawn` command if `platform === 'win32'` + +### Changed + +### Removed + +### Fixed + ## [0.7.0] - 2020-06-01 ### ✏️ Better Logging diff --git a/package.json b/package.json index f46d607..0c96587 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-cli-application", - "version": "0.7.0", + "version": "0.8.0", "description": "A bootstrapper for creating a cli application with Node.", "bin": { "create-cli-application": "./index.js" diff --git a/src/index.ts b/src/index.ts index 82fb45a..52b2bf5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ const pkg = require("../package.json"); Sentry.init({ dsn: "https://55c913cc3d394f71ba669fda095698fd@o202486.ingest.sentry.io/5254191", - release: "0.7.0", + release: "0.8.0", }); import { @@ -47,7 +47,7 @@ const main = async (): Promise => { * The program that parses the initial user input */ const program = new commander.Command("create-cli-application") - .version("0.7.0") + .version("0.8.0") .arguments("") .usage(`${chalk.blueBright("")} [options]`) .action((name) => { diff --git a/src/init.ts b/src/init.ts index 3daae56..5e431ce 100644 --- a/src/init.ts +++ b/src/init.ts @@ -66,7 +66,7 @@ export const createProjectDirectory = async ( ); } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; @@ -88,12 +88,22 @@ export const installDependencies = async ( const installCommand = "npm"; let installArgs = ["install", "--save"]; installArgs = installArgs.concat(dependencies); - // * Create a process that installs the dependencies - await executeCommand(installCommand, installArgs, { cwd: root }); - spinner.succeed("Dependencies installed successfully"); + // * Verify that the directory exists 1st + const pathExists = await fs.pathExists(root); + if (pathExists) { + // * Create a process that installs the dependencies + await executeCommand(installCommand, installArgs, { + cwd: root, + shell: process.platform === "win32", + }); + spinner.succeed("Dependencies installed successfully"); + } else { + spinner.fail(`Path: ${root} does not exist.`); + throw new Error(`Path: ${root} does not exist.`); + } } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; @@ -124,12 +134,22 @@ export const installDevDependencies = async ( installArgs = installArgs.concat(devDependencies); } - // * Creates a process that installs the dev dependencies - await executeCommand(installCommand, installArgs, { cwd: root }); - spinner.succeed("DevDependencies installed successfully"); + // * Verify that the directory exists 1st + const pathExists = await fs.pathExists(root); + if (pathExists) { + // * Create a process that installs the dependencies + await executeCommand(installCommand, installArgs, { + cwd: root, + shell: process.platform === "win32", + }); + spinner.succeed("DevDependencies installed successfully"); + } else { + spinner.fail(`Path: ${root} does not exist.`); + throw new Error(`Path: ${root} does not exist.`); + } } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; @@ -190,7 +210,7 @@ export const copyTemplateFiles = async ( spinner.succeed("Template files copied successfully"); } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; @@ -242,7 +262,7 @@ export const replaceTemplateValues = async ( spinner.succeed("Values in template files replaced successfully"); } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; @@ -283,7 +303,7 @@ export const createTSConfig = async ( spinner.succeed("tsconfig.json created successfully"); } catch (error) { spinner.fail(); - console.log("") + console.log(""); throw new Error(error); } }; diff --git a/src/util.ts b/src/util.ts index 2aec847..f1dee8a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -14,7 +14,7 @@ import validateProjectName from "validate-npm-package-name"; export const executeCommand = async ( command: string, args?: string[], - options?: { cwd?: string } + options?: { cwd?: string; shell?: boolean } ): Promise => new Promise((resolve, reject) => { const cp = spawn(command, args, options); @@ -60,7 +60,9 @@ export const cleanupError = async ( const rootExists = await fs.pathExists(root); if (rootExists) { - await executeCommand("rimraf", [root]); + await executeCommand("rimraf", [root], { + shell: process.platform === "win32", + }); } } catch (error) { throw new Error(error);