Skip to content

Commit 077381f

Browse files
author
Alex Lee
authored
Merge pull request #15 from alexlee-dev/v0.8.0
📦 v0.8.0
2 parents 5c3e159 + 213d1a8 commit 077381f

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.0] - 2020-06-01
9+
10+
### ✏️ Shell Option
11+
12+
### Added
13+
14+
- Check if directory exists before executing install commands
15+
- Use `shell` option for `spawn` command if `platform === 'win32'`
16+
17+
### Changed
18+
19+
### Removed
20+
21+
### Fixed
22+
823
## [0.7.0] - 2020-06-01
924

1025
### ✏️ Better Logging

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-cli-application",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "A bootstrapper for creating a cli application with Node.",
55
"bin": {
66
"create-cli-application": "./index.js"

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pkg = require("../package.json");
1111
Sentry.init({
1212
dsn:
1313
"https://[email protected]/5254191",
14-
release: "0.7.0",
14+
release: "0.8.0",
1515
});
1616

1717
import {
@@ -47,7 +47,7 @@ const main = async (): Promise<void> => {
4747
* The program that parses the initial user input
4848
*/
4949
const program = new commander.Command("create-cli-application")
50-
.version("0.7.0")
50+
.version("0.8.0")
5151
.arguments("<application-name>")
5252
.usage(`${chalk.blueBright("<application-name>")} [options]`)
5353
.action((name) => {

src/init.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const createProjectDirectory = async (
6666
);
6767
} catch (error) {
6868
spinner.fail();
69-
console.log("")
69+
console.log("");
7070
throw new Error(error);
7171
}
7272
};
@@ -88,12 +88,22 @@ export const installDependencies = async (
8888
const installCommand = "npm";
8989
let installArgs = ["install", "--save"];
9090
installArgs = installArgs.concat(dependencies);
91-
// * Create a process that installs the dependencies
92-
await executeCommand(installCommand, installArgs, { cwd: root });
93-
spinner.succeed("Dependencies installed successfully");
91+
// * Verify that the directory exists 1st
92+
const pathExists = await fs.pathExists(root);
93+
if (pathExists) {
94+
// * Create a process that installs the dependencies
95+
await executeCommand(installCommand, installArgs, {
96+
cwd: root,
97+
shell: process.platform === "win32",
98+
});
99+
spinner.succeed("Dependencies installed successfully");
100+
} else {
101+
spinner.fail(`Path: ${root} does not exist.`);
102+
throw new Error(`Path: ${root} does not exist.`);
103+
}
94104
} catch (error) {
95105
spinner.fail();
96-
console.log("")
106+
console.log("");
97107
throw new Error(error);
98108
}
99109
};
@@ -124,12 +134,22 @@ export const installDevDependencies = async (
124134
installArgs = installArgs.concat(devDependencies);
125135
}
126136

127-
// * Creates a process that installs the dev dependencies
128-
await executeCommand(installCommand, installArgs, { cwd: root });
129-
spinner.succeed("DevDependencies installed successfully");
137+
// * Verify that the directory exists 1st
138+
const pathExists = await fs.pathExists(root);
139+
if (pathExists) {
140+
// * Create a process that installs the dependencies
141+
await executeCommand(installCommand, installArgs, {
142+
cwd: root,
143+
shell: process.platform === "win32",
144+
});
145+
spinner.succeed("DevDependencies installed successfully");
146+
} else {
147+
spinner.fail(`Path: ${root} does not exist.`);
148+
throw new Error(`Path: ${root} does not exist.`);
149+
}
130150
} catch (error) {
131151
spinner.fail();
132-
console.log("")
152+
console.log("");
133153
throw new Error(error);
134154
}
135155
};
@@ -190,7 +210,7 @@ export const copyTemplateFiles = async (
190210
spinner.succeed("Template files copied successfully");
191211
} catch (error) {
192212
spinner.fail();
193-
console.log("")
213+
console.log("");
194214
throw new Error(error);
195215
}
196216
};
@@ -242,7 +262,7 @@ export const replaceTemplateValues = async (
242262
spinner.succeed("Values in template files replaced successfully");
243263
} catch (error) {
244264
spinner.fail();
245-
console.log("")
265+
console.log("");
246266
throw new Error(error);
247267
}
248268
};
@@ -283,7 +303,7 @@ export const createTSConfig = async (
283303
spinner.succeed("tsconfig.json created successfully");
284304
} catch (error) {
285305
spinner.fail();
286-
console.log("")
306+
console.log("");
287307
throw new Error(error);
288308
}
289309
};

src/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import validateProjectName from "validate-npm-package-name";
1414
export const executeCommand = async (
1515
command: string,
1616
args?: string[],
17-
options?: { cwd?: string }
17+
options?: { cwd?: string; shell?: boolean }
1818
): Promise<void | { code: number; signal: any }> =>
1919
new Promise((resolve, reject) => {
2020
const cp = spawn(command, args, options);
@@ -60,7 +60,9 @@ export const cleanupError = async (
6060
const rootExists = await fs.pathExists(root);
6161

6262
if (rootExists) {
63-
await executeCommand("rimraf", [root]);
63+
await executeCommand("rimraf", [root], {
64+
shell: process.platform === "win32",
65+
});
6466
}
6567
} catch (error) {
6668
throw new Error(error);

0 commit comments

Comments
 (0)