Skip to content

Commit

Permalink
Setup node bin
Browse files Browse the repository at this point in the history
  • Loading branch information
roim committed May 11, 2021
1 parent 7f9fd61 commit d00f7b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
"version": "1.0.0",
"description": "btoj (Binary to JavaScript) is a utility that converts binary files into pure JavaScript modules exporting those files as Node.js Buffers.",
"main": "src/btoj.js",
"engines": {
"node": ">= 6.0.0"
},
"files": [
"/src",
"/types"
],
"bin": {
"btoj": "./src/btoj.js"
},
"scripts": {
"btoj": "node src/btoj.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/statsig-io/btoj.git"
Expand Down
19 changes: 13 additions & 6 deletions src/btoj.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

const fs = require("fs");
const { exit } = require("process");

fs.readFile("./binary.bin", "latin1", (e, d) => {
if (e) {
console.error(e);
fs.readFile("./binary.bin", "latin1", (re, d) => {
if (re) {
console.error(re);
exit(1);
}

Expand All @@ -22,11 +24,16 @@ fs.readFile("./binary.bin", "latin1", (e, d) => {
`const data = Buffer.from("${data}", "latin1");
module.exports = data;
`,
(e) => {
if (e) {
console.error(e);

(we) => {
if (we) {
console.error(we);
exit(1);
}

console.info(
`Generated binary.js\nYou can now delete binary.bin from your project. The js file is all you need.`
);
}
);
});

0 comments on commit d00f7b4

Please sign in to comment.