@sentio/sdk 1.10.1 → 1.10.2

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/cli.js CHANGED
@@ -7,212 +7,157 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const command_line_args_1 = __importDefault(require("command-line-args"));
8
8
  const command_line_usage_1 = __importDefault(require("command-line-usage"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const https_1 = __importDefault(require("https"));
11
- const http_1 = __importDefault(require("http"));
12
10
  const path_1 = __importDefault(require("path"));
13
11
  const js_yaml_1 = __importDefault(require("js-yaml"));
14
12
  const config_1 = require("./config");
15
- const key_1 = require("./key");
16
13
  const upload_1 = require("./upload");
17
14
  const chalk_1 = __importDefault(require("chalk"));
18
15
  const build_1 = require("./build");
16
+ const run_login_1 = require("./commands/run-login");
17
+ const run_create_1 = require("./commands/run-create");
19
18
  const mainDefinitions = [{ name: 'command', defaultOption: true }];
20
19
  const mainOptions = (0, command_line_args_1.default)(mainDefinitions, {
21
20
  stopAtFirstUnknown: true,
22
21
  });
23
22
  const argv = mainOptions._unknown || [];
24
- // Process configs
25
- let processorConfig = { host: '', project: '', source: '', build: true, targets: [] };
26
- // Fist step, read from project yaml file
27
- try {
28
- console.log(chalk_1.default.blue('Loading Process config'));
29
- // TODO correctly located sentio.yaml
30
- const pwd = process.cwd();
31
- const packageJson = path_1.default.join(pwd, 'package.json');
32
- if (!fs_1.default.existsSync(packageJson)) {
33
- console.error('package.json not found, please run this command in the root of your project');
34
- process.exit(1);
35
- }
36
- const yamlPath = path_1.default.join(pwd, 'sentio.yaml');
37
- if (!fs_1.default.existsSync(yamlPath)) {
38
- console.error('sentio.yaml not found, please create one according to: TODO docs');
39
- process.exit(1);
23
+ if (mainOptions.command === 'login') {
24
+ (0, run_login_1.runLogin)(argv);
25
+ }
26
+ else if (mainOptions.command === 'create') {
27
+ (0, run_create_1.runCreate)(argv);
28
+ }
29
+ else {
30
+ // For all the commands that need read project configs
31
+ // TODO move them to their own modules
32
+ // Process configs
33
+ let processorConfig = { host: '', project: '', source: '', build: true, targets: [] };
34
+ // Fist step, read from project yaml file
35
+ try {
36
+ console.log(chalk_1.default.blue('Loading Process config'));
37
+ // TODO correctly located sentio.yaml
38
+ const pwd = process.cwd();
39
+ const packageJson = path_1.default.join(pwd, 'package.json');
40
+ if (!fs_1.default.existsSync(packageJson)) {
41
+ console.error('package.json not found, please run this command in the root of your project');
42
+ process.exit(1);
43
+ }
44
+ const yamlPath = path_1.default.join(pwd, 'sentio.yaml');
45
+ if (!fs_1.default.existsSync(yamlPath)) {
46
+ console.error('sentio.yaml not found, please create one according to: TODO docs');
47
+ process.exit(1);
48
+ }
49
+ processorConfig = js_yaml_1.default.load(fs_1.default.readFileSync('sentio.yaml', 'utf8'));
50
+ if (!processorConfig.project === undefined) {
51
+ console.error('Config yaml must have contain a valid project identifier');
52
+ process.exit(1);
53
+ }
54
+ if (processorConfig.build === undefined) {
55
+ processorConfig.build = true;
56
+ }
57
+ if (!processorConfig.host) {
58
+ processorConfig.host = 'prod';
59
+ }
60
+ if (!processorConfig.source) {
61
+ processorConfig.source = 'src/processor.ts';
62
+ }
63
+ if (!processorConfig.targets) {
64
+ console.warn('targets is not defined, use EVM as the default target');
65
+ processorConfig.targets = [];
66
+ }
67
+ if (processorConfig.targets.length === 0) {
68
+ // By default evm
69
+ processorConfig.targets.push({ chain: config_1.EVM });
70
+ }
40
71
  }
41
- processorConfig = js_yaml_1.default.load(fs_1.default.readFileSync('sentio.yaml', 'utf8'));
42
- if (!processorConfig.project === undefined) {
43
- console.error('Config yaml must have contain a valid project identifier');
72
+ catch (e) {
73
+ console.error(e);
44
74
  process.exit(1);
45
75
  }
46
- if (processorConfig.build === undefined) {
47
- processorConfig.build = true;
48
- }
49
- if (!processorConfig.host) {
50
- processorConfig.host = 'prod';
51
- }
52
- if (!processorConfig.source) {
53
- processorConfig.source = 'src/processor.ts';
54
- }
55
- if (!processorConfig.targets) {
56
- console.warn('targets is not defined, use EVM as the default target');
57
- processorConfig.targets = [];
58
- }
59
- if (processorConfig.targets.length === 0) {
60
- // By default evm
61
- processorConfig.targets.push({ chain: config_1.EVM });
62
- }
63
- }
64
- catch (e) {
65
- console.error(e);
66
- process.exit(1);
67
- }
68
- if (mainOptions.command === 'upload') {
69
- const optionDefinitions = [
70
- {
71
- name: 'help',
72
- alias: 'h',
73
- type: Boolean,
74
- description: 'Display this usage guide.',
75
- },
76
- {
77
- name: 'api-key',
78
- type: String,
79
- description: '(Optional) Manually provide API key rather than use saved credential',
80
- },
81
- {
82
- name: 'host',
83
- description: '(Optional) Override Sentio Host name',
84
- type: String,
85
- },
86
- {
87
- name: 'owner',
88
- description: '(Optional) Override Project owner',
89
- type: String,
90
- },
91
- {
92
- name: 'nobuild',
93
- description: '(Optional) Skip build & pack file before uploading, default false',
94
- type: Boolean,
95
- },
96
- ];
97
- const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
98
- if (options.help) {
99
- const usage = (0, command_line_usage_1.default)([
76
+ if (mainOptions.command === 'upload') {
77
+ const optionDefinitions = [
100
78
  {
101
- header: 'Sentio upload',
102
- content: 'Upload your project files to Sentio.',
79
+ name: 'help',
80
+ alias: 'h',
81
+ type: Boolean,
82
+ description: 'Display this usage guide.',
103
83
  },
104
84
  {
105
- header: 'Options',
106
- optionList: optionDefinitions,
85
+ name: 'api-key',
86
+ type: String,
87
+ description: '(Optional) Manually provide API key rather than use saved credential',
107
88
  },
108
- ]);
109
- console.log(usage);
110
- }
111
- else {
112
- if (options.host) {
113
- processorConfig.host = options.host;
114
- }
115
- if (options.nobuild) {
116
- processorConfig.build = false;
89
+ {
90
+ name: 'host',
91
+ description: '(Optional) Override Sentio Host name',
92
+ type: String,
93
+ },
94
+ {
95
+ name: 'owner',
96
+ description: '(Optional) Override Project owner',
97
+ type: String,
98
+ },
99
+ {
100
+ name: 'nobuild',
101
+ description: '(Optional) Skip build & pack file before uploading, default false',
102
+ type: Boolean,
103
+ },
104
+ ];
105
+ const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
106
+ if (options.help) {
107
+ const usage = (0, command_line_usage_1.default)([
108
+ {
109
+ header: 'Sentio upload',
110
+ content: 'Upload your project files to Sentio.',
111
+ },
112
+ {
113
+ header: 'Options',
114
+ optionList: optionDefinitions,
115
+ },
116
+ ]);
117
+ console.log(usage);
117
118
  }
118
- (0, config_1.FinalizeHost)(processorConfig);
119
- (0, config_1.FinalizeProjectName)(processorConfig, options.owner);
120
- console.log(processorConfig);
121
- let apiOverride = undefined;
122
- if (options['api-key']) {
123
- apiOverride = options['api-key'];
119
+ else {
120
+ if (options.host) {
121
+ processorConfig.host = options.host;
122
+ }
123
+ if (options.nobuild) {
124
+ processorConfig.build = false;
125
+ }
126
+ (0, config_1.finalizeHost)(processorConfig);
127
+ (0, config_1.FinalizeProjectName)(processorConfig, options.owner);
128
+ console.log(processorConfig);
129
+ let apiOverride = undefined;
130
+ if (options['api-key']) {
131
+ apiOverride = options['api-key'];
132
+ }
133
+ (0, upload_1.uploadFile)(processorConfig, apiOverride);
124
134
  }
125
- (0, upload_1.uploadFile)(processorConfig, apiOverride);
126
135
  }
127
- }
128
- else if (mainOptions.command === 'login') {
129
- const optionDefinitions = [
130
- {
131
- name: 'help',
132
- alias: 'h',
133
- type: Boolean,
134
- description: 'Display this usage guide.',
135
- },
136
- {
137
- name: 'api-key',
138
- type: String,
139
- description: '(Required) Your API key',
140
- },
141
- {
142
- name: 'host',
143
- description: '(Optional) Override Sentio Host name',
144
- type: String,
145
- },
146
- ];
147
- const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
148
- if (options.help || !options['api-key']) {
136
+ else if (mainOptions.command === 'build') {
137
+ (0, build_1.buildProcessor)(false, processorConfig.targets);
138
+ }
139
+ else if (mainOptions.command === 'gen') {
140
+ (0, build_1.buildProcessor)(true, processorConfig.targets);
141
+ }
142
+ else {
149
143
  const usage = (0, command_line_usage_1.default)([
150
144
  {
151
- header: 'Sentio login',
152
- content: 'Try login to Sentio with your apikey.',
145
+ header: 'Sentio',
146
+ content: 'Login & Manage your project files to Sentio.',
153
147
  },
154
148
  {
155
- header: 'Options',
156
- optionList: optionDefinitions,
149
+ header: 'Usage',
150
+ content: [
151
+ 'sentio $command --help\t\tshow detail usage of specific command',
152
+ 'sentio login --api-key=xx\t\tsave credential to local',
153
+ 'sentio create\t\t\t\tcreate a template project',
154
+ 'sentio upload\t\t\t\tbuild and upload processor to sentio',
155
+ 'sentio gen\t\t\t\tgenerate abi',
156
+ 'sentio build\t\t\t\tgenerate abi and build',
157
+ ],
157
158
  },
158
159
  ]);
159
160
  console.log(usage);
160
161
  }
161
- else {
162
- if (options.host) {
163
- processorConfig.host = options.host;
164
- }
165
- (0, config_1.FinalizeHost)(processorConfig);
166
- console.log(processorConfig);
167
- const url = new URL(processorConfig.host);
168
- const reqOptions = {
169
- hostname: url.hostname,
170
- port: url.port,
171
- path: '/api/v1/processors/check_key',
172
- method: 'HEAD',
173
- headers: {
174
- 'api-key': options['api-key'],
175
- },
176
- };
177
- const h = url.protocol == 'https:' ? https_1.default : http_1.default;
178
- const req = h.request(reqOptions, (res) => {
179
- if (res.statusCode == 200) {
180
- (0, key_1.WriteKey)(processorConfig.host, options['api-key']);
181
- console.log(chalk_1.default.green('login success'));
182
- }
183
- else {
184
- console.error(chalk_1.default.red('login failed, code:', res.statusCode, res.statusMessage));
185
- }
186
- });
187
- req.on('error', (error) => {
188
- console.error(error);
189
- });
190
- req.end();
191
- }
192
- }
193
- else if (mainOptions.command === 'build') {
194
- (0, build_1.buildProcessor)(false, processorConfig.targets);
195
- }
196
- else if (mainOptions.command === 'gen') {
197
- (0, build_1.buildProcessor)(true, processorConfig.targets);
198
- }
199
- else {
200
- const usage = (0, command_line_usage_1.default)([
201
- {
202
- header: 'Sentio',
203
- content: 'Login & Upload your project files to Sentio.',
204
- },
205
- {
206
- header: 'Usage',
207
- content: [
208
- 'sentio $command --help\t\tshow detail usage of specific command',
209
- 'sentio login --api-key=xx\t\tsave credential to local',
210
- 'sentio upload\t\t\t\tbuild and upload processor to sentio',
211
- 'sentio gen\t\t\t\tgenerate abi',
212
- 'sentio build\t\t\t\tgenerate abi and build',
213
- ],
214
- },
215
- ]);
216
- console.log(usage);
217
162
  }
218
163
  //# sourceMappingURL=cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,kDAAyB;AACzB,gDAAuB;AACvB,gDAAuB;AAEvB,sDAA0B;AAC1B,qCAAsF;AACtF,+BAAgC;AAChC,qCAAqC;AACrC,kDAAyB;AACzB,mCAAwC;AAExC,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAClE,MAAM,WAAW,GAAG,IAAA,2BAAe,EAAC,eAAe,EAAE;IACnD,kBAAkB,EAAE,IAAI;CACzB,CAAC,CAAA;AACF,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAA;AAEvC,kBAAkB;AAClB,IAAI,eAAe,GAAwB,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;AAC1G,yCAAyC;AACzC,IAAI;IACF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAA;IACjD,qCAAqC;IACrC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IACzB,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAClD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAC/B,OAAO,CAAC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,KAAK,EAAE;IACxC,IAAA,sBAAc,EAAC,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAC9C;KAAM;IACL,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,iEAAiE;gBACjE,uDAAuD;gBACvD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;aAC7C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;CACnB","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport https from 'https'\nimport http from 'http'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { EVM, FinalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { WriteKey } from './key'\nimport { uploadFile } from './upload'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\n// Process configs\nlet processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true, targets: [] }\n// Fist step, read from project yaml file\ntry {\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\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\nif (mainOptions.command === 'upload') {\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 const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'Upload your project files to Sentio.',\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 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 uploadFile(processorConfig, apiOverride)\n }\n} else if (mainOptions.command === 'login') {\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: '(Required) Your API key',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help || !options['api-key']) {\n const usage = commandLineUsage([\n {\n header: 'Sentio login',\n content: 'Try login to Sentio with your apikey.',\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 FinalizeHost(processorConfig)\n console.log(processorConfig)\n\n const url = new URL(processorConfig.host)\n const reqOptions = {\n hostname: url.hostname,\n port: url.port,\n path: '/api/v1/processors/check_key',\n method: 'HEAD',\n headers: {\n 'api-key': options['api-key'],\n },\n }\n const h = url.protocol == 'https:' ? https : http\n const req = h.request(reqOptions, (res) => {\n if (res.statusCode == 200) {\n WriteKey(processorConfig.host, options['api-key'])\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))\n }\n })\n\n req.on('error', (error) => {\n console.error(error)\n })\n\n req.end()\n }\n} else if (mainOptions.command === 'build') {\n buildProcessor(false, processorConfig.targets)\n} else if (mainOptions.command === 'gen') {\n buildProcessor(true, processorConfig.targets)\n} else {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Upload 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 --api-key=xx\\t\\tsave credential to local',\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 ],\n },\n ])\n console.log(usage)\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;AAC1B,qCAAsF;AACtF,qCAAqC;AACrC,kDAAyB;AACzB,mCAAwC;AACxC,oDAA+C;AAC/C,sDAAiD;AAEjD,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE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;KACF;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,IAAA,sBAAc,EAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;KAC/C;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,IAAA,sBAAc,EAAC,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;KAC9C;SAAM;QACL,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,8CAA8C;aACxD;YACD;gBACE,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE;oBACP,iEAAiE;oBACjE,uDAAuD;oBACvD,gDAAgD;oBAChD,2DAA2D;oBAC3D,gCAAgC;oBAChC,4CAA4C;iBAC7C;aACF;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;CACF","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 { EVM, finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { uploadFile } from './upload'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport { runLogin } from './commands/run-login'\nimport { runCreate } from './commands/run-create'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n runCreate(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: '', source: '', build: true, targets: [] }\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\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 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 const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'Upload your project files to Sentio.',\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 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 uploadFile(processorConfig, apiOverride)\n }\n } else if (mainOptions.command === 'build') {\n buildProcessor(false, processorConfig.targets)\n } else if (mainOptions.command === 'gen') {\n buildProcessor(true, processorConfig.targets)\n } else {\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 --api-key=xx\\t\\tsave credential to local',\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 ],\n },\n ])\n console.log(usage)\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function runCreate(argv: string[]): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runCreate = void 0;
7
+ const command_line_args_1 = __importDefault(require("command-line-args"));
8
+ const command_line_usage_1 = __importDefault(require("command-line-usage"));
9
+ function runCreate(argv) {
10
+ const optionDefinitions = [
11
+ {
12
+ name: 'help',
13
+ alias: 'h',
14
+ type: Boolean,
15
+ description: 'Display this usage guide.',
16
+ },
17
+ {
18
+ name: 'name',
19
+ alias: 'n',
20
+ type: String,
21
+ description: '(Required) Project name',
22
+ },
23
+ ];
24
+ const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
25
+ if (options.help || !options.name) {
26
+ const usage = (0, command_line_usage_1.default)([
27
+ {
28
+ header: 'Sentio Create',
29
+ content: 'Create a template project',
30
+ },
31
+ {
32
+ header: 'Options',
33
+ optionList: optionDefinitions,
34
+ },
35
+ ]);
36
+ console.log(usage);
37
+ }
38
+ else {
39
+ //
40
+ }
41
+ }
42
+ exports.runCreate = runCreate;
43
+ //# sourceMappingURL=run-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-create.js","sourceRoot":"","sources":["../../../src/cli/commands/run-create.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AAEjD,SAAgB,SAAS,CAAC,IAAc;IACtC,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,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,yBAAyB;SACvC;KACF,CAAA;IAED,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5D,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjC,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,eAAe;gBACvB,OAAO,EAAE,2BAA2B;aACrC;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC9B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;SAAM;QACL,EAAE;KACH;AACH,CAAC;AAhCD,8BAgCC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\n\nexport function runCreate(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: 'name',\n alias: 'n',\n type: String,\n description: '(Required) Project name',\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help || !options.name) {\n const usage = commandLineUsage([\n {\n header: 'Sentio Create',\n content: 'Create a template project',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n //\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function runLogin(argv: string[]): void;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runLogin = void 0;
7
+ const command_line_args_1 = __importDefault(require("command-line-args"));
8
+ const command_line_usage_1 = __importDefault(require("command-line-usage"));
9
+ const config_1 = require("../config");
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const https_1 = __importDefault(require("https"));
12
+ const http_1 = __importDefault(require("http"));
13
+ const key_1 = require("../key");
14
+ function runLogin(argv) {
15
+ const optionDefinitions = [
16
+ {
17
+ name: 'help',
18
+ alias: 'h',
19
+ type: Boolean,
20
+ description: 'Display this usage guide.',
21
+ },
22
+ {
23
+ name: 'api-key',
24
+ type: String,
25
+ description: '(Required) Your API key',
26
+ },
27
+ {
28
+ name: 'host',
29
+ description: '(Optional) Override Sentio Host name',
30
+ type: String,
31
+ },
32
+ ];
33
+ const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
34
+ if (options.help || !options['api-key']) {
35
+ const usage = (0, command_line_usage_1.default)([
36
+ {
37
+ header: 'Sentio Login',
38
+ content: 'Try login to Sentio with your apikey.',
39
+ },
40
+ {
41
+ header: 'Options',
42
+ optionList: optionDefinitions,
43
+ },
44
+ ]);
45
+ console.log(usage);
46
+ }
47
+ else {
48
+ const host = (0, config_1.getFinalizedHost)(options.host);
49
+ console.log(chalk_1.default.blue('login to ' + host));
50
+ const url = new URL(host);
51
+ const reqOptions = {
52
+ hostname: url.hostname,
53
+ port: url.port,
54
+ path: '/api/v1/processors/check_key',
55
+ method: 'HEAD',
56
+ headers: {
57
+ 'api-key': options['api-key'],
58
+ },
59
+ };
60
+ const h = url.protocol == 'https:' ? https_1.default : http_1.default;
61
+ const req = h.request(reqOptions, (res) => {
62
+ if (res.statusCode == 200) {
63
+ (0, key_1.WriteKey)(host, options['api-key']);
64
+ console.log(chalk_1.default.green('login success'));
65
+ }
66
+ else {
67
+ console.error(chalk_1.default.red('login failed, code:', res.statusCode, res.statusMessage));
68
+ }
69
+ });
70
+ req.on('error', (error) => {
71
+ console.error(error);
72
+ });
73
+ req.end();
74
+ }
75
+ }
76
+ exports.runLogin = runLogin;
77
+ //# sourceMappingURL=run-login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-login.js","sourceRoot":"","sources":["../../../src/cli/commands/run-login.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,sCAA4C;AAC5C,kDAAyB;AACzB,kDAAyB;AACzB,gDAAuB;AACvB,gCAAiC;AAEjC,SAAgB,QAAQ,CAAC,IAAc;IACrC,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,yBAAyB;SACvC;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SACb;KACF,CAAA;IACD,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5D,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACvC,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,uCAAuC;aACjD;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC9B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;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cesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getFinalizedHost } from '../config'\nimport chalk from 'chalk'\nimport https from 'https'\nimport http from 'http'\nimport { WriteKey } from '../key'\n\nexport function runLogin(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: '(Required) Your API key',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help || !options['api-key']) {\n const usage = commandLineUsage([\n {\n header: 'Sentio Login',\n content: 'Try login to Sentio with your apikey.',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const url = new URL(host)\n const reqOptions = {\n hostname: url.hostname,\n port: url.port,\n path: '/api/v1/processors/check_key',\n method: 'HEAD',\n headers: {\n 'api-key': options['api-key'],\n },\n }\n const h = url.protocol == 'https:' ? https : http\n const req = h.request(reqOptions, (res) => {\n if (res.statusCode == 200) {\n WriteKey(host, options['api-key'])\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))\n }\n })\n\n req.on('error', (error) => {\n console.error(error)\n })\n req.end()\n }\n}\n"]}
@@ -5,7 +5,8 @@ export interface SentioProjectConfig {
5
5
  build: boolean;
6
6
  targets: Target[];
7
7
  }
8
- export declare function FinalizeHost(config: SentioProjectConfig): void;
8
+ export declare function getFinalizedHost(host: string): string;
9
+ export declare function finalizeHost(config: SentioProjectConfig): void;
9
10
  export declare function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined): void;
10
11
  export interface Target {
11
12
  chain: string;
package/lib/cli/config.js CHANGED
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SOLANA = exports.EVM = exports.FinalizeProjectName = exports.FinalizeHost = void 0;
4
- function FinalizeHost(config) {
5
- switch (config.host) {
3
+ exports.SOLANA = exports.EVM = exports.FinalizeProjectName = exports.finalizeHost = exports.getFinalizedHost = void 0;
4
+ function getFinalizedHost(host) {
5
+ switch (host) {
6
6
  case '':
7
7
  case 'prod':
8
- config.host = 'https://app.sentio.xyz';
9
- break;
8
+ return 'https://app.sentio.xyz';
10
9
  case 'test':
11
- config.host = 'https://test.sentio.xyz';
12
- break;
10
+ return 'https://test.sentio.xyz';
13
11
  case 'staging':
14
- config.host = 'https://staging.sentio.xyz';
15
- break;
12
+ return 'https://staging.sentio.xyz';
16
13
  case 'local':
17
- config.host = 'http://localhost:10000';
14
+ return 'http://localhost:10000';
18
15
  }
16
+ return host;
19
17
  }
20
- exports.FinalizeHost = FinalizeHost;
18
+ exports.getFinalizedHost = getFinalizedHost;
19
+ function finalizeHost(config) {
20
+ config.host = getFinalizedHost(config.host);
21
+ }
22
+ exports.finalizeHost = finalizeHost;
21
23
  function FinalizeProjectName(config, owner) {
22
24
  if (owner) {
23
25
  let name = config.project;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,YAAY,CAAC,MAA2B;IACtD,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,MAAM,CAAC,IAAI,GAAG,wBAAwB,CAAA;YACtC,MAAK;QACP,KAAK,MAAM;YACT,MAAM,CAAC,IAAI,GAAG,yBAAyB,CAAA;YACvC,MAAK;QACP,KAAK,SAAS;YACZ,MAAM,CAAC,IAAI,GAAG,4BAA4B,CAAA;YAC1C,MAAK;QACP,KAAK,OAAO;YACV,MAAM,CAAC,IAAI,GAAG,wBAAwB,CAAA;KACzC;AACH,CAAC;AAfD,oCAeC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAOD,qCAAqC;AACxB,QAAA,GAAG,GAAG,KAAK,CAAA;AACX,QAAA,MAAM,GAAG,QAAQ,CAAA","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n source: string\n build: boolean\n targets: Target[]\n}\n\nexport function FinalizeHost(config: SentioProjectConfig) {\n switch (config.host) {\n case '':\n case 'prod':\n config.host = 'https://app.sentio.xyz'\n break\n case 'test':\n config.host = 'https://test.sentio.xyz'\n break\n case 'staging':\n config.host = 'https://staging.sentio.xyz'\n break\n case 'local':\n config.host = 'http://localhost:10000'\n }\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\nexport interface Target {\n chain: string\n abisDir?: string\n}\n\n// Supported target chain, lower case\nexport const EVM = 'evm'\nexport const SOLANA = 'solana'\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,OAAO,wBAAwB,CAAA;QACjC,KAAK,MAAM;YACT,OAAO,yBAAyB,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,4BAA4B,CAAA;QACrC,KAAK,OAAO;YACV,OAAO,wBAAwB,CAAA;KAClC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAbD,4CAaC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAOD,qCAAqC;AACxB,QAAA,GAAG,GAAG,KAAK,CAAA;AACX,QAAA,MAAM,GAAG,QAAQ,CAAA","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n source: string\n build: boolean\n targets: Target[]\n}\n\nexport function getFinalizedHost(host: string): string {\n switch (host) {\n case '':\n case 'prod':\n return 'https://app.sentio.xyz'\n case 'test':\n return 'https://test.sentio.xyz'\n case 'staging':\n return 'https://staging.sentio.xyz'\n case 'local':\n return 'http://localhost:10000'\n }\n return host\n}\n\nexport function finalizeHost(config: SentioProjectConfig) {\n config.host = getFinalizedHost(config.host)\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\nexport interface Target {\n chain: string\n abisDir?: string\n}\n\n// Supported target chain, lower case\nexport const EVM = 'evm'\nexport const SOLANA = 'solana'\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.10.1",
4
+ "version": "1.10.2",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli",
package/src/cli/cli.ts CHANGED
@@ -3,16 +3,15 @@
3
3
  import commandLineArgs from 'command-line-args'
4
4
  import commandLineUsage from 'command-line-usage'
5
5
  import fs from 'fs'
6
- import https from 'https'
7
- import http from 'http'
8
6
  import path from 'path'
9
7
 
10
8
  import yaml from 'js-yaml'
11
- import { EVM, FinalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'
12
- import { WriteKey } from './key'
9
+ import { EVM, finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'
13
10
  import { uploadFile } from './upload'
14
11
  import chalk from 'chalk'
15
12
  import { buildProcessor } from './build'
13
+ import { runLogin } from './commands/run-login'
14
+ import { runCreate } from './commands/run-create'
16
15
 
17
16
  const mainDefinitions = [{ name: 'command', defaultOption: true }]
18
17
  const mainOptions = commandLineArgs(mainDefinitions, {
@@ -20,198 +19,142 @@ const mainOptions = commandLineArgs(mainDefinitions, {
20
19
  })
21
20
  const argv = mainOptions._unknown || []
22
21
 
23
- // Process configs
24
- let processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true, targets: [] }
25
- // Fist step, read from project yaml file
26
- try {
27
- console.log(chalk.blue('Loading Process config'))
28
- // TODO correctly located sentio.yaml
29
- const pwd = process.cwd()
30
- const packageJson = path.join(pwd, 'package.json')
31
- if (!fs.existsSync(packageJson)) {
32
- console.error('package.json not found, please run this command in the root of your project')
33
- process.exit(1)
34
- }
22
+ if (mainOptions.command === 'login') {
23
+ runLogin(argv)
24
+ } else if (mainOptions.command === 'create') {
25
+ runCreate(argv)
26
+ } else {
27
+ // For all the commands that need read project configs
28
+ // TODO move them to their own modules
35
29
 
36
- const yamlPath = path.join(pwd, 'sentio.yaml')
37
- if (!fs.existsSync(yamlPath)) {
38
- console.error('sentio.yaml not found, please create one according to: TODO docs')
39
- process.exit(1)
40
- }
30
+ // Process configs
31
+ let processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true, targets: [] }
32
+ // Fist step, read from project yaml file
33
+ try {
34
+ console.log(chalk.blue('Loading Process config'))
35
+ // TODO correctly located sentio.yaml
36
+ const pwd = process.cwd()
37
+ const packageJson = path.join(pwd, 'package.json')
38
+ if (!fs.existsSync(packageJson)) {
39
+ console.error('package.json not found, please run this command in the root of your project')
40
+ process.exit(1)
41
+ }
41
42
 
42
- processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig
43
- if (!processorConfig.project === undefined) {
44
- console.error('Config yaml must have contain a valid project identifier')
45
- process.exit(1)
46
- }
47
- if (processorConfig.build === undefined) {
48
- processorConfig.build = true
49
- }
50
- if (!processorConfig.host) {
51
- processorConfig.host = 'prod'
52
- }
43
+ const yamlPath = path.join(pwd, 'sentio.yaml')
44
+ if (!fs.existsSync(yamlPath)) {
45
+ console.error('sentio.yaml not found, please create one according to: TODO docs')
46
+ process.exit(1)
47
+ }
53
48
 
54
- if (!processorConfig.source) {
55
- processorConfig.source = 'src/processor.ts'
56
- }
57
- if (!processorConfig.targets) {
58
- console.warn('targets is not defined, use EVM as the default target')
59
- processorConfig.targets = []
60
- }
61
- if (processorConfig.targets.length === 0) {
62
- // By default evm
63
- processorConfig.targets.push({ chain: EVM })
49
+ processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig
50
+ if (!processorConfig.project === undefined) {
51
+ console.error('Config yaml must have contain a valid project identifier')
52
+ process.exit(1)
53
+ }
54
+ if (processorConfig.build === undefined) {
55
+ processorConfig.build = true
56
+ }
57
+ if (!processorConfig.host) {
58
+ processorConfig.host = 'prod'
59
+ }
60
+
61
+ if (!processorConfig.source) {
62
+ processorConfig.source = 'src/processor.ts'
63
+ }
64
+ if (!processorConfig.targets) {
65
+ console.warn('targets is not defined, use EVM as the default target')
66
+ processorConfig.targets = []
67
+ }
68
+ if (processorConfig.targets.length === 0) {
69
+ // By default evm
70
+ processorConfig.targets.push({ chain: EVM })
71
+ }
72
+ } catch (e) {
73
+ console.error(e)
74
+ process.exit(1)
64
75
  }
65
- } catch (e) {
66
- console.error(e)
67
- process.exit(1)
68
- }
69
76
 
70
- if (mainOptions.command === 'upload') {
71
- const optionDefinitions = [
72
- {
73
- name: 'help',
74
- alias: 'h',
75
- type: Boolean,
76
- description: 'Display this usage guide.',
77
- },
78
- {
79
- name: 'api-key',
80
- type: String,
81
- description: '(Optional) Manually provide API key rather than use saved credential',
82
- },
83
- {
84
- name: 'host',
85
- description: '(Optional) Override Sentio Host name',
86
- type: String,
87
- },
88
- {
89
- name: 'owner',
90
- description: '(Optional) Override Project owner',
91
- type: String,
92
- },
93
- {
94
- name: 'nobuild',
95
- description: '(Optional) Skip build & pack file before uploading, default false',
96
- type: Boolean,
97
- },
98
- ]
99
- const options = commandLineArgs(optionDefinitions, { argv })
100
- if (options.help) {
101
- const usage = commandLineUsage([
77
+ if (mainOptions.command === 'upload') {
78
+ const optionDefinitions = [
102
79
  {
103
- header: 'Sentio upload',
104
- content: 'Upload your project files to Sentio.',
80
+ name: 'help',
81
+ alias: 'h',
82
+ type: Boolean,
83
+ description: 'Display this usage guide.',
105
84
  },
106
85
  {
107
- header: 'Options',
108
- optionList: optionDefinitions,
86
+ name: 'api-key',
87
+ type: String,
88
+ description: '(Optional) Manually provide API key rather than use saved credential',
109
89
  },
110
- ])
111
- console.log(usage)
112
- } else {
113
- if (options.host) {
114
- processorConfig.host = options.host
115
- }
116
- if (options.nobuild) {
117
- processorConfig.build = false
118
- }
119
- FinalizeHost(processorConfig)
120
- FinalizeProjectName(processorConfig, options.owner)
121
- console.log(processorConfig)
90
+ {
91
+ name: 'host',
92
+ description: '(Optional) Override Sentio Host name',
93
+ type: String,
94
+ },
95
+ {
96
+ name: 'owner',
97
+ description: '(Optional) Override Project owner',
98
+ type: String,
99
+ },
100
+ {
101
+ name: 'nobuild',
102
+ description: '(Optional) Skip build & pack file before uploading, default false',
103
+ type: Boolean,
104
+ },
105
+ ]
106
+ const options = commandLineArgs(optionDefinitions, { argv })
107
+ if (options.help) {
108
+ const usage = commandLineUsage([
109
+ {
110
+ header: 'Sentio upload',
111
+ content: 'Upload your project files to Sentio.',
112
+ },
113
+ {
114
+ header: 'Options',
115
+ optionList: optionDefinitions,
116
+ },
117
+ ])
118
+ console.log(usage)
119
+ } else {
120
+ if (options.host) {
121
+ processorConfig.host = options.host
122
+ }
123
+ if (options.nobuild) {
124
+ processorConfig.build = false
125
+ }
126
+ finalizeHost(processorConfig)
127
+ FinalizeProjectName(processorConfig, options.owner)
128
+ console.log(processorConfig)
122
129
 
123
- let apiOverride = undefined
124
- if (options['api-key']) {
125
- apiOverride = options['api-key']
130
+ let apiOverride = undefined
131
+ if (options['api-key']) {
132
+ apiOverride = options['api-key']
133
+ }
134
+ uploadFile(processorConfig, apiOverride)
126
135
  }
127
- uploadFile(processorConfig, apiOverride)
128
- }
129
- } else if (mainOptions.command === 'login') {
130
- const optionDefinitions = [
131
- {
132
- name: 'help',
133
- alias: 'h',
134
- type: Boolean,
135
- description: 'Display this usage guide.',
136
- },
137
- {
138
- name: 'api-key',
139
- type: String,
140
- description: '(Required) Your API key',
141
- },
142
- {
143
- name: 'host',
144
- description: '(Optional) Override Sentio Host name',
145
- type: String,
146
- },
147
- ]
148
- const options = commandLineArgs(optionDefinitions, { argv })
149
-
150
- if (options.help || !options['api-key']) {
136
+ } else if (mainOptions.command === 'build') {
137
+ buildProcessor(false, processorConfig.targets)
138
+ } else if (mainOptions.command === 'gen') {
139
+ buildProcessor(true, processorConfig.targets)
140
+ } else {
151
141
  const usage = commandLineUsage([
152
142
  {
153
- header: 'Sentio login',
154
- content: 'Try login to Sentio with your apikey.',
143
+ header: 'Sentio',
144
+ content: 'Login & Manage your project files to Sentio.',
155
145
  },
156
146
  {
157
- header: 'Options',
158
- optionList: optionDefinitions,
147
+ header: 'Usage',
148
+ content: [
149
+ 'sentio $command --help\t\tshow detail usage of specific command',
150
+ 'sentio login --api-key=xx\t\tsave credential to local',
151
+ 'sentio create\t\t\t\tcreate a template project',
152
+ 'sentio upload\t\t\t\tbuild and upload processor to sentio',
153
+ 'sentio gen\t\t\t\tgenerate abi',
154
+ 'sentio build\t\t\t\tgenerate abi and build',
155
+ ],
159
156
  },
160
157
  ])
161
158
  console.log(usage)
162
- } else {
163
- if (options.host) {
164
- processorConfig.host = options.host
165
- }
166
- FinalizeHost(processorConfig)
167
- console.log(processorConfig)
168
-
169
- const url = new URL(processorConfig.host)
170
- const reqOptions = {
171
- hostname: url.hostname,
172
- port: url.port,
173
- path: '/api/v1/processors/check_key',
174
- method: 'HEAD',
175
- headers: {
176
- 'api-key': options['api-key'],
177
- },
178
- }
179
- const h = url.protocol == 'https:' ? https : http
180
- const req = h.request(reqOptions, (res) => {
181
- if (res.statusCode == 200) {
182
- WriteKey(processorConfig.host, options['api-key'])
183
- console.log(chalk.green('login success'))
184
- } else {
185
- console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))
186
- }
187
- })
188
-
189
- req.on('error', (error) => {
190
- console.error(error)
191
- })
192
-
193
- req.end()
194
159
  }
195
- } else if (mainOptions.command === 'build') {
196
- buildProcessor(false, processorConfig.targets)
197
- } else if (mainOptions.command === 'gen') {
198
- buildProcessor(true, processorConfig.targets)
199
- } else {
200
- const usage = commandLineUsage([
201
- {
202
- header: 'Sentio',
203
- content: 'Login & Upload your project files to Sentio.',
204
- },
205
- {
206
- header: 'Usage',
207
- content: [
208
- 'sentio $command --help\t\tshow detail usage of specific command',
209
- 'sentio login --api-key=xx\t\tsave credential to local',
210
- 'sentio upload\t\t\t\tbuild and upload processor to sentio',
211
- 'sentio gen\t\t\t\tgenerate abi',
212
- 'sentio build\t\t\t\tgenerate abi and build',
213
- ],
214
- },
215
- ])
216
- console.log(usage)
217
160
  }
@@ -0,0 +1,36 @@
1
+ import commandLineArgs from 'command-line-args'
2
+ import commandLineUsage from 'command-line-usage'
3
+
4
+ export function runCreate(argv: string[]) {
5
+ const optionDefinitions = [
6
+ {
7
+ name: 'help',
8
+ alias: 'h',
9
+ type: Boolean,
10
+ description: 'Display this usage guide.',
11
+ },
12
+ {
13
+ name: 'name',
14
+ alias: 'n',
15
+ type: String,
16
+ description: '(Required) Project name',
17
+ },
18
+ ]
19
+
20
+ const options = commandLineArgs(optionDefinitions, { argv })
21
+ if (options.help || !options.name) {
22
+ const usage = commandLineUsage([
23
+ {
24
+ header: 'Sentio Create',
25
+ content: 'Create a template project',
26
+ },
27
+ {
28
+ header: 'Options',
29
+ optionList: optionDefinitions,
30
+ },
31
+ ])
32
+ console.log(usage)
33
+ } else {
34
+ //
35
+ }
36
+ }
@@ -0,0 +1,70 @@
1
+ import commandLineArgs from 'command-line-args'
2
+ import commandLineUsage from 'command-line-usage'
3
+ import { getFinalizedHost } from '../config'
4
+ import chalk from 'chalk'
5
+ import https from 'https'
6
+ import http from 'http'
7
+ import { WriteKey } from '../key'
8
+
9
+ export function runLogin(argv: string[]) {
10
+ const optionDefinitions = [
11
+ {
12
+ name: 'help',
13
+ alias: 'h',
14
+ type: Boolean,
15
+ description: 'Display this usage guide.',
16
+ },
17
+ {
18
+ name: 'api-key',
19
+ type: String,
20
+ description: '(Required) Your API key',
21
+ },
22
+ {
23
+ name: 'host',
24
+ description: '(Optional) Override Sentio Host name',
25
+ type: String,
26
+ },
27
+ ]
28
+ const options = commandLineArgs(optionDefinitions, { argv })
29
+
30
+ if (options.help || !options['api-key']) {
31
+ const usage = commandLineUsage([
32
+ {
33
+ header: 'Sentio Login',
34
+ content: 'Try login to Sentio with your apikey.',
35
+ },
36
+ {
37
+ header: 'Options',
38
+ optionList: optionDefinitions,
39
+ },
40
+ ])
41
+ console.log(usage)
42
+ } else {
43
+ const host = getFinalizedHost(options.host)
44
+ console.log(chalk.blue('login to ' + host))
45
+ const url = new URL(host)
46
+ const reqOptions = {
47
+ hostname: url.hostname,
48
+ port: url.port,
49
+ path: '/api/v1/processors/check_key',
50
+ method: 'HEAD',
51
+ headers: {
52
+ 'api-key': options['api-key'],
53
+ },
54
+ }
55
+ const h = url.protocol == 'https:' ? https : http
56
+ const req = h.request(reqOptions, (res) => {
57
+ if (res.statusCode == 200) {
58
+ WriteKey(host, options['api-key'])
59
+ console.log(chalk.green('login success'))
60
+ } else {
61
+ console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))
62
+ }
63
+ })
64
+
65
+ req.on('error', (error) => {
66
+ console.error(error)
67
+ })
68
+ req.end()
69
+ }
70
+ }
package/src/cli/config.ts CHANGED
@@ -6,21 +6,23 @@ export interface SentioProjectConfig {
6
6
  targets: Target[]
7
7
  }
8
8
 
9
- export function FinalizeHost(config: SentioProjectConfig) {
10
- switch (config.host) {
9
+ export function getFinalizedHost(host: string): string {
10
+ switch (host) {
11
11
  case '':
12
12
  case 'prod':
13
- config.host = 'https://app.sentio.xyz'
14
- break
13
+ return 'https://app.sentio.xyz'
15
14
  case 'test':
16
- config.host = 'https://test.sentio.xyz'
17
- break
15
+ return 'https://test.sentio.xyz'
18
16
  case 'staging':
19
- config.host = 'https://staging.sentio.xyz'
20
- break
17
+ return 'https://staging.sentio.xyz'
21
18
  case 'local':
22
- config.host = 'http://localhost:10000'
19
+ return 'http://localhost:10000'
23
20
  }
21
+ return host
22
+ }
23
+
24
+ export function finalizeHost(config: SentioProjectConfig) {
25
+ config.host = getFinalizedHost(config.host)
24
26
  }
25
27
 
26
28
  export function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {