Skip to content

Commit

Permalink
fix(create): read factory id after added
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Dec 3, 2020
1 parent a0c4fc3 commit ccd03a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ export default class CommandAdd extends Command {
super()
}

public async run(repositories: any, flags: any) {
public async run(repositories: any, flags: any): Promise<Factory[]> {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
repositories,
flags
})
const config = this.context.get('config')
const rootDir = join(config?.rootDirectory, config?.directoryName)
const result: Factory[] = []

for (const repo of repositories) {
const info = this.getBaseInfo(repo, config)
Expand All @@ -49,7 +50,7 @@ export default class CommandAdd extends Command {

if (!factory) {
this.error(`Factory '${info.name}' create field`)
return
continue
}

// save to store
Expand All @@ -70,7 +71,10 @@ export default class CommandAdd extends Command {
if (global) {
this.store.set(`${factory.id}.global`, global)
}
result.push(factory)
}

return result
}

private getBaseInfo(url: string, { organization }: any) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export default class CommandCreate extends Command {
const commandAdd = this.factory.resolveCommand('add')
if (!commandAdd) {
this.error(
`"${inputName}" not found in factories and templates. Can not add remote factory "${inputName}" because commandAdd not found.`
`"${inputName}" not found in factories and templates. Can not add remote factory "${inputName}" because command 'add' not found.`
).exit(1)
}

await commandAdd?.run([inputName], flags)
const addedFacory = this.factory.resolveFactory(inputName)
const addedFacories: Factory[] = await commandAdd?.run([inputName], flags)
const addedFacory = addedFacories[0]
if (addedFacory) {
this.factories.push(addedFacory)
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export abstract class Command extends BaseClass {
description = ''
examples: string[] = []

public abstract run(...args: any[]): void
public abstract run(...args: any[]): any
public disable(): boolean | string | Promise<boolean | string> {
return false
}
Expand Down

0 comments on commit ccd03a8

Please sign in to comment.