@neo-one/smart-contract-compiler-esnext-esm
Version:
NEO•ONE TypeScript smart contract compiler.
33 lines (31 loc) • 1.4 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils-esnext-esm';
import { normalizePath } from '@neo-one/utils-esnext-esm';
import _ from 'lodash';
import { compile } from './compile';
import { createContextForPath, updateContext } from './createContext';
import { transpile } from './transpile';
export const compileContract = ({ filePath: filePathIn, host, linked: linkedIn = {}, }) => {
const filePath = normalizePath(filePathIn);
const linked = _.fromPairs(Object.entries(linkedIn).map(([key, value]) => [normalizePath(key), value]));
const transpileContext = createContextForPath(filePath, host);
const transpileResult = transpile({
sourceFile: tsUtils.file.getSourceFileOrThrow(transpileContext.program, filePath),
context: transpileContext,
});
const context = transpileResult === undefined
? transpileContext
: updateContext(transpileContext, { [filePath]: transpileResult.text });
const { abi, sourceMap: finalSourceMap, contract } = compile({
sourceFile: tsUtils.file.getSourceFileOrThrow(context.program, filePath),
context,
linked,
sourceMaps: transpileResult === undefined ? {} : { [filePath]: transpileResult.sourceMap },
});
return {
diagnostics: context.diagnostics,
sourceMap: finalSourceMap,
abi,
contract,
};
};
//# sourceMappingURL=compileContract.js.map