@@ -5,23 +5,27 @@ const { prompt, Input, AutoComplete } = require("enquirer");
55const meow = require ( "meow" ) ;
66const chalk = require ( "chalk" ) ;
77const simpleGit = require ( "simple-git/promise" ) ;
8+ const Conf = require ( "conf" ) ;
89
910const presets = require ( "./presets" ) ;
1011const welcome = require ( "./welcome" ) ;
12+ const hash = require ( "./hash" ) ;
1113const { getConfig, hasFile } = require ( "./file-manager" ) ;
1214
1315const git = simpleGit ( ) . outputHandler ( ( command , stdout , stderr ) => {
1416 stdout . pipe ( process . stdout ) ;
1517 stderr . pipe ( process . stderr ) ;
1618} ) ;
1719
18- function getStepPrompt ( step ) {
20+ function getStepPrompt ( step , previous ) {
1921 switch ( step . type ) {
2022 case "option" :
2123 return new AutoComplete ( {
2224 name : "step" ,
2325 message : step . message ,
24- choices : step . options . map ( option => option . description )
26+ choices : step . options . map ( option => option . description ) ,
27+ initial :
28+ step . options . findIndex ( option => option . value === previous ) || 0
2529 } )
2630 . run ( )
2731 . then ( choice => {
@@ -34,7 +38,7 @@ function getStepPrompt(step) {
3438 case "text" :
3539 return new Input ( {
3640 message : step . message ,
37- initial : step . initial
41+ initial : step . initial || previous
3842 } )
3943 . run ( )
4044 . then ( choice => choice || "" ) ;
@@ -70,6 +74,7 @@ const getPresetPrompt = async () => {
7074async function main ( input , flags ) {
7175 if ( ! flags . nowelcome ) welcome ( ) ;
7276
77+ const history = new Conf ( ) ;
7378 let config = { } ;
7479
7580 try {
@@ -86,11 +91,17 @@ async function main(input, flags) {
8691 config = presets [ presetKey ] ;
8792 }
8893
89- const message = await config . steps . reduce ( async ( accum , step ) => {
94+ const message = await config . steps . reduce ( async ( accum , step , i ) => {
9095 const message = await accum ;
91- const prompt = getStepPrompt ( step ) ;
96+
97+ const stepHash = hash ( `${ config . name } ${ step . message } ${ i } ` ) ;
98+ const previous = history . get ( stepHash ) ;
99+
100+ const prompt = getStepPrompt ( step , previous ) ;
92101 const result = await prompt ;
93102
103+ history . set ( stepHash , result ) ;
104+
94105 return `${ message } ${ step . before || "" } ${ result } ${ step . after || "" } ` ;
95106 } , "" ) ;
96107
0 commit comments