Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2020-05-26

### ✏️ Application Name in Template Files

### Added

- Replace generic "APP NAME" in template files with applicationName value

### Changed

### Removed

### Fixed

## [0.2.0] - 2020-05-26

### 🔧 Vanilla JS Support
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-cli-application",
"version": "0.2.0",
"version": "0.3.0",
"description": "A bootstrapper for creating a cli application with Node.",
"bin": {
"create-cli-application": "./index.js"
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Sentry from "@sentry/node";
Sentry.init({
dsn:
"https://55c913cc3d394f71ba669fda095698fd@o202486.ingest.sentry.io/5254191",
release: "0.2.0",
release: "0.3.0",
});

import {
Expand All @@ -24,7 +24,7 @@ const main = async (): Promise<void> => {
let language: "js" | "ts";
language = "js";
const program = new commander.Command("create-cli-application")
.version("0.2.0")
.version("0.3.0")
.arguments("<application-name>")
.usage(`${chalk.yellowBright("<application-name>")} [options]`)
.action((name) => {
Expand Down
101 changes: 101 additions & 0 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,107 @@ export const copyTemplateFiles = async (
path.join(root, "/.babelrc")
);
}

// * Apply the applicationName to template files
const readmeFile = await fs.readFile(path.join(root, "README.md"), "utf-8");
const newReadmeContent = readmeFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(path.join(root, "README.md"), newReadmeContent, "utf8");

if (language === "js") {
// * src/index.js
const indexFile = await fs.readFile(
path.join(root, "/src/index.js"),
"utf-8"
);
const newIndexFileContent = indexFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/index.js"),
newIndexFileContent,
"utf8"
);

// * src/menu.js
const menuFile = await fs.readFile(
path.join(root, "/src/menu.js"),
"utf-8"
);
const newMenuFileContent = menuFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/menu.js"),
newMenuFileContent,
"utf8"
);

// * src/setup.js
const setupFile = await fs.readFile(
path.join(root, "/src/setup.js"),
"utf-8"
);
const newSetupFileContent = setupFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/setup.js"),
newSetupFileContent,
"utf8"
);
} else if (language === "ts") {
// * src/index.ts
const indexFile = await fs.readFile(
path.join(root, "/src/index.ts"),
"utf-8"
);
const newIndexFileContent = indexFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/index.ts"),
newIndexFileContent,
"utf8"
);

// * src/menu.ts
const menuFile = await fs.readFile(
path.join(root, "/src/menu.ts"),
"utf-8"
);
const newMenuFileContent = menuFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/menu.ts"),
newMenuFileContent,
"utf8"
);

// * src/setup.ts
const setupFile = await fs.readFile(
path.join(root, "/src/setup.ts"),
"utf-8"
);
const newSetupFileContent = setupFile.replace(
/___APP NAME___/gm,
applicationName
);
await fs.writeFile(
path.join(root, "/src/setup.ts"),
newSetupFileContent,
"utf8"
);
}

spinner.succeed("Template files copied successfully");
} catch (error) {
spinner.fail();
Expand Down
2 changes: 1 addition & 1 deletion src/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img width=256px height=256px src="https://svgshare.com/i/LWJ.svg" alt="Project logo"></a>
</p>

<h3 align="center">APP NAME</h3>
<h3 align="center">___APP NAME___</h3>

---

Expand Down
6 changes: 3 additions & 3 deletions src/template/js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import setup from "./setup";
const main = async () => {
const menuActionEmitter = new EventEmitter.EventEmitter();
menuActionEmitter.on("actionCompleted", async (state) => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
await displayMainMenu(state);
await interpretMenuAction(state);
});

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

const state = {
config,
Expand All @@ -30,7 +30,7 @@ const main = async () => {
clear();
}

await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
await displayMainMenu(state);

await interpretMenuAction(state);
Expand Down
8 changes: 4 additions & 4 deletions src/template/js/src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const interpretMenuAction = async (state) => {
}
const actions = {
about: async (state) => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
console.log(
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
);
Expand All @@ -81,7 +81,7 @@ export const interpretMenuAction = async (state) => {
state.menuActionEmitter.emit("actionCompleted", state);
},
option1: async (state) => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
console.log("Option 1 Logic would take place here :)");
console.log("");

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/template/js/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const setup = async (state) => {

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

Expand Down
6 changes: 3 additions & 3 deletions src/template/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { AppState } from "./types";
const main = async (): Promise<void> => {
const menuActionEmitter = new EventEmitter.EventEmitter();
menuActionEmitter.on("actionCompleted", async (state: AppState) => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
await displayMainMenu(state);
await interpretMenuAction(state);
});

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

const state: AppState = {
config,
Expand All @@ -31,7 +31,7 @@ const main = async (): Promise<void> => {
clear();
}

await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
await displayMainMenu(state);

await interpretMenuAction(state);
Expand Down
8 changes: 4 additions & 4 deletions src/template/ts/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
}
const actions = {
about: async (state: AppState): Promise<void> => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
console.log(
boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle)
);
Expand All @@ -83,7 +83,7 @@ export const interpretMenuAction = async (state: AppState): Promise<void> => {
state.menuActionEmitter.emit("actionCompleted", state);
},
option1: async (state: AppState): Promise<void> => {
await titleScreen("APP NAME");
await titleScreen("___APP NAME___");
console.log("Option 1 Logic would take place here :)");
console.log("");

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/template/ts/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const setup = async (state: AppState): Promise<void> => {

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

Expand Down