-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring findBreakUrl to improve code maintainability
*extract fileDirectory(), put that into fileRead.js *variables name changed *split index.js to fileRead.js and index.js
- Loading branch information
Showing
4 changed files
with
51 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require("fs"); | ||
const chalk = require('chalk') | ||
|
||
const fileRead = (file) => { | ||
let fileData = null; | ||
|
||
try { | ||
fileData = fs.readFileSync(`${__dirname}\\${file}`, { | ||
encoding: "utf-8", | ||
}); | ||
|
||
// wrong file name | ||
} catch (error) { | ||
console.log(file + " is a WRONG file name"); | ||
return process.exit(1); | ||
} | ||
return fileData; | ||
} | ||
|
||
const readDirectory = (yargs) => { | ||
let files = []; | ||
if (yargs.argv._.length === 1 && yargs.argv._[0] === "start") { | ||
|
||
// decide the option if it is -f or -a | ||
if (yargs.argv.a && typeof yargs.argv.f !== "string") { | ||
const tmpFiles = fs.readdirSync(__dirname, { encoding: "utf-8" }); | ||
|
||
// if -a, store all files into the files variable | ||
files = tmpFiles.filter((file) => { | ||
return file.toLowerCase().endsWith(".html"); | ||
}); | ||
|
||
} else if (typeof yargs.argv.f === "string") { | ||
files = [...yargs.argv.f.split(",")]; | ||
} else { | ||
console.log(chalk.yellow("Please enter filenames or -a following -f")) | ||
} | ||
return files; | ||
} else { | ||
console.log(chalk.yellow("Wrong argument: use [start]")); | ||
} | ||
} | ||
|
||
module.exports = { fileRead, readDirectory } |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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