1
- import { editorInsert , editorOpen , editorSave , editorSet } from '../../../actions' ;
1
+ import { editorInsert , editorOpen , editorSave , editorSet , editorWriteFileFromContent , editorWriteFileFromFile } from '../../../actions' ;
2
2
import store from '../../../store' ;
3
- import { getCommand , getOptions , getParams } from './parser' ;
3
+ import actionWrite from '../@actions/write' ;
4
+ import { getCommand , getOptions , getParams } from './parser' ;
4
5
5
6
const Type = {
6
7
OPEN : 'open' ,
7
8
SET : 'set' ,
8
9
INSERT : 'insert' ,
9
10
OPEN_CONSOLE : 'openConsole' ,
11
+ WRITE : 'write' ,
12
+ WRITE_FROM_FILE : 'writeFromFile' ,
10
13
} ;
11
14
12
15
// parse task string for command/params
@@ -61,6 +64,25 @@ export default function handleActionString(
61
64
// }
62
65
// break;
63
66
67
+ case Type . WRITE :
68
+ case Type . WRITE_FROM_FILE :
69
+ if ( params . length === 2 ) {
70
+
71
+ // write
72
+ if ( command === 'write' ) {
73
+ const [ to , content ] = params ;
74
+ store . dispatch ( editorWriteFileFromContent ( to , content ) ) ;
75
+
76
+ // writeFromFile
77
+ } else if ( command === 'writeFromFile' ) {
78
+ const [ to , from ] = params ;
79
+ store . dispatch ( editorWriteFileFromFile ( to , from ) ) ;
80
+ }
81
+ resolve ( ) ;
82
+ }
83
+ reject ( 'Invalid write params' ) ;
84
+ break ;
85
+
64
86
default :
65
87
console . log ( 'Invalid editor action command' ) ;
66
88
reject ( false ) ;
@@ -69,3 +91,8 @@ export default function handleActionString(
69
91
console . error ( 'Error handling action string' , err ) ;
70
92
} ) ;
71
93
}
94
+
95
+ function isValidPath ( filePath : string ) : boolean {
96
+ // should not go above users tutorial directory for security reasons
97
+ return ! filePath . match ( / ^ \. \. / ) ;
98
+ }
0 commit comments