1- import { editorInsert , editorOpen , editorSave , editorSet } from '../../../actions' ;
1+ import { editorInsert , editorOpen , editorSave , editorSet , editorWriteFileFromContent , editorWriteFileFromFile } from '../../../actions' ;
22import store from '../../../store' ;
3- import { getCommand , getOptions , getParams } from './parser' ;
3+ import actionWrite from '../@actions/write' ;
4+ import { getCommand , getOptions , getParams } from './parser' ;
45
56const Type = {
67 OPEN : 'open' ,
78 SET : 'set' ,
89 INSERT : 'insert' ,
910 OPEN_CONSOLE : 'openConsole' ,
11+ WRITE : 'write' ,
12+ WRITE_FROM_FILE : 'writeFromFile' ,
1013} ;
1114
1215// parse task string for command/params
@@ -61,6 +64,25 @@ export default function handleActionString(
6164 // }
6265 // break;
6366
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+
6486 default :
6587 console . log ( 'Invalid editor action command' ) ;
6688 reject ( false ) ;
@@ -69,3 +91,8 @@ export default function handleActionString(
6991 console . error ( 'Error handling action string' , err ) ;
7092 } ) ;
7193}
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