-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
that we will need in bunch of places so maybe better than echo
- Loading branch information
Showing
3 changed files
with
34 additions
and
3 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
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,29 @@ | ||
#!/usr/bin/env node | ||
import fs from 'node:fs' | ||
|
||
/** | ||
* This is used to workaround the fact that many applications such as | ||
* webpack does not natively know how to import / bundle JSON files | ||
* And we also don't want to use something ugly heavy handed like a roll up | ||
* So simpliest solution is to rewrite the JSON file as a JS file | ||
*/ | ||
const jsonFileName = process.argv[2] | ||
|
||
if (!jsonFileName) { | ||
console.error('Please provide a JSON file name as a command line argument.') | ||
process.exit(1) | ||
} | ||
|
||
try { | ||
const jsonData = fs.readFileSync(jsonFileName, 'utf8') | ||
const jsFileName = `${jsonFileName}.js` | ||
const jsContent = `module.exports = \n${jsonData}` | ||
|
||
fs.writeFileSync(jsFileName, jsContent, 'utf8') | ||
fs.rmSync(jsonFileName) | ||
|
||
console.log(`Successfully generated ${jsFileName} with JSON content.`) | ||
} catch (err) { | ||
console.error('An error occurred while generating the JavaScript file:', err) | ||
process.exit(1) | ||
} |
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