-
Notifications
You must be signed in to change notification settings - Fork 16
Added: iron-man-with-gauntlet flag #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
b0ee092
678fde4
4c18566
46e3adc
ed820d6
d5ddefc
de6ceb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ const constants = require('../constants'); | |
const cwd = process.cwd(); | ||
|
||
module.exports = () => { | ||
|
||
if(!fs.existsSync(`${os.homedir()}/.to-dust`)) { | ||
fs.mkdirSync(`${os.homedir()}/.to-dust`); | ||
} | ||
|
||
const gonnaSnapFingers = readArgs(constants.arguments.snapFingers, false); | ||
const gonnaUseGlove = readArgs(constants.arguments.withGlove); | ||
const noMercy = readArgs(constants.arguments.noMercy); | ||
|
@@ -25,6 +30,24 @@ module.exports = () => { | |
logger.log(`😈 Snapping fingers inside '${cwd}' with full power...`); | ||
} | ||
|
||
const ironManWithGauntlet = readArgs(constants.arguments.ironManWithGauntlet); | ||
|
||
if(ironManWithGauntlet) { | ||
logger.log(`I... am... Iron Man!`); | ||
const correctPaths = JSON.parse(fs.readFileSync(`${os.homedir()}/.to-dust/correct-paths.json`, 'utf8')); | ||
|
||
correctPaths.forEach((filePath) => { | ||
let splitFilePath = filePath.file.split('/'); | ||
let filename = splitFilename.join('-'); | ||
fs.rename(aFile.file, `${os.homedir()}/.to-dust/${filename}`, (err) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the sequence of argument would be reverse. We would want to move files from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, actually I was having a test branch where I was doing all this and after the fork, I just copied pasted stuff around which caused these issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested it and it works now, do let me know if you find any more issues :) |
||
if(err) throw err; | ||
}) | ||
}); | ||
|
||
logger.log(`Yours file have been restored`); | ||
process.exit(0); | ||
} | ||
|
||
/** | ||
* Takes the name of the directory and determines whether it is safe to traverse on the directory or not | ||
* For now, | ||
|
@@ -62,10 +85,19 @@ module.exports = () => { | |
? filesWithChancesSorted.slice(0, filesWithChancesSorted.length / 2) | ||
: filesWithChancesSorted.slice(filesWithChancesSorted.length / 2); | ||
|
||
fs.writeFile(`${os.homedir()}/.to-dust/correct-paths.json`, JSON.stringify(filesToBeDeleted, null, 4), (err) => { | ||
if(err) throw err; | ||
}); | ||
|
||
let deletedFilesCount = 0; | ||
filesToBeDeleted.forEach((aFile) => { | ||
try { | ||
fs.unlinkSync(aFile.file); | ||
// fs.unlinkSync(aFile.file); | ||
let splitFilename = aFile.file.split('/'); | ||
let filename = splitFilename.join('-'); | ||
fs.rename(aFile.file, `${os.homedir()}/.to-dust/${filename}`, (err) => { | ||
if(err) throw err; | ||
}) | ||
// In case `unlinkSync` throws an Exception, deletedFilesCount won't be incremented | ||
// This way, we would have the precise deletion count. | ||
deletedFilesCount++; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this will throw en error in case the
.to-dust
is not already existing.. You might want to first create the directoryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my bad, I put that checking condition below. I'll move it up.