@sentio/cli 2.0.0-rc.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +4 -4
- package/lib/cli.js.map +1 -1
- package/lib/commands/build.d.ts +14 -0
- package/lib/commands/build.js +137 -0
- package/lib/commands/build.js.map +1 -0
- package/lib/commands/run-create.js +0 -11
- package/lib/commands/run-create.js.map +1 -1
- package/lib/commands/run-test.js +3 -2
- package/lib/commands/run-test.js.map +1 -1
- package/lib/commands/run-upload.js +69 -55
- package/lib/commands/run-upload.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +4 -4
- package/src/commands/build.ts +152 -0
- package/src/commands/run-create.ts +0 -12
- package/src/commands/run-test.ts +3 -2
- package/src/commands/run-upload.ts +74 -56
- package/templates/aptos/package.json +1 -2
- package/templates/aptos/tsconfig.json +1 -1
- package/templates/{evm/abis/evm → eth/abis/eth}/x2y2.json +0 -0
- package/templates/{evm → eth}/jest.config.ts +0 -0
- package/templates/{evm → eth}/package.json +1 -1
- package/templates/{evm → eth}/sentio.yaml +0 -0
- package/templates/{evm → eth}/src/processor.ts +3 -4
- package/templates/{evm → eth}/tsconfig.json +1 -1
- package/templates/raw/tsconfig.json +1 -1
- package/templates/solana/package.json +1 -2
- package/templates/solana/src/processor.ts +3 -3
- package/templates/solana/tsconfig.json +1 -1
- package/lib/build.d.ts +0 -2
- package/lib/build.js +0 -100
- package/lib/build.js.map +0 -1
- package/src/build.ts +0 -125
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import { exec } from 'child_process'
|
|
5
|
+
import * as process from 'process'
|
|
6
|
+
import { getPackageRoot } from '../utils.js'
|
|
7
|
+
import commandLineArgs from 'command-line-args'
|
|
8
|
+
import commandLineUsage from 'command-line-usage'
|
|
9
|
+
|
|
10
|
+
export const buildOptionDefinitions = [
|
|
11
|
+
{
|
|
12
|
+
name: 'help',
|
|
13
|
+
alias: 'h',
|
|
14
|
+
type: Boolean,
|
|
15
|
+
description: 'Display this usage guide.',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'skip-gen',
|
|
19
|
+
type: Boolean,
|
|
20
|
+
description: 'Skip code generation.',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'skip-deps',
|
|
24
|
+
type: Boolean,
|
|
25
|
+
description: 'Skip dependency enforce.',
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
export async function buildProcessorWithArgs(argv: string[]) {
|
|
30
|
+
const options = commandLineArgs(buildOptionDefinitions, { argv })
|
|
31
|
+
const usage = commandLineUsage([
|
|
32
|
+
{
|
|
33
|
+
header: 'Create a template project',
|
|
34
|
+
content: 'sentio create <name>',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
header: 'Options',
|
|
38
|
+
optionList: buildOptionDefinitions,
|
|
39
|
+
},
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
if (options.help) {
|
|
43
|
+
console.log(usage)
|
|
44
|
+
process.exit(0)
|
|
45
|
+
}
|
|
46
|
+
await buildProcessor(false, options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions) {
|
|
50
|
+
if (!options['skip-deps'] && !onlyGen) {
|
|
51
|
+
await installDeps()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!options['skip-gen']) {
|
|
55
|
+
await codegen()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!onlyGen) {
|
|
59
|
+
let tsupConfig: string
|
|
60
|
+
try {
|
|
61
|
+
tsupConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts')
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(chalk.red("Wrong CLI version for sdk, can't find tsup.config.ts"))
|
|
64
|
+
process.exit(1)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js')
|
|
68
|
+
// await execStep('yarn tsc -p .', 'Compile')
|
|
69
|
+
await execStep(`node ${tsup} --config=${tsupConfig}`, 'Packaging')
|
|
70
|
+
|
|
71
|
+
const dir = fs.readdirSync(path.join(process.cwd(), 'dist'))
|
|
72
|
+
const generated = dir.filter((d) => d.endsWith('.js')).length
|
|
73
|
+
if (generated < 0) {
|
|
74
|
+
console.error(chalk.red('No filed generated, please check if your processor.ts file'))
|
|
75
|
+
process.exit(1)
|
|
76
|
+
}
|
|
77
|
+
if (generated > 1) {
|
|
78
|
+
console.error(
|
|
79
|
+
chalk.red('Packing failed: '),
|
|
80
|
+
`Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:
|
|
81
|
+
import('mine.js')
|
|
82
|
+
to
|
|
83
|
+
import 'mine.js'
|
|
84
|
+
`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function codegen() {
|
|
91
|
+
const outputBase = path.resolve('src', 'types')
|
|
92
|
+
try {
|
|
93
|
+
// @ts-ignore dynamic import
|
|
94
|
+
const codegen = await import('@sentio/sdk/eth/codegen')
|
|
95
|
+
let input = path.resolve('abis', 'eth')
|
|
96
|
+
let output = path.resolve(outputBase)
|
|
97
|
+
if (!fs.existsSync(input)) {
|
|
98
|
+
input = path.resolve('abis', 'evm')
|
|
99
|
+
output = path.resolve(outputBase)
|
|
100
|
+
}
|
|
101
|
+
// @ts-ignore dynamic import
|
|
102
|
+
await codegen.codegen(input, output)
|
|
103
|
+
} catch (e) {
|
|
104
|
+
console.error('code gen error', e)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
// @ts-ignore dynamic import
|
|
109
|
+
const codegen = await import('@sentio/sdk/solana/codegen')
|
|
110
|
+
// @ts-ignore dynamic import
|
|
111
|
+
await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'))
|
|
112
|
+
} catch (e) {
|
|
113
|
+
console.error('code gen error', e)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
// @ts-ignore dynamic import
|
|
118
|
+
const codegen = await import('@sentio/sdk/aptos/codegen')
|
|
119
|
+
// @ts-ignore dynamic import
|
|
120
|
+
await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'))
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.error('code gen error', e)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function installDeps() {
|
|
127
|
+
await execStep('yarn install --ignore-scripts', 'Yarn Install')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function execStep(cmd: string, stepName: string) {
|
|
131
|
+
const child = exec(cmd)
|
|
132
|
+
console.log(chalk.blue(stepName + ' begin'))
|
|
133
|
+
|
|
134
|
+
if (!child.stdout || !child.stderr) {
|
|
135
|
+
console.error(chalk.red(stepName + ' failed'))
|
|
136
|
+
process.exit(1)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
child.stdout.pipe(process.stdout)
|
|
140
|
+
child.stderr.pipe(process.stderr)
|
|
141
|
+
|
|
142
|
+
await new Promise((resolve) => {
|
|
143
|
+
child.on('close', resolve)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
if (child.exitCode) {
|
|
147
|
+
console.error(chalk.red(stepName + ' failed'))
|
|
148
|
+
process.exit(child.exitCode)
|
|
149
|
+
}
|
|
150
|
+
console.log(chalk.blue(stepName + ' success'))
|
|
151
|
+
console.log()
|
|
152
|
+
}
|
|
@@ -109,16 +109,6 @@ export async function runCreate(argv: string[]) {
|
|
|
109
109
|
const sdkVersion = '^' + (await latestVersion('@sentio/sdk'))
|
|
110
110
|
packageJson.dependencies['@sentio/sdk'] = sdkVersion
|
|
111
111
|
|
|
112
|
-
switch (chainType) {
|
|
113
|
-
case 'aptos':
|
|
114
|
-
packageJson.dependencies['@sentio/sdk-aptos'] = sdkVersion
|
|
115
|
-
break
|
|
116
|
-
case 'solana':
|
|
117
|
-
packageJson.dependencies['@sentio/sdk-solana'] = sdkVersion
|
|
118
|
-
break
|
|
119
|
-
default:
|
|
120
|
-
}
|
|
121
|
-
|
|
122
112
|
const cliVersion = '^' + (await latestVersion('@sentio/cli'))
|
|
123
113
|
packageJson.devDependencies['@sentio/cli'] = cliVersion
|
|
124
114
|
packageJson.name = projectName
|
|
@@ -126,8 +116,6 @@ export async function runCreate(argv: string[]) {
|
|
|
126
116
|
if (options.subproject) {
|
|
127
117
|
delete packageJson.dependencies['@sentio/sdk']
|
|
128
118
|
delete packageJson.devDependencies['@sentio/cli']
|
|
129
|
-
delete packageJson.dependencies['@sentio/sdk-aptos']
|
|
130
|
-
delete packageJson.dependencies['@sentio/sdk-solana']
|
|
131
119
|
}
|
|
132
120
|
|
|
133
121
|
// Don't add directly to avoid deps issue
|
package/src/commands/run-test.ts
CHANGED
|
@@ -3,7 +3,8 @@ import path from 'path'
|
|
|
3
3
|
import { getPackageRoot } from '../utils.js'
|
|
4
4
|
|
|
5
5
|
export function runTest(argv: string[]) {
|
|
6
|
-
const
|
|
6
|
+
const defaultJestConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib', 'jest.config.js')
|
|
7
7
|
// if config not existed copy that
|
|
8
|
-
|
|
8
|
+
const jest = path.resolve(getPackageRoot('jest'), 'bin', 'jest')
|
|
9
|
+
execSync(`NODE_OPTIONS=--experimental-vm-modules node ${jest} ${argv.join(' ')}`, { stdio: 'inherit' })
|
|
9
10
|
}
|
|
@@ -3,7 +3,7 @@ import commandLineUsage from 'command-line-usage'
|
|
|
3
3
|
import { finalizeHost, FinalizeProjectName, SentioProjectConfig } from '../config.js'
|
|
4
4
|
import { URL } from 'url'
|
|
5
5
|
import fetch from 'node-fetch'
|
|
6
|
-
import { buildProcessor } from '
|
|
6
|
+
import { buildOptionDefinitions, buildProcessor } from './build.js'
|
|
7
7
|
import chalk from 'chalk'
|
|
8
8
|
import path from 'path'
|
|
9
9
|
import { ReadKey } from '../key.js'
|
|
@@ -12,41 +12,59 @@ import { createHash } from 'crypto'
|
|
|
12
12
|
import { execSync } from 'child_process'
|
|
13
13
|
import { getSdkVersion } from '../utils.js'
|
|
14
14
|
import readline from 'readline'
|
|
15
|
+
import * as process from 'process'
|
|
16
|
+
|
|
17
|
+
const uploadOptionDefinitions = [
|
|
18
|
+
{
|
|
19
|
+
name: 'help',
|
|
20
|
+
alias: 'h',
|
|
21
|
+
type: Boolean,
|
|
22
|
+
description: 'Display this usage guide.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'api-key',
|
|
26
|
+
type: String,
|
|
27
|
+
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'host',
|
|
31
|
+
description: '(Optional) Override Sentio Host name',
|
|
32
|
+
type: String,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'owner',
|
|
36
|
+
description: '(Optional) Override Project owner',
|
|
37
|
+
type: String,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'nobuild',
|
|
41
|
+
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
42
|
+
type: Boolean,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'debug',
|
|
46
|
+
description: '(Optional) Run driver in debug mode, default false',
|
|
47
|
+
type: Boolean,
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
function mergeOptions(options1: commandLineArgs.OptionDefinition[], options2: commandLineArgs.OptionDefinition[]) {
|
|
52
|
+
const res = Object.assign([], options1)
|
|
53
|
+
const added = new Set<string>()
|
|
54
|
+
for (const opt of options1) {
|
|
55
|
+
added.add(opt.name)
|
|
56
|
+
}
|
|
57
|
+
for (const opt of options2) {
|
|
58
|
+
if (!added.has(opt.name)) {
|
|
59
|
+
res.push(opt)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return res
|
|
63
|
+
}
|
|
15
64
|
|
|
16
65
|
export async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {
|
|
17
|
-
const optionDefinitions =
|
|
18
|
-
|
|
19
|
-
name: 'help',
|
|
20
|
-
alias: 'h',
|
|
21
|
-
type: Boolean,
|
|
22
|
-
description: 'Display this usage guide.',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: 'api-key',
|
|
26
|
-
type: String,
|
|
27
|
-
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: 'host',
|
|
31
|
-
description: '(Optional) Override Sentio Host name',
|
|
32
|
-
type: String,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: 'owner',
|
|
36
|
-
description: '(Optional) Override Project owner',
|
|
37
|
-
type: String,
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'nobuild',
|
|
41
|
-
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
42
|
-
type: Boolean,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: 'debug',
|
|
46
|
-
description: '(Optional) Run driver in debug mode, default false',
|
|
47
|
-
type: Boolean,
|
|
48
|
-
},
|
|
49
|
-
]
|
|
66
|
+
const optionDefinitions = mergeOptions(uploadOptionDefinitions, buildOptionDefinitions)
|
|
67
|
+
|
|
50
68
|
const options = commandLineArgs(optionDefinitions, { argv })
|
|
51
69
|
if (options.help) {
|
|
52
70
|
const usage = commandLineUsage([
|
|
@@ -60,26 +78,30 @@ export async function runUpload(processorConfig: SentioProjectConfig, argv: stri
|
|
|
60
78
|
},
|
|
61
79
|
])
|
|
62
80
|
console.log(usage)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
processorConfig.host = options.host
|
|
66
|
-
}
|
|
67
|
-
if (options.nobuild) {
|
|
68
|
-
processorConfig.build = false
|
|
69
|
-
}
|
|
70
|
-
if (options.debug) {
|
|
71
|
-
processorConfig.debug = true
|
|
72
|
-
}
|
|
73
|
-
finalizeHost(processorConfig)
|
|
74
|
-
FinalizeProjectName(processorConfig, options.owner)
|
|
75
|
-
console.log(processorConfig)
|
|
81
|
+
process.exit(0)
|
|
82
|
+
}
|
|
76
83
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (options.host) {
|
|
85
|
+
processorConfig.host = options.host
|
|
86
|
+
}
|
|
87
|
+
if (options.nobuild) {
|
|
88
|
+
processorConfig.build = false
|
|
82
89
|
}
|
|
90
|
+
if (options.debug) {
|
|
91
|
+
processorConfig.debug = true
|
|
92
|
+
}
|
|
93
|
+
finalizeHost(processorConfig)
|
|
94
|
+
FinalizeProjectName(processorConfig, options.owner)
|
|
95
|
+
console.log(processorConfig)
|
|
96
|
+
|
|
97
|
+
let apiOverride = undefined
|
|
98
|
+
if (options['api-key']) {
|
|
99
|
+
apiOverride = options['api-key']
|
|
100
|
+
}
|
|
101
|
+
if (processorConfig.build) {
|
|
102
|
+
await buildProcessor(false, options)
|
|
103
|
+
}
|
|
104
|
+
return uploadFile(processorConfig, apiOverride)
|
|
83
105
|
}
|
|
84
106
|
|
|
85
107
|
async function createProject(options: SentioProjectConfig, apiKey: string) {
|
|
@@ -95,10 +117,6 @@ async function createProject(options: SentioProjectConfig, apiKey: string) {
|
|
|
95
117
|
}
|
|
96
118
|
|
|
97
119
|
export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {
|
|
98
|
-
if (options.build) {
|
|
99
|
-
await buildProcessor(false)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
120
|
console.log(chalk.blue('Prepare to upload'))
|
|
103
121
|
|
|
104
122
|
const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Counter, Gauge } from '@sentio/sdk'
|
|
2
|
-
import {
|
|
3
|
-
import { ERC20Processor } from '@sentio/sdk/builtin'
|
|
2
|
+
import { ERC20Processor } from '@sentio/sdk/eth/builtin'
|
|
4
3
|
import { X2y2Processor } from './types/x2y2/index.js'
|
|
5
4
|
|
|
6
5
|
const rewardPerBlock = Gauge.register('reward_per_block', {
|
|
@@ -11,7 +10,7 @@ const tokenCounter = Counter.register('token')
|
|
|
11
10
|
|
|
12
11
|
X2y2Processor.bind({ address: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1' }).onBlockInterval(async (_, ctx) => {
|
|
13
12
|
const phase = (await ctx.contract.currentPhase()).toString()
|
|
14
|
-
const reward =
|
|
13
|
+
const reward = (await ctx.contract.rewardPerBlockForStaking()).scaleDown(18)
|
|
15
14
|
rewardPerBlock.record(ctx, reward, { phase })
|
|
16
15
|
})
|
|
17
16
|
|
|
@@ -22,7 +21,7 @@ const filter = ERC20Processor.filters.Transfer(
|
|
|
22
21
|
|
|
23
22
|
ERC20Processor.bind({ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9' }).onEventTransfer(
|
|
24
23
|
async (event, ctx) => {
|
|
25
|
-
const val =
|
|
24
|
+
const val = event.args.value.scaleDown(18)
|
|
26
25
|
tokenCounter.add(ctx, val)
|
|
27
26
|
},
|
|
28
27
|
filter // filter is an optional parameter
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SPLTokenProcessor } from '@sentio/sdk
|
|
1
|
+
import { SPLTokenProcessor } from '@sentio/sdk/solana/builtin'
|
|
2
2
|
|
|
3
3
|
SPLTokenProcessor.bind({
|
|
4
4
|
address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
|
|
@@ -6,11 +6,11 @@ SPLTokenProcessor.bind({
|
|
|
6
6
|
})
|
|
7
7
|
.onMintTo((data, ctx) => {
|
|
8
8
|
if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
|
|
9
|
-
ctx.meter.Counter('totalWeth_supply').add(data.amount
|
|
9
|
+
ctx.meter.Counter('totalWeth_supply').add(data.amount)
|
|
10
10
|
}
|
|
11
11
|
})
|
|
12
12
|
.onBurn((data, ctx) => {
|
|
13
13
|
if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
|
|
14
|
-
ctx.meter.Counter('totalWeth_supply').sub(data.amount
|
|
14
|
+
ctx.meter.Counter('totalWeth_supply').sub(data.amount)
|
|
15
15
|
}
|
|
16
16
|
})
|
package/lib/build.d.ts
DELETED
package/lib/build.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { exec } from 'child_process';
|
|
5
|
-
import * as process from 'process';
|
|
6
|
-
import { getPackageRoot } from './utils.js';
|
|
7
|
-
export async function buildProcessor(onlyGen) {
|
|
8
|
-
if (!onlyGen) {
|
|
9
|
-
await installDeps();
|
|
10
|
-
}
|
|
11
|
-
// targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
|
|
12
|
-
// for (const target) {
|
|
13
|
-
await buildProcessorForTarget(onlyGen);
|
|
14
|
-
// }
|
|
15
|
-
if (!onlyGen) {
|
|
16
|
-
let WEBPACK_CONFIG;
|
|
17
|
-
try {
|
|
18
|
-
WEBPACK_CONFIG = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts');
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.error(chalk.red("Wrong CLI version for sdk, can't find tsup.config.ts"));
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
// await execStep('yarn tsc -p .', 'Compile')
|
|
25
|
-
await execStep('yarn tsup --config=' + WEBPACK_CONFIG, 'Packaging');
|
|
26
|
-
const dir = fs.readdirSync(path.join(process.cwd(), 'dist'));
|
|
27
|
-
const generated = dir.filter((d) => d.endsWith('.js')).length;
|
|
28
|
-
if (generated < 0) {
|
|
29
|
-
console.error(chalk.red('No filed generated, please check if your processor.ts file'));
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
if (generated > 1) {
|
|
33
|
-
console.error(chalk.red('Packing failed: '), `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:
|
|
34
|
-
import('mine.js')
|
|
35
|
-
to
|
|
36
|
-
import 'mine.js'
|
|
37
|
-
`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function buildProcessorForTarget(onlyGen) {
|
|
42
|
-
await codeGenEthersProcessor(path.join('abis', 'evm'));
|
|
43
|
-
try {
|
|
44
|
-
// @ts-ignore dynamic import
|
|
45
|
-
const codegen = await import('@sentio/sdk-solana/codegen');
|
|
46
|
-
codegen.codeGenSolanaProcessor(path.join('abis', 'solana'));
|
|
47
|
-
}
|
|
48
|
-
catch (e) { }
|
|
49
|
-
try {
|
|
50
|
-
// @ts-ignore dynamic import
|
|
51
|
-
const codegen = await import('@sentio/sdk-aptos/codegen');
|
|
52
|
-
codegen.codeGenAptosProcessor(path.join('abis', 'aptos'));
|
|
53
|
-
}
|
|
54
|
-
catch (e) { }
|
|
55
|
-
if (onlyGen) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function installDeps() {
|
|
60
|
-
await execStep('yarn install --ignore-scripts', 'Yarn Install');
|
|
61
|
-
}
|
|
62
|
-
export async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/target-ethers-sentio/index.cjs'), outDir = 'src/types/internal') {
|
|
63
|
-
if (!fs.existsSync(abisDir)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
let haveJson = false;
|
|
67
|
-
const files = fs.readdirSync(abisDir);
|
|
68
|
-
for (const file of files) {
|
|
69
|
-
if (file.toLowerCase().endsWith('.json')) {
|
|
70
|
-
haveJson = true;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (!haveJson) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
console.log(chalk.green('Generated Types for EVM'));
|
|
78
|
-
// TODO this will fail during postinstall, need to locate real typechain path
|
|
79
|
-
await execStep('yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`, 'Type definitions gen');
|
|
80
|
-
}
|
|
81
|
-
async function execStep(cmd, stepName) {
|
|
82
|
-
const child = exec(cmd);
|
|
83
|
-
console.log(chalk.blue(stepName + ' begin'));
|
|
84
|
-
if (!child.stdout || !child.stderr) {
|
|
85
|
-
console.error(chalk.red(stepName + ' failed'));
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
child.stdout.pipe(process.stdout);
|
|
89
|
-
child.stderr.pipe(process.stderr);
|
|
90
|
-
await new Promise((resolve) => {
|
|
91
|
-
child.on('close', resolve);
|
|
92
|
-
});
|
|
93
|
-
if (child.exitCode) {
|
|
94
|
-
console.error(chalk.red(stepName + ' failed'));
|
|
95
|
-
process.exit(child.exitCode);
|
|
96
|
-
}
|
|
97
|
-
console.log(chalk.blue(stepName + ' success'));
|
|
98
|
-
console.log();
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=build.js.map
|
package/lib/build.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAA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AAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport * as process from 'process'\nimport { getPackageRoot } from './utils.js'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n let WEBPACK_CONFIG: string\n try {\n WEBPACK_CONFIG = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts')\n } catch (e) {\n console.error(chalk.red(\"Wrong CLI version for sdk, can't find tsup.config.ts\"))\n process.exit(1)\n }\n\n // await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn tsup --config=' + WEBPACK_CONFIG, 'Packaging')\n\n const dir = fs.readdirSync(path.join(process.cwd(), 'dist'))\n const generated = dir.filter((d) => d.endsWith('.js')).length\n if (generated < 0) {\n console.error(chalk.red('No filed generated, please check if your processor.ts file'))\n process.exit(1)\n }\n if (generated > 1) {\n console.error(\n chalk.red('Packing failed: '),\n `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:\nimport('mine.js')\nto\nimport 'mine.js'\n`\n )\n }\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk-solana/codegen')\n codegen.codeGenSolanaProcessor(path.join('abis', 'solana'))\n } catch (e) {}\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk-aptos/codegen')\n codegen.codeGenAptosProcessor(path.join('abis', 'aptos'))\n } catch (e) {}\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/target-ethers-sentio/index.cjs'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|