@sentio/sdk 1.10.0 → 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"]}
@@ -118,6 +118,32 @@ function codeGenSentioFile(contract) {
118
118
  return contract
119
119
  }
120
120
  `;
121
+ const eventsImports = Object.values(contract.events).flatMap((events) => {
122
+ if (events.length === 1) {
123
+ return [`${events[0].name}Event`, `${events[0].name}EventFilter`];
124
+ }
125
+ else {
126
+ return events.flatMap((e) => [
127
+ `${(0, typechain_1.getFullSignatureAsSymbolForEvent)(e)}_Event`,
128
+ `${(0, typechain_1.getFullSignatureAsSymbolForEvent)(e)}_EventFilter`,
129
+ ]);
130
+ }
131
+ });
132
+ const structImports = Object.values(contract.structs).flatMap((structs) => {
133
+ return structs.flatMap((s) => {
134
+ if (!s.structName) {
135
+ return [];
136
+ }
137
+ if (s.structName.namespace) {
138
+ return [s.structName.namespace];
139
+ }
140
+ else {
141
+ return [s.structName.identifier];
142
+ }
143
+ });
144
+ });
145
+ // dedup namespace
146
+ const uniqueStructImports = [...new Set(structImports)];
121
147
  const imports = (0, typechain_1.createImportsForUsedIdentifiers)({
122
148
  ethers: ['BigNumber', 'BigNumberish', 'CallOverrides', 'BytesLike'],
123
149
  '@ethersproject/providers': ['Networkish'],
@@ -140,17 +166,7 @@ function codeGenSentioFile(contract) {
140
166
  ],
141
167
  './common': ['PromiseOrValue'],
142
168
  './index': [`${contract.name}`, `${contract.name}__factory`],
143
- [`./${contract.name}`]: [].concat(...Object.values(contract.events).map((events) => {
144
- if (events.length === 1) {
145
- return [`${events[0].name}Event`, `${events[0].name}EventFilter`];
146
- }
147
- else {
148
- return events.flatMap((e) => [
149
- `${(0, typechain_1.getFullSignatureAsSymbolForEvent)(e)}_Event`,
150
- `${(0, typechain_1.getFullSignatureAsSymbolForEvent)(e)}_EventFilter`,
151
- ]);
152
- }
153
- })),
169
+ [`./${contract.name}`]: eventsImports.concat(uniqueStructImports),
154
170
  }, source);
155
171
  return imports + source;
156
172
  }