@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/src/build.ts DELETED
@@ -1,125 +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
-
8
- export async function buildProcessor(onlyGen: boolean) {
9
- if (!onlyGen) {
10
- await installDeps()
11
- }
12
-
13
- // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
14
- // for (const target) {
15
- await buildProcessorForTarget(onlyGen)
16
- // }
17
-
18
- if (!onlyGen) {
19
- let WEBPACK_CONFIG: string
20
- try {
21
- WEBPACK_CONFIG = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts')
22
- } catch (e) {
23
- console.error(chalk.red("Wrong CLI version for sdk, can't find tsup.config.ts"))
24
- process.exit(1)
25
- }
26
-
27
- // await execStep('yarn tsc -p .', 'Compile')
28
- await execStep('yarn tsup --config=' + WEBPACK_CONFIG, 'Packaging')
29
-
30
- const dir = fs.readdirSync(path.join(process.cwd(), 'dist'))
31
- const generated = dir.filter((d) => d.endsWith('.js')).length
32
- if (generated < 0) {
33
- console.error(chalk.red('No filed generated, please check if your processor.ts file'))
34
- process.exit(1)
35
- }
36
- if (generated > 1) {
37
- console.error(
38
- chalk.red('Packing failed: '),
39
- `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:
40
- import('mine.js')
41
- to
42
- import 'mine.js'
43
- `
44
- )
45
- }
46
- }
47
- }
48
-
49
- async function buildProcessorForTarget(onlyGen: boolean) {
50
- await codeGenEthersProcessor(path.join('abis', 'evm'))
51
-
52
- try {
53
- // @ts-ignore dynamic import
54
- const codegen = await import('@sentio/sdk-solana/codegen')
55
- codegen.codeGenSolanaProcessor(path.join('abis', 'solana'))
56
- } catch (e) {}
57
-
58
- try {
59
- // @ts-ignore dynamic import
60
- const codegen = await import('@sentio/sdk-aptos/codegen')
61
- codegen.codeGenAptosProcessor(path.join('abis', 'aptos'))
62
- } catch (e) {}
63
-
64
- if (onlyGen) {
65
- return
66
- }
67
- }
68
-
69
- async function installDeps() {
70
- await execStep('yarn install --ignore-scripts', 'Yarn Install')
71
- }
72
-
73
- export async function codeGenEthersProcessor(
74
- abisDir: string,
75
- ETHERS_TARGET = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/target-ethers-sentio/index.cjs'),
76
- outDir = 'src/types/internal'
77
- ) {
78
- if (!fs.existsSync(abisDir)) {
79
- return
80
- }
81
-
82
- let haveJson = false
83
- const files = fs.readdirSync(abisDir)
84
- for (const file of files) {
85
- if (file.toLowerCase().endsWith('.json')) {
86
- haveJson = true
87
- break
88
- }
89
- }
90
- if (!haveJson) {
91
- return
92
- }
93
-
94
- console.log(chalk.green('Generated Types for EVM'))
95
-
96
- // TODO this will fail during postinstall, need to locate real typechain path
97
- await execStep(
98
- 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,
99
- 'Type definitions gen'
100
- )
101
- }
102
-
103
- async function execStep(cmd: string, stepName: string) {
104
- const child = exec(cmd)
105
- console.log(chalk.blue(stepName + ' begin'))
106
-
107
- if (!child.stdout || !child.stderr) {
108
- console.error(chalk.red(stepName + ' failed'))
109
- process.exit(1)
110
- }
111
-
112
- child.stdout.pipe(process.stdout)
113
- child.stderr.pipe(process.stderr)
114
-
115
- await new Promise((resolve) => {
116
- child.on('close', resolve)
117
- })
118
-
119
- if (child.exitCode) {
120
- console.error(chalk.red(stepName + ' failed'))
121
- process.exit(child.exitCode)
122
- }
123
- console.log(chalk.blue(stepName + ' success'))
124
- console.log()
125
- }