@@ -2,9 +2,15 @@ import { mkdirSync, readFile, writeFile } from 'fs';
2
2
import fileExists from 'node-file-exists' ;
3
3
import { join } from 'path' ;
4
4
5
- export function writeFileFromContent ( { to, content, dir} ) {
5
+ /**
6
+ * writes content to a user file
7
+ * @param { } {to user file path
8
+ * @param { } content text editor content
9
+ * @param { } dir} user directory
10
+ */
11
+ export function writeFileFromContent ( { to, content, dir} ) : void {
6
12
const toAbs = join ( dir , to ) ;
7
- createFolders ( { dir, to} ) . then ( ( ) => {
13
+ createFolder ( { dir, to} ) . then ( ( ) => {
8
14
writeFile ( toAbs , content , ( writeErr ) => {
9
15
if ( writeErr ) {
10
16
console . log ( `Error: tried but failed to write to ${ toAbs } with: ${ content } ` , writeErr ) ;
@@ -14,11 +20,19 @@ export function writeFileFromContent({to, content, dir}) {
14
20
} ) ;
15
21
}
16
22
17
- export function writeFileFromFile ( { to, from, dir, tutorialDir} ) {
23
+ /**
24
+ * writes from a tutorial file to a user file
25
+ * @param { } {to user file path
26
+ * @param { } from tutorial file path
27
+ * @param { } dir user directory
28
+ * @param { } tutorialDir} tutorial directory
29
+ * @returns void
30
+ */
31
+ export function writeFileFromFile ( { to, from, dir, tutorialDir} ) : void {
18
32
const toAbs = join ( dir , to ) ;
19
33
const fromAbs = join ( tutorialDir , from ) ;
20
34
21
- createFolders ( { dir, to} ) . then ( ( ) => {
35
+ createFolder ( { dir, to} ) . then ( ( ) => {
22
36
// writes { to: './dest.js', from: '' }
23
37
readFile ( fromAbs , 'utf8' , ( readErr , data ) => {
24
38
const err = `Error: tried to write '${ fromAbs } ' to '${ toAbs } ' but failed.` ;
@@ -31,7 +45,12 @@ export function writeFileFromFile({to, from, dir, tutorialDir}) {
31
45
} ) ;
32
46
}
33
47
34
- function createFolders ( { dir, to} ) {
48
+ /**
49
+ * create user folder
50
+ * @param { } {dir user directory
51
+ * @param { } to} user folder path
52
+ */
53
+ function createFolder ( { dir, to} ) : Promise < any > {
35
54
return new Promise ( ( resolve , reject ) => {
36
55
// extract folders without final file name
37
56
const folders = to . split ( '/' ) . slice ( 0 , - 1 ) ;
0 commit comments