Skip to content

Commit 7cf9c7d

Browse files
committed
refactor(constants): fixed contants names
1 parent 827e5ec commit 7cf9c7d

File tree

9 files changed

+30
-30
lines changed

9 files changed

+30
-30
lines changed

src/commands/generate/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TPConfig, TPStructureItem } from '../../utils/definitions';
88
import { findTPTemplateByName } from '../../utils/functions';
99
import CustomCommand from '../../utils/oclif/custom-command';
1010
import CustomError from '../../utils/oclif/custom-error';
11-
import { DOBBY_CONFIG_FILE } from '../../utils/variables';
11+
import { TP_CONFIG_FILE } from '../../utils/variables';
1212
import { replaceTextWithWildcards } from '../../utils/wildcards';
1313
import { readYamlFile } from '../../utils/yaml';
1414

@@ -40,7 +40,7 @@ export default class Generate extends CustomCommand {
4040
const { args, flags } = await this.parse(Generate);
4141

4242
const currentPath = process.cwd();
43-
const tpConfigPath = join(currentPath, DOBBY_CONFIG_FILE);
43+
const tpConfigPath = join(currentPath, TP_CONFIG_FILE);
4444

4545
if (!existsSync(tpConfigPath))
4646
throw new CustomError('To be able to generate some resource, you should first mark the ');

src/commands/list/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TPConfig, TPTemplate } from '../../utils/definitions';
77
import { findTPTemplateByName } from '../../utils/functions';
88
import CustomCommand from '../../utils/oclif/custom-command';
99
import CustomError from '../../utils/oclif/custom-error';
10-
import { DOBBY_CONFIG_FILE, DOBBY_TEMPLATES_FOLDER } from '../../utils/variables';
10+
import { TP_CONFIG_FILE, TP_TEMPLATES_FOLDER } from '../../utils/variables';
1111
import { readYamlFile } from '../../utils/yaml';
1212

