@sentio/cli 2.5.0-rc.2 → 2.5.0-rc.3

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.
@@ -109,8 +109,12 @@ import 'mine.js'
109
109
  }
110
110
  }
111
111
  export async function codegen(genExample) {
112
- const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8'));
113
- for (const contract of processorConfig.contracts || []) {
112
+ let contractsForUsage = [];
113
+ if (genExample) {
114
+ const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8'));
115
+ contractsForUsage = processorConfig.contracts;
116
+ }
117
+ for (const contract of contractsForUsage) {
114
118
  const outputPath = getABIFilePath(contract.chain, contract.name || contract.address);
115
119
  if (fs.existsSync(outputPath)) {
116
120
  continue;
@@ -131,7 +135,7 @@ export async function codegen(genExample) {
131
135
  }
132
136
  fs.emptyDirSync(output);
133
137
  // @ts-ignore dynamic import
134
- await codegen.codegen(input, output, processorConfig.contracts);
138
+ await codegen.codegen(input, output, contractsForUsage);
135
139
  }
136
140
  catch (e) {
137
141
  console.error('code gen error', e);
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEhE,MAAM,CAAC,MAAM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CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;IAED,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACjC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport { exec } from 'child_process'\nimport * as process from 'process'\nimport { getPackageRoot } from '../utils.js'\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport yaml from 'yaml'\nimport { YamlProjectConfig } from '../config.js'\nimport { getABIFilePath, getABI, writeABIFile } from '../abi.js'\n\nexport const buildOptionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'skip-gen',\n type: Boolean,\n description: 'Skip code generation.',\n },\n {\n name: 'skip-deps',\n type: Boolean,\n description: 'Skip dependency enforce.',\n },\n {\n name: 'example',\n type: Boolean,\n description: 'Generate example usage of the processor.',\n },\n]\n\nexport const GenOptionDefinitions = [\n {\n name: 'example',\n type: Boolean,\n description: 'Generate example usage of the processor.',\n },\n]\n\nexport async function buildProcessorWithArgs(argv: string[]) {\n const options = commandLineArgs(buildOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Build project',\n content: 'sentio build',\n },\n {\n header: 'Options',\n optionList: buildOptionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n await buildProcessor(false, options)\n}\n\nexport async function generate(argv: string[]) {\n const options = commandLineArgs(GenOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Generate type binding',\n content: 'sentio gen [--example]',\n },\n {\n header: 'Options',\n optionList: GenOptionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n await buildProcessor(true, options)\n}\n\nexport async function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions) {\n if (!options['skip-deps'] && !onlyGen) {\n await installDeps()\n }\n\n if (!options['skip-gen']) {\n await codegen(options.example || false)\n }\n\n if (!onlyGen) {\n let tsupConfig: string\n try {\n tsupConfig = 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 const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js')\n // await execStep('yarn tsc -p .', 'Compile')\n await execStep(`node ${tsup} --config=${tsupConfig}`, '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\nexport async function codegen(genExample: boolean) {\n const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8')) as YamlProjectConfig\n\n for (const contract of processorConfig.contracts || []) {\n const outputPath = getABIFilePath(contract.chain, contract.name || contract.address)\n if (fs.existsSync(outputPath)) {\n continue\n }\n console.log('Download Missing ABI specified in sentio.yaml')\n const res = await getABI(contract.chain, contract.address, contract.name)\n writeABIFile(res.abi, outputPath)\n }\n\n const outputBase = path.resolve('src', 'types')\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/eth/codegen')\n let input = path.resolve('abis', 'eth')\n let output = path.resolve(outputBase, 'eth')\n if (!fs.existsSync(input)) {\n input = path.resolve('abis', 'evm')\n output = path.resolve(outputBase, 'eth')\n }\n fs.emptyDirSync(output)\n // @ts-ignore dynamic import\n await codegen.codegen(input, output, processorConfig.contracts)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/solana/codegen')\n\n const output = path.resolve(outputBase, 'solana')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'solana'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/aptos/codegen')\n\n const output = path.resolve(outputBase, 'aptos')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'aptos'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/sui/codegen')\n\n const output = path.resolve(outputBase, 'sui')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'sui'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\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"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEhE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC;QACE,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,2BAA2B;KACzC;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,uBAAuB;KACrC;IACD;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0BAA0B;KACxC;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0CAA0C;KACxD;CACF,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,OAAO;Q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IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport { exec } from 'child_process'\nimport * as process from 'process'\nimport { getPackageRoot } from '../utils.js'\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport yaml from 'yaml'\nimport { YamlContractConfig, YamlProjectConfig } from '../config.js'\nimport { getABIFilePath, getABI, writeABIFile } from '../abi.js'\n\nexport const buildOptionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'skip-gen',\n type: Boolean,\n description: 'Skip code generation.',\n },\n {\n name: 'skip-deps',\n type: Boolean,\n description: 'Skip dependency enforce.',\n },\n {\n name: 'example',\n type: Boolean,\n description: 'Generate example usage of the processor.',\n },\n]\n\nexport const GenOptionDefinitions = [\n {\n name: 'example',\n type: Boolean,\n description: 'Generate example usage of the processor.',\n },\n]\n\nexport async function buildProcessorWithArgs(argv: string[]) {\n const options = commandLineArgs(buildOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Build project',\n content: 'sentio build',\n },\n {\n header: 'Options',\n optionList: buildOptionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n await buildProcessor(false, options)\n}\n\nexport async function generate(argv: string[]) {\n const options = commandLineArgs(GenOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Generate type binding',\n content: 'sentio gen [--example]',\n },\n {\n header: 'Options',\n optionList: GenOptionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n await buildProcessor(true, options)\n}\n\nexport async function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions) {\n if (!options['skip-deps'] && !onlyGen) {\n await installDeps()\n }\n\n if (!options['skip-gen']) {\n await codegen(options.example || false)\n }\n\n if (!onlyGen) {\n let tsupConfig: string\n try {\n tsupConfig = 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 const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js')\n // await execStep('yarn tsc -p .', 'Compile')\n await execStep(`node ${tsup} --config=${tsupConfig}`, '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\nexport async function codegen(genExample: boolean) {\n let contractsForUsage: YamlContractConfig[] = []\n if (genExample) {\n const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8')) as YamlProjectConfig\n contractsForUsage = processorConfig.contracts\n }\n for (const contract of contractsForUsage) {\n const outputPath = getABIFilePath(contract.chain, contract.name || contract.address)\n if (fs.existsSync(outputPath)) {\n continue\n }\n console.log('Download Missing ABI specified in sentio.yaml')\n const res = await getABI(contract.chain, contract.address, contract.name)\n writeABIFile(res.abi, outputPath)\n }\n\n const outputBase = path.resolve('src', 'types')\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/eth/codegen')\n let input = path.resolve('abis', 'eth')\n let output = path.resolve(outputBase, 'eth')\n if (!fs.existsSync(input)) {\n input = path.resolve('abis', 'evm')\n output = path.resolve(outputBase, 'eth')\n }\n fs.emptyDirSync(output)\n // @ts-ignore dynamic import\n await codegen.codegen(input, output, contractsForUsage)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/solana/codegen')\n\n const output = path.resolve(outputBase, 'solana')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'solana'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/aptos/codegen')\n\n const output = path.resolve(outputBase, 'aptos')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'aptos'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/sui/codegen')\n\n const output = path.resolve(outputBase, 'sui')\n fs.emptyDirSync(output)\n\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'sui'), output, genExample)\n } catch (e) {\n console.error('code gen error', e)\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\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"]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "license": "Apache-2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "2.5.0-rc.2",
6
+ "version": "2.5.0-rc.3",
7
7
  "scripts": {
8
8
  "compile": "tsc",
9
9
  "build": "yarn compile",
@@ -7,7 +7,7 @@ import { getPackageRoot } from '../utils.js'
7
7
  import commandLineArgs from 'command-line-args'
8
8
  import commandLineUsage from 'command-line-usage'
9
9
  import yaml from 'yaml'
10
- import { YamlProjectConfig } from '../config.js'
10
+ import { YamlContractConfig, YamlProjectConfig } from '../config.js'
11
11
  import { getABIFilePath, getABI, writeABIFile } from '../abi.js'
12
12
 
13
13
  export const buildOptionDefinitions = [
@@ -124,9 +124,12 @@ import 'mine.js'
124
124
  }
125
125
 
126
126
  export async function codegen(genExample: boolean) {
127
- const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8')) as YamlProjectConfig
128
-
129
- for (const contract of processorConfig.contracts || []) {
127
+ let contractsForUsage: YamlContractConfig[] = []
128
+ if (genExample) {
129
+ const processorConfig = yaml.parse(fs.readFileSync('sentio.yaml', 'utf8')) as YamlProjectConfig
130
+ contractsForUsage = processorConfig.contracts
131
+ }
132
+ for (const contract of contractsForUsage) {
130
133
  const outputPath = getABIFilePath(contract.chain, contract.name || contract.address)
131
134
  if (fs.existsSync(outputPath)) {
132
135
  continue
@@ -149,7 +152,7 @@ export async function codegen(genExample: boolean) {
149
152
  }
150
153
  fs.emptyDirSync(output)
151
154
  // @ts-ignore dynamic import
152
- await codegen.codegen(input, output, processorConfig.contracts)
155
+ await codegen.codegen(input, output, contractsForUsage)
153
156
  } catch (e) {
154
157
  console.error('code gen error', e)
155
158
  }