Skip to content

Commit

Permalink
refactor: reduce barrel files
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecasar committed Jan 31, 2024
1 parent a9b12a1 commit 8fd509f
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 183 deletions.
157 changes: 39 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,32 @@
"author": "SNGULAR",
"license": "MPL-2.0",
"dependencies": {
"@inquirer/prompts": "^3.3.0",
"@inquirer/checkbox": "^1.0.0",
"@inquirer/confirm": "^2.0.0",
"@inquirer/input": "^1.0.0",
"@sngular/open-api-mocker": "^1.0.0",
"commander": "^11.1.0"
"commander": "^11.0.0"
},
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
"@esm-bundle/chai": "^4.0.0",
"@sngular/commitlint-config": "^1.0.0",
"@sngular/eslint-config": "^1.0.0",
"@sngular/lint-staged-config": "^1.0.0",
"@sngular/prettier-config": "^1.0.0",
"@sngular/semantic-release-config": "^1.0.0",
"@sngular/tsconfig": "^1.0.0",
"@types/mocha": "^10.0.2",
"@types/sinon": "^10.0.19",
"@types/sinon-chai": "^3.2.10",
"c8": "^8.0.1",
"chai-as-promised": "^7.1.1",
"@types/mocha": "^10.0.0",
"@types/sinon": "^10.0.0",
"@types/sinon-chai": "^3.0.0",
"c8": "^8.0.0",
"chai-as-promised": "^7.0.0",
"eslint-config-prettier": "^9.0.0",
"esmock": "^2.6.3",
"esmock": "^2.0.0",
"husky": "^8.0.0",
"mocha": "^10.2.0",
"mock-fs": "^5.2.0",
"sinon": "^16.1.0",
"sinon-chai": "^3.7.0"
"mocha": "^10.0.0",
"mock-fs": "^5.0.0",
"sinon": "^16.0.0",
"sinon-chai": "^3.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
11 changes: 6 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { program } from 'commander';
import fs from 'node:fs';
import path from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';

import { RC_FILE_NAME } from './helpers/constants.js';
import { Logger } from './helpers/logger.js';
Expand Down Expand Up @@ -29,8 +29,9 @@ export const main = async () => {
.option('-p, --port [ports...]', 'port to serve each schema')
.option('-r, --run-config', 'use saved config');
program.parse();
const options = /** @type {ProgramOptions} */ (program.opts());
const configFileExists = fs.existsSync(path.join(process.cwd(), RC_FILE_NAME));
/** @type {ProgramOptions} */
const options = program.opts();
const configFileExists = existsSync(join(process.cwd(), RC_FILE_NAME));
let config;
if (options.runConfig) {
if (configFileExists) {
Expand Down Expand Up @@ -64,5 +65,5 @@ export const main = async () => {
* @returns {Config} Content of the config file.
*/
function getConfigFromFile() {
return /** @type {Config} */ (JSON.parse(fs.readFileSync(path.join(process.cwd(), RC_FILE_NAME), 'utf-8'))) || {};
return /** @type {Config} */ (JSON.parse(readFileSync(join(process.cwd(), RC_FILE_NAME), 'utf-8'))) || {};
}
8 changes: 4 additions & 4 deletions src/services/check-string-in-file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs';
import readline from 'node:readline';
import { createReadStream } from 'node:fs';
import { createInterface } from 'node:readline';

/**
* Check if a string is in a file.
Expand All @@ -10,8 +10,8 @@ import readline from 'node:readline';
* @returns {Promise<boolean>} True if the string is in the file, false otherwise.
*/
export async function check(stringToCheck, filePath) {
const input = fs.createReadStream(filePath);
const reader = readline.createInterface({ input });
const input = createReadStream(filePath);
const reader = createInterface({ input });
for await (const line of reader) {
if (line === stringToCheck) {
return true;
Expand Down
18 changes: 9 additions & 9 deletions src/services/clone-git-repository.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import child_process from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { execSync } from 'node:child_process';
import { mkdirSync, existsSync, rmSync } from 'node:fs';
import { resolve } from 'node:path';
import { cwd } from 'node:process';

/**
* Clone a git repository.
Expand All @@ -21,7 +21,7 @@ export function cloneRepository(repositoryURL, dirName) {
*/
function resetDirectory(dirName) {
removeDirectory(dirName);
fs.mkdirSync(dirName);
mkdirSync(dirName);
}

/**
Expand All @@ -30,8 +30,8 @@ function resetDirectory(dirName) {
* @param {string} dirName - The name of the directory to remove.
*/
function removeDirectory(dirName) {
if (fs.existsSync(dirName)) {
fs.rmSync(dirName, { recursive: true });
if (existsSync(dirName)) {
rmSync(dirName, { recursive: true });
}
}

Expand All @@ -42,7 +42,7 @@ function removeDirectory(dirName) {
* @param {string} dirName - The name of the directory where the repository will be cloned.
*/
function clone(repositoryURL, dirName) {
child_process.execSync(`git clone ${repositoryURL} .`, {
cwd: path.resolve(process.cwd(), dirName), // path to where you want to save the file
execSync(`git clone ${repositoryURL} .`, {
cwd: resolve(cwd(), dirName), // path to where you want to save the file
});
}
Loading

0 comments on commit 8fd509f

Please sign in to comment.