@@ -32,53 +32,59 @@ import { fileURLToPath } from "url";
32
32
import { log } from "./util-log.js" ;
33
33
import { promiseAll , splitMapTrim } from "../ext-ramda.js" ;
34
34
35
- const deleteFiles = compose ( promiseAll , map ( unlink ) ) ;
35
+ export const deleteFiles = compose ( promiseAll , map ( unlink ) ) ;
36
36
37
- const dirnameFromMetaUrl = ( metaUrl ) => {
37
+ // snippet-start:[javascript.v3.utils.dirnameFromMetaUrl]
38
+ export const dirnameFromMetaUrl = ( metaUrl ) => {
38
39
return fileURLToPath ( new URL ( "." , metaUrl ) ) ;
39
40
} ;
41
+ // snippet-end:[javascript.v3.utils.dirnameFromMetaUrl]
40
42
41
- const getDelimitedEntries = curry ( ( delimiter , str ) =>
43
+ export const getDelimitedEntries = curry ( ( delimiter , str ) =>
42
44
pipe ( getTmp , defaultTo ( "" ) , splitMapTrim ( delimiter ) ) ( str )
43
45
) ;
44
46
45
- const getNewLineDelimitedEntries = getDelimitedEntries ( "\n" ) ;
47
+ export const getNewLineDelimitedEntries = getDelimitedEntries ( "\n" ) ;
46
48
47
- const getTmp = tryCatch (
49
+ export const getTmp = tryCatch (
48
50
( name ) => readFileSync ( `./${ name } .tmp` , { encoding : "utf-8" } ) ,
49
51
always ( null )
50
52
) ;
51
53
52
- const setTmp = ( name , data ) =>
54
+ export const setTmp = ( name , data ) =>
53
55
writeFileSync ( `./${ name } .tmp` , data , { encoding : "utf-8" } ) ;
54
56
55
- const handleZipWarning = ( resolve ) => ( w ) => {
57
+ export const handleZipWarning = ( resolve ) => ( w ) => {
56
58
log ( w ) ;
57
59
resolve ( ) ;
58
60
} ;
59
61
60
- const handleZipEnd = ( resolve , path ) => async ( ) => {
62
+ export const handleZipEnd = ( resolve , path ) => async ( ) => {
61
63
log ( `Zipped successfully.` ) ;
62
64
const buffer = await readFile ( path ) ;
63
65
resolve ( buffer ) ;
64
66
} ;
65
67
66
- const makeDir = ifElse ( existsSync , identity , tap ( mkdirSync ) ) ;
68
+ export const makeDir = ifElse ( existsSync , identity , tap ( mkdirSync ) ) ;
67
69
68
- const readLines = pipe ( readFileSync , invoker ( 0 , "toString" ) , split ( "\n" ) ) ;
70
+ export const readLines = pipe (
71
+ readFileSync ,
72
+ invoker ( 0 , "toString" ) ,
73
+ split ( "\n" )
74
+ ) ;
69
75
70
- const readSubdirSync = pipe (
76
+ export const readSubdirSync = pipe (
71
77
readdirSync ,
72
78
filter ( invoker ( 0 , "isDirectory" ) ) ,
73
79
map ( prop ( "name" ) )
74
80
) ;
75
81
76
82
/**
77
- *
78
- * @param {string } inputPath
83
+ *
84
+ * @param {string } inputPath
79
85
* @returns {Promise<Buffer> }
80
86
*/
81
- const zip = ( inputPath ) =>
87
+ export const zip = ( inputPath ) =>
82
88
new Promise ( ( resolve , reject ) => {
83
89
try {
84
90
readdirSync ( inputPath ) ;
@@ -102,16 +108,3 @@ const zip = (inputPath) =>
102
108
archive . directory ( inputPath , false ) ;
103
109
archive . finalize ( ) ;
104
110
} ) ;
105
-
106
- export {
107
- deleteFiles ,
108
- dirnameFromMetaUrl ,
109
- getTmp ,
110
- makeDir ,
111
- readLines ,
112
- readSubdirSync ,
113
- getDelimitedEntries ,
114
- getNewLineDelimitedEntries ,
115
- setTmp ,
116
- zip ,
117
- } ;
0 commit comments