Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0f7bce

Browse files
committed
cleanup stepAction loading
1 parentd7b7ed3 commita0f7bce

File tree

9 files changed

+45
-42
lines changed

9 files changed

+45
-42
lines changed

‎src/Channel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class Channel implements Channel {
2828
tutorialConfig(action.payload)
2929
return
3030
case'SETUP_ACTIONS':
31+
console.log(action.payload)
3132
setupActions(action.payload)
3233
return
3334
case'SOLUTION_ACTIONS':
35+
console.log(action.payload)
3436
solutionActions(action.payload)
3537
return
3638
default:

‎src/actions/runTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asvscodefrom'vscode'
2-
import{exec}from'../services/node'
2+
importnodefrom'../services/node'
33

44
// ensure only latest run_test action is taken
55
letcurrentId=0
@@ -50,7 +50,7 @@ export default async function runTest({onSuccess, onFail}: Props): Promise<void>
5050
try{
5151
// capture position early on test start
5252
// in case position changes
53-
const{stdout}=awaitexec(commandLine)
53+
const{stdout}=awaitnode.exec(commandLine)
5454
if(shouldExitEarly(processId)){
5555
// exit early
5656
return
@@ -98,7 +98,7 @@ export default async function runTest({onSuccess, onFail}: Props): Promise<void>
9898
console.error('SOMETHING WENT WRONG WITH A PASSING TEST')
9999
}
100100
// test runner failed
101-
constchannel=getOutputChannel(outputChannelName)
101+
channel=getOutputChannel(outputChannelName)
102102

103103
if(stdout){
104104
constlines=stdout.split(/\r{0,1}\n/)

‎src/actions/setupActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as G from 'typings/graphql'
22
import{join}from'path'
33
import*asvscodefrom'vscode'
44
import*asgitfrom'../services/git'
5-
import{exec}from'../services/node'
5+
importnodefrom'../services/node'
66

77
interfaceErrorMessageFilter{
88
[lang:string]:{
@@ -25,7 +25,7 @@ const setupActions = async ({commands, commits, files}: G.StepActions): Promise<
2525

2626
// run command
2727
for(constcommandofcommands){
28-
const{stdout, stderr}=awaitexec(command)
28+
const{stdout, stderr}=awaitnode.exec(command)
2929
if(stderr){
3030
console.error(stderr)
3131
// language specific error messages from running commands

‎src/editor/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import*asvscodefrom'vscode'
2-
import{setWorkspaceRoot}from'../services/node'
32
import{createCommands}from'./commands'
43

54
classEditor{
@@ -9,12 +8,10 @@ class Editor {
98

109
constructor(){
1110
// set workspace root for node executions
12-
const{workspace}=vscode
13-
const{rootPath}=workspace
11+
constrootPath=vscode.workspace.rootPath
1412
if(!rootPath){
1513
thrownewError('Requires a workspace. Please open a folder')
1614
}
17-
setWorkspaceRoot(rootPath)
1815
}
1916
publicactivate=(vscodeExt:vscode.ExtensionContext):void=>{
2017
console.log('ACTIVATE!')

‎src/editor/workspace.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import*asfsfrom'fs'
22
import*aspathfrom'path'
33
import*asvscodefrom'vscode'
4-
import{exec,exists}from'../services/node'
4+
importnodefrom'../services/node'
55

66
exportasyncfunctionisEmptyWorkspace():Promise<boolean>{
7-
const{stdout, stderr}=awaitexec('ls')
7+
const{stdout, stderr}=awaitnode.exec('ls')
88
if(stderr){
99
thrownewError('Error validating if project is empty')
1010
}
@@ -13,15 +13,15 @@ export async function isEmptyWorkspace(): Promise<boolean> {
1313

1414
// // TODO: workspace change listener
1515
exportasyncfunctionopenReadme():Promise<void>{
16-
const{stderr}=awaitexec('ls')
16+
const{stderr}=awaitnode.exec('ls')
1717
if(stderr){
1818
thrownewError('Error looking for initial file')
1919
}
2020

2121
constfile='README.md'
2222
constfilePath=path.join(vscode.workspace.rootPath||'',file)
2323
console.log('filePath',filePath)
24-
consthasReadme=awaitexists(file)
24+
consthasReadme=awaitnode.exists(file)
2525

2626
if(!hasReadme){
2727
// add readme if none exists

‎src/services/git/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import*asCRfrom'typings'
2-
import{exec,exists}from'../node'
2+
importnodefrom'../node'
33

44

55
constgitOrigin='coderoad'
66

77
conststashAllFiles=async()=>{
88
console.log('stashAllFiles')
99
// stash files including untracked (eg. newly created file)
10-
const{stdout, stderr}=awaitexec(`git stash --include-untracked`)
10+
const{stdout, stderr}=awaitnode.exec(`git stash --include-untracked`)
1111
if(stderr){
1212
console.error(stderr)
1313
thrownewError('Error stashing files')
@@ -20,7 +20,7 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<void> => {
2020
return
2121
}
2222
try{
23-
const{stdout}=awaitexec(`git cherry-pick${commit}`)
23+
const{stdout}=awaitnode.exec(`git cherry-pick${commit}`)
2424
if(!stdout){
2525
thrownewError('No cherry-pick output')
2626
}
@@ -49,7 +49,7 @@ export function loadCommit(commit: string): Promise<void> {
4949

5050
exportasyncfunctionsaveCommit(position:CR.Position):Promise<void>{
5151
const{levelId, stageId, stepId}=position
52-
const{stdout, stderr}=awaitexec(`git commit -am 'completed${levelId}/${stageId}/${stepId}'`)
52+
const{stdout, stderr}=awaitnode.exec(`git commit -am 'completed${levelId}/${stageId}/${stepId}'`)
5353
if(stderr){
5454
console.error(stderr)
5555
thrownewError('Error saving progress to Git')
@@ -60,7 +60,7 @@ export async function saveCommit(position: CR.Position): Promise<void> {
6060
exportasyncfunctionclear():Promise<void>{
6161
try{
6262
// commit progress to git
63-
const{stderr}=awaitexec('git reset HEAD --hard && git clean -fd')
63+
const{stderr}=awaitnode.exec('git reset HEAD --hard && git clean -fd')
6464
if(!stderr){
6565
return
6666
}
@@ -72,7 +72,7 @@ export async function clear(): Promise<void> {
7272
}
7373

7474
exportasyncfunctionversion():Promise<string|boolean>{
75-
const{stdout, stderr}=awaitexec('git --version')
75+
const{stdout, stderr}=awaitnode.exec('git --version')
7676
if(!stderr){
7777
constmatch=stdout.match(/^gitversion(\d+\.)?(\d+\.)?(\*|\d+)/)
7878
if(match){
@@ -85,7 +85,7 @@ export async function version(): Promise<string | boolean> {
8585
}
8686

8787
asyncfunctioninit():Promise<void>{
88-
const{stderr}=awaitexec('git init')
88+
const{stderr}=awaitnode.exec('git init')
8989
if(stderr){
9090
thrownewError('Error initializing Gits')
9191
}
@@ -98,14 +98,14 @@ export async function initIfNotExists(): Promise<void> {
9898
thrownewError('Git must be installed')
9999
}
100100

101-
consthasGitInit=exists('.git')
101+
consthasGitInit=node.exists('.git')
102102
if(!hasGitInit){
103103
awaitinit()
104104
}
105105
}
106106

107107
exportasyncfunctionaddRemote(repo:string):Promise<void>{
108-
const{stderr}=awaitexec(`git remote add${gitOrigin}${repo} && git fetch${gitOrigin}`)
108+
const{stderr}=awaitnode.exec(`git remote add${gitOrigin}${repo} && git fetch${gitOrigin}`)
109109
if(stderr){
110110
constalreadyExists=stderr.match(`${gitOrigin} already exists.`)
111111
constsuccessfulNewBranch=stderr.match('new branch')
@@ -120,7 +120,7 @@ export async function addRemote(repo: string): Promise<void> {
120120

121121
exportasyncfunctioncheckRemoteExists():Promise<boolean>{
122122
try{
123-
const{stdout, stderr}=awaitexec('git remote -v')
123+
const{stdout, stderr}=awaitnode.exec('git remote -v')
124124
if(stderr){
125125
returnfalse
126126
}

‎src/services/node/index.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import*asfsfrom'fs'
2-
import{join}from'path'
3-
import{execascpExec}from'child_process'
4-
import{promisify}from'util'
2+
import{join}from'path'
3+
import{execascpExec}from'child_process'
4+
import{promisify}from'util'
5+
import*asvscodefrom'vscode'
56

67
constasyncExec=promisify(cpExec)
78

8-
letworkspaceRoot:string
9+
classNode{
10+
privateworkspaceRoot:string
11+
constructor(){
12+
this.workspaceRoot=vscode.workspace.rootPath||''
13+
if(!this.workspaceRoot.length){
14+
thrownewError('Invalid workspaceRoot')
15+
}
16+
console.log(`workspaceRoot:${this.workspaceRoot}`)
17+
}
18+
publicexec=(cmd:string):Promise<{stdout:string;stderr:string}>=>asyncExec(cmd,{
19+
cwd:this.workspaceRoot,
20+
})
921

10-
// set workspace root
11-
// other function will use this to target the correct cwd
12-
exportfunctionsetWorkspaceRoot(rootPath:string):void{
13-
workspaceRoot=rootPath
22+
publicexists=(...paths:string[]):boolean=>fs.existsSync(join(this.workspaceRoot, ...paths))
1423
}
1524

16-
exportconstexec=(cmd:string):Promise<{stdout:string;stderr:string}>=>
17-
asyncExec(cmd,{
18-
cwd:workspaceRoot,
19-
})
25+
exportdefaultnewNode()
2026

21-
// note: fs.exists is deprecated
22-
// collect all paths together
23-
exportconstexists=(...paths:string[]):boolean=>fs.existsSync(join(workspaceRoot, ...paths))
2427

2528
// export async function clear(): Promise<void> {
2629
// // remove all files including ignored

‎web-app/src/services/state/actions/editor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import*asGfrom'typings/graphql'
12
import*asCRfrom'typings'
23
import*asselectorsfrom'../../selectors'
34
importchannelfrom'../../channel'
@@ -31,7 +32,7 @@ export default {
3132
})
3233
},
3334
loadLevel(context:CR.MachineContext):void{
34-
constlevel=selectors.currentLevel(context)
35+
constlevel:G.Level=selectors.currentLevel(context)
3536
if(level.setup){
3637
// load step actions
3738
channel.editorSend({
@@ -41,7 +42,7 @@ export default {
4142
}
4243
},
4344
loadStage(context:CR.MachineContext):void{
44-
conststage=selectors.currentStage(context)
45+
conststage:G.Stage=selectors.currentStage(context)
4546
if(stage.setup){
4647
// load step actions
4748
channel.editorSend({
@@ -51,7 +52,7 @@ export default {
5152
}
5253
},
5354
loadStep(context:CR.MachineContext):void{
54-
conststep=selectors.currentStep(context)
55+
conststep:G.Step=selectors.currentStep(context)
5556
if(step.setup){
5657
// load step actions
5758
channel.editorSend({

‎web-app/src/services/state/machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
105105
},
106106
Stage:{
107107
id:'tutorial-stage',
108-
onEntry:['loadStage'],
108+
onEntry:['loadStage','loadStep'],
109109
initial:'Normal',
110110
states:{
111111
Normal:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp