-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#34 unsort maps
- Loading branch information
Showing
8 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,6 @@ yarn-debug.log* | |
yarn-error.log* | ||
|
||
# downloads | ||
cncnet-yuri-maps* | ||
cncnet-* | ||
experiment | ||
packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const { getRecursiveFileList, removeDirectory } = require('./util'); | ||
const { getConfig } = require('./configuration'); | ||
|
||
/** | ||
* Given a path, removes all empty directoies in that path | ||
* | ||
* @param {string} targetDir Target directory to remove empty directories in. | ||
*/ | ||
const deleteEmptyDirectories = async (targetDir) => { | ||
const targetDirFilelist = fs.readdirSync(targetDir).filter((filePath) => { | ||
try { | ||
return fs.statSync(path.resolve(targetDir, filePath)).isDirectory(); | ||
} catch (error) { | ||
if (getConfig().debug) { | ||
console.error('Failed to stat file', error); | ||
} | ||
return false; | ||
} | ||
}); | ||
|
||
const dirFilelists = await Promise.all( | ||
targetDirFilelist.map(async (dirPath) => { | ||
const absolutePath = path.resolve(targetDir, dirPath); | ||
const filelist = await getRecursiveFileList(absolutePath); | ||
|
||
return { | ||
filelist, | ||
dirPath, | ||
}; | ||
}) | ||
); | ||
const emptyDirs = dirFilelists | ||
.filter(({ filelist }) => { | ||
return filelist.length === 0; | ||
}) | ||
.map(({ dirPath }) => dirPath); | ||
|
||
const dirRemovalPromises = emptyDirs.map(removeDirectory(targetDir)); | ||
return Promise.all(dirRemovalPromises); | ||
}; | ||
|
||
module.exports = { | ||
deleteEmptyDirectories, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const { getConfig } = require('./configuration'); | ||
const { getRecursiveFileList, moveFile } = require('./util'); | ||
|
||
/** | ||
* Given a path, unsorts files, essentially flattening all directories. | ||
* | ||
* @param {string} targetDir Target directory to sort files in. | ||
*/ | ||
const unsortMaps = async (targetDir) => { | ||
console.log(`\nUn-sorting maps...`); | ||
|
||
const targetDirFilelist = (await getRecursiveFileList(targetDir)).filter((filePath) => { | ||
try { | ||
return fs.statSync(path.resolve(targetDir, filePath)).isFile(); | ||
} catch (error) { | ||
if (getConfig().debug) { | ||
console.error('Failed to stat file', error); | ||
} | ||
return false; | ||
} | ||
}); | ||
|
||
return targetDirFilelist.map(async (filePath) => { | ||
try { | ||
const fileName = filePath.slice(filePath.lastIndexOf('/') + 1); | ||
|
||
await moveFile(path.resolve(targetDir, filePath), path.resolve(targetDir, fileName)); | ||
} catch (error) { | ||
if (getConfig().debug) { | ||
console.error('Failed to move file', error); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
unsortMaps, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters