From d3ff9a5776a40578c13d4f7baa5659c1b61615b7 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Fri, 9 Feb 2024 15:12:31 +0600 Subject: [PATCH] Convert to ECMAScript --- package-lock.json | 6 ++--- package.json | 12 ++++----- ...-command.js => docker-compose-command.mjs} | 8 +++--- .../{init-command.js => init-command.mjs} | 18 ++++++------- src/constants/color-codes.js | 5 ---- src/constants/color-codes.mjs | 3 +++ src/constants/commands.js | 3 --- src/constants/commands.mjs | 1 + src/constants/{services.js => services.mjs} | 26 +++++++++---------- src/{index.js => index.mjs} | 8 +++--- src/utils/{index.js => index.mjs} | 23 ++++++---------- 11 files changed, 48 insertions(+), 65 deletions(-) rename src/console/{docker-compose-command.js => docker-compose-command.mjs} (59%) rename src/console/{init-command.js => init-command.mjs} (93%) delete mode 100644 src/constants/color-codes.js create mode 100644 src/constants/color-codes.mjs delete mode 100644 src/constants/commands.js create mode 100644 src/constants/commands.mjs rename src/constants/{services.js => services.mjs} (65%) rename src/{index.js => index.mjs} (53%) rename src/utils/{index.js => index.mjs} (85%) diff --git a/package-lock.json b/package-lock.json index 4ecf6aa..13fb34a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vail", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vail", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "dependencies": { "child_process": "^1.0.2", @@ -14,7 +14,7 @@ "js-yaml": "^4.1.0" }, "bin": { - "vail": "src/index.js" + "vail": "src/index.mjs" }, "devDependencies": { "eslint": "^8.46.0", diff --git a/package.json b/package.json index b31628d..e8aff92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vail", - "version": "1.0.1", + "version": "1.0.2", "description": "Docker powered local development experience for JavaScript/TypeScript Apps.", "license": "MIT", "author": "arifszn", @@ -13,13 +13,13 @@ }, "type": "module", "bin": { - "vail": "./src/index.js" + "vail": "./src/index.mjs" }, "scripts": { - "lint": "eslint --ext .js,.jsx .", - "lint:fix": "eslint --ext .js,.jsx --fix .", - "prettier": "prettier --check './**/*.{js,jsx,ts,tsx,css,md,json}'", - "prettier:fix": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}'" + "lint": "eslint --ext .js,.jsx,.mjs .", + "lint:fix": "eslint --ext .js,.jsx,.mjs --fix .", + "prettier": "prettier --check './**/*.{js,jsx,mjs,ts,tsx,css,md,json}'", + "prettier:fix": "prettier --write './**/*.{js,jsx,mjs,ts,tsx,css,md,json}'" }, "files": [ "src", diff --git a/src/console/docker-compose-command.js b/src/console/docker-compose-command.mjs similarity index 59% rename from src/console/docker-compose-command.js rename to src/console/docker-compose-command.mjs index bfd5ea4..5ee6ced 100644 --- a/src/console/docker-compose-command.js +++ b/src/console/docker-compose-command.mjs @@ -1,7 +1,7 @@ -const { execSync } = require('child_process'); -const { displayErrorMessage } = require('../utils'); +import { execSync } from 'child_process'; +import { displayErrorMessage } from '../utils/index.mjs'; -const dockerComposeCommand = async (processArgv) => { +export const dockerComposeCommand = async (processArgv) => { try { // Execute the Docker Compose command using execSync execSync(`docker-compose ${processArgv.slice(2).join(' ')}`, { @@ -12,5 +12,3 @@ const dockerComposeCommand = async (processArgv) => { process.exit(1); } }; - -module.exports = { dockerComposeCommand }; diff --git a/src/console/init-command.js b/src/console/init-command.mjs similarity index 93% rename from src/console/init-command.js rename to src/console/init-command.mjs index 08c98bb..f49aea2 100644 --- a/src/console/init-command.js +++ b/src/console/init-command.mjs @@ -1,20 +1,20 @@ -const fs = require('fs'); -const path = require('path'); -const { +import fs from 'fs'; +import path from 'path'; +import { displayErrorMessage, displaySuccessMessage, writeDockerComposeFileWithService, -} = require('../utils'); -const inquirer = require('inquirer'); -const { +} from '../utils/index.mjs'; +import inquirer from 'inquirer'; +import { NODE_VERSIONS, DEFAULT_NODE_VERSION, SERVICES, SERVICES_WITH_VOLUME, DEFAULT_SELECTED_SERVICES, -} = require('../constants/services'); +} from '../constants/services.mjs'; -const initCommand = async () => { +export const initCommand = async () => { const dockerComposePath = path.resolve(process.cwd(), 'docker-compose.yml'); // Check if docker-compose.yml is already present @@ -139,5 +139,3 @@ networks: displaySuccessMessage('Vail successfully initialized.'); }; - -module.exports = { initCommand }; diff --git a/src/constants/color-codes.js b/src/constants/color-codes.js deleted file mode 100644 index 62954c1..0000000 --- a/src/constants/color-codes.js +++ /dev/null @@ -1,5 +0,0 @@ -const RED_COLOR_CODE = '\x1b[31m'; -const GREEN_COLOR_CODE = '\x1b[32m'; -const RESET_COLOR_CODE = '\x1b[0m'; - -module.exports = { RED_COLOR_CODE, RESET_COLOR_CODE, GREEN_COLOR_CODE }; diff --git a/src/constants/color-codes.mjs b/src/constants/color-codes.mjs new file mode 100644 index 0000000..5f0f40f --- /dev/null +++ b/src/constants/color-codes.mjs @@ -0,0 +1,3 @@ +export const RED_COLOR_CODE = '\x1b[31m'; +export const GREEN_COLOR_CODE = '\x1b[32m'; +export const RESET_COLOR_CODE = '\x1b[0m'; diff --git a/src/constants/commands.js b/src/constants/commands.js deleted file mode 100644 index bc265b1..0000000 --- a/src/constants/commands.js +++ /dev/null @@ -1,3 +0,0 @@ -const INIT = 'init'; - -module.exports = { INIT }; diff --git a/src/constants/commands.mjs b/src/constants/commands.mjs new file mode 100644 index 0000000..b80f316 --- /dev/null +++ b/src/constants/commands.mjs @@ -0,0 +1 @@ +export const INIT = 'init'; diff --git a/src/constants/services.js b/src/constants/services.mjs similarity index 65% rename from src/constants/services.js rename to src/constants/services.mjs index 6b8fd0a..afe75e5 100644 --- a/src/constants/services.js +++ b/src/constants/services.mjs @@ -16,7 +16,7 @@ const NODE_19 = '19'; const NODE_20 = '20'; const NODE_21 = '21'; -const SERVICES = [ +export const SERVICES = [ MY_SQL, ADMINER, REDIS, @@ -29,7 +29,7 @@ const SERVICES = [ MARIADB, ]; -const SERVICES_WITH_VOLUME = [ +export const SERVICES_WITH_VOLUME = [ MY_SQL, MINIO, RABBITMQ, @@ -39,7 +39,7 @@ const SERVICES_WITH_VOLUME = [ MEILISEARCH, ]; -const DEFAULT_SELECTED_SERVICES = [ +export const DEFAULT_SELECTED_SERVICES = [ MY_SQL, ADMINER, REDIS, @@ -48,15 +48,13 @@ const DEFAULT_SELECTED_SERVICES = [ MEILISEARCH, ]; -const NODE_VERSIONS = [NODE_14, NODE_16, NODE_18, NODE_19, NODE_20, NODE_21]; - -const DEFAULT_NODE_VERSION = NODE_21; +export const NODE_VERSIONS = [ + NODE_14, + NODE_16, + NODE_18, + NODE_19, + NODE_20, + NODE_21, +]; -// export all -module.exports = { - NODE_VERSIONS, - DEFAULT_NODE_VERSION, - SERVICES, - SERVICES_WITH_VOLUME, - DEFAULT_SELECTED_SERVICES, -}; +export const DEFAULT_NODE_VERSION = NODE_21; diff --git a/src/index.js b/src/index.mjs similarity index 53% rename from src/index.js rename to src/index.mjs index 285b8a0..415bc80 100755 --- a/src/index.js +++ b/src/index.mjs @@ -1,9 +1,9 @@ #!/usr/bin/env node -const { dockerComposeCommand } = require('./console/docker-compose-command'); -const { initCommand } = require('./console/init-command'); -const { INIT } = require('./constants/commands'); -const { displayErrorMessage } = require('./utils'); +import { dockerComposeCommand } from './console/docker-compose-command.mjs'; +import { initCommand } from './console/init-command.mjs'; +import { INIT } from './constants/commands.mjs'; +import { displayErrorMessage } from './utils/index.mjs'; const command = process.argv[2]; diff --git a/src/utils/index.js b/src/utils/index.mjs similarity index 85% rename from src/utils/index.js rename to src/utils/index.mjs index 3020123..3ccdc42 100644 --- a/src/utils/index.js +++ b/src/utils/index.mjs @@ -1,22 +1,21 @@ -const fs = require('fs'); -const yaml = require('js-yaml'); -const path = require('path'); - -const { +import fs from 'fs'; +import yaml from 'js-yaml'; +import path from 'path'; +import { RED_COLOR_CODE, RESET_COLOR_CODE, GREEN_COLOR_CODE, -} = require('../constants/color-codes'); +} from '../constants/color-codes.mjs'; -const displayErrorMessage = (message) => { +export const displayErrorMessage = (message) => { console.log(`${RED_COLOR_CODE}${message}${RESET_COLOR_CODE}`); }; -const displaySuccessMessage = (message) => { +export const displaySuccessMessage = (message) => { console.log(`${GREEN_COLOR_CODE}${message}${RESET_COLOR_CODE}`); }; -const writeDockerComposeFileWithService = ( +export const writeDockerComposeFileWithService = ( selectedServices, availableVolumes, ) => { @@ -78,9 +77,3 @@ const writeDockerComposeFileWithService = ( // Write the updated YAML content to docker-compose.yml fs.writeFileSync(dockerComposePath, updatedComposeContent, 'utf8'); }; - -module.exports = { - displayErrorMessage, - displaySuccessMessage, - writeDockerComposeFileWithService, -};