Skip to content

Commit 8bf150c

Browse files
author
alexlee-dev
committed
✨ Replace generic 'APP Name' in template files with applicationName value
1 parent 53b6249 commit 8bf150c

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Replace generic "APP NAME" in template files with applicationName value
13+
1214
### Changed
1315

1416
### Removed

src/init.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,105 @@ export const copyTemplateFiles = async (
146146
}
147147

148148
// * Apply the applicationName to template files
149-
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+
150248
spinner.succeed("Template files copied successfully");
151249
} catch (error) {
152250
spinner.fail();

src/template/js/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const main = async () => {
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,

src/template/ts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const main = async (): Promise<void> => {
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,

0 commit comments

Comments
 (0)