@sentio/cli 2.0.0-rc.10 → 2.0.0-rc.12

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 } 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';
@@ -85,10 +85,10 @@ else {
85
85
  await runUpload(processorConfig, argv);
86
86
  }
87
87
  else if (mainOptions.command === 'build') {
88
- await buildProcessor(false);
88
+ await buildProcessor(false, argv);
89
89
  }
90
90
  else if (mainOptions.command === 'gen') {
91
- await buildProcessor(true);
91
+ await buildProcessor(true, argv);
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,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,MAAM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C;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,MAAM,cAAc,CAAC,KAAK,CAAC,CAAA;KAC5B;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,MAAM,cAAc,CAAC,IAAI,CAAC,CAAA;KAC3B;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 await runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n await buildProcessor(false)\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"]}
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,qBAAqB,CAAA;AACpD,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,QAAQ,CAAC,IAAI,CAAC,CAAA;CACf;KAAM,IAAI,WAAW,CAAC,OAAO,KAAK,Q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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 './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 buildProcessor(false, argv)\n } else if (mainOptions.command === 'gen') {\n await buildProcessor(true, argv)\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 @@
1
+ export declare function buildProcessor(onlyGen: boolean, argv: string[]): Promise<void>;
@@ -3,15 +3,49 @@ import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { exec } from 'child_process';
5
5
  import * as process from 'process';
6
- import { getPackageRoot } from './utils.js';
7
- export async function buildProcessor(onlyGen) {
8
- if (!onlyGen) {
6
+ import { getPackageRoot } from '../utils.js';
7
+ import commandLineArgs from 'command-line-args';
8
+ import commandLineUsage from 'command-line-usage';
9
+ export async function buildProcessor(onlyGen, argv) {
10
+ const optionDefinitions = [
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
+ const options = commandLineArgs(optionDefinitions, { argv });
29
+ const usage = commandLineUsage([
30
+ {
31
+ header: 'Create a template project',
32
+ content: 'sentio create <name>',
33
+ },
34
+ {
35
+ header: 'Options',
36
+ optionList: optionDefinitions,
37
+ },
38
+ ]);
39
+ if (options.help) {
40
+ console.log(usage);
41
+ process.exit(0);
42
+ }
43
+ if (!options['skip-deps'] && !onlyGen) {
9
44
  await installDeps();
10
45
  }
11
- // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
12
- // for (const target) {
13
- await buildProcessorForTarget(onlyGen);
14
- // }
46
+ if (!options['skip-gen']) {
47
+ await codegen();
48
+ }
15
49
  if (!onlyGen) {
16
50
  let tsupConfig;
17
51
  try {
@@ -39,7 +73,7 @@ import 'mine.js'
39
73
  }
40
74
  }
41
75
  }
42
- async function buildProcessorForTarget(onlyGen) {
76
+ async function codegen() {
43
77
  const outputBase = path.resolve('src', 'types');
44
78
  try {
45
79
  // @ts-ignore dynamic import
@@ -74,9 +108,6 @@ async function buildProcessorForTarget(onlyGen) {
74
108
  catch (e) {
75
109
  console.error('code gen error', e);
76
110
  }
77
- if (onlyGen) {
78
- return;
79
- }
80
111
  }
81
112
  async function installDeps() {
82
113
  await execStep('yarn install --ignore-scripts', 'Yarn Install');
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"A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O,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 async function buildProcessor(onlyGen: boolean, 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: '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\n const options = commandLineArgs(optionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create <name>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help) {\n console.log(usage)\n process.exit(0)\n }\n\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"]}
@@ -1,3 +1,3 @@
1
1
  import { SentioProjectConfig } from '../config.js';
2
2
  export declare function runUpload(processorConfig: SentioProjectConfig, argv: string[]): Promise<void>;
3
- export declare function uploadFile(options: SentioProjectConfig, apiKeyOverride: string): Promise<void>;
3
+ export declare function uploadFile(options: SentioProjectConfig, apiKeyOverride: string, argv: string[]): Promise<void>;
@@ -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 { buildProcessor } from './build.js';
7
7
  import chalk from 'chalk';
8
8
  import path from 'path';
9
9
  import { ReadKey } from '../key.js';
@@ -12,6 +12,7 @@ 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';
15
16
  export async function runUpload(processorConfig, argv) {
16
17
  const optionDefinitions = [
17
18
  {
@@ -59,26 +60,25 @@ export async function runUpload(processorConfig, argv) {
59
60
  },
60
61
  ]);
61
62
  console.log(usage);
63
+ process.exit(0);
62
64
  }
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);
65
+ if (options.host) {
66
+ processorConfig.host = options.host;
67
+ }
68
+ if (options.nobuild) {
69
+ processorConfig.build = false;
70
+ }
71
+ if (options.debug) {
72
+ processorConfig.debug = true;
73
+ }
74
+ finalizeHost(processorConfig);
75
+ FinalizeProjectName(processorConfig, options.owner);
76
+ console.log(processorConfig);
77
+ let apiOverride = undefined;
78
+ if (options['api-key']) {
79
+ apiOverride = options['api-key'];
81
80
  }
81
+ return uploadFile(processorConfig, apiOverride, argv);
82
82
  }
83
83
  async function createProject(options, apiKey) {
84
84
  const url = new URL('/api/v1/projects', options.host);
@@ -91,9 +91,9 @@ async function createProject(options, apiKey) {
91
91
  body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),
92
92
  });
93
93
  }
94
- export async function uploadFile(options, apiKeyOverride) {
94
+ export async function uploadFile(options, apiKeyOverride, argv) {
95
95
  if (options.build) {
96
- await buildProcessor(false);
96
+ await buildProcessor(false, argv);
97
97
  }
98
98
  console.log(chalk.blue('Prepare to upload'));
99
99
  const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js');
@@ -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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,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 { 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,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,OAAO,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CAAA;aACjB;SACF;IACH,CAAC,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;AACtB,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,MAAc,EAAE,WAAmB,EAAE,UAAkB;IAC7F,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAA;IACrE,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE;QAC/B,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;SACxB,CAAC;KACH,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,YAAY,CACzB,IAAY,EACZ,MAAc,EACd,WAAmB,EACnB,UAAkB,EAClB,MAAc,EACd,SAAiB,EACjB,MAAc,EACd,KAAc;IAEd,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAA;IACzE,OAAO,KAAK,CAAC,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 { 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\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 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 return uploadFile(processorConfig, apiOverride, argv)\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, argv: string[]) {\n if (options.build) {\n await buildProcessor(false, argv)\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"]}
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.0.0-rc.10",
6
+ "version": "2.0.0-rc.12",
7
7
  "scripts": {
8
8
  "compile": "tsc",
9
9
  "build": "yarn compile",
@@ -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 } 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'
@@ -90,9 +90,9 @@ if (mainOptions.command === 'login') {
90
90
  if (mainOptions.command === 'upload') {
91
91
  await runUpload(processorConfig, argv)
92
92
  } else if (mainOptions.command === 'build') {
93
- await buildProcessor(false)
93
+ await buildProcessor(false, argv)
94
94
  } else if (mainOptions.command === 'gen') {
95
- await buildProcessor(true)
95
+ await buildProcessor(true, argv)
96
96
  } else {
97
97
  usage()
98
98
  }
@@ -3,17 +3,54 @@ import path from 'path'
3
3
  import fs from 'fs'
4
4
  import { exec } from 'child_process'
5
5
  import * as process from 'process'
6
- import { getPackageRoot } from './utils.js'
6
+ import { getPackageRoot } from '../utils.js'
7
+ import commandLineArgs from 'command-line-args'
8
+ import commandLineUsage from 'command-line-usage'
7
9
 
8
- export async function buildProcessor(onlyGen: boolean) {
9
- if (!onlyGen) {
10
+ export async function buildProcessor(onlyGen: boolean, argv: string[]) {
11
+ const optionDefinitions = [
12
+ {
13
+ name: 'help',
14
+ alias: 'h',
15
+ type: Boolean,
16
+ description: 'Display this usage guide.',
17
+ },
18
+ {
19
+ name: 'skip-gen',
20
+ type: Boolean,
21
+ description: 'Skip code generation.',
22
+ },
23
+ {
24
+ name: 'skip-deps',
25
+ type: Boolean,
26
+ description: 'Skip dependency enforce.',
27
+ },
28
+ ]
29
+
30
+ const options = commandLineArgs(optionDefinitions, { argv })
31
+ const usage = commandLineUsage([
32
+ {
33
+ header: 'Create a template project',
34
+ content: 'sentio create <name>',
35
+ },
36
+ {
37
+ header: 'Options',
38
+ optionList: optionDefinitions,
39
+ },
40
+ ])
41
+
42
+ if (options.help) {
43
+ console.log(usage)
44
+ process.exit(0)
45
+ }
46
+
47
+ if (!options['skip-deps'] && !onlyGen) {
10
48
  await installDeps()
11
49
  }
12
50
 
13
- // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
14
- // for (const target) {
15
- await buildProcessorForTarget(onlyGen)
16
- // }
51
+ if (!options['skip-gen']) {
52
+ await codegen()
53
+ }
17
54
 
18
55
  if (!onlyGen) {
19
56
  let tsupConfig: string
@@ -47,7 +84,7 @@ import 'mine.js'
47
84
  }
48
85
  }
49
86
 
50
- async function buildProcessorForTarget(onlyGen: boolean) {
87
+ async function codegen() {
51
88
  const outputBase = path.resolve('src', 'types')
52
89
  try {
53
90
  // @ts-ignore dynamic import
@@ -81,10 +118,6 @@ async function buildProcessorForTarget(onlyGen: boolean) {
81
118
  } catch (e) {
82
119
  console.error('code gen error', e)
83
120
  }
84
-
85
- if (onlyGen) {
86
- return
87
- }
88
121
  }
89
122
 
90
123
  async function installDeps() {
@@ -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 { buildProcessor } from './build.js'
7
7
  import chalk from 'chalk'
8
8
  import path from 'path'
9
9
  import { ReadKey } from '../key.js'
@@ -12,6 +12,7 @@ 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'
15
16
 
16
17
  export async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {
17
18
  const optionDefinitions = [
@@ -60,26 +61,27 @@ export async function runUpload(processorConfig: SentioProjectConfig, argv: stri
60
61
  },
61
62
  ])
62
63
  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)
64
+ process.exit(0)
65
+ }
76
66
 
77
- let apiOverride = undefined
78
- if (options['api-key']) {
79
- apiOverride = options['api-key']
80
- }
81
- return uploadFile(processorConfig, apiOverride)
67
+ if (options.host) {
68
+ processorConfig.host = options.host
69
+ }
70
+ if (options.nobuild) {
71
+ processorConfig.build = false
72
+ }
73
+ if (options.debug) {
74
+ processorConfig.debug = true
75
+ }
76
+ finalizeHost(processorConfig)
77
+ FinalizeProjectName(processorConfig, options.owner)
78
+ console.log(processorConfig)
79
+
80
+ let apiOverride = undefined
81
+ if (options['api-key']) {
82
+ apiOverride = options['api-key']
82
83
  }
84
+ return uploadFile(processorConfig, apiOverride, argv)
83
85
  }
84
86
 
85
87
  async function createProject(options: SentioProjectConfig, apiKey: string) {
@@ -94,9 +96,9 @@ async function createProject(options: SentioProjectConfig, apiKey: string) {
94
96
  })
95
97
  }
96
98
 
97
- export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {
99
+ export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string, argv: string[]) {
98
100
  if (options.build) {
99
- await buildProcessor(false)
101
+ await buildProcessor(false, argv)
100
102
  }
101
103
 
102
104
  console.log(chalk.blue('Prepare to upload'))
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
File without changes
File without changes
package/lib/build.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function buildProcessor(onlyGen: boolean): Promise<void>;
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,IA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C,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 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 buildProcessorForTarget(onlyGen: boolean) {\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 if (onlyGen) {\n return\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"]}