import { join } from 'path' ; import { existsSync , writeFileSync } from 'fs' ; import { config } from 'dotenv' ; import toEmoji from 'emoji-name-map' ; const isTest = process . env . IS_TEST === '1' ; config ( isTest ? { path : join ( __dirname , '../test' , './test.env' ) } : { } ) ; const gitmojiPath = process . env . GITMOJI_PATH ; const filePath = gitmojiPath ? join ( process . cwd ( ) , gitmojiPath ) : join ( __dirname , 'gitmojis.json' ) ; if ( ! existsSync ( filePath ) ) { const url = process . env . GITMOJI_URL || 'https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json' ; try { const result = require ( 'child_process' ) . execFileSync ( 'curl' , [ '--silent' , '-L' , url ] , { encoding : 'utf8' , maxBuffer : Infinity , } ) ; writeFileSync ( filePath , result ) ; } catch ( e ) { throw Error ( 'Failed to fetch gitmoji JSON, please refer to https://github.com/arvinxx/gitmoji-commit-workflow/tree/master/packages/commitlint-plugin#fetch-error for help.' ) ; } } const { gitmojis } = require ( filePath ) ; export const gitmojiCodes = gitmojis . map ( ( gitmoji ) => gitmoji . code ) ; export const gitmojiUnicode = gitmojis . map ( ( gitmoji ) => toEmoji . get ( gitmoji . code ) ) ; export const localPath = filePath ;