Skip to content

Commit 8ff0a64

Browse files
authored
Merge pull request #43 from ShMcK/fix/update-to-api
Fix/update to api
2 parents 72a14f8 + a792113 commit 8ff0a64

File tree

40 files changed

+612
-680
lines changed

40 files changed

+612
-680
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"prettier": "^1.18.2",
5050
"tslint": "^5.20.0",
5151
"tslint-config-prettier": "^1.18.0",
52-
"typescript": "^3.6.4",
52+
"typescript": "^3.7.0-beta",
5353
"vscode": "^1.1.36",
5454
"vscode-test": "^1.2.0"
5555
},

src/actions/runTest.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as vscode from 'vscode'
22
import node from '../services/node'
33

4+
// TODO: use tap parser to make it easier to support other test runners
5+
46
// ensure only latest run_test action is taken
57
let currentId = 0
68

@@ -35,12 +37,6 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void
3537

3638
const outputChannelName = 'Test Output'
3739

38-
// TODO: validate test directory from package.json exists
39-
// let testFile = path.join('test');
40-
// if (!await exists(testFile)) {
41-
// return emptyTasks;
42-
// }
43-
4440
// TODO: verify test runner for args
4541
// jest CLI docs https://jestjs.io/docs/en/cli
4642
const testArgs = [
@@ -51,12 +47,6 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void
5147
'--maxWorkers=4'
5248
]
5349

54-
// if .git repo, use --onlyChanged
55-
// const hasGit = path.join('.git');
56-
// if (await exists(hasGit)) {
57-
// testArgs.push('--onlyChanged')
58-
// }
59-
6050
const commandLine = `npm test -- ${testArgs.join(' ')}`
6151

