Skip to content

Commit 9a8b781

Browse files
committed
create write file, readwrite file
1 parent 4e57617 commit 9a8b781

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/services/write.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
function getPath(filePath: string) {
5+
return path.normalize(path.join(window.coderoad.dir, filePath));
6+
}
7+
8+
export function write(filePath: string, text) {
9+
try {
10+
fs.writeFileSync(getPath(filePath), text, 'utf8');
11+
} catch (e) {
12+
if (e) { console.log('Error writing to filePath', filePath); }
13+
}
14+
}
15+
16+
export function readWrite(writePath: string, readPath: string) {
17+
try {
18+
write(writePath, fs.readFileSync(getPath(readPath)));
19+
} catch (e) {
20+
if (e) { console.log('Error reading from filePath', readPath); }
21+
}
22+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"src/services/setup-actions.ts",
9696
"src/services/setup-checks.ts",
9797
"src/services/tutorials.ts",
98+
"src/services/write.ts",
9899
"src/store/initialState.ts",
99100
"src/store/store.ts",
100101
"src/components/account/account.tsx",

0 commit comments

Comments
 (0)