This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.js
98 lines (93 loc) · 3.06 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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,
createReservedNameSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
transferTokensSchema,
transferTokensLockedSchema,
createVaultSchema,
extendVaultSchema,
increaseVaultSchema,
saveObservationsSchema,
updateGatewaySchema,
delegateStakeSchema,
decreaseDelegateStakeSchema,
decreaseOperatorStakeSchema,
} = require('./schemas');
// build our validation source code
const ajv = new Ajv({
schemas: [
auctionBidSchema,
buyRecordSchema,
createReservedNameSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
transferTokensSchema,
transferTokensLockedSchema,
createVaultSchema,
extendVaultSchema,
increaseVaultSchema,
saveObservationsSchema,
updateGatewaySchema,
delegateStakeSchema,
decreaseOperatorStakeSchema,
decreaseDelegateStakeSchema,
],
code: { source: true, esm: true },
allErrors: true,
});
const moduleCode = standaloneCode(ajv, {
validateAuctionBid: '#/definitions/auctionBid',
validateBuyRecord: '#/definitions/buyRecord',
validateCreateReservedName: '#/definitions/createReservedName',
validateExtendRecord: '#/definitions/extendRecord',
validateIncreaseUndernameCount: '#/definitions/increaseUndernameCount',
validateJoinNetwork: '#/definitions/joinNetwork',
validateTransferToken: '#/definitions/transferTokens',
validateTransferTokensLocked: '#/definitions/transferTokensLocked',
validateCreateVault: '#/definitions/createVault',
validateExtendVault: '#/definitions/extendVault',
validateIncreaseVault: '#/definitions/increaseVault',
validateSaveObservations: '#/definitions/saveObservations',
validateUpdateGateway: '#/definitions/updateGateway',
validateDelegateStake: '#/definitions/delegateStake',
validateDecreaseDelegateStake: '#/definitions/decreaseDelegateStake',
validateDecreaseOperatorStake: '#/definitions/decreaseOperatorStake',
});
// Now you can write the module code to file
fs.writeFileSync(path.join(__dirname, '/src/validations.js'), moduleCode);
const contract = ['/contract.ts'];
build({
entryPoints: contract.map((source) => {
return `./src${source}`;
}),
outdir: './dist',
minify: false,
bundle: true,
format: 'iife',
packages: 'external',
tsconfig: 'tsconfig.json',
})
.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,
});
});