Skip to content

Commit accfd44

Browse files
committed
feat: Solicit label and description for state machines
1 parent 4cab3bc commit accfd44

8 files changed

Lines changed: 57 additions & 18 deletions

File tree

lib/actions/add-state-machine/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const c = require('ansi-colors')
22
const ask = require('../util/ask')
33
const Blueprint = require('../blueprint')
44
const Scaffold = require('@wmfs/tymly-scaffold')
5+
const labelAndDescription = require('../util/label-and-description')
56
const selectInternalModel = require('../util/select-model')
67
const chooseCategories = require('../util/choose-categories')
78
const chooseRoles = require('../util/choose-roles')
@@ -14,10 +15,20 @@ async function addStateMachine (options) {
1415

1516
const stateMachine = await selectMachine()
1617
if (!stateMachine) return
18+
19+
console.log()
1720
const form = await selectForm(blueprint)
1821
if (!form) return
1922
const model = await selectModel(form, blueprint)
2023
if (!model) return
24+
25+
console.log()
26+
const { label, description } =
27+
await labelAndDescription(
28+
`${_.upperFirst(stateMachine)} ${model}`,
29+
`${_.upperFirst(stateMachine)} ${model} using ${form.name} form.`
30+
)
31+
2132
const categories = await chooseCategories(blueprint)
2233

2334
const roles = await chooseRoles(blueprint)
@@ -27,6 +38,8 @@ async function addStateMachine (options) {
2738

2839
const scaffold = blueprint.scaffold
2940
scaffold.makeStateMachine({
41+
label: label,
42+
description: description,
3043
stateMachine: stateMachine,
3144
namespace: blueprint.namespace,
3245
modelName: model,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const validator = require('../util/validators')
2+
const ask = require('../util/ask')
3+
4+
async function labelDescription (
5+
labelSuggestion,
6+
descriptionSuggestion
7+
) {
8+
const label = await ask({
9+
message: 'Label',
10+
initial: labelSuggestion,
11+
validate: validator.notEmpty()
12+
})
13+
const description = await ask({
14+
message: 'Description',
15+
initial: descriptionSuggestion
16+
})
17+
18+
return {
19+
label,
20+
description
21+
}
22+
} // labelDescription
23+
24+
module.exports = labelDescription

lib/actions/util/name-label-and-description.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const validator = require('../util/validators')
22
const ask = require('../util/ask')
3+
const labelAndDescription = require('./label-and-description')
34
const _ = require('lodash')
45

56
async function nameLabelDescription (thing) {
@@ -8,15 +9,10 @@ async function nameLabelDescription (thing) {
89
validate: validator.notEmptyNoSpaces()
910
})
1011
console.log()
11-
const label = await ask({
12-
message: 'Label',
13-
initial: _.upperFirst(_.lowerCase(name)),
14-
validate: validator.notEmpty()
15-
})
16-
const description = await ask({
17-
message: 'Description',
18-
initial: _.upperFirst(_.lowerCase(name))
19-
})
12+
13+
const suggestion = _.upperFirst(_.lowerCase(name))
14+
const { label, description } =
15+
await labelAndDescription(suggestion, suggestion)
2016

2117
return {
2218
name,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"tymly": "bin/tymly-cli.js"
2424
},
2525
"dependencies": {
26-
"@wmfs/tymly-scaffold": "1.15.0",
26+
"@wmfs/tymly-scaffold": "1.17.0",
2727
"ansi-colors": "3.2.3",
2828
"commander": "2.19.0",
2929
"enquirer": "2.3.0",

test/add-state-machine-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ describe('tymly add-state-machine', () => {
88
const tests = {
99
'update': [
1010
helpers.down,
11+
'', // default title
12+
'', // default description
1113
'', // default role
1214
''
1315
],
1416
'two-forms-no-meta': [
1517
helpers.down + helpers.down, // state machine
1618
helpers.down, // choose form
1719
helpers.down, // choose model
20+
'', // default title
21+
'', // default description
1822
'', // default role
1923
''
2024
],
2125
'set-file-name': [
2226
helpers.down,
23-
'', // default role
27+
'', // default title
28+
'Pizza for everyone!',
29+
' ', // $everyone role
2430
'futz-around-with-pizza'
2531
]
2632
}

test/fixtures/add-state-machine/expected/set-file-name/state-machines/futz-around-with-pizza.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"Comment": "Edit pizza using pizza-editing-form form.",
3-
"name": "Edit pizza",
2+
"Comment": "Pizza for everyone!",
3+
"name": "Update pizza",
44
"version": "1.0",
55
"categories": [
66
"pizza"
@@ -40,7 +40,7 @@
4040
},
4141
"restrictions": [
4242
{
43-
"roleId": "$authenticated",
43+
"roleId": "$everyone",
4444
"allows": [
4545
"*"
4646
]

test/fixtures/add-state-machine/expected/two-forms-no-meta/state-machines/view-pizza.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"Comment": "Edit pizza using pizza-editing-form form.",
3-
"name": "Edit pizza",
2+
"Comment": "View pizza using pizza-editing-form form.",
3+
"name": "View pizza",
44
"version": "1.0",
55
"categories": [
66
"pizza"

test/fixtures/add-state-machine/expected/update/state-machines/update-pizza.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"Comment": "Edit pizza using pizza-editing-form form.",
3-
"name": "Edit pizza",
2+
"Comment": "Update pizza using pizza-editing-form form.",
3+
"name": "Update pizza",
44
"version": "1.0",
55
"categories": [
66
"pizza"

0 commit comments

Comments
 (0)