-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathhelpers.js
44 lines (40 loc) · 1.17 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Listr } from 'listr2'
import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
import { deleteFilesTask } from '../../lib/index.js'
const tasks = ({ componentName, filesFn, name }) =>
new Listr(
[
{
title: `Destroying ${componentName} files...`,
task: async () => {
const f = await filesFn({ name, stories: true, tests: true })
return deleteFilesTask(f)
},
},
],
{ rendererOptions: { collapseSubtasks: false }, exitOnError: true },
)
export const createYargsForComponentDestroy = ({
componentName,
preTasksFn = (options) => options,
filesFn,
}) => {
return {
command: `${componentName} <name>`,
description: `Destroy a ${componentName} component`,
builder: (yargs) => {
yargs.positional('name', {
description: `Name of the ${componentName}`,
type: 'string',
})
},
handler: async (options) => {
recordTelemetryAttributes({
command: `destroy ${componentName}`,
})
options = await preTasksFn({ ...options, isDestroyer: true })
await tasks({ componentName, filesFn, name: options.name }).run()
},
tasks,
}
}