Skip to content

Commit 47ed13a

Browse files
author
Alex Lee
authored
Merge pull request #4 from alexlee-dev/v0.4.0
📦 v0.4.0
2 parents 66b90b1 + 5324a25 commit 47ed13a

File tree

16 files changed

+378
-133
lines changed

16 files changed

+378
-133
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ 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.4.0] - 2020-05-27
9+
10+
### ✨ Interactivity
11+
12+
### Added
13+
14+
- Interactive option. Use the flag `--interactive` to use this mode
15+
- Comments :)
16+
- Cleanup on global error
17+
- Option for Author Name
18+
- Validation of application name according to NPM conventions
19+
20+
### Changed
21+
22+
- Refactored `copyTemplateFiles()`
23+
24+
### Removed
25+
26+
### Fixed
27+
828
## [0.3.0] - 2020-05-26
929

1030
### ✏️ Application Name in Template Files

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Want support for an additional language? Feel free to open a [new issue](https:/
6868
- [ora](https://github.com/sindresorhus/ora) - Elegant terminal spinner.
6969
- [pickitt](https://pickitt.netlify.com/) - When you need a computer to just pick it, reach for Pickitt!
7070
- [TypeScript](https://www.typescriptlang.org/) - A typed superset of JavaScript that compiles to plain JavaScript.
71+
- [validate-npm-package-name](https://github.com/npm/validate-npm-package-name) - Is the given string an acceptable npm package name?
7172

7273
## ✍️ Authors <a name = "authors"></a>
7374

package-lock.json

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-cli-application",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "A bootstrapper for creating a cli application with Node.",
55
"bin": {
66
"create-cli-application": "./index.js"
@@ -38,6 +38,7 @@
3838
"@types/fs-extra": "^9.0.1",
3939
"@types/inquirer": "^6.5.0",
4040
"@types/node": "^14.0.5",
41+
"@types/validate-npm-package-name": "^3.0.0",
4142
"@types/yargs": "^15.0.5",
4243
"copyfiles": "^2.2.0",
4344
"typescript": "^3.9.3"
@@ -52,6 +53,7 @@
5253
"fs-extra": "^9.0.0",
5354
"inquirer": "^7.1.0",
5455
"ora": "^4.0.4",
55-
"pickitt": "^3.2.0"
56+
"pickitt": "^3.2.0",
57+
"validate-npm-package-name": "^3.0.0"
5658
}
5759
}

src/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* These dependencies are required for the cli application regardless of language.
3+
*/
14
export const dependencies = [
25
"boxen",
36
"chalk",
@@ -7,6 +10,9 @@ export const dependencies = [
710
"pickitt",
811
];
912

13+
/**
14+
* These dev dependencies are for JavaScript projects.
15+
*/
1016
export const devDependencies = [
1117
"@babel/core",
1218
"@babel/cli",
@@ -15,6 +21,9 @@ export const devDependencies = [
1521
"@babel/runtime",
1622
];
1723

24+
/**
25+
* These dev dependencies are for TypeScript projects.
26+
*/
1827
export const devDependenciesTS = [
1928
"@types/clear",
2029
"@types/configstore",

src/index.ts

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import * as Sentry from "@sentry/node";
12
import chalk from "chalk";
23
import commander from "commander";
3-
import * as Sentry from "@sentry/node";
4+
import inquirer from "inquirer";
45

6+
/**
7+
* Initialize Sentry
8+
*/
59
Sentry.init({
610
dsn:
711
"https://55c913cc3d394f71ba669fda095698fd@o202486.ingest.sentry.io/5254191",
8-
release: "0.3.0",
12+
release: "0.4.0",
913
});
1014

1115
import {
@@ -15,24 +19,43 @@ import {
1519
installDevDependencies,
1620
createTSConfig,
1721
displaySuccessMessage,
22+
replaceTemplateValues,
1823
} from "./init";
1924
import { handleIncorrectApplicationName } from "./program";
25+
import { cleanupError, validateApplicationName } from "./util";
2026

27+
/**
28+
* Main CLI Program
29+
*/
2130
const main = async (): Promise<void> => {
31+
let applicationName;
32+
let authorName = "YOUR NAME";
33+
2234
try {
23-
let applicationName;
35+
// * Used to set the directory, application name, and inserted into templates
2436
let language: "js" | "ts";
37+
// * Default language is JavaScript
2538
language = "js";
39+
40+
/**
41+
* The program that parses the initial user input
42+
*/
2643
const program = new commander.Command("create-cli-application")
27-
.version("0.3.0")
44+
.version("0.4.0")
2845
.arguments("<application-name>")
2946
.usage(`${chalk.yellowBright("<application-name>")} [options]`)
3047
.action((name) => {
3148
applicationName = name;
3249
})
3350
.option(
3451
"--typescript",
35-
"use TypeScript as the cli application source language"
52+
"use TypeScript as the cli application source language",
53+
false
54+
)
55+
.option(
56+
"--interactive",
57+
"Have the bootstrapper walk you through the process",
58+
false
3659
)
3760
.on("--help", () => {
3861
console.log(
@@ -47,26 +70,71 @@ const main = async (): Promise<void> => {
4770
})
4871
.parse(process.argv);
4972

50-
// TODO - Catch names like "my.app.name" or "my app name"
51-
if (applicationName === "." || !applicationName) {
52-
return handleIncorrectApplicationName(program);
73+
// * Application Name must exist, and not consist of illegal characters
74+
validateApplicationName(applicationName);
75+
if (!applicationName) return;
76+
77+
if (program.interactive) {
78+
// * Interactive walk-thru
79+
80+
// * Language
81+
const languageAnswer = await inquirer.prompt([
82+
{
83+
type: "list",
84+
name: "language",
85+
message: "Please select a source language:",
86+
choices: [
87+
{ value: "js", name: "JavaScript" },
88+
{ value: "ts", name: "TypeScript" },
89+
],
90+
},
91+
]);
92+
const languageChoice: "js" | "ts" = languageAnswer.language;
93+
language = languageChoice;
94+
95+
// * Author Name
96+
const nameAnswer = await inquirer.prompt([
97+
{
98+
type: "input",
99+
name: "name",
100+
message:
101+
"Please input your name (used for the 'About' screen, but not required):",
102+
},
103+
]);
104+
const name: string = nameAnswer.name;
105+
authorName = name;
106+
107+
// TODO - Compiler Choice (Babel vs. other)
108+
// TODO - Add Prettier
109+
// TODO - Add ESLint / Other Linter
110+
// TODO - Menu Color Option
53111
}
54112

55-
if (program.typescript) language = "ts";
113+
// * Set language to 'ts' if user passed --typescript flag
114+
if (program.typescript && !program.interactive) language = "ts";
56115

116+
// * Creates a project directory and package.json
57117
await createProjectDirectory(applicationName, language);
58118

119+
// * Installs dependencies
59120
await installDependencies(applicationName);
60121

122+
// * Installs dev dependencies
61123
await installDevDependencies(applicationName, language);
62124

125+
// * Copies template files
63126
await copyTemplateFiles(applicationName, language);
64127

128+
// * Replaces template files placeholder values with real values for the application.
129+
await replaceTemplateValues(applicationName, language, authorName);
130+
131+
// * Creates a tsconfig.json file
65132
if (language === "ts") await createTSConfig(applicationName);
66133

134+
// * Displays a success message to the user
67135
displaySuccessMessage(applicationName);
68136
} catch (error) {
69-
// TODO - Cleanup
137+
await cleanupError(applicationName);
70138
console.error(error);
71139
throw new Error(error);
72140
}

0 commit comments

Comments
 (0)