Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -47,7 +47,7 @@ const main = async (): Promise<void> => {
* 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("<application-name>")
.usage(`${chalk.blueBright("<application-name>")} [options]`)
.action((name) => {
Expand Down
44 changes: 32 additions & 12 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createProjectDirectory = async (
);
} catch (error) {
spinner.fail();
console.log("")
console.log("");
throw new Error(error);
}
};
Expand All @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void | { code: number; signal: any }> =>
new Promise((resolve, reject) => {
const cp = spawn(command, args, options);
Expand Down Expand Up @@ -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);
Expand Down