Skip to content

Commit 4a059b2

Browse files
committed
much nicer api with clack
1 parent ab96cbd commit 4a059b2

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

packages/create-waku/src/index.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,32 @@ async function doPrompts() {
107107
let targetDir = values['project-name'] || defaultProjectName;
108108

109109
try {
110-
const { projectName } = await p.group(
110+
const results = await p.group(
111111
{
112112
projectName: () =>
113113
p.text({
114114
defaultValue: targetDir,
115115
message: 'Project Name',
116116
placeholder: defaultProjectName,
117117
}),
118-
},
119-
{ onCancel },
120-
);
121-
targetDir =
122-
typeof projectName === 'string' ? projectName.trim() : targetDir;
123-
if (!canSafelyOverwrite(targetDir)) {
124-
const confirmed = await p.confirm({
125-
message: `${targetDir} is not empty. Remove existing files and continue?`,
126-
});
127-
if (!confirmed) {
128-
p.cancel(red('✖') + ' Operation cancelled');
129-
process.exit(0);
130-
}
131-
}
132-
133-
const results = await p.group(
134-
{
118+
overwrites: ({ results }) => {
119+
targetDir =
120+
typeof results.projectName === 'string'
121+
? results.projectName.trim()
122+
: targetDir;
123+
if (!canSafelyOverwrite(targetDir)) {
124+
return p.confirm({
125+
message: `would you like to overwrite ${results.projectName}?`,
126+
});
127+
}
128+
return Promise.resolve(true);
129+
},
130+
checkOverwrites: ({ results }) => {
131+
if (!results.overwrites) {
132+
p.cancel(red('✖') + ' Operation cancelled');
133+
}
134+
return Promise.resolve(true);
135+
},
135136
packageName: () =>
136137
p.text({
137138
message: 'Package name',
@@ -150,9 +151,7 @@ async function doPrompts() {
150151
})),
151152
}),
152153
},
153-
{
154-
onCancel,
155-
},
154+
{ onCancel },
156155
);
157156

158157
return {

0 commit comments

Comments
 (0)