6252
try {

src/actions/setupActions.ts

+33-27
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,45 @@ const runCommands = async (commands: string[], language: string = 'JAVASCRIPT')
4040

4141
const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files}: G.StepActions): Promise<void> => {
4242
// run commits
43-
for (const commit of commits) {
44-
await git.loadCommit(commit)
43+
if (commits) {
44+
for (const commit of commits) {
45+
await git.loadCommit(commit)
46+
}
4547
}
4648

4749
// run command
48-
await runCommands(commands)
50+
if (commands) {
51+
await runCommands(commands)
52+
}
4953

5054
// open files
51-
for (const filePath of files) {
52-
try {
53-
// TODO: figure out why this does not work
54-
// try {
55-
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
56-
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
57-
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
58-
// // there are times when initialization leave the panel behind any files opened
59-
// // ensure the panel is redrawn on the right side first
60-
// // webview.createOrShow()
61-
// } catch (error) {
62-
// console.log(`Failed to open file ${filePath}`, error)
63-
// }
64-
const wr = vscode.workspace.rootPath
65-
if (!wr) {
66-
throw new Error('No workspace root path')
55+
if (files) {
56+
for (const filePath of files) {
57+
try {
58+
// TODO: figure out why this does not work
59+
// try {
60+
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
61+
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
62+
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
63+
// // there are times when initialization leave the panel behind any files opened
64+
// // ensure the panel is redrawn on the right side first
65+
// // webview.createOrShow()
66+
// } catch (error) {
67+
// console.log(`Failed to open file ${filePath}`, error)
68+
// }
69+
const wr = vscode.workspace.rootPath
70+
if (!wr) {
71+
throw new Error('No workspace root path')
72+
}
73+
const absoluteFilePath = join(wr, filePath)
74+
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
75+
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
76+
// there are times when initialization leave the panel behind any files opened
77+
// ensure the panel is redrawn on the right side first
78+
vscode.commands.executeCommand('coderoad.open_webview')
79+
} catch (error) {
80+
console.log(`Failed to open file ${filePath}`, error)
6781
}
68-
const absoluteFilePath = join(wr, filePath)
69-
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
70-
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
71-
// there are times when initialization leave the panel behind any files opened
72-
// ensure the panel is redrawn on the right side first
73-
vscode.commands.executeCommand('coderoad.open_webview')
74-
} catch (error) {
75-
console.log(`Failed to open file ${filePath}`, error)
7682
}
7783
}
7884
}

src/actions/tutorialConfig.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@ import * as vscode from 'vscode'
33
import * as git from '../services/git'
44

55
interface TutorialConfigParams {
6-
tutorial: G.Tutorial,
6+
config: G.TutorialConfig,
77
alreadyConfigured?: boolean
88
onComplete?(): void
99
}
1010

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

1716
// TODO: if remote not already set
18-
await git.setupRemote(tutorial.repo.uri)
19-
if (onComplete) {onComplete()}
17+
await git.setupRemote(config.repo.uri)
2018
}
2119

22-
// TODO: allow multiple coding languages in a tutorial
23-
const language = tutorial.codingLanguage.toLowerCase()
20+
// allow multiple coding languages in a tutorial
21+
const languages: string[] = config.codingLanguages.map((lang: G.CodingLanguage) => lang.toLowerCase())
2422

2523
// setup onSave hook
2624
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
27-
if (document.uri.scheme === 'file' && language === document.languageId) {
25+
// @ts-ignore // issue with GQL enums in TS
26+
if (document.uri.scheme === 'file' && languages.includes(document.languageId)) {
2827
vscode.commands.executeCommand('coderoad.run_test')
2928
}
3029
})

src/channel/index.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,33 @@ class Channel implements Channel {
8282
return
8383
// configure test runner, language, git
8484
case 'EDITOR_TUTORIAL_CONFIG':
85-
const tutorialData = action.payload.tutorial
85+
const tutorialData: G.Tutorial = action.payload.tutorial
86+
// setup tutorial config (save listener, test runner, etc)
8687
this.context.setTutorial(this.workspaceState, tutorialData)
87-
tutorialConfig({
88-
tutorial: tutorialData,
89-
// must await async git setup or commit loading fails
90-
onComplete: () => this.send({type: 'TUTORIAL_CONFIGURED'})
91-
})
88+
89+
const data: G.TutorialData = tutorialData.version.data
90+
91+
await tutorialConfig({config: data.config})
92+
93+
// run init setup actions
94+
if (data.init) {
95+
const setup: G.StepActions | null | undefined = data.init.setup
96+
if (setup) {
97+
setupActions(this.workspaceRoot, setup)
98+
}
99+
}
100+
101+
// report back to the webview that setup is complete
102+
this.send({type: 'TUTORIAL_CONFIGURED'})
92103
return
93104
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
94105
const tutorialContinue: G.Tutorial | null = this.context.tutorial.get()
95106
if (!tutorialContinue) {
96107
throw new Error('Invalid tutorial to continue')
97108
}
109+
const continueConfig: G.TutorialConfig = tutorialContinue.version.data.config
98110
tutorialConfig({
99-
tutorial: tutorialContinue,
111+
config: continueConfig,
100112
alreadyConfigured: true
101113
})
102114
return

src/channel/state/Position.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as G from 'typings/graphql'
33

44
const defaultValue: CR.Position = {
55
levelId: '',
6-
stageId: '',
76
stepId: '',
87
}
98

@@ -31,7 +30,11 @@ class Position {
3130
return this.value
3231
}
3332

34-
const {levels} = tutorial.version
33+
if (!tutorial || !tutorial.version || !tutorial.version.data || !tutorial.version.data.levels) {
34+
throw new Error('Error setting position from progress')
35+
}
36+
37+
const {levels} = tutorial.version.data
3538

3639
const lastLevelIndex: number | undefined = levels.findIndex((l: G.Level) => !progress.levels[l.id])
3740
// TODO: consider all levels complete as progress.complete
@@ -40,15 +43,7 @@ class Position {
4043
}
4144
const currentLevel: G.Level = levels[lastLevelIndex]
4245

43-
const {stages} = currentLevel
44-
45-
const lastStageIndex: number | undefined = stages.findIndex((s: G.Stage) => !progress.stages[s.id])
46-
if (lastStageIndex >= stages.length) {
47-
throw new Error('Error setting progress stage')
48-
}
49-
const currentStage: G.Stage = stages[lastStageIndex]
50-
51-
const {steps} = currentStage
46+
const {steps} = currentLevel
5247

5348
const lastStepIndex: number | undefined = steps.findIndex((s: G.Step) => !progress.steps[s.id])
5449
if (lastStepIndex >= steps.length) {
@@ -60,7 +55,6 @@ class Position {
6055

6156
this.value = {
6257
levelId: currentLevel.id,
63-
stageId: currentStage.id,
6458
stepId: currentStep.id,
6559
}
6660
return this.value

src/channel/state/Progress.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Storage from '../../services/storage'
66

77
const defaultValue: CR.Progress = {
88
levels: {},
9-
stages: {},
109
steps: {},
1110
complete: false
1211
}

src/editor/ReactWebView.ts

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class ReactWebView {
5252

5353
// // // prevents moving coderoad panel on top of left panel
5454
// vscode.window.onDidChangeVisibleTextEditors((textEditors: vscode.TextEditor[]) => {
55-
// console.log('onDidChangeVisibleTextEditors')
56-
// console.log(textEditors)
5755
// // updateWindows()
5856
// })
5957

src/services/git/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function loadCommit(commit: string): Promise<void> {
4242

4343
/*
4444
save commit
45-
git commit -am '${level}/${stage}/${step} complete'
45+
git commit -am '${level}/${step} complete'
4646
*/
4747

4848
export async function saveCommit(message: string): Promise<void> {

src/services/storage/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class Storage<T> {
1616
this.defaultValue = defaultValue
1717
}
1818
public get = async (): Promise<T> => {
19-
const value: string | undefined = await this.storage.get(this.key)
20-
if (value) {
21-
return JSON.parse(value)
22-
}
19+
// const value: string | undefined = await this.storage.get(this.key)
20+
// if (value) {
21+
// return JSON.parse(value)
22+
// }
2323
return this.defaultValue
2424
}
2525
public set = (value: T): void => {

src/test/runTest.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as path from 'path'
33
import {runTests} from 'vscode-test'
44

55
async function main() {
6-
console.log('__dirname', __dirname)
76
// The folder containing the Extension Manifest package.json
87
// Passed to `--extensionDevelopmentPath`
98
const extensionDevelopmentPath: string = path.resolve(__dirname, '../../')

src/test/suite/extension.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ suite('Extension tests', () => {
1515
await vscode.commands.executeCommand('coderoad.start')
1616
await setTimeout(() => Promise.resolve(), 5000)
1717
// const webview = vscode.window.activeTextEditor
18-
// console.log(webview)
1918
assert.equal(2, 2)
2019
})
2120

typings/context.d.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import * as CR from './index'
22

3-
export interface Step extends Exclude<CR.TutorialStep, 'actions'> {
4-
status: {
5-
complete: boolean
6-
active: boolean
7-
}
3+
interface ProgressStatus {
4+
active: boolean
5+
complete: boolean
86
}
97

10-
export interface ReceivedEvent {
11-
data: CR.Action
8+
export interface Step extends Exclude<CR.TutorialStep, 'actions'> {
9+
status: ProgressStatus
1210
}
1311

14-
export interface StageStepStatus {
15-
active: boolean
16-
complete: boolean
12+
export interface ReceivedEvent {
13+
data: CR.Action
1714
}
1815

19-
export interface StageWithStatus extends CR.TutorialStage {
20-
status: StageStepStatus
16+
export interface LevelWithStatus extends CR.TutorialLevel {
17+
status: ProgressStatus
2118
}

0 commit comments

Comments
 (0)