Skip to content

Commit

Permalink
fix: always resolve gobal factories
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Sep 14, 2020
1 parent 28e0825 commit 084389c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Cli extends BaseClass {
} else {
const factoryId = (config.factory && config.factory.id) || ''
const factoryVersion = (config.factory && config.factory.version) || ''
let factories: Factory[] = []
const factories: Factory[] = this.fbi.resolveGlobalFactories()

if (factoryId) {
const factory = this.fbi.resolveFactory(factoryId, factoryVersion)
Expand All @@ -35,11 +35,8 @@ export class Cli extends BaseClass {
`factory "${factoryId}${factoryVersion ? `@${factoryVersion}` : ''}" not found`
)
} else {
factories.push(factory)
factories.unshift(factory)
}
} else {
const _factories = this.fbi.resolveGlobalFactories()
factories = factories.concat(_factories)
}

for (let factory of factories) {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export default class CommandList extends Command {
.map((id: string) => this.factory.resolveFactory(id))
.filter(Boolean)
} else {
// show using
factories = [this.factory.resolveFactory(current.id, current.version)].filter(
// show using & global
factories = this.factory.resolveGlobalFactories()
factories = ([this.factory.resolveFactory(current.id, current.version)].filter(
Boolean
) as Factory[]
) as Factory[]).concat(factories)
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { isValidArray } from './type'

type Argv = string | number

const exec = (str: string, opts: Record<string, any> = {}) => {
const arr = str.split(' ').filter(Boolean)
return execa(arr[0], arr.slice(1), opts)
const exec = async (str: string, opts: Record<string, any> = {}) => {
const cmd = str.split(' ').filter(Boolean).join(' ')
try {
const { stdout } = await execa.command(cmd, opts)
return stdout
} catch (err) {
throw err
}
}

const pathOrAll = (arr: any) => (isValidArray(arr) ? arr.join(' ') : '.')
// string to array
const s2a = ({ stdout }: any): string[] | PromiseLike<string[]> =>
const s2a = (stdout: any): string[] | PromiseLike<string[]> =>
stdout
.trim()
.split('\n')
Expand Down Expand Up @@ -51,11 +56,11 @@ const status = {
.then(s2a)
.catch(() => false),
isRebasing: (opts?: object) =>
exec('git status', opts).then(({ stdout }) => stdout.includes('rebase in progress')),
exec('git status', opts).then((stdout) => stdout && stdout.includes('rebase in progress')),
conflictStrings: (opts?: object) => exec('git grep -n "<<<<<<< "', opts).then(s2a),
conflictFiles: (opts?: object) => exec('git grep --name-only "<<<<<<< "', opts).then(s2a),
changes: (opts?: object) => exec('git status --porcelain', opts).then(s2a),
needPull: (opts?: object) => exec('git fetch --dry-run', opts).then(res => !!res),
needPull: (opts?: object) => exec('git fetch --dry-run', opts).then((res) => !!res),

// action
show: (opts?: object) =>
Expand All @@ -78,7 +83,7 @@ const stash = {
const tag = {
// info
list: (opts?: object) => exec('git tag', opts).then(s2a),
latest: (opts?: object) => exec('git describe --abbrev=0', opts),
latest: (opts?: object) => exec('git describe --abbrev=0', opts).catch((err) => console.log),

// action
add: (n: Argv, opts?: object) => exec(`git tag -a ${n}`, opts),
Expand All @@ -97,7 +102,7 @@ const branch = {
remotes: (opts?: object) =>
exec('git branch -vvr --format="%(refname:lstrip=3)"', opts)
.then(s2a)
.then(r => r.filter(n => n !== 'HEAD')),
.then((r) => r.filter((n) => n !== 'HEAD')),
stales: (opts?: object) =>
exec(
'git branch -vv --format="%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)"',
Expand Down

0 comments on commit 084389c

Please sign in to comment.