Skip to content

Commit

Permalink
chore: Re-order functions in object config-
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed May 30, 2024
1 parent 7cdeaa1 commit f5dc7ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/commands/project/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function viewProjectConfigCommand() {
.aliases(['get', 'show'])
.summary('Shows the current project config')
.action(() => {
console.log(projectConfig.getConfigContent())
console.log(projectConfig.get())
})
}

Expand All @@ -18,7 +18,7 @@ function generateProjectConfigCommand() {
.alias('create')
.summary('Generate a new deafult project config')
.action(() => {
projectConfig.generate()
projectConfig.save(projectConfig.default())
})
}

Expand All @@ -27,9 +27,6 @@ function removeProjectConfigCommand() {
.name('remove')
.alias('delete')
.summary('Removes the config for the current project')
.action(() => {
projectConfig.remove()
})
}

export function projectConfigCommand() {
Expand Down
10 changes: 5 additions & 5 deletions src/config/cli.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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.')
Expand Down
18 changes: 9 additions & 9 deletions src/config/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ProjectConfigSpec {
}
}

const projectConfig = {
export const projectConfig = {
default(): ProjectConfigSpec {
return {
projectName: 'demo',
Expand Down Expand Up @@ -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)
},
}

0 comments on commit f5dc7ad

Please sign in to comment.