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

Commit

Permalink
fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Apr 30, 2017
1 parent c93dced commit ccee685
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async (props: Props, env: SystemEnvironment, authServer: AuthServ
try {
token = await authServer.requestAuthToken()
} catch (e) {
out.write(couldNotRetrieveTokenMessage)
out.writeError(couldNotRetrieveTokenMessage)
process.exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
const currentProjectId = readProjectIdFromProjectFile(resolver)

if (!currentProjectId) {
out.write(noProjectFileMessageFound)
out.writeError(noProjectFileMessageFound)
process.exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async(props: Props, env: SystemEnvironment): Promise<void> => {

const projectId = props.projectId ? props.projectId : readProjectIdFromProjectFile(resolver)
if (!projectId) {
out.write(noProjectIdMessage)
out.writeError(noProjectIdMessage)
process.exit(0)
}

Expand All @@ -37,7 +37,7 @@ export default async(props: Props, env: SystemEnvironment): Promise<void> => {
if (e.errors) {
const errors = parseErrors(e)
const output = generateErrorOutput(errors)
out.write(`${output}`)
out.writeError(`${output}`)
} else {
throw e
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
const {resolver, out} = env

if (resolver.exists(graphcoolProjectFileName) && resolver.read(graphcoolProjectFileName).toString().includes('# projectId:')) {
out.write(projectAlreadyExistsMessage)
out.writeError(projectAlreadyExistsMessage)
process.exit(1)
}

Expand Down Expand Up @@ -57,12 +57,12 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
} catch (e) {
out.stopSpinner()
debug(`Could not create project: ${JSON.stringify(e)}`)
out.write(`${couldNotCreateProjectMessage}`)
out.writeError(`${couldNotCreateProjectMessage}`)

if (e.errors) {
const errors = parseErrors(e)
const output = generateErrorOutput(errors)
out.write(`${output}`)
out.writeError(`${output}`)
} else {
throw e
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
// out.write(outputString)
out.write(output)
} catch (e) {
out.write(`${couldNotFetchProjectsMessage} ${e.message}`)
out.writeError(`${couldNotFetchProjectsMessage} ${e.message}`)
process.exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
const projectId = props.projectId ? props.projectId : readProjectIdFromProjectFile(resolver)

if (!projectId) {
out.write(noProjectIdMessage)
out.writeError(noProjectIdMessage)
process.exit(1)
}

Expand All @@ -43,7 +43,7 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
if (e.errors) {
const errors = parseErrors(e)
const output = generateErrorOutput(errors)
out.write(`${output}`)
out.writeError(`${output}`)
} else {
throw e
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
const {resolver, out} = env

if (!resolver.exists(graphcoolProjectFileName) && !resolver.exists(`${props.projectFilePath}/${graphcoolProjectFileName}`)) {
out.write(noProjectFileMessage)
out.writeError(noProjectFileMessage)
process.exit(1)
}

const projectInfo = readProjectInfoFromProjectFile(resolver, props.projectFilePath)
if (!projectInfo) {
out.write(invalidProjectFileMessage)
out.writeError(invalidProjectFileMessage)
process.exit(1)
}

Expand Down Expand Up @@ -71,20 +71,20 @@ export default async (props: Props, env: SystemEnvironment): Promise<void> => {
}
}

// something went wrong
// can't do migration because of issues with schema
else if (migrationResult.messages.length === 0 && migrationResult.errors.length > 0) {
out.write(`\n${migrationErrorMessage}`)
printMigrationErrors(migrationResult.errors, out)
}

} catch (e) {
out.stopSpinner()
out.write(couldNotMigrateSchemaMessage)
out.writeError(couldNotMigrateSchemaMessage)

if (e.errors) {
const errors = parseErrors(e)
const output = generateErrorOutput(errors)
out.write(`${output}`)
out.writeError(`${output}`)
} else {
throw e
}
Expand Down
4 changes: 4 additions & 0 deletions src/system/StdOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class StdOut implements Out {
process.stdout.write(message)
}

writeError(message: string): void {
process.stderr.write(message)
}

startSpinner(message: string) {
this.spinner = ora(message).start()
}
Expand Down
3 changes: 3 additions & 0 deletions src/system/TestOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default class TestOut implements Out {
write(message: string): void {
}

writeError(message: string): void {
}

startSpinner(message: string) {
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface MigrationResult {

export interface Out {
write(message: string): void
writeError(message: string): void
startSpinner(message: string): void
stopSpinner(): void
}
Expand Down

0 comments on commit ccee685

Please sign in to comment.