diff --git a/src/commands/project/config.ts b/src/commands/project/config.ts index 87fb81f..2ee8ff6 100644 --- a/src/commands/project/config.ts +++ b/src/commands/project/config.ts @@ -8,7 +8,7 @@ function viewProjectConfigCommand() { .aliases(['get', 'show']) .summary('Shows the current project config') .action(() => { - console.log(projectConfig.getConfigContent()) + console.log(projectConfig.get()) }) } @@ -18,7 +18,7 @@ function generateProjectConfigCommand() { .alias('create') .summary('Generate a new deafult project config') .action(() => { - projectConfig.generate() + projectConfig.save(projectConfig.default()) }) } @@ -27,9 +27,6 @@ function removeProjectConfigCommand() { .name('remove') .alias('delete') .summary('Removes the config for the current project') - .action(() => { - projectConfig.remove() - }) } export function projectConfigCommand() { diff --git a/src/config/cli.config.ts b/src/config/cli.config.ts index b5dbd41..08f9d82 100644 --- a/src/config/cli.config.ts +++ b/src/config/cli.config.ts @@ -66,6 +66,11 @@ export const cliConfig = { process.exit(1) }, + get(configFile = CONFIG_FILE_PATH): CLIConfigSpec { + this.check(CONFIG_FILE_PATH) + return JSON.parse(fs.readFileSync(configFile).toString()) + }, + save(config: CLIConfigSpec) { if (isFile(CONFIG_FILE_PATH)) { logger.error('New DEMS CLI config file could not be created.') @@ -76,11 +81,6 @@ export const cliConfig = { fs.writeFileSync(CONFIG_FILE_PATH, JSON.stringify(config, null, 2)) }, - get(configFile = CONFIG_FILE_PATH): CLIConfigSpec { - this.check(CONFIG_FILE_PATH) - return JSON.parse(fs.readFileSync(configFile).toString()) - }, - check(configFile = CONFIG_FILE_PATH) { if (isFile(configFile)) return logger.warn('DEMS config file does not exist or is not a valid file.') diff --git a/src/config/project.config.ts b/src/config/project.config.ts index 952c3b9..4177364 100644 --- a/src/config/project.config.ts +++ b/src/config/project.config.ts @@ -42,7 +42,7 @@ interface ProjectConfigSpec { } } -const projectConfig = { +export const projectConfig = { default(): ProjectConfigSpec { return { projectName: 'demo', @@ -78,18 +78,18 @@ const projectConfig = { return JSON.parse(fs.readFileSync(configFile).toString()) }, - check(configFile = PROJECT_CONFIG_FILE) { - if (isFile(configFile)) return - logger.warn('Project config file does not exist or is not a valid file.') - logger.warn("Run 'dems setup' to create it.") - process.exit(1) - }, - - generate(config: ProjectConfigSpec) { + save(config: ProjectConfigSpec) { createPath({ path: PROJECT_CONFIG_ROOT }) createFile({ file: `${config.projectRootPath}/config.json`, content: JSON.stringify(config), }) }, + + check(configFile = PROJECT_CONFIG_FILE) { + if (isFile(configFile)) return + logger.warn('Project config file does not exist or is not a valid file.') + logger.warn("Run 'dems setup' to create it.") + process.exit(1) + }, }