@@ -15,9 +15,10 @@ import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
15
15
// todo: figure out embedded images etc. served from elsewhere in the project
16
16
// todo: prettier/clearer CSS
17
17
18
+ let unpackedDir = path . join ( __dirname , 'unpacked' ) ;
19
+
18
20
// bundle up the test-running JS
19
21
function createUnpackedBundle ( ) {
20
- let unpackedDir = path . join ( __dirname , 'unpacked' ) ;
21
22
fs . mkdirp ( unpackedDir , ( err ) => {
22
23
if ( err && err . code !== 'EEXIST' ) {
23
24
console . log ( err ) ;
@@ -44,20 +45,34 @@ function createUnpackedBundle() {
44
45
45
46
let currentlyUnpackingDir = null ;
46
47
48
+ async function cleanUnpackedDir ( unpackedChallengeBlockDir ) {
49
+ let promiseToDelete = function ( filePath ) {
50
+ filePath = path . join ( unpackedChallengeBlockDir , filePath ) ;
51
+ return new Promise ( ( ) => fs . unlink ( filePath ) ) ;
52
+ } ;
53
+ let promises = fs . readdirSync ( unpackedChallengeBlockDir )
54
+ . filter ( filePath => ( / \. h t m l $ / i) . test ( filePath ) )
55
+ . map ( promiseToDelete ) ;
56
+ await Promise . all ( promises ) ;
57
+ }
58
+
47
59
function unpackChallengeBlock ( challengeBlock ) {
48
60
let challengeBlockPath = path . parse ( challengeBlock . fileName ) ;
49
61
let unpackedChallengeBlockDir = path . join (
50
- __dirname ,
51
- 'unpacked' ,
62
+ unpackedDir ,
52
63
challengeBlockPath . dir ,
53
64
challengeBlockPath . name
54
65
) ;
66
+
55
67
fs . mkdirp ( unpackedChallengeBlockDir , ( err ) => {
56
68
if ( err && err . code !== 'EEXIST' ) {
57
69
console . log ( err ) ;
58
70
throw err ;
59
71
}
60
72
73
+ // remove existing unpacked files
74
+ cleanUnpackedDir ( unpackedChallengeBlockDir ) ;
75
+
61
76
if ( currentlyUnpackingDir !== challengeBlockPath . dir ) {
62
77
currentlyUnpackingDir = challengeBlockPath . dir ;
63
78
console . log ( `Unpacking into ${ currentlyUnpackingDir } :` ) ;
0 commit comments