@sentio/cli 2.0.0-rc.9 → 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 CHANGED
@@ -5,7 +5,7 @@ import fs from 'fs';
5
5
  import path from 'path';
6
6
  import yaml from 'js-yaml';
7
7
  import chalk from 'chalk';
8
- import { buildProcessor } from './build.js';
8
+ import { buildProcessor, buildProcessorWithArgs } from './commands/build.js';
9
9
  import { runCreate } from './commands/run-create.js';
10
10
  import { runVersion } from './commands/run-version.js';
11
11
  import { runLogin } from './commands/run-login.js';
@@ -82,13 +82,13 @@ else {
82
82
  process.exit(1);
83
83
  }
84
84
  if (mainOptions.command === 'upload') {
85
- runUpload(processorConfig, argv);
85
+ await runUpload(processorConfig, argv);
86
86
  }
87
87
  else if (mainOptions.command === 'build') {
88
- buildProcessor(false);
88
+ await buildProcessorWithArgs(argv);
89
89
  }
90
90
  else if (mainOptions.command === 'gen') {
91
- buildProcessor(true);
91
+ await buildProcessor(true, []);
92
92
  }
93
93
  else {
94
94
  usage();
package/lib/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAA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O,KAAK,QAAQ,EAAE;QACpC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;KACjC;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,cAAc,CAAC,KAAK,CAAC,CAAA;KACtB;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,cAAc,CAAC,IAAI,CAAC,CAAA;KACrB;SAAM;QACL,KAAK,EAAE,CAAA;KACR;CACF;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,kEAAkE;gBAClE,qCAAqC;gBACrC,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,8BAA8B;gBAC9B,yCAAyC;aAC1C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { SentioProjectConfig } from './config.js'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build.js'\nimport { runCreate } from './commands/run-create.js'\nimport { runVersion } from './commands/run-version.js'\nimport { runLogin } from './commands/run-login.js'\nimport { runUpload } from './commands/run-upload.js'\nimport { runTest } from './commands/run-test.js'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n await runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else if (mainOptions.command === 'test') {\n runTest(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true, debug: false }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n if (processorConfig.debug === undefined) {\n processorConfig.debug = false\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n buildProcessor(true)\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login\\t\\t\\t\\tlogin to sentio',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio test\\t\\t\\t\\trun tests',\n 'sentio version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAClE,MAAM,WAAW,GAAG,eAAe,CAAC,eAAe,EAAE;IACnD,kBAAkB,EAAE,IAAI;CACzB,CAAC,CAAA;AACF,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAA;AAEvC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;IACxB,KAAK,EAAE,CAAA;CACR;AAED,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;IACnC,QA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xD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,kEAAkE;gBAClE,qCAAqC;gBACrC,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,8BAA8B;gBAC9B,yCAAyC;aAC1C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { SentioProjectConfig } from './config.js'\nimport chalk from 'chalk'\nimport { buildProcessor, buildProcessorWithArgs } from './commands/build.js'\nimport { runCreate } from './commands/run-create.js'\nimport { runVersion } from './commands/run-version.js'\nimport { runLogin } from './commands/run-login.js'\nimport { runUpload } from './commands/run-upload.js'\nimport { runTest } from './commands/run-test.js'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n await runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else if (mainOptions.command === 'test') {\n runTest(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true, debug: false }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n if (processorConfig.debug === undefined) {\n processorConfig.debug = false\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n await runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n await buildProcessorWithArgs(argv)\n } else if (mainOptions.command === 'gen') {\n await buildProcessor(true, [])\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login\\t\\t\\t\\tlogin to sentio',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio test\\t\\t\\t\\trun tests',\n 'sentio version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import commandLineArgs from 'command-line-args';
2
+ export declare const buildOptionDefinitions: ({
3
+ name: string;
4
+ alias: string;
5
+ type: BooleanConstructor;
6
+ description: string;
7
+ } | {
8
+ name: string;
9
+ type: BooleanConstructor;
10
+ description: string;
11
+ alias?: undefined;
12
+ })[];
13
+ export declare function buildProcessorWithArgs(argv: string[]): Promise<void>;
14
+ export declare function buildProcessor(onlyGen: boolean, options: commandLineArgs.CommandLineOptions): Promise<void>;
@@ -0,0 +1,137 @@
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
+ export const buildOptionDefinitions = [
10
+ {
11
+ name: 'help',
12
+ alias: 'h',
13
+ type: Boolean,
14
+ description: 'Display this usage guide.',
15
+ },
16
+ {
17
+ name: 'skip-gen',
18
+ type: Boolean,
19
+ description: 'Skip code generation.',
20
+ },
21
+ {
22
+ name: 'skip-deps',
23
+ type: Boolean,
24
+ description: 'Skip dependency enforce.',
25
+ },
26
+ ];
27
+ export async function buildProcessorWithArgs(argv) {
28
+ const options = commandLineArgs(buildOptionDefinitions, { argv });
29
+ const usage = commandLineUsage([
30
+ {
31
+ header: 'Create a template project',
32
+ content: 'sentio create <name>',
33
+ },
34
+ {
35
+ header: 'Options',
36
+ optionList: buildOptionDefinitions,
37
+ },
38
+ ]);
39
+ if (options.help) {
40
+ console.log(usage);
41
+ process.exit(0);
42
+ }
43
+ await buildProcessor(false, options);
44
+ }
45
+ export async function buildProcessor(onlyGen, options) {
46
+ if (!options['skip-deps'] && !onlyGen) {
47
+ await installDeps();
48
+ }
49
+ if (!options['skip-gen']) {
50
+ await codegen();
51
+ }
52
+ if (!onlyGen) {
53
+ let tsupConfig;
54
+ try {
55
+ tsupConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts');
56
+ }
57
+ catch (e) {
58
+ console.error(chalk.red("Wrong CLI version for sdk, can't find tsup.config.ts"));
59
+ process.exit(1);
60
+ }
61
+ const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js');
62
+ // await execStep('yarn tsc -p .', 'Compile')
63
+ await execStep(`node ${tsup} --config=${tsupConfig}`, 'Packaging');
64
+ const dir = fs.readdirSync(path.join(process.cwd(), 'dist'));
65
+ const generated = dir.filter((d) => d.endsWith('.js')).length;
66
+ if (generated < 0) {
67
+ console.error(chalk.red('No filed generated, please check if your processor.ts file'));
68
+ process.exit(1);
69
+ }
70
+ if (generated > 1) {
71
+ console.error(chalk.red('Packing failed: '), `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:
72
+ import('mine.js')
73
+ to
74
+ import 'mine.js'
75
+ `);
76
+ }
77
+ }
78
+ }
79
+ async function codegen() {
80
+ const outputBase = path.resolve('src', 'types');
81
+ try {
82
+ // @ts-ignore dynamic import
83
+ const codegen = await import('@sentio/sdk/eth/codegen');
84
+ let input = path.resolve('abis', 'eth');
85
+ let output = path.resolve(outputBase);
86
+ if (!fs.existsSync(input)) {
87
+ input = path.resolve('abis', 'evm');
88
+ output = path.resolve(outputBase);
89
+ }
90
+ // @ts-ignore dynamic import
91
+ await codegen.codegen(input, output);
92
+ }
93
+ catch (e) {
94
+ console.error('code gen error', e);
95
+ }
96
+ try {
97
+ // @ts-ignore dynamic import
98
+ const codegen = await import('@sentio/sdk/solana/codegen');
99
+ // @ts-ignore dynamic import
100
+ await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'));
101
+ }
102
+ catch (e) {
103
+ console.error('code gen error', e);
104
+ }
105
+ try {
106
+ // @ts-ignore dynamic import
107
+ const codegen = await import('@sentio/sdk/aptos/codegen');
108
+ // @ts-ignore dynamic import
109
+ await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'));
110
+ }
111
+ catch (e) {
112
+ console.error('code gen error', e);
113
+ }
114
+ }
115
+ async function installDeps() {
116
+ await execStep('yarn install --ignore-scripts', 'Yarn Install');
117
+ }
118
+ async function execStep(cmd, stepName) {
119
+ const child = exec(cmd);
120
+ console.log(chalk.blue(stepName + ' begin'));
121
+ if (!child.stdout || !child.stderr) {
122
+ console.error(chalk.red(stepName + ' failed'));
123
+ process.exit(1);
124
+ }
125
+ child.stdout.pipe(process.stdout);
126
+ child.stderr.pipe(process.stderr);
127
+ await new Promise((resolve) => {
128
+ child.on('close', resolve);
129
+ });
130
+ if (child.exitCode) {
131
+ console.error(chalk.red(stepName + ' failed'));
132
+ process.exit(child.exitCode);
133
+ }
134
+ console.log(chalk.blue(stepName + ' success'));
135
+ console.log();
136
+ }
137
+ //# sourceMappingURL=build.js.map
@@ -0,0 +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,IAAI,CAAA;AACnB,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;AAEjD,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;CACF,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAc;IACzD,MAAM,OAAO,GAAG,eAAe,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACjE,MAAM,KAAK,GA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,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'\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'\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\nexport async function buildProcessorWithArgs(argv: string[]) {\n const options = commandLineArgs(buildOptionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create <name>',\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 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()\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\nasync function codegen() {\n const outputBase = path.resolve('src', 'types')\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)\n if (!fs.existsSync(input)) {\n input = path.resolve('abis', 'evm')\n output = path.resolve(outputBase)\n }\n // @ts-ignore dynamic import\n await codegen.codegen(input, output)\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 // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'))\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 // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'))\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"]}
@@ -2,8 +2,9 @@ import { execSync } from 'child_process';
2
2
  import path from 'path';
3
3
  import { getPackageRoot } from '../utils.js';
4
4
  export function runTest(argv) {
5
- const defaultJest = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/jest.config.js');
5
+ const defaultJestConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib', 'jest.config.js');
6
6
  // if config not existed copy that
7
- execSync(`NODE_OPTIONS=--experimental-vm-modules yarn jest ` + argv.join(' '), { stdio: 'inherit' });
7
+ const jest = path.resolve(getPackageRoot('jest'), 'bin', 'jest');
8
+ execSync(`NODE_OPTIONS=--experimental-vm-modules node ${jest} ${argv.join(' ')}`, { stdio: 'inherit' });
8
9
  }
9
10
  //# sourceMappingURL=run-test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-test.js","sourceRoot":"","sources":["../../src/commands/run-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,UAAU,OAAO,CAAC,IAAc;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC,CAAA;IACrF,kCAAkC;IAClC,QAAQ,CAAC,mDAAmD,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;AACtG,CAAC","sourcesContent":["import { execSync } from 'child_process'\nimport path from 'path'\nimport { getPackageRoot } from '../utils.js'\n\nexport function runTest(argv: string[]) {\n const defaultJest = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/jest.config.js')\n // if config not existed copy that\n execSync(`NODE_OPTIONS=--experimental-vm-modules yarn jest ` + argv.join(' '), { stdio: 'inherit' })\n}\n"]}
1
+ {"version":3,"file":"run-test.js","sourceRoot":"","sources":["../../src/commands/run-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,UAAU,OAAO,CAAC,IAAc;IACpC,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAA;IAC9F,kCAAkC;IAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAChE,QAAQ,CAAC,+CAA+C,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;AACzG,CAAC","sourcesContent":["import { execSync } from 'child_process'\nimport path from 'path'\nimport { getPackageRoot } from '../utils.js'\n\nexport function runTest(argv: string[]) {\n const defaultJestConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib', 'jest.config.js')\n // if config not existed copy that\n const jest = path.resolve(getPackageRoot('jest'), 'bin', 'jest')\n execSync(`NODE_OPTIONS=--experimental-vm-modules node ${jest} ${argv.join(' ')}`, { stdio: 'inherit' })\n}\n"]}
@@ -3,7 +3,7 @@ import commandLineUsage from 'command-line-usage';
3
3
  import { finalizeHost, FinalizeProjectName } from '../config.js';
4
4
  import { URL } from 'url';
5
5
  import fetch from 'node-fetch';
6
- import { buildProcessor } from '../build.js';
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,40 +12,55 @@ 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
+ const uploadOptionDefinitions = [
17
+ {
18
+ name: 'help',
19
+ alias: 'h',
20
+ type: Boolean,
21
+ description: 'Display this usage guide.',
22
+ },
23
+ {
24
+ name: 'api-key',
25
+ type: String,
26
+ description: '(Optional) Manually provide API key rather than use saved credential',
27
+ },
28
+ {
29
+ name: 'host',
30
+ description: '(Optional) Override Sentio Host name',
31
+ type: String,
32
+ },
33
+ {
34
+ name: 'owner',
35
+ description: '(Optional) Override Project owner',
36
+ type: String,
37
+ },
38
+ {
39
+ name: 'nobuild',
40
+ description: '(Optional) Skip build & pack file before uploading, default false',
41
+ type: Boolean,
42
+ },
43
+ {
44
+ name: 'debug',
45
+ description: '(Optional) Run driver in debug mode, default false',
46
+ type: Boolean,
47
+ },
48
+ ];
49
+ function mergeOptions(options1, options2) {
50
+ const res = Object.assign([], options1);
51
+ const added = new Set();
52
+ for (const opt of options1) {
53
+ added.add(opt.name);
54
+ }
55
+ for (const opt of options2) {
56
+ if (!added.has(opt.name)) {
57
+ res.push(opt);
58
+ }
59
+ }
60
+ return res;
61
+ }
15
62
  export async function runUpload(processorConfig, argv) {
16
- const optionDefinitions = [
17
- {
18
- name: 'help',
19
- alias: 'h',
20
- type: Boolean,
21
- description: 'Display this usage guide.',
22
- },
23
- {
24
- name: 'api-key',
25
- type: String,
26
- description: '(Optional) Manually provide API key rather than use saved credential',
27
- },
28
- {
29
- name: 'host',
30
- description: '(Optional) Override Sentio Host name',
31
- type: String,
32
- },
33
- {
34
- name: 'owner',
35
- description: '(Optional) Override Project owner',
36
- type: String,
37
- },
38
- {
39
- name: 'nobuild',
40
- description: '(Optional) Skip build & pack file before uploading, default false',
41
- type: Boolean,
42
- },
43
- {
44
- name: 'debug',
45
- description: '(Optional) Run driver in debug mode, default false',
46
- type: Boolean,
47
- },
48
- ];
63
+ const optionDefinitions = mergeOptions(uploadOptionDefinitions, buildOptionDefinitions);
49
64
  const options = commandLineArgs(optionDefinitions, { argv });
50
65
  if (options.help) {
51
66
  const usage = commandLineUsage([
@@ -59,26 +74,28 @@ export async function runUpload(processorConfig, argv) {
59
74
  },
60
75
  ]);
61
76
  console.log(usage);
77
+ process.exit(0);
62
78
  }
63
- else {
64
- if (options.host) {
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);
76
- let apiOverride = undefined;
77
- if (options['api-key']) {
78
- apiOverride = options['api-key'];
79
- }
80
- return uploadFile(processorConfig, apiOverride);
79
+ if (options.host) {
80
+ processorConfig.host = options.host;
81
+ }
82
+ if (options.nobuild) {
83
+ processorConfig.build = false;
81
84
  }
85
+ if (options.debug) {
86
+ processorConfig.debug = true;
87
+ }
88
+ finalizeHost(processorConfig);
89
+ FinalizeProjectName(processorConfig, options.owner);
90
+ console.log(processorConfig);
91
+ let apiOverride = undefined;
92
+ if (options['api-key']) {
93
+ apiOverride = options['api-key'];
94
+ }
95
+ if (processorConfig.build) {
96
+ await buildProcessor(false, options);
97
+ }
98
+ return uploadFile(processorConfig, apiOverride);
82
99
  }
83
100
  async function createProject(options, apiKey) {
84
101
  const url = new URL('/api/v1/projects', options.host);
@@ -92,9 +109,6 @@ async function createProject(options, apiKey) {
92
109
  });
93
110
  }
94
111
  export async function uploadFile(options, apiKeyOverride) {
95
- if (options.build) {
96
- await buildProcessor(false);
97
- }
98
112
  console.log(chalk.blue('Prepare to upload'));
99
113
  const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js');
100
114
  const apiKey = apiKeyOverride || ReadKey(options.host);
@@ -1 +1 @@
1
- {"version":3,"file":"run-upload.js","sourceRoot":"","sources":["../../src/commands/run-upload.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAuB,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,eAAoC,EAAE,IAAc;IAClF,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sEAAsE;SACpF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EA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ACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,KAAK;SACb,CAAC;KACH,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from '../config.js'\nimport { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { buildProcessor } from '../build.js'\nimport chalk from 'chalk'\nimport path from 'path'\nimport { ReadKey } from '../key.js'\nimport fs from 'fs'\nimport { createHash } from 'crypto'\nimport { execSync } from 'child_process'\nimport { getSdkVersion } from '../utils.js'\nimport readline from 'readline'\n\nexport async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n {\n name: 'debug',\n description: '(Optional) Run driver in debug mode, default false',\n type: Boolean,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n if (options.debug) {\n processorConfig.debug = true\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n return uploadFile(processorConfig, apiOverride)\n }\n}\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n let commitSha = ''\n let gitUrl = ''\n const sha256 = digest\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n gitUrl = execSync('git remote get-url origin').toString().trim()\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n\n // get gcs upload url\n const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getSdkVersion())\n if (!initUploadResRaw.ok) {\n // console.error(chalk.red('Failed to get upload url'))\n console.error(chalk.red(((await initUploadResRaw.json()) as { message: string }).message))\n\n if (initUploadResRaw.status === 404) {\n // create project if not exist\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red(((await res.json()) as { message: string }).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n return\n }\n const initUploadRes = (await initUploadResRaw.json()) as { url: string }\n const uploadUrl = initUploadRes.url\n\n // do actual uploading\n const file = fs.createReadStream(PROCESSOR_FILE)\n const uploadResRaw = await fetch(uploadUrl, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/octet-stream',\n },\n body: file,\n })\n if (!uploadResRaw.ok) {\n console.error(chalk.red('Failed to upload'))\n console.error(chalk.red(await uploadResRaw.text()))\n return\n }\n\n // finish uploading\n const finishUploadResRaw = await finishUpload(\n options.host,\n apiKey,\n options.project,\n getSdkVersion(),\n sha256,\n commitSha,\n gitUrl,\n options.debug\n )\n if (!finishUploadResRaw.ok) {\n console.error(chalk.red('Failed to finish uploading'))\n console.error(chalk.red(await finishUploadResRaw.text()))\n return\n }\n\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { projectFullSlug, version } = (await finishUploadResRaw.json()) as {\n projectFullSlug: string\n version: string\n }\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${projectFullSlug}/datasource`)\n console.log('\\t', chalk.blue('Version:'), version)\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n\nasync function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {\n const initUploadUrl = new URL(`/api/v1/processors/init_upload`, host)\n return fetch(initUploadUrl.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n }),\n })\n}\n\nasync function finishUpload(\n host: string,\n apiKey: string,\n projectSlug: string,\n sdkVersion: string,\n sha256: string,\n commitSha: string,\n gitUrl: string,\n debug: boolean\n) {\n const finishUploadUrl = new URL(`/api/v1/processors/finish_upload`, host)\n return fetch(finishUploadUrl.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n sha256: sha256,\n commit_sha: commitSha,\n git_url: gitUrl,\n debug: debug,\n }),\n })\n}\n"]}
1
+ {"version":3,"file":"run-upload.js","sourceRoot":"","sources":["../../src/commands/run-upload.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAuB,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,OAAO,E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,eAAe,CAAC,IAAI,EAAE;QACjC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,KAAK;SACb,CAAC;KACH,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from '../config.js'\nimport { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { buildOptionDefinitions, buildProcessor } from './build.js'\nimport chalk from 'chalk'\nimport path from 'path'\nimport { ReadKey } from '../key.js'\nimport fs from 'fs'\nimport { createHash } from 'crypto'\nimport { execSync } from 'child_process'\nimport { getSdkVersion } from '../utils.js'\nimport readline from 'readline'\nimport * as process from 'process'\n\nconst uploadOptionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n {\n name: 'debug',\n description: '(Optional) Run driver in debug mode, default false',\n type: Boolean,\n },\n]\n\nfunction mergeOptions(options1: commandLineArgs.OptionDefinition[], options2: commandLineArgs.OptionDefinition[]) {\n const res = Object.assign([], options1)\n const added = new Set<string>()\n for (const opt of options1) {\n added.add(opt.name)\n }\n for (const opt of options2) {\n if (!added.has(opt.name)) {\n res.push(opt)\n }\n }\n return res\n}\n\nexport async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {\n const optionDefinitions = mergeOptions(uploadOptionDefinitions, buildOptionDefinitions)\n\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n process.exit(0)\n }\n\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n if (options.debug) {\n processorConfig.debug = true\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n if (processorConfig.build) {\n await buildProcessor(false, options)\n }\n return uploadFile(processorConfig, apiOverride)\n}\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n let commitSha = ''\n let gitUrl = ''\n const sha256 = digest\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n gitUrl = execSync('git remote get-url origin').toString().trim()\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n\n // get gcs upload url\n const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getSdkVersion())\n if (!initUploadResRaw.ok) {\n // console.error(chalk.red('Failed to get upload url'))\n console.error(chalk.red(((await initUploadResRaw.json()) as { message: string }).message))\n\n if (initUploadResRaw.status === 404) {\n // create project if not exist\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red(((await res.json()) as { message: string }).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n return\n }\n const initUploadRes = (await initUploadResRaw.json()) as { url: string }\n const uploadUrl = initUploadRes.url\n\n // do actual uploading\n const file = fs.createReadStream(PROCESSOR_FILE)\n const uploadResRaw = await fetch(uploadUrl, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/octet-stream',\n },\n body: file,\n })\n if (!uploadResRaw.ok) {\n console.error(chalk.red('Failed to upload'))\n console.error(chalk.red(await uploadResRaw.text()))\n return\n }\n\n // finish uploading\n const finishUploadResRaw = await finishUpload(\n options.host,\n apiKey,\n options.project,\n getSdkVersion(),\n sha256,\n commitSha,\n gitUrl,\n options.debug\n )\n if (!finishUploadResRaw.ok) {\n console.error(chalk.red('Failed to finish uploading'))\n console.error(chalk.red(await finishUploadResRaw.text()))\n return\n }\n\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { projectFullSlug, version } = (await finishUploadResRaw.json()) as {\n projectFullSlug: string\n version: string\n }\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${projectFullSlug}/datasource`)\n console.log('\\t', chalk.blue('Version:'), version)\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n\nasync function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {\n const initUploadUrl = new URL(`/api/v1/processors/init_upload`, host)\n return fetch(initUploadUrl.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n }),\n })\n}\n\nasync function finishUpload(\n host: string,\n apiKey: string,\n projectSlug: string,\n sdkVersion: string,\n sha256: string,\n commitSha: string,\n gitUrl: string,\n debug: boolean\n) {\n const finishUploadUrl = new URL(`/api/v1/processors/finish_upload`, host)\n return fetch(finishUploadUrl.href, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n sha256: sha256,\n commit_sha: commitSha,\n git_url: gitUrl,\n debug: debug,\n }),\n })\n}\n"]}
package/package.json CHANGED
@@ -3,9 +3,9 @@
3
3
  "license": "Apache-2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "2.0.0-rc.9",
6
+ "version": "2.0.0",
7
7
  "scripts": {
8
- "compile": "tsc -p .",
8
+ "compile": "tsc",
9
9
  "build": "yarn compile",
10
10
  "postbuild": "../../scripts/link-bin.sh",
11
11
  "cli": "ts-node-esm src/cli.ts",
@@ -28,7 +28,8 @@
28
28
  "jest": "^29.4.1",
29
29
  "ts-jest": "^29.0.5",
30
30
  "@jest/types": "^29.4.1",
31
- "ts-node": "^10.9.1"
31
+ "ts-node": "^10.9.1",
32
+ "@types/node": "^18.11.18"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/command-line-args": "^5.2.0",
@@ -37,7 +38,6 @@
37
38
  "@types/express": "^4.17.14",
38
39
  "@types/fs-extra": "^11.0.1",
39
40
  "@types/js-yaml": "^4.0.5",
40
- "@types/node": "^18.0.4",
41
41
  "@types/node-fetch": "^2.6.2"
42
42
  },
43
43
  "bin": {
package/src/cli.ts CHANGED
@@ -8,7 +8,7 @@ import path from 'path'
8
8
  import yaml from 'js-yaml'
9
9
  import { SentioProjectConfig } from './config.js'
10
10
  import chalk from 'chalk'
11
- import { buildProcessor } from './build.js'
11
+ import { buildProcessor, buildProcessorWithArgs } from './commands/build.js'
12
12
  import { runCreate } from './commands/run-create.js'
13
13
  import { runVersion } from './commands/run-version.js'
14
14
  import { runLogin } from './commands/run-login.js'
@@ -88,11 +88,11 @@ if (mainOptions.command === 'login') {
88
88
  }
89
89
 
90
90
  if (mainOptions.command === 'upload') {
91
- runUpload(processorConfig, argv)
91
+ await runUpload(processorConfig, argv)
92
92
  } else if (mainOptions.command === 'build') {
93
- buildProcessor(false)
93
+ await buildProcessorWithArgs(argv)
94
94
  } else if (mainOptions.command === 'gen') {
95
- buildProcessor(true)
95
+ await buildProcessor(true, [])
96
96
  } else {
97
97
  usage()
98
98
  }
@@ -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
+ }
@@ -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 defaultJest = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/jest.config.js')
6
+ const defaultJestConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib', 'jest.config.js')
7
7
  // if config not existed copy that
8
- execSync(`NODE_OPTIONS=--experimental-vm-modules yarn jest ` + argv.join(' '), { stdio: 'inherit' })
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 '../build.js'
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
- } else {
64
- if (options.host) {
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
- let apiOverride = undefined
78
- if (options['api-key']) {
79
- apiOverride = options['api-key']
80
- }
81
- return uploadFile(processorConfig, apiOverride)
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')
@@ -13,8 +13,8 @@
13
13
  "stripInternal": true,
14
14
  "noFallthroughCasesInSwitch": true,
15
15
  "noEmitOnError": true,
16
- "outDir": "dist",
17
16
  "rootDir": "./src",
17
+ "outDir": "./dist",
18
18
  "skipLibCheck": true
19
19
  },
20
20
  "exclude": ["dist", "jest.config.ts"]
File without changes
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "template-evm",
2
+ "name": "template-eth",
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "type": "module",
File without changes
@@ -1,6 +1,5 @@
1
1
  import { Counter, Gauge } from '@sentio/sdk'
2
- import { scaleDown } from '@sentio/sdk/utils'
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 = scaleDown(await ctx.contract.rewardPerBlockForStaking(), 18)
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 = scaleDown(event.args.value, 18)
24
+ const val = event.args.value.scaleDown(18)
26
25
  tokenCounter.add(ctx, val)
27
26
  },
28
27
  filter // filter is an optional parameter
@@ -13,8 +13,8 @@
13
13
  "stripInternal": true,
14
14
  "noFallthroughCasesInSwitch": true,
15
15
  "noEmitOnError": true,
16
- "outDir": "dist",
17
16
  "rootDir": "./src",
17
+ "outDir": "./dist",
18
18
  "skipLibCheck": true
19
19
  },
20
20
  "exclude": ["dist", "jest.config.ts"]
@@ -13,8 +13,8 @@
13
13
  "stripInternal": true,
14
14
  "noFallthroughCasesInSwitch": true,
15
15
  "noEmitOnError": true,
16
- "outDir": "dist",
17
16
  "rootDir": "./src",
17
+ "outDir": "./dist",
18
18
  "skipLibCheck": true
19
19
  },
20
20
  "exclude": ["dist", "jest.config.ts"]
@@ -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 as number)
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 as number)
14
+ ctx.meter.Counter('totalWeth_supply').sub(data.amount)
15
15
  }
16
16
  })
@@ -13,8 +13,8 @@
13
13
  "stripInternal": true,
14
14
  "noFallthroughCasesInSwitch": true,
15
15
  "noEmitOnError": true,
16
- "outDir": "dist",
17
16
  "rootDir": "./src",
17
+ "outDir": "./dist",
18
18
  "skipLibCheck": true
19
19
  },
20
20
  "exclude": ["dist", "jest.config.ts"]
package/lib/build.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function buildProcessor(onlyGen: boolean): Promise<void>;
2
- export declare function codeGenEthersProcessor(abisDir: string, ETHERS_TARGET?: string, outDir?: string): Promise<void>;
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,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAgB;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI;IAEJ,IAAI,CAAC,OAAO,EAAE;QACZ,IAAI,cAAsB,CAAA;QAC1B,IAAI;YACF,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC,CAAA;SACnF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC,CAAA;YAChF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAChB;QAED,6CAA6C;QAC7C,MAAM,QAAQ,CAAC,qBAAqB,GAAG,cAAc,EAAE,WAAW,CAAC,CAAA;QAEnE,MAAM,GAAG,GAAG,EAAE,CA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AAI,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'\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"]}
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
- }