6
6
isOSX = ( process . platform === 'darwin' ) ,
7
7
isWindows = ( process . platform === 'win32' ) ;
8
8
9
+ let unset ;
10
+
9
11
class PackDir {
10
12
constructor ( ) {
11
13
this . params = {
@@ -37,20 +39,23 @@ class PackDir {
37
39
}
38
40
}
39
41
40
- dmg ( path ) {
41
- let fileName = path + this . DMG ;
42
+ dmg ( path , callback ) {
43
+ let fileName = path + this . DMG ,
44
+ cmd = `hdiutil create -format ${ this . params . dmgFormat } -srcfolder "${ path } " "${ fileName } "` ;
42
45
43
46
this . cleanFile ( fileName ) ;
44
- this . exec ( ) ( `hdiutil create -format ${ this . params . dmgFormat } -srcfolder " ${ path } " " ${ fileName } "` ) ;
47
+ this . exec ( cmd , unset , callback || unset ) ;
45
48
this . log ( `DMG file created: "${ fileName } "` ) ;
46
49
47
50
return fileName ;
48
51
}
49
52
50
- exec ( ) {
51
- return this . params . isSync
53
+ exec ( cmd , params , callback ) {
54
+ let execute = this . params . isSync
52
55
? require ( 'child_process' ) . execSync
53
56
: require ( 'child_process' ) . exec ;
57
+
58
+ return execute ( cmd , params , callback ) ;
54
59
}
55
60
56
61
extract ( path , destination ) {
@@ -76,17 +81,17 @@ class PackDir {
76
81
return this . unzip ( path , destination ) ;
77
82
}
78
83
79
- path ( path ) {
84
+ path ( path , callback ) {
80
85
try {
81
86
if ( ! FS . existsSync ( path ) ) {
82
87
console . error ( `Specified path does not exist: "${ path } ".` ) ;
83
88
return false ;
84
89
}
85
90
86
91
if ( this . asDMG ( path ) ) {
87
- return this . dmg ( path ) ;
92
+ return this . dmg ( path , callback ) ;
88
93
} else {
89
- return this . zip ( path ) ;
94
+ return this . zip ( path , callback ) ;
90
95
}
91
96
}
92
97
catch ( e ) {
@@ -96,13 +101,13 @@ class PackDir {
96
101
return false ;
97
102
}
98
103
99
- paths ( paths ) {
104
+ paths ( paths , callback ) {
100
105
let packs = false ;
101
106
102
107
if ( Array . isArray ( paths ) ) {
103
108
// Recursive packing for Array of paths
104
109
packs = paths . map ( path => {
105
- return this . path ( path ) ;
110
+ return this . path ( path , callback ) ;
106
111
} ) ;
107
112
}
108
113
@@ -138,20 +143,20 @@ class PackDir {
138
143
return this . params [ name ] = value ;
139
144
}
140
145
141
- unzip ( path , destination ) {
146
+ unzip ( path , destination , callback ) {
142
147
let pathInfo = Path . parse ( path ) ,
143
148
pathToUnZip = isWindows
144
149
? this . getUnZipPath ( )
145
150
: 'unzip' ,
146
151
extractTo = destination || pathInfo . dir ,
147
152
cmd = `${ pathToUnZip } -o "${ path } " -d "${ extractTo } "` ;
148
153
149
- this . exec ( ) ( cmd ) ;
154
+ this . exec ( cmd , unset , callback || unset ) ;
150
155
151
156
return extractTo ;
152
157
}
153
158
154
- zip ( path ) {
159
+ zip ( path , callback ) {
155
160
let fileName = path + this . ZIP ,
156
161
pathInfo = Path . parse ( path ) ,
157
162
pathStat = FS . statSync ( path ) ,
@@ -169,7 +174,7 @@ class PackDir {
169
174
}
170
175
171
176
this . cleanFile ( fileName ) ;
172
- this . exec ( ) ( cmd , params ) ;
177
+ this . exec ( cmd , params , callback || unset ) ;
173
178
this . log ( `ZIP archive created: "${ fileName } "` ) ;
174
179
175
180
return fileName ;
0 commit comments