Skip to content

In progress: Feature/api #28

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

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9004e35
setup server api
ShMcK Aug 14, 2019
4bd3fad
setup apollo on web
ShMcK Aug 14, 2019
4456261
setup new page query
ShMcK Aug 14, 2019
d0f984b
npm updates
ShMcK Aug 16, 2019
a591a2d
sort-package-json
ShMcK Aug 18, 2019
5a060fd
migrate codegen graphql typings
ShMcK Aug 18, 2019
f3f9765
cleanup routes
ShMcK Aug 18, 2019
2d84fa8
setup apollo decorator
ShMcK Aug 18, 2019
1114d13
new queryTutorials loaded
ShMcK Aug 18, 2019
4b1d714
migrate latestVersion to version
ShMcK Aug 18, 2019
5d38263
remove data from version, schema change
ShMcK Aug 18, 2019
8d4d43f
ckean up new container loading
ShMcK Aug 18, 2019
64837c0
load continue container
ShMcK Aug 18, 2019
b2fcd7a
add error component
ShMcK Aug 18, 2019
0c9b0b9
clenaup level summary progress
ShMcK Aug 18, 2019
f57b367
apollo decorator with local cache
ShMcK Aug 18, 2019
2b16a0b
working LevelStage container
ShMcK Aug 18, 2019
204840f
update level stories & structure
ShMcK Aug 18, 2019
2bc96a1
cleanup gql paths
ShMcK Aug 18, 2019
372658d
add level/stage/step to gql
ShMcK Aug 18, 2019
44613b6
migrate stage page
ShMcK Aug 18, 2019
df11100
fix typing paths for storybook
ShMcK Aug 18, 2019
7bab14b
cleanup Stage story
ShMcK Aug 18, 2019
c69b868
working stage container
ShMcK Aug 18, 2019
00b3550
cleanup storybook summary
ShMcK Aug 18, 2019
223019e
cleanup step stories
ShMcK Aug 18, 2019
d0d2f07
restructure single use components into containers
ShMcK Aug 18, 2019
b022179
remove old web api
ShMcK Aug 19, 2019
24eb6a6
absolute paths not allowed
ShMcK Aug 19, 2019
be46fad
create setStatus mutation
ShMcK Aug 19, 2019
26ae887
resolve build issues
ShMcK Aug 19, 2019
c39666a
update deps
ShMcK Aug 20, 2019
6c73657
fix react webview script issue
ShMcK Aug 22, 2019
36af369
create script for styles
ShMcK Aug 22, 2019
a058eff
update deps
ShMcK Aug 22, 2019
8c72738
cleanup logs
ShMcK Aug 22, 2019
d784c57
fix use effects
ShMcK Aug 22, 2019
f4e9877
fix no route unclear object
ShMcK Aug 22, 2019
6a13fcd
update api url for src
ShMcK Aug 22, 2019
39af55d
cleanup apollo server
ShMcK Aug 22, 2019
8740c1d
migrate to graphql-request on server
ShMcK Aug 23, 2019
5776877
tutorial command progress
ShMcK Aug 23, 2019
47224c4
update deps
ShMcK Aug 25, 2019
7bbacd6
update typings
ShMcK Aug 25, 2019
0dd047f
create Tutorial model
ShMcK Aug 25, 2019
97b878a
initialize state machine with tutorial model
ShMcK Aug 25, 2019
57675e5
tutorialModel progress
ShMcK Aug 25, 2019
a92d52f
heavy refactoring
ShMcK Aug 25, 2019
46d1e27
fix launch errors
ShMcK Aug 25, 2019
98c9cc9
remove unusued loading tutorial
ShMcK Aug 25, 2019
b358130
fix send data to client
ShMcK Aug 25, 2019
b6ec3e8
cleanup env vars & fix request
ShMcK Aug 25, 2019
bf0ad9b
clenaup typings
ShMcK Aug 25, 2019
0ad9d2c
add additional logging
ShMcK Aug 26, 2019
f462b39
heavy refactor
ShMcK Aug 26, 2019
1253177
Refactor editor dispatch uses
ShMcK Sep 1, 2019
c32d670
add jest
ShMcK Sep 1, 2019
3886921
fix stateToString function
ShMcK Sep 1, 2019
63f28db
fix jest mismatch build errors
ShMcK Sep 1, 2019
0d50ab6
update deps
ShMcK Sep 1, 2019
44cf7d7
cleanup client state
ShMcK Sep 1, 2019
957d05b
rename select to start
ShMcK Sep 1, 2019
0133ab8
migrate git into tutorial model
ShMcK Sep 1, 2019
50cad58
setup initial start/loaded actions
ShMcK Sep 1, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migrate git into tutorial model
  • Loading branch information
