Skip to content

Commit

Permalink
fix: set allowUnknownOption=true for factory's commands
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Sep 21, 2020
1 parent 9b342a2 commit b22e423
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 17 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
"devDependencies": {
"@types/ejs": "^3.0.4",
"@types/fs-extra": "^9.0.1",
"@types/node": "^14.10.1",
"@types/semver": "^7.3.3",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"@types/node": "^14.11.1",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"eslint": "^7.9.0",
"eslint-config-prettier": "^6.11.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
"typescript": "^4.0.3"
}
}
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Cli extends BaseClass {
}
}
cmd.option('-d, --debug', 'output extra debugging')
cmd.allowUnknownOption(true)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default class CommandAdd extends Command {
}

public async run(repositories: any, flags: any) {
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)

Expand Down
3 changes: 3 additions & 0 deletions src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default class CommandClean extends Command {
}

public async run(flags: any) {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
flags
})
await this.removeUnavailableFactories()
await this.removeUnavailableProjects()
}
Expand Down
12 changes: 8 additions & 4 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export default class CommandCreate extends Command {
}

async run(inputTemplate: any, project: any, flags: any) {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
inputTemplate,
project,
flags
})
const factories = this.factory.createAllFactories()

// if is fbi project
Expand Down Expand Up @@ -57,19 +62,18 @@ export default class CommandCreate extends Command {
templateInstances = templates.filter((t: Template) => t.id === inputTemplate)
if (!isValidArray(templateInstances)) {
// 若已有添加模板中不存在则添加远程模板
const addCommand = this.factory.commands.find(it => it.id === 'add')
const addCommand = this.factory.commands.find((it) => it.id === 'add')
await addCommand?.run([inputTemplate], flags)
const nowFactories = this.factory.createAllFactories() || []
const addFactory = nowFactories.find(it => it.id === inputTemplate)
templates = flatten(nowFactories.map((f:Factory) => f.templates))
const addFactory = nowFactories.find((it) => it.id === inputTemplate)
templates = flatten(nowFactories.map((f: Factory) => f.templates))
templateInstances = addFactory?.templates
if (!isValidArray(templateInstances)) {
return this.error(`template "${inputTemplate}" not found`).exit()
}
}
}


templateInstances = groupBy(
(isValidArray(templateInstances) && templateInstances) || templates,
'factory.id'
Expand Down
3 changes: 3 additions & 0 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export default class CommandInfo extends Command {

async run(flags: any) {
this.clear()
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
flags
})

const config = this.loadConfig()
let globalConfig = {}
Expand Down
4 changes: 4 additions & 0 deletions src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export default class CommandLink extends Command {
}

async run(factories: any, flags: any) {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
factories,
flags
})
const ids = (Array.isArray(factories) && factories.length > 0 && factories) || ['.']

const config = this.context.get('config')
Expand Down
5 changes: 4 additions & 1 deletion src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default class CommandList extends Command {
}

async run(targetFactories: any, flags: any) {
this.debug(`Factory: (${this.factory.id})`, 'from command', this.id, { targetFactories, flags })
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
targetFactories,
flags
})
this.showProjects = flags.projects
this.showVersions = flags.versions

Expand Down
4 changes: 4 additions & 0 deletions src/commands/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default class CommandRemove extends Command {
}

async run(factories: any, flags: any) {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
factories,
flags
})
const ids = (Array.isArray(factories) && factories.length > 0 && factories) || [
process
.cwd()
Expand Down
9 changes: 5 additions & 4 deletions src/commands/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export default class CommandUnLink extends Command {
}

async run(factories: any, flags: any) {
this.debug(`Running command "${this.id}" from factory "${this.factory.id}" with options:`, {
factories,
flags
})
const ids = (Array.isArray(factories) && factories.length > 0 && factories) || [
process
.cwd()
.split(sep)
.pop()
process.cwd().split(sep).pop()
]
for (const id of ids) {
const factory = this.store.get(id)
Expand Down
7 changes: 4 additions & 3 deletions src/fbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class Fbi extends Factory {
const info: any = value
if (info.global) {
globalFactories.push(this.createFactory(info.path))
this.debug('Fbi<resolveGlobalFactories>:', info.id)
}
}

Expand All @@ -145,7 +146,7 @@ export class Fbi extends Factory {
if (!factory) {
return null
}
this.debug('Fbi:', `Factory "${targetId}" found in memory`)
this.debug(`Factory "${targetId}" found in memory`)
return factory
}

Expand All @@ -155,7 +156,7 @@ export class Fbi extends Factory {
if (!factoryInfo) {
return null
}
this.debug('Fbi:', `Factory "${targetId}" found in store`)
this.debug(`Factory "${targetId}" found in store`)
// local link not support version control
if (targetVersion && factoryInfo.type !== 'local') {
const matchVersion = factoryInfo.version?.versions
Expand Down Expand Up @@ -183,7 +184,7 @@ export class Fbi extends Factory {
const arr = realpath.split(sep)
const idx = arr.lastIndexOf('node_modules')
const dir = arr.slice(0, idx + 2).join(sep)
this.debug('Fbi:', `Factory "${targetId}" found in node_modules`)
this.debug(`Factory "${targetId}" found in node_modules`)
return this.createFactory(dir)
}
}

0 comments on commit b22e423

Please sign in to comment.