Skip to content

Commit

Permalink
♻️ Migrate to ESModules
Browse files Browse the repository at this point in the history
♻️ Migrate to ESModules

♻️ Migrate to ESModules
  • Loading branch information
carloscuesta committed Sep 26, 2022
1 parent 45f00e0 commit 659a886
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 92 deletions.
15 changes: 10 additions & 5 deletions src/cli.js
Expand Up @@ -2,13 +2,17 @@
// @flow
import meow from 'meow'
import updateNotifier from 'update-notifier'
import { readFileSync } from 'fs'

import pkg from '../package.json'
import commands from './commands'
import FLAGS from '@constants/flags'
import findGitmojiCommand from '@utils/findGitmojiCommand'
import commands from '@commands/index.js'
import FLAGS from '@constants/flags.js'
import findGitmojiCommand from '@utils/findGitmojiCommand.js'

updateNotifier({ pkg }).notify({ isGlobal: true })
const packageJson: Object = readFileSync(
new URL('../package.json', import.meta.url)
)

updateNotifier({ pkg: JSON.parse(packageJson) }).notify({ isGlobal: true })

const cli = meow(
`
Expand All @@ -28,6 +32,7 @@ const cli = meow(
$ gitmoji bug linter -s
`,
{
importMeta: import.meta,
flags: {
[FLAGS.COMMIT]: { type: 'boolean', alias: 'c' },
[FLAGS.CONFIG]: { type: 'boolean', alias: 'g' },
Expand Down
10 changes: 5 additions & 5 deletions src/commands/commit/index.js
@@ -1,14 +1,14 @@
// @flow
import inquirer from 'inquirer'

import getEmojis from '@utils/getEmojis'
import COMMIT_MODES from '@constants/commit'
import getEmojis from '@utils/getEmojis.js'
import COMMIT_MODES from '@constants/commit.js'
import withHook, {
registerHookInterruptionHandler,
cancelIfNeeded
} from './withHook'
import withClient from './withClient'
import prompts from './prompts'
} from './withHook/index.js'
import withClient from './withClient/index.js'
import prompts from './prompts.js'

export type CommitOptions = {
message?: string,
Expand Down
13 changes: 7 additions & 6 deletions src/commands/commit/prompts.js
@@ -1,15 +1,16 @@
// @flow
import inquirer from 'inquirer'
import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt'

import configurationVault from '@utils/configurationVault'
import filterGitmojis from '@utils/filterGitmojis'
import getDefaultCommitContent from '@utils/getDefaultCommitContent'
import { type CommitOptions } from './index'
import guard from './guard'
import configurationVault from '@utils/configurationVault/index.js'
import filterGitmojis from '@utils/filterGitmojis.js'
import getDefaultCommitContent from '@utils/getDefaultCommitContent.js'
import { type CommitOptions } from './index.js'
import guard from './guard.js'

const TITLE_MAX_LENGTH_COUNT: number = 48

inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'))
inquirer.registerPrompt('autocomplete', inquirerAutocompletePrompt)

export type Gitmoji = {
code: string,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/commit/withClient/index.js
@@ -1,11 +1,11 @@
// @flow
import execa from 'execa'
import { execa } from 'execa'
import fs from 'fs'
import chalk from 'chalk'

import isHookCreated from '@utils/isHookCreated'
import configurationVault from '@utils/configurationVault'
import { type Answers } from '../prompts'
import isHookCreated from '@utils/isHookCreated.js'
import configurationVault from '@utils/configurationVault/index.js'
import { type Answers } from '../prompts.js'

const withClient = async (answers: Answers): Promise<void> => {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/commit/withHook/index.js
@@ -1,8 +1,8 @@
// @flow
import execa from 'execa'
import { execa } from 'execa'
import fs from 'fs'

import { type Answers } from '../prompts'
import { type Answers } from '../prompts.js'

const withHook = (answers: Answers) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/guard.js
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import isURL from 'validator/lib/isURL'
import isURL from 'validator/lib/isURL.js'

const errors = {
url: chalk.red('Enter a valid API URL')
Expand Down
6 changes: 3 additions & 3 deletions src/commands/config/index.js
@@ -1,9 +1,9 @@
// @flow
import inquirer from 'inquirer'

import configurationPrompts from './prompts'
import { CONFIG } from '@constants/configuration'
import configurationVault from '@utils/configurationVault'
import configurationPrompts from './prompts.js'
import { CONFIG } from '@constants/configuration.js'
import configurationVault from '@utils/configurationVault/index.js'

const config = () => {
inquirer.prompt(configurationPrompts()).then((answers) => {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/config/prompts.js
@@ -1,7 +1,7 @@
// @flow
import configurationVault from '@utils/configurationVault'
import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration'
import guard from './guard'
import configurationVault from '@utils/configurationVault/index.js'
import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration.js'
import guard from './guard.js'

export default (): Array<Object> => [
{
Expand Down
4 changes: 2 additions & 2 deletions src/commands/hook/create/index.js
Expand Up @@ -2,8 +2,8 @@
import fs from 'fs'
import ora from 'ora'

import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath'
import HOOK from '../hook'
import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath.js'
import HOOK from '../hook.js'

const createHook = async () => {
const spinner = ora('Creating the gitmoji commit hook').start()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/hook/index.js
@@ -1,5 +1,5 @@
import create from './create'
import remove from './remove'
import create from './create/index.js'
import remove from './remove/index.js'

export default {
create,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/hook/remove/index.js
Expand Up @@ -2,8 +2,8 @@
import fs from 'fs'
import ora from 'ora'

import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath'
import HOOK from '../hook'
import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath.js'
import HOOK from '../hook.js'

const removeHook = async () => {
const spinner = ora('Creating the gitmoji commit hook').start()
Expand Down
12 changes: 6 additions & 6 deletions src/commands/index.js
@@ -1,10 +1,10 @@
// @flow
import commit from './commit'
import config from './config'
import hook from './hook'
import list from './list'
import search from './search'
import update from './update'
import commit from './commit/index.js'
import config from './config/index.js'
import hook from './hook/index.js'
import list from './list/index.js'
import search from './search/index.js'
import update from './update/index.js'

export default {
commit,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/list/index.js
@@ -1,6 +1,6 @@
// @flow
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'

const list = (): Promise<void> =>
getEmojis().then((gitmojis) => printEmojis(gitmojis))
Expand Down
6 changes: 3 additions & 3 deletions src/commands/search/index.js
@@ -1,7 +1,7 @@
// @flow
import filterGitmojis from '@utils/filterGitmojis'
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import filterGitmojis from '@utils/filterGitmojis.js'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'

const search = (query: string): Promise<void> => {
return getEmojis()
Expand Down
4 changes: 2 additions & 2 deletions src/commands/update/index.js
@@ -1,6 +1,6 @@
// @flow
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'

const update = (): Promise<void> =>
getEmojis(true).then((gitmojis) => printEmojis(gitmojis))
Expand Down
8 changes: 4 additions & 4 deletions src/utils/configurationVault/getConfiguration.js
@@ -1,8 +1,8 @@
import Conf from 'conf'
import { cwd } from 'process'
import pathExists from 'path-exists'
import { pathExistsSync } from 'path-exists'

import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration'
import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration.js'

const DEFAULT_CONFIGURATION = {
[CONFIG.AUTO_ADD]: false,
Expand Down Expand Up @@ -30,11 +30,11 @@ const getConfiguration = (): { get: Function, set: Function } => {
const packageJson = `${cwd()}/package.json`
const configurationFile = `${cwd()}/.gitmojirc.json`

if (pathExists.sync(packageJson)) {
if (pathExistsSync(packageJson)) {
return require(packageJson).gitmoji || LOCAL_CONFIGURATION.store
}

if (pathExists.sync(configurationFile)) {
if (pathExistsSync(configurationFile)) {
return require(configurationFile) || LOCAL_CONFIGURATION.store
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/configurationVault/index.js
@@ -1,6 +1,6 @@
// @flow
import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration'
import getConfiguration from './getConfiguration'
import { CONFIG, EMOJI_COMMIT_FORMATS } from '@constants/configuration.js'
import getConfiguration from './getConfiguration.js'

const configuration = getConfiguration()

Expand Down
6 changes: 3 additions & 3 deletions src/utils/emojisCache.js
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import pathExists from 'path-exists'
import { pathExistsSync } from 'path-exists'

export const GITMOJI_CACHE: Object = {
FOLDER: '.gitmoji',
Expand All @@ -16,7 +16,7 @@ export const CACHE_PATH: string = path.join(
)

const createEmojis = (emojis: Array<Object>): void => {
if (!pathExists.sync(path.dirname(CACHE_PATH))) {
if (!pathExistsSync(path.dirname(CACHE_PATH))) {
fs.mkdirSync(path.dirname(CACHE_PATH))
}

Expand All @@ -31,7 +31,7 @@ const getEmojis = (): Array<Object> => {
}
}

const isAvailable = (): boolean => pathExists.sync(CACHE_PATH)
const isAvailable = (): boolean => pathExistsSync(CACHE_PATH)

export default {
createEmojis,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/filterGitmojis.js
@@ -1,7 +1,7 @@
// @flow
import Fuse from 'fuse.js'

import { type Gitmoji } from '@commands/commit/prompts'
import { type Gitmoji } from '@commands/commit/prompts.js'

export const options = {
threshold: 0.5,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/findGitmojiCommand.js
@@ -1,6 +1,6 @@
// @flow
import COMMIT_MODES from '@constants/commit'
import FLAGS from '@constants/flags'
import COMMIT_MODES from '@constants/commit.js'
import FLAGS from '@constants/flags.js'

const getOptionsForCommand = (command: ?string, flags: Object): ?Object => {
const commandsWithOptions = [FLAGS.COMMIT, FLAGS.HOOK]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getAbsoluteHooksPath.js
@@ -1,5 +1,5 @@
// @flow
import execa from 'execa'
import { execa } from 'execa'
import path from 'path'

const getAbsoluteHooksPath = async (hookName: string): Promise<string> => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getDefaultCommitContent.js
@@ -1,8 +1,8 @@
// @flow
import fs from 'fs'

import { type CommitOptions } from '@commands/commit/index'
import COMMIT_MODES from '@constants/commit'
import { type CommitOptions } from '@commands/commit/index.js'
import COMMIT_MODES from '@constants/commit.js'

const COMMIT_FILE_PATH_INDEX = 3
const COMMIT_TITLE_LINE_INDEX = 0
Expand Down
6 changes: 3 additions & 3 deletions src/utils/getEmojis.js
Expand Up @@ -3,9 +3,9 @@ import chalk from 'chalk'
import fetch from 'node-fetch'
import ora from 'ora'

import cache from './emojisCache'
import buildFetchOptions from './buildFetchOptions'
import configurationVault from './configurationVault'
import cache from './emojisCache.js'
import buildFetchOptions from './buildFetchOptions.js'
import configurationVault from './configurationVault/index.js'

const getEmojis = async (
skipCache: boolean = false
Expand Down
4 changes: 2 additions & 2 deletions src/utils/isHookCreated.js
@@ -1,8 +1,8 @@
// @flow
import fs from 'fs'

import HOOK from '@commands/hook/hook'
import getAbsoluteHooksPath from './getAbsoluteHooksPath'
import HOOK from '@commands/hook/hook.js'
import getAbsoluteHooksPath from './getAbsoluteHooksPath.js'

const isHookCreated = async (): Promise<?boolean> => {
try {
Expand Down
8 changes: 4 additions & 4 deletions test/commands/commit.spec.js
@@ -1,12 +1,12 @@
import inquirer from 'inquirer'
import execa from 'execa'
import { execa } from 'execa'
import fs from 'fs'
import chalk from 'chalk'
const mockProcess = require('jest-mock-process')

import configurationVault from '@utils/configurationVault'
import getDefaultCommitContent from '@utils/getDefaultCommitContent'
import getEmojis from '@utils/getEmojis'
import configurationVault from '@utils/configurationVault/index.js'
import getDefaultCommitContent from '@utils/getDefaultCommitContent.js'
import getEmojis from '@utils/getEmojis.js'
import isHookCreated from '@utils/isHookCreated'
import commit from '@commands/commit'
import guard from '@commands/commit/guard'
Expand Down
2 changes: 1 addition & 1 deletion test/commands/config.spec.js
Expand Up @@ -3,7 +3,7 @@ import inquirer from 'inquirer'
import config from '@commands/config'
import configurationPrompts from '@commands/config/prompts'
import guard from '@commands/config/guard'
import configurationVault from '@utils/configurationVault'
import configurationVault from '@utils/configurationVault/index.js'
import * as stubs from './stubs'

jest.mock('@utils/configurationVault')
Expand Down
2 changes: 1 addition & 1 deletion test/commands/hook.spec.js
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'

import hook from '@commands/hook'
import hookConfig from '@commands/hook/hook'
import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath'
import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath.js'
import * as stubs from './stubs'

jest.mock('@utils/getAbsoluteHooksPath')
Expand Down
4 changes: 2 additions & 2 deletions test/commands/list.spec.js
@@ -1,5 +1,5 @@
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'
import list from '@commands/list'

import * as stubs from './stubs'
Expand Down
4 changes: 2 additions & 2 deletions test/commands/search.spec.js
@@ -1,5 +1,5 @@
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'
import search from '@commands/search'

import * as stubs from './stubs'
Expand Down
4 changes: 2 additions & 2 deletions test/commands/update.spec.js
@@ -1,5 +1,5 @@
import getEmojis from '@utils/getEmojis'
import printEmojis from '@utils/printEmojis'
import getEmojis from '@utils/getEmojis.js'
import printEmojis from '@utils/printEmojis.js'
import update from '@commands/update'

import * as stubs from './stubs'
Expand Down
2 changes: 1 addition & 1 deletion test/utils/configurationVault/defaults.spec.js
@@ -1,4 +1,4 @@
import configurationVault from '@utils/configurationVault'
import configurationVault from '@utils/configurationVault/index.js'

describe('index', () => {
it('should match the module', () => {
Expand Down

0 comments on commit 659a886

Please sign in to comment.