Skip to content

Commit f7a1941

Browse files
author
alexlee-dev
committed
✏️ Add suport for Author Name
1 parent 9296b33 commit f7a1941

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Interactive option. Use the flag `--interactive` to use this mode.
1313
- Comments :)
1414
- Cleanup on global error
15+
- Option for Author Name
1516

1617
### Changed
1718

src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { cleanupError } from "./util";
2828
*/
2929
const main = async (): Promise<void> => {
3030
let applicationName;
31+
let authorName = "YOUR NAME";
3132

3233
try {
3334
// * Used to set the directory, application name, and inserted into templates
@@ -79,7 +80,7 @@ const main = async (): Promise<void> => {
7980
// * Interactive walk-thru
8081

8182
// * Language
82-
const answers = await inquirer.prompt([
83+
const languageAnswer = await inquirer.prompt([
8384
{
8485
type: "list",
8586
name: "language",
@@ -90,10 +91,21 @@ const main = async (): Promise<void> => {
9091
],
9192
},
9293
]);
93-
const languageChoice: "js" | "ts" = answers.language;
94+
const languageChoice: "js" | "ts" = languageAnswer.language;
9495
language = languageChoice;
9596

96-
// TODO - Author Name
97+
// * Author Name
98+
const nameAnswer = await inquirer.prompt([
99+
{
100+
type: "input",
101+
name: "name",
102+
message:
103+
"Please input your name (used for the 'About' screen, but not required):",
104+
},
105+
]);
106+
const name: string = nameAnswer.name;
107+
authorName = name;
108+
97109
// TODO - Compiler Choice (Babel vs. other)
98110
// TODO - Add Prettier
99111
// TODO - Add ESLint / Other Linter
@@ -113,7 +125,7 @@ const main = async (): Promise<void> => {
113125
await installDevDependencies(applicationName, language);
114126

115127
// * Copies template files and inserts `applicationName` into the files
116-
await copyTemplateFiles(applicationName, language);
128+
await copyTemplateFiles(applicationName, language, authorName);
117129

118130
// * Creates a tsconfig.json file
119131
if (language === "ts") await createTSConfig(applicationName);

src/init.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export const installDevDependencies = async (
139139
*/
140140
export const copyTemplateFiles = async (
141141
applicationName: string,
142-
language: "js" | "ts"
142+
language: "js" | "ts",
143+
authorName: string
143144
): Promise<void> => {
144145
// * Application Directory
145146
const root = path.resolve(applicationName);
@@ -201,10 +202,14 @@ export const copyTemplateFiles = async (
201202
path.join(root, "/src/menu.js"),
202203
"utf-8"
203204
);
204-
const newMenuFileContent = menuFile.replace(
205+
let newMenuFileContent = menuFile.replace(
205206
/___APP NAME___/gm,
206207
applicationName
207208
);
209+
newMenuFileContent = newMenuFileContent.replace(
210+
/___AUTHOR NAME___/gm,
211+
authorName
212+
);
208213
await fs.writeFile(
209214
path.join(root, "/src/menu.js"),
210215
newMenuFileContent,
@@ -246,10 +251,14 @@ export const copyTemplateFiles = async (
246251
path.join(root, "/src/menu.ts"),
247252
"utf-8"
248253
);
249-
const newMenuFileContent = menuFile.replace(
254+
let newMenuFileContent = menuFile.replace(
250255
/___APP NAME___/gm,
251256
applicationName
252257
);
258+
newMenuFileContent = newMenuFileContent.replace(
259+
/___AUTHOR NAME___/gm,
260+
authorName
261+
);
253262
await fs.writeFile(
254263
path.join(root, "/src/menu.ts"),
255264
newMenuFileContent,

src/template/js/src/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const interpretMenuAction = async (state) => {
7373
about: async (state) => {
7474
await titleScreen("___APP NAME___");
7575
console.log(
76-
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
76+
boxen(chalk.yellow(`Author: `) + "___AUTHOR NAME___", blankBoxenStyle)
7777
);
7878

7979
console.log("Press any key to return to Main Menu ...");

src/template/ts/src/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
7575
about: async (state: AppState): Promise<void> => {
7676
await titleScreen("___APP NAME___");
7777
console.log(
78-
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
78+
boxen(chalk.yellow(`Author: `) + "___AUTHOR NAME___", blankBoxenStyle)
7979
);
8080

8181
console.log("Press any key to return to Main Menu ...");

0 commit comments

Comments
 (0)