Skip to content

Commit

Permalink
Merge pull request #26 from tonlabs/fix-wasm-gen
Browse files Browse the repository at this point in the history
Fix wasm gen
  • Loading branch information
melsomino authored May 19, 2020
2 parents 7e24724 + fb7bb70 commit a981597
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 234 deletions.
6 changes: 4 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ window.addEventListener('load', () => {
debugLog(`Client version: ${await client.config.getVersion()}`);
debugLog(`Client connected to: ${await client.config.data.servers}`);
const queryStart = Date.now();
const accounts = await client.queries.accounts.query({}, 'id balance', [{path:'balance', direction:'DESC'}], 10);
const accounts = await client.queries.accounts.query({}, 'id balance(format:DEC)', [{path:'balance', direction:'DESC'}], 10);
debugLog(`Query time: ${(Date.now() - queryStart)}`);
debugLog(`<table>${accounts.map(x => `<tr><td>${x.id}</td><td>${BigInt(x.balance)}</td></tr>`).join('')}</table>`);
debugLog(`<table>${accounts.map(x => `<tr><td>${x.id}</td><td>${x.balance}</td></tr>`).join('')}</table>`);
debugLog(`Now is: ${new Date()}`);
debugLog(`sha512: ${await client.crypto.sha512({text:'text'})}`);
debugLog(`random: ${await client.crypto.randomGenerateBytes(12)}`);
})();
});
138 changes: 0 additions & 138 deletions install-index.js

This file was deleted.

31 changes: 0 additions & 31 deletions install-worker.js

This file was deleted.

63 changes: 1 addition & 62 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,70 +77,9 @@ async function dl(dst, src) {
process.stdout.write('\n');
}

function scriptToStringLiteral(s) {
return `\`${s.split('`').join('\\``')}\``;
}

function getClientVersion() {
return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf-8')).version;
}

function getTemplate(name) {
const template = fs.readFileSync(path.join(root, name), 'utf-8').split('//---');
if (template.length > 1) {
template.shift();
}
return template.join('');
}

function getWasmWrapperScript() {
let script = fs.readFileSync(path.join(root, 'tonclient.wasm.js'), 'utf-8');
script = script.replace(
/^import \* as wasm from .*$/gm,
`
const wasmWrapper = (function() {
let wasm = null;
const result = {
setup: (newWasm) => {
wasm = newWasm;
},
};
`,
);
script = script.replace(/^export const /gm, 'result.');
script = script.replace(/^export function (\w+)/gm, 'result.$1 = function');
script +=
` return result;
})()`;
return script;
}

function getWorkerScript() {
return [
getWasmWrapperScript(),
getTemplate('install-worker.js'),
].join('\n');
}

function getIndexScript() {
const workerScript = getWorkerScript();
const script = [
`import { TONClient } from 'ton-client-js';`,
`const workerScript = ${scriptToStringLiteral(workerScript)};`,
getTemplate('install-index.js').replace('__VERSION__', getClientVersion()),
];
return script.join('\n');
}

async function main() {
await dl('tonclient.wasm', `tonclient_${bv}_wasm`);
await dl('tonclient.wasm.js', `tonclient_${bv}_wasm_js`);
process.chdir(root);

fs.writeFileSync(path.join(root, 'index.js'), getIndexScript());

console.log('"index.js" have generated from "index-template.js" and "worker-template.js"');
fs.unlinkSync(path.join(root, 'tonclient.wasm.js'));
await dl('index.js', `tonclient_${bv}_wasm_js`);
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-client-web-js",
"version": "0.23.0",
"version": "0.23.1",
"binaries_version": "0.23.1",
"description": "TON Client Library for Web",
"scripts": {
Expand Down

0 comments on commit a981597

Please sign in to comment.