Skip to content

Commit

Permalink
Merge pull request #66 from arifszn/support-modern-js
Browse files Browse the repository at this point in the history
Convert to ECMAScript
  • Loading branch information
arifszn authored Feb 9, 2024
2 parents 696107a + d3ff9a5 commit 90b1b3c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 65 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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(' ')}`, {
Expand All @@ -12,5 +12,3 @@ const dockerComposeCommand = async (processArgv) => {
process.exit(1);
}
};

module.exports = { dockerComposeCommand };
18 changes: 8 additions & 10 deletions src/console/init-command.js → src/console/init-command.mjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -139,5 +139,3 @@ networks:

displaySuccessMessage('Vail successfully initialized.');
};

module.exports = { initCommand };
5 changes: 0 additions & 5 deletions src/constants/color-codes.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/constants/color-codes.mjs
Original file line number Diff line number Diff line change
@@ -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';
3 changes: 0 additions & 3 deletions src/constants/commands.js

This file was deleted.

1 change: 1 addition & 0 deletions src/constants/commands.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const INIT = 'init';
26 changes: 12 additions & 14 deletions src/constants/services.js → src/constants/services.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,7 +29,7 @@ const SERVICES = [
MARIADB,
];

const SERVICES_WITH_VOLUME = [
export const SERVICES_WITH_VOLUME = [
MY_SQL,
MINIO,
RABBITMQ,
Expand All @@ -39,7 +39,7 @@ const SERVICES_WITH_VOLUME = [
MEILISEARCH,
];

const DEFAULT_SELECTED_SERVICES = [
export const DEFAULT_SELECTED_SERVICES = [
MY_SQL,
ADMINER,
REDIS,
Expand All @@ -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;
8 changes: 4 additions & 4 deletions src/index.js → src/index.mjs
Original file line number Diff line number Diff line change
@@ -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];

Expand Down
23 changes: 8 additions & 15 deletions src/utils/index.js → src/utils/index.mjs
Original file line number Diff line number Diff line change
@@ -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,
) => {
Expand Down Expand Up @@ -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,
};

0 comments on commit 90b1b3c

Please sign in to comment.