Skip to content

Commit

Permalink
fix: use path join to compose paths
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-sierra-sngular authored and jorgecasar committed Jan 12, 2024
1 parent aa3c923 commit b997f35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,15 +31,15 @@ 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();
return startMockServer.run(config.selectedSchemas);
}
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) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/user-flow-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { messages } from '../utils/messages.js';
* @returns {Promise<Config>} 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);
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit b997f35

Please # to comment.