Skip to content

Setup #3

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 23 commits into from
Jun 8, 2019
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
Prev Previous commit
Next Next commit
refactor files
  • Loading branch information
ShMcK committed Jun 2, 2019
commit b51dd2f6e6c93eb3de6df89fc4249c0bfde4ffa4
11 changes: 1 addition & 10 deletions src/commands/tutorialLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ async function newTutorial(tutorial: CR.Tutorial) {
await openReadme()
}

function onSaveHook(languageIds: string[]) {
// trigger command on save
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (languageIds.includes(document.languageId) && document.uri.scheme === 'file') {
// do work
vscode.commands.executeCommand('coderoad.test_run')
}
})
}

async function validateCanContinue(): Promise<boolean> {
// validate tutorial & progress found in local storage
Expand Down Expand Up @@ -127,7 +118,7 @@ export default async function tutorialLoad(context: vscode.ExtensionContext): Pr
// }

// // setup hook to run tests on save
// onSaveHook(tutorial.meta.languages)


// TODO: start
}
2 changes: 1 addition & 1 deletion src/utils/fetch.ts → src/services/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CR from 'typings'

// temporary tutorials
import basicTutorial from '../state/context/tutorials/basic'
import basicTutorial from '../../state/context/tutorials/basic'

interface Options {
resource: string
Expand Down
32 changes: 32 additions & 0 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as CR from 'typings'

// temporary tutorials
import basicTutorial from '../../state/context/tutorials/basic'

interface Options {
resource: string
params?: any
}

const tutorialsData: { [key: string]: CR.Tutorial } = {
tutorialId: basicTutorial,
}

// TODO: replace with fetch resource
export default async function fetch(options: Options): Promise<any> {
console.log('options', options)
switch (options.resource) {
case 'getTutorialsSummary':
// list of ids with summaries
let data: { [id: string]: CR.TutorialSummary } = {}
for (const tutorial of Object.values(tutorialsData)) {
data[tutorial.id] = tutorial.data.summary
}
return data
case 'getTutorial':
// specific tutorial by id
return tutorialsData[options.params.id]
default:
throw new Error('Resource not found')
}
}
12 changes: 0 additions & 12 deletions src/services/fs.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/services/git.ts → src/services/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CR from 'typings'
import { exec, exists, openFile } from '../utils/node'
import { exec, exists, openFile } from '../node'

const gitOrigin = 'coderoad'

Expand Down
12 changes: 12 additions & 0 deletions src/utils/node.ts → src/services/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ export const openFile = async (relativeFilePath: string): Promise<void> => {
console.log(`Failed to open file ${relativeFilePath}`, error)
}
}


// export async function clear(): Promise<void> {
// // remove all files including ignored
// // NOTE: Linux only
// const command = 'ls -A1 | xargs rm -rf'
// const { stderr } = await exec(command)
// if (stderr) {
// console.error(stderr)
// throw new Error('Error removing all files & folders')
// }
// }
File renamed without changes.
2 changes: 1 addition & 1 deletion src/services/position.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CR from 'typings'
import * as storage from './storage'
import * as storage from './vscode/storage'

export async function getInitial(tutorial: CR.Tutorial): Promise<CR.Position> {
const { data } = tutorial
Expand Down
4 changes: 2 additions & 2 deletions src/services/rootSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode'
import { setWorkspaceRoot } from '../utils/node'
import { setStorage } from './storage'
import { setWorkspaceRoot } from '../services/node'
import { setStorage } from './vscode/storage'

export default async function setupRoot(context: vscode.ExtensionContext) {
await setWorkspaceRoot()
Expand Down
2 changes: 1 addition & 1 deletion src/services/testResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as CR from 'typings'
import * as vscode from 'vscode'
import * as storage from './storage'
import * as storage from './vscode/storage'


export async function onSuccess(position: CR.Position) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/tutorialSetup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CR from 'typings'
import * as position from '../services/position'
import * as storage from '../services/storage'
import { isEmptyWorkspace } from '../utils/workspace'
import * as storage from '../services/vscode/storage'
import { isEmptyWorkspace } from '../services/vscode/workspace'
import { gitLoadCommits, gitInitIfNotExists, gitSetupRemote } from '../services/git'

const testRepo = 'https://github.com/ShMcK/coderoad-tutorial-basic.git'
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions src/services/vscode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as CR from 'typings'
import onSaveHook from './save'

const vscodeAction = (action: CR.Action) => {
switch (action.type) {
case 'ON_FILE_SAVE_RUN_TEST': {
onSaveHook(action.payload.languages)
}
}
}
13 changes: 13 additions & 0 deletions src/services/vscode/save.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as vscode from 'vscode'

function onSaveHook(languageIds: string[]) {
// trigger command on save
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (languageIds.includes(document.languageId) && document.uri.scheme === 'file') {
// do work
vscode.commands.executeCommand('coderoad.test_run')
}
})
}

export default onSaveHook
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs'
import * as path from 'path'
import * as vscode from 'vscode'
import { exec, exists } from './node'
import { exec, exists } from '../node'

export async function isEmptyWorkspace(): Promise<boolean> {
const { stdout, stderr } = await exec('ls')
Expand Down