Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compile script #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/Nft.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.0;

import "./ERC721Tradeable.sol";
import "./ERC721Tradable.sol";

contract MyNFT is ERC721Tradable {
constructor() public ERC721Tradable("MyNFT", "MNFT"){}
Expand Down
49 changes: 49 additions & 0 deletions lib/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const solc = require("solc");
const fs = require("fs");
const path = require("path");

const target = process.argv[2];

const source = fs.readFileSync(target, { encoding: "utf-8" });
var input = {
language: "Solidity",
sources: {
"Nft.sol": {
content: source,
},
},
settings: {
outputSelection: {
"*": {
"*": ["*"],
},
},
},
};

const findImports = (p) => {
const s = p.split("/");
if (s[0].startsWith("openzeppelin")) {
const path_pre = path.resolve(
__dirname,
"..",
"node_modules",
"openzeppelin-solidity"
);
return {
contents: fs.readFileSync(path.join(path_pre, ...s.slice(1)), "utf-8"),
};
} else {
const new_path = path.resolve(__dirname, "..", "contracts", p);
return {
contents: fs.readFileSync(new_path, "utf-8"),
};
}
};

var output = JSON.parse(
solc.compile(JSON.stringify(input), {
import: findImports,
})
);
console.log(output);
Loading