Skip to content

Commit 8efe2de

Browse files
author
Alex Lee
authored
Merge pull request #2 from alexlee-dev/v0.2.0
📦 v0.2.0
2 parents a1fa374 + a11dcff commit 8efe2de

File tree

12 files changed

+297
-18
lines changed

12 files changed

+297
-18
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ 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.2.0] - 2020-05-26
9+
10+
### 🔧 Vanilla JS Support
11+
12+
### Added
13+
14+
- Support for both JS (deafult language) and TS (passed as '--typescript' option)
15+
16+
### Changed
17+
18+
- Add "release" to Sentry config
19+
20+
### Removed
21+
22+
### Fixed
23+
24+
- Fixed broken links on README
25+
826
## [0.1.0] - 2020-05-26
927

1028
### 🚀 First Happy Path Solution

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424

2525
- [About](#about)
2626
- [Getting Started](#getting_started)
27-
- [Deployment](#deployment)
2827
- [Usage](#usage)
2928
- [Built Using](#built_using)
30-
- [TODO](../TODO.md)
31-
- [Contributing](../CONTRIBUTING.md)
3229
- [Authors](#authors)
3330
- [Acknowledgments](#acknowledgement)
3431

@@ -51,6 +48,14 @@ I generally use a template when developing CLI applications for myself. I want t
5148

5249
`create-cli-application cool-app-name`
5350

51+
### Changing the Source Language
52+
53+
By deafault, **create-cli-application** will create your application as a JavaScript project. You can pass the `--typescript` flag to create a TypeScript project instead.
54+
55+
`create-cli-application cool-app-name --typescript`
56+
57+
Want support for an additional language? Feel free to open a [new issue](https://github.com/alexlee-dev/create-cli-application/issues/new).
58+
5459
## ⛏️ Built Using <a name = "built_using"></a>
5560

5661
- [@sentry/node](https://sentry.io/welcome/) - Sentry is cross-platform application monitoring, with a focus on error reporting.

package-lock.json

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

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.1.0",
3+
"version": "0.2.0",
44
"description": "A bootstrapper for creating a cli application with Node.",
55
"bin": {
66
"create-cli-application": "./index.js"

src/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export const dependencies = [
88
];
99

1010
export const devDependencies = [
11+
"@babel/core",
12+
"@babel/cli",
13+
"@babel/preset-env",
14+
"@babel/plugin-transform-runtime",
15+
"@babel/runtime",
16+
];
17+
18+
export const devDependenciesTS = [
1119
"@types/clear",
1220
"@types/configstore",
1321
"@types/inquirer",

src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Sentry from "@sentry/node";
55
Sentry.init({
66
dsn:
77
"https://55c913cc3d394f71ba669fda095698fd@o202486.ingest.sentry.io/5254191",
8+
release: "0.2.0",
89
});
910

1011
import {
@@ -20,13 +21,19 @@ import { handleIncorrectApplicationName } from "./program";
2021
const main = async (): Promise<void> => {
2122
try {
2223
let applicationName;
24+
let language: "js" | "ts";
25+
language = "js";
2326
const program = new commander.Command("create-cli-application")
24-
.version("0.0.0")
27+
.version("0.2.0")
2528
.arguments("<application-name>")
2629
.usage(`${chalk.yellowBright("<application-name>")} [options]`)
2730
.action((name) => {
2831
applicationName = name;
2932
})
33+
.option(
34+
"--typescript",
35+
"use TypeScript as the cli application source language"
36+
)
3037
.on("--help", () => {
3138
console.log(
3239
`\nOnly ${chalk.yellowBright("<application-name>")} is required.`
@@ -40,21 +47,22 @@ const main = async (): Promise<void> => {
4047
})
4148
.parse(process.argv);
4249

50+
// TODO - Catch names like "my.app.name" or "my app name"
4351
if (applicationName === "." || !applicationName) {
4452
return handleIncorrectApplicationName(program);
4553
}
4654

47-
// TODO - Catch names like "my.app.name" or "my app name"
55+
if (program.typescript) language = "ts";
4856

49-
await createProjectDirectory(applicationName);
57+
await createProjectDirectory(applicationName, language);
5058

5159
await installDependencies(applicationName);
5260

53-
await installDevDependencies(applicationName);
61+
await installDevDependencies(applicationName, language);
5462

55-
await copyTemplateFiles(applicationName);
63+
await copyTemplateFiles(applicationName, language);
5664

57-
await createTSConfig(applicationName);
65+
if (language === "ts") await createTSConfig(applicationName);
5866

5967
displaySuccessMessage(applicationName);
6068
} catch (error) {

src/init.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ import ora from "ora";
44
import os from "os";
55
import path from "path";
66

7-
import { dependencies, devDependencies } from "./constants";
7+
import { dependencies, devDependencies, devDependenciesTS } from "./constants";
88
import { executeCommand } from "./util";
99

1010
export const createProjectDirectory = async (
11-
applicationName: string
11+
applicationName: string,
12+
language: "js" | "ts"
1213
): Promise<void> => {
1314
const root = path.resolve(applicationName);
14-
// const originalDirectory = process.cwd();
1515

1616
fs.ensureDirSync(root);
1717

1818
console.log();
1919
console.log(`Creating a new CLI app in ${chalk.yellowBright(root)}.`);
2020
console.log();
21+
console.log(
22+
`Source Language: ${
23+
language === "js"
24+
? chalk.yellowBright("JavaScript")
25+
: chalk.yellowBright("TypeScript")
26+
}`
27+
);
28+
console.log();
2129

2230
// TODO - Interactive mode to fill in some of these values
2331

@@ -30,7 +38,7 @@ export const createProjectDirectory = async (
3038
[applicationName]: "./index.js",
3139
},
3240
scripts: {
33-
build: "rimraf build && tsc",
41+
build: language === "ts" ? "rimraf build && tsc" : "babel src -d build",
3442
start: "node build/index.js -- start",
3543
test: 'echo "Error: no test specified" && exit 1',
3644
},
@@ -77,7 +85,8 @@ export const installDependencies = async (
7785
};
7886

7987
export const installDevDependencies = async (
80-
applicationName: string
88+
applicationName: string,
89+
language: "js" | "ts"
8190
): Promise<void> => {
8291
const root = path.resolve(applicationName);
8392

@@ -88,6 +97,13 @@ export const installDevDependencies = async (
8897
const installCommand = "npm";
8998
let installArgs = ["install", "--save"];
9099
installArgs = installArgs.concat(devDependencies);
100+
101+
if (language === "ts") {
102+
installArgs = installArgs.concat(devDependenciesTS);
103+
} else {
104+
installArgs = installArgs.concat(devDependencies);
105+
}
106+
91107
await executeCommand(installCommand, installArgs, { cwd: root });
92108
spinner.succeed("DevDependencies installed successfully");
93109
} catch (error) {
@@ -97,7 +113,8 @@ export const installDevDependencies = async (
97113
};
98114

99115
export const copyTemplateFiles = async (
100-
applicationName: string
116+
applicationName: string,
117+
language: "js" | "ts"
101118
): Promise<void> => {
102119
const root = path.resolve(applicationName);
103120

@@ -106,7 +123,7 @@ export const copyTemplateFiles = async (
106123
try {
107124
spinner.start();
108125
await fs.copy(
109-
path.join(__dirname, "template/ts/src"),
126+
path.join(__dirname, `template/${language}/src`),
110127
path.join(root, "/src")
111128
);
112129
await fs.copy(
@@ -121,6 +138,12 @@ export const copyTemplateFiles = async (
121138
path.join(__dirname, "template/gitignore"),
122139
path.join(root, "/.gitignore")
123140
);
141+
if (language === "js") {
142+
await fs.copy(
143+
path.join(__dirname, "template/babelrc"),
144+
path.join(root, "/.babelrc")
145+
);
146+
}
124147
spinner.succeed("Template files copied successfully");
125148
} catch (error) {
126149
spinner.fail();

src/template/babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["@babel/plugin-transform-runtime"],
3+
"presets": [
4+
"@babel/preset-env"
5+
]
6+
}

src/template/js/src/constants.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Options } from "boxen";
2+
3+
/**
4+
* Blank style applied to Boxen.
5+
*/
6+
export const blankBoxenStyle = {
7+
borderStyle: {
8+
topLeft: " ",
9+
topRight: " ",
10+
bottomLeft: " ",
11+
bottomRight: " ",
12+
horizontal: " ",
13+
vertical: " ",
14+
},
15+
float: "center",
16+
padding: { top: 0, bottom: 0, right: 1, left: 1 },
17+
};

src/template/js/src/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import clear from "clear";
2+
import Configstore from "configstore";
3+
import EventEmitter from "events";
4+
import { titleScreen } from "pickitt";
5+
6+
import { displayMainMenu, interpretMenuAction } from "./menu";
7+
import setup from "./setup";
8+
9+
const main = async () => {
10+
const menuActionEmitter = new EventEmitter.EventEmitter();
11+
menuActionEmitter.on("actionCompleted", async (state) => {
12+
await titleScreen("APP NAME");
13+
await displayMainMenu(state);
14+
await interpretMenuAction(state);
15+
});
16+
17+
const config = new Configstore("app-name");
18+
19+
const state = {
20+
config,
21+
menuAction: null,
22+
menuActionEmitter,
23+
};
24+
25+
try {
26+
const isSetUp = config.get("isSetUp");
27+
28+
if (!isSetUp) {
29+
await setup(state);
30+
clear();
31+
}
32+
33+
await titleScreen("APP NAME");
34+
await displayMainMenu(state);
35+
36+
await interpretMenuAction(state);
37+
} catch (e) {
38+
console.error("ERROR");
39+
console.log(state);
40+
console.error(e);
41+
}
42+
};
43+
44+
if (process.argv[3] === "start") main();
45+
46+
export default main;

0 commit comments

Comments
 (0)