Skip to content

Commit

Permalink
feat: Refactor build tools
Browse files Browse the repository at this point in the history
Improve readability of code
Add comments for easier understanding
Marginaly improve decorator type definitions
  • Loading branch information
petarvujovic98 committed Sep 19, 2022
1 parent 962335b commit dba601b
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 301 deletions.
4 changes: 1 addition & 3 deletions lib/build-tools/include-bytes.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions lib/build-tools/include-bytes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 93 additions & 67 deletions lib/build-tools/near-bindgen-exporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions lib/near-bindgen.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions lib/near-bindgen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/build-tools/include-bytes.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import * as t from "@babel/types";
import fs from "fs";
import path from "path";
export default function ({ types: t }) {

export default function () {
return {
visitor: {
CallExpression(p, state) {
let name = p.node.callee.name;
let args = p.node.arguments;
const name = p.node.callee.name;
const args = p.node.arguments;

if (name === "includeBytes") {
// Get the path of file
var filename = this.file.opts.filename;
const filename = this.file.opts.filename;

// User settings
let root = state.opts.root || path.dirname(filename);
const root = state.opts.root || path.dirname(filename);

// Read binary file into bytes, so encoding is 'latin1' (each byte is 0-255, become one character)
const encoding = "latin1";
Expand All @@ -25,9 +27,9 @@ export default function ({ types: t }) {
throw new Error("`includeBytes` function called outside of file");

// Generate and locate the file
let fileRelPath = args[0].value; // Get literal string value
let filePath = path.join(root, fileRelPath);
let fileSrc = fs
const fileRelPath = args[0].value; // Get literal string value
const filePath = path.join(root, fileRelPath);
const fileSrc = fs
.readFileSync(filePath, { encoding })
.toString(encoding);

Expand Down
Loading

0 comments on commit dba601b

Please sign in to comment.