Skip to content

Commit 66b90b1

Browse files
author
Alex Lee
authored
Merge pull request #3 from alexlee-dev/v0.3.0
📦 v0.3.0
2 parents 8efe2de + 7a4fab8 commit 66b90b1

File tree

11 files changed

+135
-20
lines changed

11 files changed

+135
-20
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ 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.3.0] - 2020-05-26
9+
10+
### ✏️ Application Name in Template Files
11+
12+
### Added
13+
14+
- Replace generic "APP NAME" in template files with applicationName value
15+
16+
### Changed
17+
18+
### Removed
19+
20+
### Fixed
21+
822
## [0.2.0] - 2020-05-26
923

1024
### 🔧 Vanilla JS Support

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.2.0",
3+
"version": "0.3.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
@@ -5,7 +5,7 @@ import * as Sentry from "@sentry/node";
55
Sentry.init({
66
dsn:
77
"https://[email protected]/5254191",
8-
release: "0.2.0",
8+
release: "0.3.0",
99
});
1010

1111
import {
@@ -24,7 +24,7 @@ const main = async (): Promise<void> => {
2424
let language: "js" | "ts";
2525
language = "js";
2626
const program = new commander.Command("create-cli-application")
27-
.version("0.2.0")
27+
.version("0.3.0")
2828
.arguments("<application-name>")
2929
.usage(`${chalk.yellowBright("<application-name>")} [options]`)
3030
.action((name) => {

src/init.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,107 @@ export const copyTemplateFiles = async (
144144
path.join(root, "/.babelrc")
145145
);
146146
}
147+
148+
// * Apply the applicationName to template files
149+
const readmeFile = await fs.readFile(path.join(root, "README.md"), "utf-8");
150+
const newReadmeContent = readmeFile.replace(
151+
/___APP NAME___/gm,
152+
applicationName
153+
);
154+
await fs.writeFile(path.join(root, "README.md"), newReadmeContent, "utf8");
155+
156+
if (language === "js") {
157+
// * src/index.js
158+
const indexFile = await fs.readFile(
159+
path.join(root, "/src/index.js"),
160+
"utf-8"
161+
);
162+
const newIndexFileContent = indexFile.replace(
163+
/___APP NAME___/gm,
164+
applicationName
165+
);
166+
await fs.writeFile(
167+
path.join(root, "/src/index.js"),
168+
newIndexFileContent,
169+
"utf8"
170+
);
171+
172+
// * src/menu.js
173+
const menuFile = await fs.readFile(
174+
path.join(root, "/src/menu.js"),
175+
"utf-8"
176+
);
177+
const newMenuFileContent = menuFile.replace(
178+
/___APP NAME___/gm,
179+
applicationName
180+
);
181+
await fs.writeFile(
182+
path.join(root, "/src/menu.js"),
183+
newMenuFileContent,
184+
"utf8"
185+
);
186+
187+
// * src/setup.js
188+
const setupFile = await fs.readFile(
189+
path.join(root, "/src/setup.js"),
190+
"utf-8"
191+
);
192+
const newSetupFileContent = setupFile.replace(
193+
/___APP NAME___/gm,
194+
applicationName
195+
);
196+
await fs.writeFile(
197+
path.join(root, "/src/setup.js"),
198+
newSetupFileContent,
199+
"utf8"
200+
);
201+
} else if (language === "ts") {
202+
// * src/index.ts
203+
const indexFile = await fs.readFile(
204+
path.join(root, "/src/index.ts"),
205+
"utf-8"
206+
);
207+
const newIndexFileContent = indexFile.replace(
208+
/___APP NAME___/gm,
209+
applicationName
210+
);
211+
await fs.writeFile(
212+
path.join(root, "/src/index.ts"),
213+
newIndexFileContent,
214+
"utf8"
215+
);
216+
217+
// * src/menu.ts
218+
const menuFile = await fs.readFile(
219+
path.join(root, "/src/menu.ts"),
220+
"utf-8"
221+
);
222+
const newMenuFileContent = menuFile.replace(
223+
/___APP NAME___/gm,
224+
applicationName
225+
);
226+
await fs.writeFile(
227+
path.join(root, "/src/menu.ts"),
228+
newMenuFileContent,
229+
"utf8"
230+
);
231+
232+
// * src/setup.ts
233+
const setupFile = await fs.readFile(
234+
path.join(root, "/src/setup.ts"),
235+
"utf-8"
236+
);
237+
const newSetupFileContent = setupFile.replace(
238+
/___APP NAME___/gm,
239+
applicationName
240+
);
241+
await fs.writeFile(
242+
path.join(root, "/src/setup.ts"),
243+
newSetupFileContent,
244+
"utf8"
245+
);
246+
}
247+
147248
spinner.succeed("Template files copied successfully");
148249
} catch (error) {
149250
spinner.fail();

src/template/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img width=256px height=256px src="https://svgshare.com/i/LWJ.svg" alt="Project logo"></a>
44
</p>
55

6-
<h3 align="center">APP NAME</h3>
6+
<h3 align="center">___APP NAME___</h3>
77

88
---
99

src/template/js/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import setup from "./setup";
99
const main = async () => {
1010
const menuActionEmitter = new EventEmitter.EventEmitter();
1111
menuActionEmitter.on("actionCompleted", async (state) => {
12-
await titleScreen("APP NAME");
12+
await titleScreen("___APP NAME___");
1313
await displayMainMenu(state);
1414
await interpretMenuAction(state);
1515
});
1616

17-
const config = new Configstore("app-name");
17+
const config = new Configstore("___APP NAME___");
1818

1919
const state = {
2020
config,
@@ -30,7 +30,7 @@ const main = async () => {
3030
clear();
3131
}
3232

33-
await titleScreen("APP NAME");
33+
await titleScreen("___APP NAME___");
3434
await displayMainMenu(state);
3535

3636
await interpretMenuAction(state);

src/template/js/src/menu.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const interpretMenuAction = async (state) => {
7171
}
7272
const actions = {
7373
about: async (state) => {
74-
await titleScreen("APP NAME");
74+
await titleScreen("___APP NAME___");
7575
console.log(
7676
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
7777
);
@@ -81,7 +81,7 @@ export const interpretMenuAction = async (state) => {
8181
state.menuActionEmitter.emit("actionCompleted", state);
8282
},
8383
option1: async (state) => {
84-
await titleScreen("APP NAME");
84+
await titleScreen("___APP NAME___");
8585
console.log("Option 1 Logic would take place here :)");
8686
console.log("");
8787

@@ -90,7 +90,7 @@ export const interpretMenuAction = async (state) => {
9090
state.menuActionEmitter.emit("actionCompleted", state);
9191
},
9292
option2: async (state) => {
93-
await titleScreen("APP NAME");
93+
await titleScreen("___APP NAME___");
9494
console.log("Option 2 Logic would take place here :)");
9595
console.log("");
9696

@@ -99,7 +99,7 @@ export const interpretMenuAction = async (state) => {
9999
state.menuActionEmitter.emit("actionCompleted", state);
100100
},
101101
option3: async (state) => {
102-
await titleScreen("APP NAME");
102+
await titleScreen("___APP NAME___");
103103
console.log("Option 3 Logic would take place here :)");
104104
console.log("");
105105

src/template/js/src/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const setup = async (state) => {
88

99
console.log(
1010
`Welcome to ${chalk.yellowBright(
11-
"APP NAME"
11+
"___APP NAME___"
1212
)}! Let's walk you through the initial set up.\n`
1313
);
1414

src/template/ts/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { AppState } from "./types";
1010
const main = async (): Promise<void> => {
1111
const menuActionEmitter = new EventEmitter.EventEmitter();
1212
menuActionEmitter.on("actionCompleted", async (state: AppState) => {
13-
await titleScreen("APP NAME");
13+
await titleScreen("___APP NAME___");
1414
await displayMainMenu(state);
1515
await interpretMenuAction(state);
1616
});
1717

18-
const config = new Configstore("app-name");
18+
const config = new Configstore("___APP NAME___");
1919

2020
const state: AppState = {
2121
config,
@@ -31,7 +31,7 @@ const main = async (): Promise<void> => {
3131
clear();
3232
}
3333

34-
await titleScreen("APP NAME");
34+
await titleScreen("___APP NAME___");
3535
await displayMainMenu(state);
3636

3737
await interpretMenuAction(state);

src/template/ts/src/menu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
7373
}
7474
const actions = {
7575
about: async (state: AppState): Promise<void> => {
76-
await titleScreen("APP NAME");
76+
await titleScreen("___APP NAME___");
7777
console.log(
7878
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
7979
);
@@ -83,7 +83,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
8383
state.menuActionEmitter.emit("actionCompleted", state);
8484
},
8585
option1: async (state: AppState): Promise<void> => {
86-
await titleScreen("APP NAME");
86+
await titleScreen("___APP NAME___");
8787
console.log("Option 1 Logic would take place here :)");
8888
console.log("");
8989

@@ -92,7 +92,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
9292
state.menuActionEmitter.emit("actionCompleted", state);
9393
},
9494
option2: async (state: AppState): Promise<void> => {
95-
await titleScreen("APP NAME");
95+
await titleScreen("___APP NAME___");
9696
console.log("Option 2 Logic would take place here :)");
9797
console.log("");
9898

@@ -101,7 +101,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
101101
state.menuActionEmitter.emit("actionCompleted", state);
102102
},
103103
option3: async (state: AppState): Promise<void> => {
104-
await titleScreen("APP NAME");
104+
await titleScreen("___APP NAME___");
105105
console.log("Option 3 Logic would take place here :)");
106106
console.log("");
107107

0 commit comments

Comments
 (0)