Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
598 changes: 536 additions & 62 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@aduh95/viz.js": "^3.5.0",
"@inquirer/prompts": "^5.0.5",
"ajv": "^8.10.0",
"chalk": "^4.1.2",
"cli-table": "^0.3.11",
Expand Down
10 changes: 4 additions & 6 deletions src/cmd/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export const handler: BaseHandler = async (argv) => {
let errors = []

// Parse YAML
const yaml = new Yaml()
const input = yaml.load(sourcePath)
errors = yaml.validate(input)
const yaml = new Yaml(sourcePath)
errors = yaml.validate()
if (errors.length > 0) {
errors.forEach(err => {
error(err)
Expand All @@ -40,8 +39,7 @@ export const handler: BaseHandler = async (argv) => {
}

// RDRA Model
const rdra = new RDRA()
const model = rdra.resolve(input)
const model = yaml.getModel()
errors = ErrorCollector.collect(model)
if (errors.length > 0) {
errors.forEach(err => {
Expand All @@ -51,4 +49,4 @@ export const handler: BaseHandler = async (argv) => {
}

outputAllActors(model)
}
}
92 changes: 92 additions & 0 deletions src/cmd/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { BaseBuilder, BaseHandler } from './util/types'
import { Yaml } from '../util/Yaml'
import { ErrorCollector } from '../util/ErrorCollector'
import { error } from './output/console'
import { checkFileExists, getSourcePath } from './util/options'
import select from '@inquirer/select'
import { selectActorMenu } from './commands/actor'


export const command = 'command'
export const desc = 'Choose a command to execute'


export const builder: BaseBuilder = (yargs) =>
yargs
.options({
file: { type: 'string', alias: 'f', conflicts: 'value' }
})
.positional('value', { type: 'string' })
.check((argv, _options) => {
const { file, value } = argv
checkFileExists(file, value)
return argv
})


export const handler: BaseHandler = async (argv) => {
const { file, value } = argv
const sourcePath = getSourcePath(file, value)
let errors = []

// Parse YAML
const yaml = new Yaml(sourcePath)
errors = yaml.validate()
if (errors.length > 0) {
errors.forEach(err => {
error(err)
})
process.exit(1)
}

const model = yaml.getModel()
errors = ErrorCollector.collect(model)
if (errors.length > 0) {
errors.forEach(err => {
error(err)
})
process.exit(1)
}

// Show commands
selectMenu(sourcePath)

}

export const selectMenu = async (sourcePath: string) => {
const menu = ['actor', 'division', 'buc', 'activity', 'usecase', 'state', 'view', 'information', 'overview', 'Quit']
const selected = await select({
message: 'Please Select',
choices: menu.map(layer => ({ name: layer, value: layer })),
pageSize: 5,
},
{
clearPromptOnDone: true,
})
switch (selected) {
case 'actor':
await selectActorMenu(sourcePath)
break
case 'division':
break
case 'buc':
break
case 'activity':
break
case 'usecase':
break
case 'state':
break
case 'view':
break
case 'information':
break
case 'overview':
break
default:
process.exit(0)
break
}

await selectMenu(sourcePath)
}
20 changes: 20 additions & 0 deletions src/cmd/commands/actor/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { input } from '@inquirer/prompts'
import { Yaml } from '../../../util/Yaml'
import { RDRA } from '../../../model/RDRA'
import { ErrorCollector } from '../../../util/ErrorCollector'

export const createActor = async (sourcePath: string) => {
const name = await input({ message: '名前を入力してください' }, { clearPromptOnDone: true })
const description = await input({ message: '説明を入力してください' }, { clearPromptOnDone: true })

const yaml = new Yaml(sourcePath)
const rdra = RDRA.from(yaml.getModel())
rdra.addActor(name, description)

const json = rdra.toJSON();
const err = ErrorCollector.printJsonErrors(json)
if (err) return

Yaml.export(sourcePath, json)
console.log('Actorを追加しました。名前:' + name, '説明:' + description)
}
18 changes: 18 additions & 0 deletions src/cmd/commands/actor/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { list } from './list'
import { Yaml } from '../../../util/Yaml'
import { RDRA } from '../../../model/RDRA'
import { ErrorCollector } from '../../../util/ErrorCollector'

export const deleteActor = async (sourcePath: string) => {
const selected = await list(sourcePath)
const yaml = new Yaml(sourcePath)
const rdra = RDRA.from(yaml.getModel())
rdra.deleteActor(selected)

const json = rdra.toJSON()
const err = ErrorCollector.printJsonErrors(json)
if (err) return

Yaml.export(sourcePath, json)
console.log('Actorを削除しました。名前:' + selected)
}
88 changes: 88 additions & 0 deletions src/cmd/commands/actor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { createActor } from './create'
import select from '@inquirer/select'
import { selectMenu } from '../../command'
import { Yaml } from '../../../util/Yaml'
import { Actor } from '../../../model/actor/Actor'
import { showActor } from './show'
import { updateActor } from './update'
import { deleteActor } from './delete'

export const actorCommands = {
create: {
command: createActor,
description: 'Create a new actor',
}
,
show: {
command: showActor,
description: 'Show an actor',
},
update: {
command: updateActor,
description: 'Update an actor',
},
delete: {
command: deleteActor,
description: 'Delete an actor',
}
}

class Row {
constructor(public name: string, public description: string | undefined) {
this.name = name as string
this.description = description
}
}

function tableView(actor: Actor) {
console.table(actor.instances.map(it => new Row(it.name, it.description)))
}

export const selectActorMenu = async (sourcePath: string) => {
const yaml = new Yaml(sourcePath)
const actor = yaml.getModel().actor
tableView(actor)

const menu = [actorCommands.create.description]
if (actor.instances.length > 0) {
menu.push(
actorCommands.show.description,
actorCommands.update.description,
actorCommands.delete.description
)
}
menu.push('Go back', 'Quit')

const selected = await select({
message: 'Please Select',
choices: menu.map(m => ({ name: m, value: m })),
pageSize: 3
},
{
clearPromptOnDone: true,
})
switch (selected) {
case actorCommands.create.description:
await actorCommands.create.command(sourcePath)
await selectActorMenu(sourcePath)
break
case actorCommands.show.description:
await actorCommands.show.command(sourcePath)
await selectActorMenu(sourcePath)
break
case actorCommands.update.description:
await actorCommands.update.command(sourcePath)
await selectActorMenu(sourcePath)
break
case actorCommands.delete.description:
await actorCommands.delete.command(sourcePath)
await selectActorMenu(sourcePath)
break
case 'Go back':
await selectMenu(sourcePath)
break
default:
process.exit(0)
break
}
}
13 changes: 13 additions & 0 deletions src/cmd/commands/actor/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import select from '@inquirer/select'
import { Yaml } from '../../../util/Yaml'

export const list = (sourcePath: string) => {
return select({
message: 'Select an actor',
choices: new Yaml(sourcePath).getModel().actor.names.map(it => ({ name: it, value: it })),
},
{
clearPromptOnDone: true,
})
}

2 changes: 2 additions & 0 deletions src/cmd/commands/actor/show.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export const showActor = async (sourcePath: string) => {}
26 changes: 26 additions & 0 deletions src/cmd/commands/actor/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { input } from '@inquirer/prompts'
import { Yaml } from '../../../util/Yaml'
import { RDRA } from '../../../model/RDRA'
import { list } from './list'
import { ErrorCollector } from '../../../util/ErrorCollector'

export const updateActor = async (sourcePath: string) => {
const selected = await list(sourcePath)
const newName = await input({ message: '名前を入力してください' }, { clearPromptOnDone: true })
const newDescription = await input({ message: '説明を入力してください' }, { clearPromptOnDone: true })
if (!newName) {
console.log('名前は必須です。')
return
}

const yaml = new Yaml(sourcePath)
const rdra = RDRA.from(yaml.getModel())
rdra.updateActor(selected, newName, newDescription)

const json = rdra.toJSON()
const err = ErrorCollector.printJsonErrors(json)
if (err) return

Yaml.export(sourcePath, json)
console.log('Actorを更新しました。名前:' + newName, '説明:' + newDescription)
}
22 changes: 22 additions & 0 deletions src/cmd/commands/initialize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { input } from '@inquirer/prompts'
import { RDRA } from '../../model/RDRA'
import { Overview } from '../../model/actor/Overview'
import { Actor } from '../../model/actor/Actor'
import { Yaml } from '../../util/Yaml'

export const initialize = async (sourcePath: string) => {
const business = await input({ message: 'ビジネス領域を入力してください' })
const system = await input({ message: 'システム名を入力してください' })
const actors = await input({ message: 'システムの利用者を入力してください(カンマで複数入力)' })

const model = new RDRA(
Overview.create(business, system),
Actor.create(
actors.split(',')
.map((name: string) => {
return { name: name.trim() }
})
)
)
Yaml.export(sourcePath, model.toJSON())
}
10 changes: 4 additions & 6 deletions src/cmd/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ export const handler: BaseHandler = async (argv) => {
let errors = []

// Parse YAML
const yaml = new Yaml()
const input = yaml.load(sourcePath)
errors = yaml.validate(input)
const yaml = new Yaml(sourcePath)
errors = yaml.validate()
if (errors.length > 0) {
errors.forEach(err => {
error(err)
Expand All @@ -48,8 +47,7 @@ export const handler: BaseHandler = async (argv) => {
}

// RDRA Model
const rdra = new RDRA()
const model = rdra.resolve(input)
const model = yaml.getModel()
errors = ErrorCollector.collect(model)
if (errors.length > 0) {
errors.forEach(err => {
Expand Down Expand Up @@ -283,4 +281,4 @@ ${edges}
}`

fs.writeFileSync(`output/st_${group.name}.svg`, vizRenderStringSync(code))
}
}
8 changes: 3 additions & 5 deletions src/cmd/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export const handler: BaseHandler = async (argv) => {
let errors = []

// Parse YAML
const yaml = new Yaml()
const input = yaml.load(sourcePath)
errors = yaml.validate(input)
const yaml = new Yaml(sourcePath)
errors = yaml.validate()
if (errors.length > 0) {
errors.forEach(err => {
error(err)
Expand All @@ -41,8 +40,7 @@ export const handler: BaseHandler = async (argv) => {
}

// RDRA Model
const rdra = new RDRA()
const model = rdra.resolve(input)
const model = yaml.getModel()
errors = ErrorCollector.collect(model)
if (errors.length > 0) {
errors.forEach(err => {
Expand Down
Loading