Skip to content

Refactor #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
minor updates
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Apr 19, 2020
commit ac037f2d035f39d1338074db048c802f8e40452d
8 changes: 0 additions & 8 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import openFiles from './utils/openFiles'
import runCommands from './utils/runCommands'
import onError from '../services/sentry/onError'

async function wait(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

interface SetupActions {
actions: TT.StepActions
send: (action: T.Action) => void // send messages to client
Expand All @@ -35,8 +29,6 @@ export const setupActions = async ({ actions, send, path }: SetupActions): Promi
// 3. start file watchers
loadWatchers(watchers || [])

await wait(1000)

// 4. run command
await runCommands({ commands: commands || [], send, path }).catch(onError)
}
Expand Down
37 changes: 19 additions & 18 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,31 @@ class Channel implements Channel {
const tutorial: TT.Tutorial | null = this.context.tutorial.get()

// new tutorial
if (!tutorial || !tutorial.id) {
this.send({ type: 'START_NEW_TUTORIAL', payload: { env } })
return
}
this.send({ type: 'START_NEW_TUTORIAL', payload: { env } })
return

// set tutorial
const { position, progress } = await this.context.setTutorial(this.workspaceState, tutorial)
// disable continue until fixed

if (progress.complete) {
// tutorial is already complete
this.send({ type: 'TUTORIAL_ALREADY_COMPLETE', payload: { env } })
return
}
// communicate to client the tutorial & stepProgress state
this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, progress, position } })
// // set tutorial
// const { position, progress } = await this.context.setTutorial(this.workspaceState, tutorial)

return
// if (progress.complete) {
// // tutorial is already complete
// this.send({ type: 'TUTORIAL_ALREADY_COMPLETE', payload: { env } })
// return
// }
// // communicate to client the tutorial & stepProgress state
// this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, progress, position } })

// return
} catch (e) {
const error = {
type: 'UnknownError',
message: `Location: Editor startup\n\n${e.message}`,
}
this.send({ type: 'EDITOR_STARTUP_FAILED', payload: { error } })
}
return

// clear tutorial local storage
case 'TUTORIAL_CLEAR':
Expand Down Expand Up @@ -203,14 +204,14 @@ class Channel implements Channel {

// report back to the webview that setup is complete
this.send({ type: 'TUTORIAL_CONFIGURED' })
return
} catch (e) {
const error = {
type: 'UnknownError',
message: `Location: EditorTutorialConfig.\n\n ${e.message}`,
}
this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
}
return
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
try {
const tutorialContinue: TT.Tutorial | null = this.context.tutorial.get()
Expand All @@ -224,14 +225,14 @@ class Channel implements Channel {
})
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
return
} catch (e) {
const error = {
type: 'UnknownError',
message: `Location: Editor tutorial continue config.\n\n ${e.message}`,
}
this.send({ type: 'CONTINUE_FAILED', payload: { error } })
}
return
case 'EDITOR_VALIDATE_SETUP':
try {
// check workspace is selected
Expand Down Expand Up @@ -272,14 +273,14 @@ class Channel implements Channel {
return
}
this.send({ type: 'SETUP_VALIDATED' })
return
} catch (e) {
const error = {
type: 'UknownError',
message: e.message,
}
this.send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
}
return
case 'EDITOR_REQUEST_WORKSPACE':
openWorkspace()
return
Expand Down Expand Up @@ -329,7 +330,7 @@ class Channel implements Channel {
case 'TEST_PASS':
const tutorial = this.context.tutorial.get()
if (!tutorial) {
throw new Error('Error with current tutorial')
throw new Error('Error with current tutorial. Tutorial may be missing an id.')
}
// update local storage stepProgress
const progress = this.context.progress.setStepComplete(tutorial, action.payload.stepId)
Expand Down
4 changes: 2 additions & 2 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface CreateCommandProps {
export const createCommands = ({ extensionPath, workspaceState }: CreateCommandProps) => {
// React panel webview
let webview: any
let currentStepId = ''
let currentStepId: string | null = ''
let testRunner: any

return {
Expand Down Expand Up @@ -79,7 +79,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
},
[COMMANDS.RUN_TEST]: (current: Payload | undefined, onSuccess: () => void) => {
// use stepId from client, or last set stepId
const payload: Payload = { stepId: current && current.stepId.length ? current.stepId : currentStepId }
const payload: Payload = { stepId: current && current.stepId?.length ? current.stepId : currentStepId }
testRunner(payload, onSuccess)
},
}
Expand Down
3 changes: 1 addition & 2 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export type Env = 'test' | 'local' | 'development' | 'production'
export const NODE_ENV: Env = process.env.NODE_ENV || 'production'

// toggle logging in development
export const LOG: boolean =
(process.env.REACT_APP_LOG || '').toLowerCase() === 'true' && process.env.NODE_ENV !== 'production'
export const LOG: boolean = (process.env.REACT_APP_LOG || '').toLowerCase() === 'true'

// error logging tool
export const SENTRY_DSN: string | null = process.env.SENTRY_DSN || null
Expand Down
16 changes: 11 additions & 5 deletions src/services/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { LOG } from '../../environment'

const logger = (message: string | string[]) => {
export type Log = string | object | null

const logger = (...messages: Log[]): void => {
if (!LOG) {
return
}
if (Array.isArray(message)) {
message.forEach(console.log)
} else {
console.log(message)
// Inside vscode, you console.log does not allow more than 1 param
// to get around it, we can log with multiple log statements
for (const message of messages) {
if (typeof message === 'object') {
console.log(JSON.stringify(message))
} else {
console.log(message)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { clearOutput, displayOutput } from './output'
import { formatFailOutput } from './formatOutput'

export interface Payload {
stepId: string
stepId: string | null
}

interface Callbacks {
Expand Down