diff --git a/src/main.js b/src/main.js index 93902e0..b190691 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,6 @@ import { program } from 'commander'; import fs from 'node:fs'; +import path from 'node:path'; import { startMockServer } from './services/start-mock-server.js'; import { userFlowSteps } from './services/user-flow-steps.js'; @@ -30,7 +31,7 @@ export const main = async () => { /** @type {ProgramOptions} */ const options = program.opts(); - const configFileExists = fs.existsSync(`${process.cwd()}/${RC_FILE_NAME}`); + const configFileExists = fs.existsSync(path.join(process.cwd(), RC_FILE_NAME)); if (options.runConfig && !configFileExists) { Logger.warn(messages.CONFIG_FILE_NOT_FOUND, RC_FILE_NAME); const config = await userFlowSteps.init(); @@ -38,7 +39,7 @@ export const main = async () => { } if (options.runConfig) { const config = - /** @type {Config} */ (JSON.parse(fs.readFileSync(`${process.cwd()}/${RC_FILE_NAME}`, 'utf-8'))) || {}; + /** @type {Config} */ (JSON.parse(fs.readFileSync(path.join(process.cwd(), RC_FILE_NAME), 'utf-8'))) || {}; return startMockServer.run(config.selectedSchemas); } if (options?.origin) { diff --git a/src/services/user-flow-steps.js b/src/services/user-flow-steps.js index 10a4d38..6022516 100644 --- a/src/services/user-flow-steps.js +++ b/src/services/user-flow-steps.js @@ -25,7 +25,7 @@ import { messages } from '../utils/messages.js'; * @returns {Promise} An object with the initial values from the user. */ async function initWithConfigFile() { - const configFilePath = `${process.cwd()}/${RC_FILE_NAME}`; + const configFilePath = path.join(process.cwd(), RC_FILE_NAME); const fileContent = fs.readFileSync(configFilePath, 'utf-8'); const existingConfig = /** @type {Config} */ (JSON.parse(fileContent)) || {}; Logger.info(messages.CURRENT_CONFIG, existingConfig); @@ -102,7 +102,7 @@ async function init({ origin, schemaPaths, ports } = { schemaPaths: [], ports: [ /** @type {Config} */ const config = { schemasOrigin, selectedSchemas }; - fs.writeFileSync(`${process.cwd()}/${RC_FILE_NAME}`, JSON.stringify(config, null, '\t')); + fs.writeFileSync(path.join(process.cwd(), RC_FILE_NAME), JSON.stringify(config, null, '\t')); Logger.info(messages.SAVED_CONFIG, config); await addToGitignore(RC_FILE_NAME); @@ -120,7 +120,7 @@ async function initWithSchemaPaths({ schemaPaths, ports } = { schemaPaths: [], p const selectedSchemas = ports?.length ? assignPorts(schemaPaths, ports) : await askForPorts(schemaPaths); const config = { selectedSchemas }; - fs.writeFileSync(`${process.cwd()}/${RC_FILE_NAME}`, JSON.stringify(config, null, '\t')); + fs.writeFileSync(path.join(process.cwd(), RC_FILE_NAME), JSON.stringify(config, null, '\t')); Logger.info(messages.USING_PROVIDED_CONFIG, config); return config;