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

Commit

Permalink
Rename diff to deploy --dry-run. Closes #883
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Oct 18, 2017
1 parent 72d101c commit 2736133
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 62 deletions.
89 changes: 89 additions & 0 deletions cli/packages/graphcool-cli-core/src/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ ${chalk.gray(
default: flags.boolean({
char: 'd',
description: 'Set specified target as default'
}),
'dry-run': flags.boolean({
char: 'D',
description: 'Perform a dry-run of the deployment'
})
}
async run() {
Expand All @@ -73,6 +77,11 @@ ${chalk.gray(
const useDefault = this.flags.default
let newServiceName = this.flags['new-service']
const newServiceCluster = this.flags['new-service-cluster']
const dryRun = this.flags['dry-run']

if (dryRun) {
return this.dryRun()
}

if (newServiceCluster) {
this.env.setActiveCluster(newServiceCluster)
Expand Down Expand Up @@ -402,6 +411,86 @@ https://console.graph.cool/${encodeURIComponent(info.name)}/settings/general`)
return target
}

private async dryRun() {
const {target} = this.flags

await this.definition.load(this.flags)
await this.auth.ensureAuth()

const { id } = await this.env.getTarget(target)
const targetName = target || 'default'

this.out.action.start(
`Getting diff for ${chalk.bold(id)} with target ${chalk.bold(
targetName,
)}.`,
)

try {
const migrationResult = await this.client.push(
id,
false,
true,
this.definition.definition!,
)
this.out.action.stop()

// no action required
if (
(!migrationResult.migrationMessages ||
migrationResult.migrationMessages.length === 0) &&
(!migrationResult.errors || migrationResult.errors.length === 0)
) {
this.out.log(
`Identical project definition for project ${chalk.bold(
id,
)} in env ${chalk.bold(targetName)}, no action required.\n`,
)
return
}

if (migrationResult.migrationMessages.length > 0) {
this.out.log(
chalk.blue(
`Your project ${chalk.bold(id)} of env ${chalk.bold(
targetName,
)} has the following changes:`,
),
)

this.out.migration.printMessages(migrationResult.migrationMessages)
this.definition.set(migrationResult.projectDefinition)
}

if (migrationResult.errors.length > 0) {
this.out.log(
chalk.rgb(244, 157, 65)(
`There are issues with the new project definition:`,
),
)
this.out.migration.printErrors(migrationResult.errors)
this.out.log('')
}

if (
migrationResult.errors &&
migrationResult.errors.length > 0 &&
migrationResult.errors[0].description.includes(`destructive changes`)
) {
// potentially destructive changes
this.out.log(
`Your changes might result in data loss.
Use ${chalk.cyan(
`\`graphcool deploy --force\``,
)} if you know what you're doing!\n`,
)
}
} catch (e) {
this.out.action.stop()
this.out.error(e)
}
}

}

export function isValidProjectName(projectName: string): boolean {
Expand Down
2 changes: 0 additions & 2 deletions cli/packages/graphcool-cli-core/src/commands/diff/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import * as chalk from 'chalk'

export default class Diff extends Command {
static topic = 'diff'
static description = 'Receive service changes'
static group = 'general'
static flags: Flags = {
Expand All @@ -21,7 +20,6 @@ export default class Diff extends Command {

await this.definition.load(this.flags)
await this.auth.ensureAuth()
// temporary ugly solution

const { id } = await this.env.getTarget(target)
const targetName = target || 'default'
Expand Down
54 changes: 0 additions & 54 deletions cli/packages/graphcool-cli-core/src/commands/init/mock.ts

This file was deleted.

6 changes: 0 additions & 6 deletions cli/packages/graphcool-cli-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ export const topics = [
{ name: 'list', description: 'List all deployed services', group: 'general' },
{ name: 'root-token', description: 'Get the service root tokens', group: 'general' },
{ name: 'logs', description: 'Get logs of functions', group: 'general' },
{
name: 'diff',
description: 'Get the diff of the local and remote service definition',
group: 'general'
},
{
name: 'delete',
description: 'Delete a service',
Expand Down Expand Up @@ -102,7 +97,6 @@ export const commands = [
Delete,
RootTokens,
FunctionLogs,
Diff,
Pull,
Export,
InvokeLocal,
Expand Down

0 comments on commit 2736133

Please sign in to comment.