Skip to content

load tutorial from env url on startup #325

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 1 commit into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/jest": "^25.2.1",
"@types/jsdom": "^16.2.1",
"@types/node": "^13.13.4",
"@types/node-fetch": "^2.5.7",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
Expand All @@ -50,6 +51,7 @@
"git-url-parse": "^11.1.2",
"jest": "^25.4.0",
"jsdom": "^16.2.2",
"node-fetch": "^2.6.0",
"prettier": "^2.0.5",
"semver": "^7.3.2",
"ts-jest": "^25.4.0",
Expand Down
19 changes: 16 additions & 3 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as T from 'typings'
import * as TT from 'typings/tutorial'
import * as E from 'typings/error'
import * as vscode from 'vscode'
import fetch from 'node-fetch'
import { satisfies } from 'semver'
import saveCommit from '../actions/saveCommit'
import { setupActions, solutionActions } from '../actions/setupActions'
Expand All @@ -15,7 +16,7 @@ import { readFile } from 'fs'
import { join } from 'path'
import { promisify } from 'util'
import { showOutput } from '../services/testRunner/output'
import { WORKSPACE_ROOT } from '../environment'
import { WORKSPACE_ROOT, TUTORIAL_URL } from '../environment'

const readFileAsync = promisify(readFile)

Expand Down Expand Up @@ -52,8 +53,8 @@ class Channel implements Channel {
case 'EDITOR_STARTUP':
try {
// check if a workspace is open, otherwise nothing works
const noActiveWorksapce = !WORKSPACE_ROOT.length
if (noActiveWorksapce) {
const noActiveWorkspace = !WORKSPACE_ROOT.length
if (noActiveWorkspace) {
const error: E.ErrorMessage = {
type: 'NoWorkspaceFound',
message: '',
Expand All @@ -73,6 +74,18 @@ class Channel implements Channel {
sessionId: vscode.env.sessionId,
}

// load tutorial from url
if (TUTORIAL_URL) {
try {
const tutorialRes = await fetch(TUTORIAL_URL)
const tutorial = await tutorialRes.json()
this.send({ type: 'START_TUTORIAL_FROM_URL', payload: { tutorial } })
return
} catch (e) {
console.log(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
}
}

// continue from tutorial from local storage
const tutorial: TT.Tutorial | null = this.context.tutorial.get()

Expand Down
4 changes: 3 additions & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 = true
export const LOG = false

// error logging tool
export const SENTRY_DSN: string | null = null
Expand All @@ -33,3 +33,5 @@ const supportedOS = [
if (!supportedOS.includes(OS_PLATFORM)) {
throw new Error(`OS ${OS_PLATFORM}" not supported with CodeRoad`)
}

export const TUTORIAL_URL: string | null = process.env.CODEROAD_TUTORIAL_URL || null
4 changes: 4 additions & 0 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const createMachine = (options: any) => {
target: 'Start',
actions: ['setStart'],
},
START_TUTORIAL_FROM_URL: {
target: 'SetupNewTutorial',
actions: ['setTutorialContext'],
},
// TODO: handle completed tutorial differently
TUTORIAL_ALREADY_COMPLETE: {
target: 'Start',
Expand Down