1- const _ = require ( 'lodash' )
2- const execSync = require ( 'child_process' ) . execSync
3- const inquirer = require ( 'inquirer' )
4- const emoji = require ( 'node-emoji' )
1+ import _ from 'lodash'
2+ import inquirer from 'inquirer'
3+ import emoji from 'node-emoji'
4+ import { execSync } from 'child_process'
55
6- const colors = require ( './colors' )
6+ import colors from './colors.js'
77
88//
99// Functions
@@ -171,29 +171,29 @@ const createQuestion = (definition, term) => {
171171 }
172172}
173173
174- const createQuestions = ( program , definitions ) => {
174+ const createQuestions = ( options , definitions ) => {
175175 return _ ( definitions )
176176 . map ( ( definition , term ) => {
177- if ( ! _ . isUndefined ( program [ term ] ) || ! _ . isUndefined ( definition . default ) ) return
177+ if ( ! _ . isUndefined ( options [ term ] ) || ! _ . isUndefined ( definition . default ) ) return
178178 return createQuestion ( definitions [ term ] , term )
179179 } )
180180 . compact ( )
181181 . value ( )
182182}
183183
184- const getValue = ( program , definition , answer , term ) => {
184+ const getValue = ( options , definition , answer , term ) => {
185185 const val = branchText ( definition )
186186
187187 switch ( definition . type ) {
188188 case 'enum' :
189189 case 'string' :
190190 case 'text' :
191- if ( ! _ . isUndefined ( program [ term ] ) ) return program [ term ]
191+ if ( ! _ . isUndefined ( options [ term ] ) ) return options [ term ]
192192 if ( ! _ . isUndefined ( answer ) ) return answer
193193 if ( ! _ . isUndefined ( definition . default ) ) return definition . default
194194 return ''
195195 case 'variable' :
196- if ( ! _ . isUndefined ( program [ definition . origin ] ) ) return program [ definition . origin ]
196+ if ( ! _ . isUndefined ( options [ definition . origin ] ) ) return options [ definition . origin ]
197197 return ''
198198 case 'branch' :
199199 if ( ! _ . isUndefined ( val ) ) return val
@@ -203,17 +203,16 @@ const getValue = (program, definition, answer, term) => {
203203 }
204204}
205205
206- const replaceTerms = async ( program , template , definitions , callback ) => {
206+ const replaceTerms = async ( options , template , definitions , callback ) => {
207207 await inquirer
208- . prompt ( createQuestions ( program , definitions ) )
208+ . prompt ( createQuestions ( options , definitions ) )
209209 . then ( ( answers ) => {
210210 let result = template
211211 _ . forEach ( definitions , ( definition , term ) => {
212212 const answer = answers [ term ]
213- const value = getValue ( program , definition , answer , term ) . trim ( )
214-
215- program [ term ] = value
213+ const value = getValue ( options , definition , answer , term ) . trim ( )
216214
215+ options [ term ] = value
217216 const errorMessages = checkValue ( term , value , definition )
218217 if ( ! _ . isEmpty ( errorMessages ) ) throw new Error ( errorMessages )
219218
@@ -256,10 +255,12 @@ const gitCommit = (commitMessage, duet = false, silent = false, dryRun = false)
256255//
257256// Main
258257//
259- module . exports = async ( program , template , definitions ) => {
260- if ( ! program . dryRun ) checkAddedFile ( )
258+ export default async ( program , template , definitions ) => {
259+ const options = program . opts ( )
260+
261+ if ( ! options . dryRun ) checkAddedFile ( )
261262
262- await replaceTerms ( program , template , definitions , ( commitMessage ) => {
263- gitCommit ( commitMessage . trim ( ) , program . duet , program . silent , program . dryRun )
263+ await replaceTerms ( options , template , definitions , ( commitMessage ) => {
264+ gitCommit ( commitMessage . trim ( ) , options . duet , options . silent , options . dryRun )
264265 } )
265266}
0 commit comments