forked from ar-io/testnet-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
67 lines (62 loc) · 1.91 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs');
const path = require('path');
const Ajv = require('ajv');
const standaloneCode = require('ajv/dist/standalone').default;
const { build } = require('esbuild');
const replace = require('replace-in-file');
const {
auctionBidSchema,
buyRecordSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
transferTokensSchema,
} = require('./schemas');
// build our validation source code
const ajv = new Ajv({
schemas: [
auctionBidSchema,
buyRecordSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
transferTokensSchema,
],
code: { source: true, esm: true },
allErrors: true,
});
const moduleCode = standaloneCode(ajv, {
validateAuctionBid: '#/definitions/auctionBid',
validateBuyRecord: '#/definitions/buyRecord',
validateExtendRecord: '#/definitions/extendRecord',
validateIncreaseUndernameCount: '#/definitions/increaseUndernameCount',
validateJoinNetwork: '#/definitions/joinNetwork',
validateTransferToken: '#/definitions/transferTokens',
});
// Now you can write the module code to file
fs.writeFileSync(path.join(__dirname, '/src/validations.mjs'), moduleCode);
const contract = ['/contract.ts'];
build({
entryPoints: contract.map((source) => {
return `./src${source}`;
}),
outdir: './dist',
minify: false,
bundle: true,
format: 'iife',
packages: 'external',
})
.catch(() => process.exit(1))
// note: SmartWeave SDK currently does not support files in IIFE bundle format, so we need to remove the "iife" part ;-)
// update: it does since 0.4.31, but because viewblock.io is still incompatibile with this version, leaving as is for now.
.finally(() => {
const files = contract.map((source) => {
return `./dist${source}`.replace('.ts', '.js');
});
replace.sync({
files: files,
from: [/\(\(\) => {/g, /}\)\(\);/g],
to: '',
countMatches: true,
});
});