ShMcK committed Sep 1, 2019
commit 0133ab8b64d410dfae1073f118d6473aabf21f05
31 changes: 19 additions & 12 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const getNonce = (): string => {
}


/**
* Manages React webview panels
*/
// Manages webview panel
class ReactWebView {
// @ts-ignore
public loaded: boolean
Expand All @@ -28,7 +26,7 @@ class ReactWebView {
// Create and show a new webview panel
this.panel = this.createWebviewPanel(vscode.ViewColumn.Two)

// Set the webview's initial html content
// Set the webview initial html content
this.panel.webview.html = this.getHtmlForWebview()

// Listen for when the panel is disposed
Expand All @@ -37,12 +35,21 @@ class ReactWebView {

// Handle messages from the webview
const onReceive = (action: string | CR.Action) => {
// await loading of webview in React before proceeding with loaded state
if (action === 'WEBVIEW_LOADED') {
this.loaded = true
} else {
console.log('onReceive', action)
vscode.commands.executeCommand('coderoad.receive_action', action)
const actionType: string = typeof action === 'string' ? action : action.type
switch (actionType) {
case 'WEBVIEW_LOADED':
// await loading of webview in React before proceeding with loaded state
this.loaded = true
break
case 'TUTORIAL_START':
console.log('TUTORIAL_START called')
console.log(action)
break
// add other cases
default:
// send to state machine
console.log('onReceive', action)
vscode.commands.executeCommand('coderoad.receive_machine_action', action)
}
}
this.panel.webview.onDidReceiveMessage(onReceive, null, this.disposables)
Expand All @@ -55,7 +62,7 @@ class ReactWebView {
})
}

// prevents new panels from going ontop of coderoad panel
// prevents new panels from going on top of coderoad panel
vscode.window.onDidChangeActiveTextEditor((textEditor?: vscode.TextEditor) => {
console.log('onDidChangeActiveTextEditor')
console.log(textEditor)
Expand Down Expand Up @@ -115,7 +122,7 @@ class ReactWebView {
const config = {
// Enable javascript in the webview
enableScripts: true,
// And restric the webview to only loading content from our extension's `media` directory.
// And restrict the webview to only loading content from our extension's `media` directory.
localResourceRoots: [vscode.Uri.file(path.join(this.extensionPath, 'build'))],
// prevents destroying the window when it is in the background
retainContextWhenHidden: true,
Expand Down
6 changes: 3 additions & 3 deletions src/editor/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const COMMANDS = {
OPEN_WEBVIEW: 'coderoad.open_webview',
SEND_STATE: 'coderoad.send_state',
SEND_DATA: 'coderoad.send_data',
RECEIVE_ACTION: 'coderoad.receive_action',
RECEIVE_MACHINE_ACTION: 'coderoad.receive_machine_action',
OPEN_FILE: 'coderoad.open_file',
RUN_TEST: 'coderoad.run_test',
TEST_PASS: 'coderoad.test_pass',
Expand Down Expand Up @@ -102,7 +102,7 @@ export const createCommands = ({vscodeExt, machine}: CreateCommandProps) => {
const absoluteFilePath = join(workspaceRoot, relativeFilePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when intialization leave the panel behind any files opened
// there are times when initialization leave the panel behind any files opened
// ensure the panel is redrawn on the right side first
webview.createOrShow(vscode.ViewColumn.Two)
} catch (error) {
Expand All @@ -116,7 +116,7 @@ export const createCommands = ({vscodeExt, machine}: CreateCommandProps) => {
[COMMANDS.SEND_DATA]: (payload: {data: any}) => {
webview.postMessage({type: 'SET_DATA', payload})
},
[COMMANDS.RECEIVE_ACTION]: (action: string | CR.Action) => {
[COMMANDS.RECEIVE_MACHINE_ACTION]: (action: string | CR.Action) => {
// send received actions from web-app into state machine
console.log('receive action', action)
machine.send(action)
Expand Down
246 changes: 123 additions & 123 deletions src/editor/commands/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode'
import { exec } from '../../services/node'
import {exec} from '../../services/node'
import * as storage from '../../services/storage'

// ensure only latest run_test action is taken
Expand All @@ -8,135 +8,135 @@ let currentId = 0
// quick solution to prevent processing multiple results
// NOTE: may be possible to kill child process early
const shouldExitEarly = (processId: number): boolean => {
return currentId !== processId
return currentId !== processId
}

let _channel: vscode.OutputChannel
let channel: vscode.OutputChannel

const getOutputChannel = (name: string): vscode.OutputChannel => {
if (!_channel) {
_channel = vscode.window.createOutputChannel(name)
}
return _channel
if (!channel) {
channel = vscode.window.createOutputChannel(name)
}
return channel
}

interface Props {
onSuccess(): void
onFail(): void
onSuccess(): void
onFail(): void
}

export default async function runTest({ onSuccess, onFail }: Props): Promise<void> {
// increment process id
let processId = ++currentId

const outputChannelName = 'Test Output'

// TODO: validate test directory from package.json exists
// let testFile = path.join('test');
// if (!await exists(testFile)) {
// return emptyTasks;
// }

// TODO: verify test runner for args
const testArgs = ['--json']

// if .git repo, use --onlyChanged
// const hasGit = path.join('.git');
// if (await exists(hasGit)) {
// testArgs.push('--onlyChanged')
// }

let commandLine = `npm test -- ${testArgs.join(' ')}`

try {
// capture position early on test start
// in case position changes
const [position, { stdout }] = await Promise.all([storage.getPosition(), exec(commandLine)])
if (shouldExitEarly(processId)) {
// exit early
return
}

if (stdout) {
let lines = stdout.split(/\r{0,1}\n/)
console.log('SUCCESS LINES', lines)
for (let line of lines) {
if (line.length === 0) {
continue
}

const regExp = /^{\"numFailedTestSuites/
const matches = regExp.exec(line)
if (matches && matches.length) {
console.log('MATCHES SUCCESS')
const result = JSON.parse(line)

if (result.success) {
console.log('SUCCESS')
if (shouldExitEarly(processId)) {
// exit early
return
}
console.log('call onSuccess')
onSuccess()
} else {
console.log('NOT SUCCESS?')
}
}
}
}
} catch (err) {
if (shouldExitEarly(processId)) {
// exit early
return
}
// error contains output & error message
// output can be parsed as json
const { stdout, stderr } = err
console.log('TEST FAILED', stdout)

if (!stdout) {
console.error('SOMETHING WENT WRONG WITH A PASSING TEST')
}
// test runner failed
const channel = getOutputChannel(outputChannelName)

if (stdout) {
let lines = stdout.split(/\r{0,1}\n/)

for (let line of lines) {
if (line.length === 0) {
continue
}

const dataRegExp = /^{\"numFailedTestSuites"/
const matches = dataRegExp.exec(line)

if (matches && matches.length) {
const result = JSON.parse(line)
const firstError = result.testResults.find((t: any) => t.status === 'failed')

if (firstError) {
if (shouldExitEarly(processId)) {
// exit early
return
}
console.log('ERROR', firstError.message)
console.log('call onFail')
onFail()
} else {
console.error('NOTE: PARSER DID NOT WORK FOR ', line)
}
}
}
}

if (stderr) {
channel.show(false)
channel.appendLine(stderr)
}
// if (err.stdout) {
// channel.appendLine(err.stdout);
// }
}
export default async function runTest({onSuccess, onFail}: Props): Promise<void> {
// increment process id
const processId = ++currentId

const outputChannelName = 'Test Output'

// TODO: validate test directory from package.json exists
// let testFile = path.join('test');
// if (!await exists(testFile)) {
// return emptyTasks;
// }

// TODO: verify test runner for args
const testArgs = ['--json']

// if .git repo, use --onlyChanged
// const hasGit = path.join('.git');
// if (await exists(hasGit)) {
// testArgs.push('--onlyChanged')
// }

const commandLine = `npm test -- ${testArgs.join(' ')}`

try {
// capture position early on test start
// in case position changes
const [position, {stdout}] = await Promise.all([storage.getPosition(), exec(commandLine)])
if (shouldExitEarly(processId)) {
// exit early
return
}

if (stdout) {
const lines = stdout.split(/\r{0,1}\n/)
console.log('SUCCESS LINES', lines)
for (const line of lines) {
if (line.length === 0) {
continue
}

const regExp = /^{\"numFailedTestSuites/
const matches = regExp.exec(line)
if (matches && matches.length) {
console.log('MATCHES SUCCESS')
const result = JSON.parse(line)

if (result.success) {
console.log('SUCCESS')
if (shouldExitEarly(processId)) {
// exit early
return
}
console.log('call onSuccess')
onSuccess()
} else {
console.log('NOT SUCCESS?')
}
}
}
}
} catch (err) {
if (shouldExitEarly(processId)) {
// exit early
return
}
// error contains output & error message
// output can be parsed as json
const {stdout, stderr} = err
console.log('TEST FAILED', stdout)

if (!stdout) {
console.error('SOMETHING WENT WRONG WITH A PASSING TEST')
}
// test runner failed
const channel = getOutputChannel(outputChannelName)

if (stdout) {
const lines = stdout.split(/\r{0,1}\n/)

for (const line of lines) {
if (line.length === 0) {
continue
}

const dataRegExp = /^{\"numFailedTestSuites"/
const matches = dataRegExp.exec(line)

if (matches && matches.length) {
const result = JSON.parse(line)
const firstError = result.testResults.find((t: any) => t.status === 'failed')

if (firstError) {
if (shouldExitEarly(processId)) {
// exit early
return
}
console.log('ERROR', firstError.message)
console.log('call onFail')
onFail()
} else {
console.error('NOTE: PARSER DID NOT WORK FOR ', line)
}
}
}
}

if (stderr) {
channel.show(false)
channel.appendLine(stderr)
}
// if (err.stdout) {
// channel.appendLine(err.stdout);
// }
}
}
4 changes: 2 additions & 2 deletions src/services/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<void> => {
SINGLE git cherry-pick %COMMIT%
if fails, will stash all and retry
*/
export async function gitLoadCommits(actions: G.StepActions, editorDispatch: CR.EditorDispatch): Promise<void> {
export async function gitLoadCommits(actions: G.StepActions, openFile: (file: string) => void): Promise<void> {
const {commits, commands, files} = actions

console.log(`load commits: ${commits.join(', ')}`)
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function gitLoadCommits(actions: G.StepActions, editorDispatch: CR.

if (files) {
for (const filePath of files) {
editorDispatch('coderoad.open_file', filePath)
openFile(filePath)
}
}
}
Expand Down
Loading