diff --git a/CHANGELOG.md b/CHANGELOG.md index dbdad79..228b95c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index 37a8f63..9665cd2 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/index.ts b/src/index.ts index 8fed4d0..313a55c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { @@ -24,7 +24,7 @@ const main = async (): Promise => { let language: "js" | "ts"; language = "js"; const program = new commander.Command("create-cli-application") - .version("0.2.0") + .version("0.3.0") .arguments("") .usage(`${chalk.yellowBright("")} [options]`) .action((name) => { diff --git a/src/init.ts b/src/init.ts index e90ff29..5774507 100644 --- a/src/init.ts +++ b/src/init.ts @@ -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(); diff --git a/src/template/README.md b/src/template/README.md index bc4bcc6..1b1dff0 100644 --- a/src/template/README.md +++ b/src/template/README.md @@ -3,7 +3,7 @@ Project logo

-

APP NAME

+

___APP NAME___

--- diff --git a/src/template/js/src/index.js b/src/template/js/src/index.js index f2e8bd3..6532d41 100644 --- a/src/template/js/src/index.js +++ b/src/template/js/src/index.js @@ -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, @@ -30,7 +30,7 @@ const main = async () => { clear(); } - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); await displayMainMenu(state); await interpretMenuAction(state); diff --git a/src/template/js/src/menu.js b/src/template/js/src/menu.js index 2953718..12ec199 100644 --- a/src/template/js/src/menu.js +++ b/src/template/js/src/menu.js @@ -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) ); @@ -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(""); @@ -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(""); @@ -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(""); diff --git a/src/template/js/src/setup.js b/src/template/js/src/setup.js index fc04df1..bbf6de4 100644 --- a/src/template/js/src/setup.js +++ b/src/template/js/src/setup.js @@ -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` ); diff --git a/src/template/ts/src/index.ts b/src/template/ts/src/index.ts index 6a2454a..48da734 100644 --- a/src/template/ts/src/index.ts +++ b/src/template/ts/src/index.ts @@ -10,12 +10,12 @@ import { AppState } from "./types"; const main = async (): Promise => { 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, @@ -31,7 +31,7 @@ const main = async (): Promise => { clear(); } - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); await displayMainMenu(state); await interpretMenuAction(state); diff --git a/src/template/ts/src/menu.ts b/src/template/ts/src/menu.ts index 38eae99..1d88a50 100644 --- a/src/template/ts/src/menu.ts +++ b/src/template/ts/src/menu.ts @@ -73,7 +73,7 @@ export const interpretMenuAction = async (state: AppState): Promise => { } const actions = { about: async (state: AppState): Promise => { - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); console.log( boxen(chalk.yellow(`Author: `) + "YOUR NAME", blankBoxenStyle) ); @@ -83,7 +83,7 @@ export const interpretMenuAction = async (state: AppState): Promise => { state.menuActionEmitter.emit("actionCompleted", state); }, option1: async (state: AppState): Promise => { - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); console.log("Option 1 Logic would take place here :)"); console.log(""); @@ -92,7 +92,7 @@ export const interpretMenuAction = async (state: AppState): Promise => { state.menuActionEmitter.emit("actionCompleted", state); }, option2: async (state: AppState): Promise => { - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); console.log("Option 2 Logic would take place here :)"); console.log(""); @@ -101,7 +101,7 @@ export const interpretMenuAction = async (state: AppState): Promise => { state.menuActionEmitter.emit("actionCompleted", state); }, option3: async (state: AppState): Promise => { - await titleScreen("APP NAME"); + await titleScreen("___APP NAME___"); console.log("Option 3 Logic would take place here :)"); console.log(""); diff --git a/src/template/ts/src/setup.ts b/src/template/ts/src/setup.ts index cd1c076..5c9bc99 100644 --- a/src/template/ts/src/setup.ts +++ b/src/template/ts/src/setup.ts @@ -9,7 +9,7 @@ const setup = async (state: AppState): Promise => { console.log( `Welcome to ${chalk.yellowBright( - "APP NAME" + "___APP NAME___" )}! Let's walk you through the initial set up.\n` );