Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Make version available at -v and --version. Closes #670
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Sep 28, 2017
1 parent d89cbf6 commit b47e395
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cli/packages/graphcool-cli-core/src/commands/invoke/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ export default class InvokeLocal extends Command {
// gather event
const json = await this.getEvent(projectId, fnName)

// TODO rm any
const invoker = new LocalInvoker(
this.config,
this.env,
this.out,
module,
fnName,
fn,
fn as any,
)

const invocationResult = await invoker.invoke(json)
Expand Down
4 changes: 4 additions & 0 deletions cli/packages/graphcool-cli-engine/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AuthTrigger } from './types'
import { Client } from './Client/Client'
import { GraphQLClient } from 'graphql-request'
import * as chalk from 'chalk'
const debug = require('debug')('auth')

export class Auth {
out: Output
Expand Down Expand Up @@ -88,10 +89,13 @@ export class Auth {
this.out.action.stop()
return authToken as string
}
await new Promise(r => setTimeout(r, 500))
}
}

async validateAuthToken(token: string): Promise<string | null> {
debug('requesting', this.config.systemAPIEndpoint)
debug('token', token)
const client = new GraphQLClient(this.config.systemAPIEndpoint, {
headers: {
Authorization: `Bearer ${token}`,
Expand Down
16 changes: 16 additions & 0 deletions cli/packages/graphcool-cli-engine/src/CLI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ describe('cli help', () => {
})
})
})

describe('cli version', () => {
test('-v', async () => {
const cli = await run('-v')
expect(cli.cmd.out.stdout.output).toMatchSnapshot()
})
test('--version', async () => {
const cli = await run('--version')
expect(cli.cmd.out.stdout.output).toMatchSnapshot()
})
test('version', async () => {
const cli = await run('version')
expect(cli.cmd.out.stdout.output).toMatchSnapshot()
})
})

12 changes: 7 additions & 5 deletions cli/packages/graphcool-cli-engine/src/CLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RunOptions } from './types'
import Lock from './Plugin/Lock'
import { Dispatcher } from './Dispatcher/Dispatcher'
import { NotFound } from './NotFound'
import * as nock from 'nock'
import fs from './fs'

const debug = require('debug')('cli')
Expand Down Expand Up @@ -102,15 +101,15 @@ export class CLI {
await lock.unread()
debug('running cmd')
// TODO remove this
if (process.env.NOCK_WRITE_RESPONSE_CLI) {
if (process.env.NOCK_WRITE_RESPONSE_CLI === 'true') {
debug('RECORDING')
nock.recorder.rec({
require('nock').recorder.rec({
dont_print: true,
})
}
this.cmd = await foundCommand.run(this.config)
if (process.env.NOCK_WRITE_RESPONSE_CLI) {
const requests = nock.recorder.play()
if (process.env.NOCK_WRITE_RESPONSE_CLI === 'true') {
const requests = require('nock').recorder.play()
const requestsPath = path.join(process.cwd(), 'requests.js')
debug('WRITING', requestsPath)
fs.writeFileSync(requestsPath, requests.join('\n'))
Expand Down Expand Up @@ -165,6 +164,9 @@ export class CLI {
}

private getCommandId(argv: string[]) {
if (argv.length === 1 && ['-v', '--version'].includes(argv[0])) {
return 'version'
}
if (argv.includes('help') || argv.includes('init')) {
return argv[0]
}
Expand Down
7 changes: 3 additions & 4 deletions cli/packages/graphcool-cli-engine/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { Auth } from './Auth'
import { Environment } from './Environment'
import packagejson = require('../package.json')
import * as mock from './mock'
const debug = require('debug')('command')
import * as nock from 'nock'
import * as fs from 'fs-extra'
import * as path from 'path'
const debug = require('debug')('command')

const pjson = packagejson as any

Expand Down Expand Up @@ -57,7 +56,7 @@ export class Command {
static async run(config?: RunOptions): Promise<Command> {
if (process.env.NOCK_WRITE_RESPONSE_CMD === 'true') {
debug('RECORDING')
nock.recorder.rec({
require('nock').recorder.rec({
dont_print: true,
})
}
Expand All @@ -72,7 +71,7 @@ export class Command {
}

if (process.env.NOCK_WRITE_RESPONSE_CMD === 'true') {
const requests = nock.recorder.play()
const requests = require('nock').recorder.play()
const requestsPath = path.join(process.cwd(), 'requests.js')
debug('WRITING', requestsPath)
fs.writeFileSync(requestsPath, requests.join('\n'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cli version --version 1`] = `
"graphcool/1.3.11 (darwin-x64) node-v8.4.0
"
`;

exports[`cli version -v 1`] = `
"graphcool/1.3.11 (darwin-x64) node-v8.4.0
"
`;

exports[`cli version version 1`] = `
"graphcool/1.3.11 (darwin-x64) node-v8.4.0
"
`;

0 comments on commit b47e395

Please sign in to comment.