Skip to content

Fix/update to api #43

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 12 commits into from
Oct 15, 2019
Prev Previous commit
Next Next commit
fix setup and config
  • Loading branch information
ShMcK committed Oct 15, 2019
commit b0ceeab6318bb02c3db9bd61f6f6b5da3860ff6c
6 changes: 4 additions & 2 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const runCommands = async (commands: string[], language: string = 'JAVASCRIPT')

const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files}: G.StepActions): Promise<void> => {
// run commits
for (const commit of commits) {
await git.loadCommit(commit)
if (commits) {
for (const commit of commits) {
await git.loadCommit(commit)
}
}

// run command
Expand Down
10 changes: 4 additions & 6 deletions src/actions/tutorialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ import * as vscode from 'vscode'
import * as git from '../services/git'

interface TutorialConfigParams {
tutorial: G.Tutorial,
config: G.TutorialConfig,
alreadyConfigured?: boolean
onComplete?(): void
}

const tutorialConfig = async ({tutorial, alreadyConfigured, onComplete}: TutorialConfigParams) => {
console.log('---------- tutorialConfig -----------')
const tutorialConfig = async ({config, alreadyConfigured, }: TutorialConfigParams) => {
if (!alreadyConfigured) {
// setup git, add remote
await git.initIfNotExists()

// TODO: if remote not already set
await git.setupRemote(tutorial.version.data.config.repo.uri)
if (onComplete) {onComplete()}
await git.setupRemote(config.repo.uri)
}

// allow multiple coding languages in a tutorial
const languages: string[] = tutorial.version.data.config.codingLanguages.map(lang => lang.toLowerCase())
const languages: string[] = config.codingLanguages.map((lang: G.CodingLanguage) => lang.toLowerCase())

// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
Expand Down
24 changes: 18 additions & 6 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,32 @@ class Channel implements Channel {
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
const tutorialData: G.Tutorial = action.payload.tutorial
// setup tutorial config (save listener, test runner, etc)
this.context.setTutorial(this.workspaceState, tutorialData)
tutorialConfig({
tutorial: tutorialData,
// must await async git setup or commit loading fails
onComplete: () => this.send({type: 'TUTORIAL_CONFIGURED'})
})

const data: G.TutorialData = tutorialData.version.data

await tutorialConfig({config: data.config})

// run init setup actions
if (data.init) {
const setup: G.StepActions | null | undefined = data.init.setup
if (setup) {
setupActions(this.workspaceRoot, setup)
}
}

// report back to the webview that setup is complete
this.send({type: 'TUTORIAL_CONFIGURED'})
return
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
const tutorialContinue: G.Tutorial | null = this.context.tutorial.get()
if (!tutorialContinue) {
throw new Error('Invalid tutorial to continue')
}
const continueConfig: G.TutorialConfig = tutorialContinue.version.data.config
tutorialConfig({
tutorial: tutorialContinue,
config: continueConfig,
alreadyConfigured: true
})
return
Expand Down