-
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.
Merge pull request #13 from wp-blocks/splitting-bin
move bin script to a separate file
- Loading branch information
Showing
7 changed files
with
122 additions
and
53 deletions.
There are no files selected for viewing
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
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,49 @@ | ||
#!/usr/bin/env node | ||
|
||
// Run the script as an async function | ||
import { humanFileSize, logMessage } from "./utils.js"; | ||
import { OutputData } from "./types.js"; | ||
import squashify from "./index.js"; | ||
import { getCliOptions } from "./parseArgs.js"; | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
import process from "node:process"; | ||
|
||
// Get the cli settings | ||
export default async function main() { | ||
const cliOptions = getCliOptions(yargs(hideBin(process.argv))); | ||
|
||
squashify(cliOptions) | ||
.then((response) => { | ||
const { timeElapsed, result, verbose } = response; | ||
|
||
if (result.length) { | ||
result.forEach((result) => { | ||
if (result.status !== "fulfilled") { | ||
logMessage("🔴 " + result.reason, true); | ||
} else { | ||
const { status, value } = | ||
result as PromiseFulfilledResult<OutputData>; | ||
logMessage( | ||
"✅ " + | ||
JSON.stringify( | ||
"size" in value | ||
? { ...value, size: humanFileSize(value.size) } | ||
: value, | ||
), | ||
verbose, | ||
); | ||
} | ||
return; | ||
}); | ||
} | ||
|
||
// Print the time elapsed in seconds to the console | ||
logMessage(`The end 🎉 - Time elapsed: ${timeElapsed} seconds`, true); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
} | ||
|
||
await main(); |
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