Skip to content

Commit

Permalink
fix: updated to work with new config/command
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent 4822c42 commit fa184da
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 1,120 deletions.
4 changes: 2 additions & 2 deletions .circleci/greenkeeper
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH

if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then
yarn
yarn check
# yarn check
exit 0
fi

Expand All @@ -21,5 +21,5 @@ if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then
fi

greenkeeper-lockfile-update
yarn install
yarn
greenkeeper-lockfile-upload
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/anycli/test/issues",
"dependencies": {
"fancy-test": "^0.6.6",
"fancy-test": "^0.6.8",
"lodash": "^4.17.4"
},
"devDependencies": {
"@anycli/config": "^0.3.0",
"@anycli/engine": "^0.3.2",
"@anycli/tslint": "^0.2.2",
"@anycli/command": "^1.2.0",
"@anycli/config": "^1.0.8",
"@anycli/tslint": "^0.2.5",
"@anycli/version": "^0.1.19",
"@commitlint/cli": "^6.0.5",
"@commitlint/config-conventional": "^6.0.4",
"@types/chai": "^4.1.2",
"@types/lodash": "^4.14.100",
"@types/mocha": "^2.2.48",
Expand All @@ -25,13 +23,10 @@
"chai": "^4.1.2",
"cli-ux": "^3.3.13",
"concurrently": "^3.5.1",
"eslint": "^4.16.0",
"eslint-config-anycli": "^1.3.1",
"eslint": "^4.17.0",
"eslint-config-anycli": "^1.3.2",
"husky": "^0.14.3",
"mocha": "^5.0.0",
"mocha-junit-reporter": "^1.17.0",
"nps": "^5.7.1",
"nps-utils": "^1.5.0",
"ts-node": "^4.1.0",
"typescript": "^2.7.1"
},
Expand Down
9 changes: 4 additions & 5 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {IConfig} from '@anycli/config'
import Run from '@anycli/engine'
import * as _ from 'lodash'

import loadConfig from './load_config'
import {loadConfig} from './load_config'

export default (args: string[] | string | undefined) => ({
async run(ctx: {config: IConfig, expectation: string}) {
const run: typeof Run = require('@anycli/engine').default
if (!ctx.config) ctx.config = await loadConfig().run({} as any)
if (!ctx.config) ctx.config = loadConfig().run({} as any)
args = _.castArray(args)
let [cmd, ...extra] = args
ctx.expectation = ctx.expectation || `runs ${args.join(' ')}`
await run(args, ctx)
await ctx.config.runCommand(cmd, extra)
}
})
15 changes: 5 additions & 10 deletions src/hook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {IConfig} from '@anycli/config'
import {Engine} from '@anycli/engine'

import loadConfig from './load_config'
import * as Config from '@anycli/config'

/**
* tests a anycli hook
Expand All @@ -15,12 +12,10 @@ import loadConfig from './load_config'
* @param hookOpts - options to pass to hook. Config object will be passed automatically.
*/
export default (event?: string, hookOpts: object = {}) => ({
async run(ctx: {config: IConfig, expectation: string}) {
if (!ctx.config) ctx.config = await loadConfig().run({} as any)
async run(ctx: {config: Config.IConfig, expectation: string}) {
if (!event) throw new Error('no hook provided')
if (!ctx.config) ctx.config = Config.load()
ctx.expectation = ctx.expectation || `runs ${event} hook`
const EEngine: typeof Engine = require('@anycli/engine').Engine
const engine = new EEngine()
await engine.load(ctx.config)
await engine.runHook(event!, hookOpts || {})
await ctx.config.runHook(event, hookOpts || {})
}
})
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
// tslint:disable no-var-before-return
import {IConfig, IEngine} from '@anycli/config'
import * as Config from '@anycli/config'
import {expect, fancy, FancyTypes, NockScope} from 'fancy-test'

import command from './command'
import exit from './exit'
import hook from './hook'
import loadConfig from './load_config'
import loadEngine from './load_engine'
import {loadConfig} from './load_config'

loadConfig.root = module.parent!.filename

export const test = fancy
.register('loadConfig', loadConfig)
.register('loadEngine', loadEngine)
.register('command', command)
.register('exit', exit)
.register('hook', hook)
Expand All @@ -21,9 +18,7 @@ export default test

export {
expect,

IEngine,
FancyTypes,
NockScope,
IConfig,
Config,
}
16 changes: 8 additions & 8 deletions src/load_config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {IConfig, read} from '@anycli/config'

export type WithRoot<T> = T & {root: string}
import * as Config from '@anycli/config'

/**
* loads CLI plugin/multi config
*/
export const _loadConfig = (opts: {root?: string} = {}) => {
export function loadConfig(root?: string) {
return {
async run(ctx: {config: IConfig}) {
return ctx.config = await read({root: opts.root || loadConfig.root})
run(ctx: {config: Config.IConfig}) {
return ctx.config = Config.load(root || loadConfig.root)
}
}
}
const loadConfig = _loadConfig as WithRoot<typeof _loadConfig>
export default loadConfig

export namespace loadConfig {
export let root: string
}
22 changes: 0 additions & 22 deletions src/load_engine.ts

This file was deleted.

6 changes: 3 additions & 3 deletions test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const root = path.join(__dirname, 'fixtures/multi')

describe('command', () => {
test
.loadConfig({root})
.loadConfig(root)
.stdout()
.command(['foo:bar'], {root})
.do(output => expect(output.stdout).to.equal('hello world!\n'))
.it()

test
.loadConfig({root})
.loadConfig(root)
.stdout()
.command(['foo:bar', '--name=foo'], {root})
.do(output => expect(output.stdout).to.equal('hello foo!\n'))
.it()

test
.loadConfig({root})
.loadConfig(root)
.stdout()
.command(['foo:bar', '--name=foo'], {root})
.do(output => expect(output.stdout).to.equal('hello foo!\n'))
Expand Down
17 changes: 0 additions & 17 deletions test/engine.test.ts

This file was deleted.

20 changes: 20 additions & 0 deletions test/fixtures/multi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"declaration": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"module": "commonjs",
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./lib",
"pretty": true,
"rootDirs": [
"./src"
],
"strict": true,
"target": "es2017"
},
"include": [
"./src/**/*"
]
}
6 changes: 3 additions & 3 deletions test/hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ describe('hooks', () => {
const stdout = `test/0.0.0 (${process.platform}-${process.arch}) node-${process.version}\n`

test
.loadConfig({root})
.loadConfig(root)
.stdout()
.hook('init', {id: '-v'}, {root})
.exit(0)
.do(output => expect(output.stdout).to.equal(stdout))
.it('catches -v')

test
.loadConfig({root})
.loadConfig(root)
.stdout()
.hook('init', {id: '--version'}, {root})
.exit(0)
.do(output => expect(output.stdout).to.equal(stdout))
.it('catches --version')

test
.loadConfig({root})
.loadConfig(root)
.stdout()
.hook('init', {}, {root})
.it()
Expand Down
Loading

0 comments on commit fa184da

Please sign in to comment.