1313
export default class List extends CustomCommand {
@@ -47,16 +47,16 @@ export default class List extends CustomCommand {
4747

4848
if (locally) {
4949
const currentPath = process.cwd();
50-
const tpConfigPath = join(currentPath, DOBBY_CONFIG_FILE);
50+
const tpConfigPath = join(currentPath, TP_CONFIG_FILE);
5151

5252
if (!existsSync(tpConfigPath))
53-
throw new CustomError(`In order to be able to list the locally installed features, you must first generate the "${DOBBY_CONFIG_FILE}" with "tp local <template-name>".`);
53+
throw new CustomError(`In order to be able to list the locally installed features, you must first generate the "${TP_CONFIG_FILE}" with "tp local <template-name>".`);
5454

5555
const tpConfig = await readYamlFile(tpConfigPath).then(config => TPConfig.parse(config));
5656

5757
templateFolders = Object.keys(tpConfig.templates);
5858
} else {
59-
templateFolders = await readdir(DOBBY_TEMPLATES_FOLDER);
59+
templateFolders = await readdir(TP_TEMPLATES_FOLDER);
6060
}
6161

6262
return Promise.all(

src/commands/local/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { join } from 'node:path';
66
import { TPConfig, TPTemplate } from '../../utils/definitions';
77
import { findTPTemplateContentByName } from '../../utils/functions';
88
import CustomCommand from '../../utils/oclif/custom-command';
9-
import { DOBBY_CONFIG_FILE } from '../../utils/variables';
9+
import { TP_CONFIG_FILE } from '../../utils/variables';
1010
import { readYamlFile, writeYamlFile } from '../../utils/yaml';
1111

1212
export default class Local extends CustomCommand {
@@ -48,7 +48,7 @@ export default class Local extends CustomCommand {
4848

4949
private async toLocal(name: string, url: string): Promise<void> {
5050
const currentPath = process.cwd();
51-
const configFilepath = join(currentPath, DOBBY_CONFIG_FILE);
51+
const configFilepath = join(currentPath, TP_CONFIG_FILE);
5252

5353
let configFile: TPConfig = {
5454
templates: {},
@@ -63,6 +63,6 @@ export default class Local extends CustomCommand {
6363

6464
await writeYamlFile(configFilepath, configFile);
6565

66-
this.log(`The template ${name} was saved at ${DOBBY_CONFIG_FILE}.`);
66+
this.log(`The template ${name} was saved at ${TP_CONFIG_FILE}.`);
6767
}
6868
}

src/commands/open/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { join } from 'node:path';
44
import openFolder from 'open';
55
import CustomCommand from '../../utils/oclif/custom-command';
66
import CustomError from '../../utils/oclif/custom-error';
7-
import { DOBBY_TEMPLATES_FOLDER } from '../../utils/variables';
7+
import { TP_TEMPLATES_FOLDER } from '../../utils/variables';
88

99
export default class Open extends CustomCommand {
1010
static description = 'Open the folder where templates are saved.';
@@ -21,10 +21,10 @@ export default class Open extends CustomCommand {
2121

2222
async run(): Promise<void> {
2323
const { args } = await this.parse(Open);
24-
const pathToOpen = join(DOBBY_TEMPLATES_FOLDER, args.name || '');
24+
const pathToOpen = join(TP_TEMPLATES_FOLDER, args.name || '');
2525

2626
if (!existsSync(pathToOpen))
27-
throw new CustomError(`The template with name "${args.name}" was not found at "${DOBBY_TEMPLATES_FOLDER}"`);
27+
throw new CustomError(`The template with name "${args.name}" was not found at "${TP_TEMPLATES_FOLDER}"`);
2828

2929
await openFolder(pathToOpen);
3030
}

src/commands/remove/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { rm } from 'node:fs/promises';
44
import { join } from 'node:path';
55
import CustomCommand from '../../utils/oclif/custom-command';
66
import CustomError from '../../utils/oclif/custom-error';
7-
import { DOBBY_TEMPLATES_FOLDER } from '../../utils/variables';
7+
import { TP_TEMPLATES_FOLDER } from '../../utils/variables';
88

99
export default class Remove extends CustomCommand {
1010
static description = 'Remove an installed template.';
@@ -25,10 +25,10 @@ export default class Remove extends CustomCommand {
2525

2626
async run(): Promise<void> {
2727
const { args } = await this.parse(Remove);
28-
const pathToRemove = join(DOBBY_TEMPLATES_FOLDER, args.name || '');
28+
const pathToRemove = join(TP_TEMPLATES_FOLDER, args.name || '');
2929

3030
if (!existsSync(pathToRemove))
31-
throw new CustomError(`The template with name "${args.name}" was not found at "${DOBBY_TEMPLATES_FOLDER}"`);
31+
throw new CustomError(`The template with name "${args.name}" was not found at "${TP_TEMPLATES_FOLDER}"`);
3232

3333
await rm(pathToRemove, {
3434
force: true,

src/commands/restore/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { join } from 'node:path';
77
import { TPConfig, TPTemplate } from '../../utils/definitions';
88
import CustomCommand from '../../utils/oclif/custom-command';
99
import CustomError from '../../utils/oclif/custom-error';
10-
import { DOBBY_CONFIG_FILE, DOBBY_TEMPLATES_FOLDER } from '../../utils/variables';
10+
import { TP_CONFIG_FILE, TP_TEMPLATES_FOLDER } from '../../utils/variables';
1111
import { readYamlFile } from '../../utils/yaml';
1212
import Start from '../start';
1313

1414
export default class Restore extends CustomCommand {
15-
static description = `Restore saved templates from "${DOBBY_CONFIG_FILE}"`;
15+
static description = `Restore saved templates from "${TP_CONFIG_FILE}"`;
1616

1717
static examples = [
1818
'$ tp restore',
@@ -30,10 +30,10 @@ export default class Restore extends CustomCommand {
3030
const { args, flags } = await this.parse(Restore);
3131

3232
const currentPath = process.cwd();
33-
const configFilepath = join(currentPath, DOBBY_CONFIG_FILE);
33+
const configFilepath = join(currentPath, TP_CONFIG_FILE);
3434

3535
if (!existsSync(configFilepath))
36-
throw new CustomError(`You do not have a "${DOBBY_CONFIG_FILE}" in this current path. Are you in the correct folder?`);
36+
throw new CustomError(`You do not have a "${TP_CONFIG_FILE}" in this current path. Are you in the correct folder?`);
3737

3838
const configFile = await readYamlFile<TPConfig>(configFilepath)
3939
.then(config => TPConfig.parse(config));
@@ -58,7 +58,7 @@ export default class Restore extends CustomCommand {
5858
inputEncoding: 'Base64',
5959
outputEncoding: 'String',
6060
});
61-
const templateFolder = join(DOBBY_TEMPLATES_FOLDER, name);
61+
const templateFolder = join(TP_TEMPLATES_FOLDER, name);
6262
const alreadyExist = existsSync(templateFolder);
6363

6464
if (alreadyExist && !force)

src/commands/start/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { join } from 'node:path';
77
import { TPTemplate } from '../../utils/definitions';
88
import CustomCommand from '../../utils/oclif/custom-command';
99
import CustomError from '../../utils/oclif/custom-error';
10-
import { DOBBY_TEMPLATE_FILE, DOBBY_TEMPLATES_FOLDER } from '../../utils/variables';
10+
import { TP_TEMPLATE_FILE, TP_TEMPLATES_FOLDER } from '../../utils/variables';
1111

1212
export default class Start extends CustomCommand {
1313
static description = 'Start a new template.'
@@ -39,8 +39,8 @@ export default class Start extends CustomCommand {
3939

4040
const templateName = paramCase(name);
4141

42-
const outputFolder = join(DOBBY_TEMPLATES_FOLDER, templateName);
43-
const outputFile = join(outputFolder, DOBBY_TEMPLATE_FILE);
42+
const outputFolder = join(TP_TEMPLATES_FOLDER, templateName);
43+
const outputFile = join(outputFolder, TP_TEMPLATE_FILE);
4444

4545
const alreadyExist = existsSync(outputFile);
4646

src/utils/functions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { TPTemplate } from './definitions';
44
import CustomError from './oclif/custom-error';
5-
import { DOBBY_TEMPLATE_FILE, DOBBY_TEMPLATES_FOLDER } from './variables';
5+
import { TP_TEMPLATE_FILE, TP_TEMPLATES_FOLDER } from './variables';
66
import { readYamlFile } from './yaml';
77

88
export async function findTPTemplateByName(name: string): Promise<TPTemplate> {
9-
const filePath = join(DOBBY_TEMPLATES_FOLDER, name, DOBBY_TEMPLATE_FILE);
9+
const filePath = join(TP_TEMPLATES_FOLDER, name, TP_TEMPLATE_FILE);
1010

1111
try {
1212
return await readYamlFile<unknown>(filePath).then(template => TPTemplate.parse(template));
@@ -19,7 +19,7 @@ export async function findTPTemplateByName(name: string): Promise<TPTemplate> {
1919
}
2020

2121
export async function findTPTemplateContentByName(name: string): Promise<string> {
22-
const filePath = join(DOBBY_TEMPLATES_FOLDER, name, DOBBY_TEMPLATE_FILE);
22+
const filePath = join(TP_TEMPLATES_FOLDER, name, TP_TEMPLATE_FILE);
2323

2424
try {
2525
return await readFile(filePath, { encoding: 'utf8' });

src/utils/variables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { homedir } from 'node:os';
22
import { join } from 'node:path';
33

4-
export const DOBBY_CONFIG_FILE = '.tp.yml';
5-
export const DOBBY_TEMPLATE_FILE = 'tp.yml';
6-
export const DOBBY_FOLDER = join(homedir(), '.tp');
7-
export const DOBBY_TEMPLATES_FOLDER = join(DOBBY_FOLDER, 'templates');
4+
export const TP_CONFIG_FILE = '.tp.yml';
5+
export const TP_TEMPLATE_FILE = 'tp.yml';
6+
export const TP_FOLDER = join(homedir(), '.tp');
7+
export const TP_TEMPLATES_FOLDER = join(TP_FOLDER, 'templates');

0 commit comments

Comments
 (0)