@sentio/cli 1.37.2 → 1.37.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build.d.ts +2 -0
- package/lib/build.js +86 -0
- package/lib/build.js.map +1 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +186 -0
- package/lib/cli.js.map +1 -0
- package/lib/commands/login-server.d.ts +7 -0
- package/lib/commands/login-server.js +133 -0
- package/lib/commands/login-server.js.map +1 -0
- package/lib/commands/run-create.d.ts +1 -0
- package/lib/commands/run-create.js +121 -0
- package/lib/commands/run-create.js.map +1 -0
- package/lib/commands/run-login.d.ts +1 -0
- package/lib/commands/run-login.js +136 -0
- package/lib/commands/run-login.js.map +1 -0
- package/lib/commands/run-version.d.ts +1 -0
- package/lib/commands/run-version.js +69 -0
- package/lib/commands/run-version.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.js +64 -0
- package/lib/config.js.map +1 -0
- package/lib/key.d.ts +2 -0
- package/lib/key.js +44 -0
- package/lib/key.js.map +1 -0
- package/lib/upload.d.ts +2 -0
- package/lib/upload.js +189 -0
- package/lib/upload.js.map +1 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +28 -0
- package/lib/utils.js.map +1 -0
- package/lib/webpack.config.js +50 -0
- package/package.json +2 -2
- package/src/commands/run-create.ts +0 -1
package/lib/build.d.ts
ADDED
package/lib/build.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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.codeGenEthersProcessor = exports.buildProcessor = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const child_process_1 = require("child_process");
|
|
11
|
+
async function buildProcessor(onlyGen) {
|
|
12
|
+
if (!onlyGen) {
|
|
13
|
+
await installDeps();
|
|
14
|
+
}
|
|
15
|
+
// targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
|
|
16
|
+
// for (const target) {
|
|
17
|
+
await buildProcessorForTarget(onlyGen);
|
|
18
|
+
// }
|
|
19
|
+
if (!onlyGen) {
|
|
20
|
+
const WEBPACK_CONFIG = path_1.default.join(__dirname, 'webpack.config.js');
|
|
21
|
+
await execStep('yarn tsc -p .', 'Compile');
|
|
22
|
+
await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.buildProcessor = buildProcessor;
|
|
26
|
+
async function buildProcessorForTarget(onlyGen) {
|
|
27
|
+
await codeGenEthersProcessor(path_1.default.join('abis', 'evm'));
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
|
+
const solanaModule = require('@sentio/sdk-solana/lib/codegen/codegen');
|
|
31
|
+
solanaModule.codeGenSolanaProcessor(path_1.default.join('abis', 'solana'));
|
|
32
|
+
}
|
|
33
|
+
catch (e) { }
|
|
34
|
+
try {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
36
|
+
const aptosModuole = require('@sentio/sdk-aptos/lib/codegen/codegen');
|
|
37
|
+
aptosModuole.codeGenAptosProcessor(path_1.default.join('abis', 'aptos'));
|
|
38
|
+
}
|
|
39
|
+
catch (e) { }
|
|
40
|
+
if (onlyGen) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function installDeps() {
|
|
45
|
+
await execStep('yarn install --ignore-scripts', 'Yarn Install');
|
|
46
|
+
}
|
|
47
|
+
async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path_1.default.dirname(require.resolve('@sentio/sdk/lib/target-ethers-sentio')), outDir = 'src/types/internal') {
|
|
48
|
+
if (!fs_1.default.existsSync(abisDir)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let haveJson = false;
|
|
52
|
+
const files = fs_1.default.readdirSync(abisDir);
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
if (file.toLowerCase().endsWith('.json')) {
|
|
55
|
+
haveJson = true;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!haveJson) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
console.log(chalk_1.default.green('Generated Types for EVM'));
|
|
63
|
+
// TODO this will fail during postinstall, need to locate real typechain path
|
|
64
|
+
await execStep('yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path_1.default.join(abisDir, '*.json')}`, 'Type definitions gen');
|
|
65
|
+
}
|
|
66
|
+
exports.codeGenEthersProcessor = codeGenEthersProcessor;
|
|
67
|
+
async function execStep(cmd, stepName) {
|
|
68
|
+
const child = (0, child_process_1.exec)(cmd);
|
|
69
|
+
console.log(chalk_1.default.blue(stepName + ' begin'));
|
|
70
|
+
if (!child.stdout || !child.stderr) {
|
|
71
|
+
console.error(chalk_1.default.red(stepName + ' failed'));
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
child.stdout.pipe(process.stdout);
|
|
75
|
+
child.stderr.pipe(process.stderr);
|
|
76
|
+
await new Promise((resolve) => {
|
|
77
|
+
child.on('close', resolve);
|
|
78
|
+
});
|
|
79
|
+
if (child.exitCode) {
|
|
80
|
+
console.error(chalk_1.default.red(stepName + ' failed'));
|
|
81
|
+
process.exit(child.exitCode);
|
|
82
|
+
}
|
|
83
|
+
console.log(chalk_1.default.blue(stepName + ' success'));
|
|
84
|
+
console.log();
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=build.js.map
|
package/lib/build.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRo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CAAC,CAAC,CAAC,CAAA;KAChB;IAED,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACjC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,IAAI,KAAK,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const solanaModule = require('@sentio/sdk-solana/lib/codegen/codegen')\n solanaModule.codeGenSolanaProcessor(path.join('abis', 'solana'))\n } catch (e) {}\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const aptosModuole = require('@sentio/sdk-aptos/lib/codegen/codegen')\n aptosModuole.codeGenAptosProcessor(path.join('abis', 'aptos'))\n } catch (e) {}\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.dirname(require.resolve('@sentio/sdk/lib/target-ethers-sentio')),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
package/lib/cli.d.ts
ADDED
package/lib/cli.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
8
|
+
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
|
+
const config_1 = require("./config");
|
|
13
|
+
const upload_1 = require("./upload");
|
|
14
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
+
const build_1 = require("./build");
|
|
16
|
+
const run_create_1 = require("./commands/run-create");
|
|
17
|
+
const run_version_1 = require("./commands/run-version");
|
|
18
|
+
const run_login_1 = require("./commands/run-login");
|
|
19
|
+
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
20
|
+
const mainOptions = (0, command_line_args_1.default)(mainDefinitions, {
|
|
21
|
+
stopAtFirstUnknown: true,
|
|
22
|
+
});
|
|
23
|
+
const argv = mainOptions._unknown || [];
|
|
24
|
+
if (!mainOptions.command) {
|
|
25
|
+
usage();
|
|
26
|
+
}
|
|
27
|
+
if (mainOptions.command === 'login') {
|
|
28
|
+
(0, run_login_1.runLogin)(argv);
|
|
29
|
+
}
|
|
30
|
+
else if (mainOptions.command === 'create') {
|
|
31
|
+
(0, run_create_1.runCreate)(argv);
|
|
32
|
+
}
|
|
33
|
+
else if (mainOptions.command === 'version') {
|
|
34
|
+
(0, run_version_1.runVersion)(argv);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// For all the commands that need read project configs
|
|
38
|
+
// TODO move them to their own modules
|
|
39
|
+
// Process configs
|
|
40
|
+
let processorConfig = { host: '', project: '', build: true, debug: false };
|
|
41
|
+
// Fist step, read from project yaml file
|
|
42
|
+
try {
|
|
43
|
+
console.log(chalk_1.default.blue('Loading Process config'));
|
|
44
|
+
// TODO correctly located sentio.yaml
|
|
45
|
+
const pwd = process.cwd();
|
|
46
|
+
const packageJson = path_1.default.join(pwd, 'package.json');
|
|
47
|
+
if (!fs_1.default.existsSync(packageJson)) {
|
|
48
|
+
console.error('package.json not found, please run this command in the root of your project');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const yamlPath = path_1.default.join(pwd, 'sentio.yaml');
|
|
52
|
+
if (!fs_1.default.existsSync(yamlPath)) {
|
|
53
|
+
console.error('sentio.yaml not found, please create one according to: TODO docs');
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
processorConfig = js_yaml_1.default.load(fs_1.default.readFileSync('sentio.yaml', 'utf8'));
|
|
57
|
+
if (!processorConfig.project === undefined) {
|
|
58
|
+
console.error('Config yaml must have contain a valid project identifier');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
if (processorConfig.build === undefined) {
|
|
62
|
+
processorConfig.build = true;
|
|
63
|
+
}
|
|
64
|
+
if (!processorConfig.host) {
|
|
65
|
+
processorConfig.host = 'prod';
|
|
66
|
+
}
|
|
67
|
+
if (processorConfig.debug === undefined) {
|
|
68
|
+
processorConfig.debug = false;
|
|
69
|
+
}
|
|
70
|
+
// if (!processorConfig.source) {
|
|
71
|
+
// processorConfig.source = 'src/processor.ts'
|
|
72
|
+
// }
|
|
73
|
+
// if (!processorConfig.targets) {
|
|
74
|
+
// console.warn('targets is not defined, use EVM as the default target')
|
|
75
|
+
// processorConfig.targets = []
|
|
76
|
+
// }
|
|
77
|
+
// if (processorConfig.targets.length === 0) {
|
|
78
|
+
// // By default evm
|
|
79
|
+
// processorConfig.targets.push({ chain: EVM })
|
|
80
|
+
// }
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
console.error(e);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (mainOptions.command === 'upload') {
|
|
87
|
+
const optionDefinitions = [
|
|
88
|
+
{
|
|
89
|
+
name: 'help',
|
|
90
|
+
alias: 'h',
|
|
91
|
+
type: Boolean,
|
|
92
|
+
description: 'Display this usage guide.',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'api-key',
|
|
96
|
+
type: String,
|
|
97
|
+
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'host',
|
|
101
|
+
description: '(Optional) Override Sentio Host name',
|
|
102
|
+
type: String,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'owner',
|
|
106
|
+
description: '(Optional) Override Project owner',
|
|
107
|
+
type: String,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'nobuild',
|
|
111
|
+
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
112
|
+
type: Boolean,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'debug',
|
|
116
|
+
description: '(Optional) Set driver logging level to debug',
|
|
117
|
+
type: Boolean,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
|
|
121
|
+
if (options.help) {
|
|
122
|
+
const usage = (0, command_line_usage_1.default)([
|
|
123
|
+
{
|
|
124
|
+
header: 'Sentio upload',
|
|
125
|
+
content: 'sentio upload',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
header: 'Options',
|
|
129
|
+
optionList: optionDefinitions,
|
|
130
|
+
},
|
|
131
|
+
]);
|
|
132
|
+
console.log(usage);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
if (options.host) {
|
|
136
|
+
processorConfig.host = options.host;
|
|
137
|
+
}
|
|
138
|
+
if (options.nobuild) {
|
|
139
|
+
processorConfig.build = false;
|
|
140
|
+
}
|
|
141
|
+
if (options.debug) {
|
|
142
|
+
processorConfig.debug = true;
|
|
143
|
+
}
|
|
144
|
+
(0, config_1.finalizeHost)(processorConfig);
|
|
145
|
+
(0, config_1.FinalizeProjectName)(processorConfig, options.owner);
|
|
146
|
+
console.log(processorConfig);
|
|
147
|
+
let apiOverride = undefined;
|
|
148
|
+
if (options['api-key']) {
|
|
149
|
+
apiOverride = options['api-key'];
|
|
150
|
+
}
|
|
151
|
+
(0, upload_1.uploadFile)(processorConfig, apiOverride);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (mainOptions.command === 'build') {
|
|
155
|
+
(0, build_1.buildProcessor)(false);
|
|
156
|
+
}
|
|
157
|
+
else if (mainOptions.command === 'gen') {
|
|
158
|
+
(0, build_1.buildProcessor)(true);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
usage();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function usage() {
|
|
165
|
+
const usage = (0, command_line_usage_1.default)([
|
|
166
|
+
{
|
|
167
|
+
header: 'Sentio',
|
|
168
|
+
content: 'Login & Manage your project files to Sentio.',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
header: 'Usage',
|
|
172
|
+
content: [
|
|
173
|
+
'sentio <command> --help\t\tshow detail usage of specific command',
|
|
174
|
+
'sentio login\t\t\t\tlogin to sentio',
|
|
175
|
+
'sentio create\t\t\t\tcreate a template project',
|
|
176
|
+
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
177
|
+
'sentio gen\t\t\t\tgenerate abi',
|
|
178
|
+
'sentio build\t\t\t\tgenerate abi and build',
|
|
179
|
+
'sentio version\t\t\tcurrent cli version',
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
]);
|
|
183
|
+
console.log(usage);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=cli.js.map
|
package/lib/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;AAC1B,qCAAiF;AACjF,qCAAqC;AACrC,kDAAyB;AACzB,mCAAwC;AACxC,sDAAiD;AACjD,wDAAmD;AACnD,oDAA+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OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;YAE5B,IAAI,WAAW,GAAG,SAAS,CAAA;YAC3B,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;gBACtB,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;aACjC;YACD,IAAA,mBAAU,EAAC,eAAe,EAAE,WAAW,CAAC,CAAA;SACzC;KACF;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAA;KACtB;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAA;KACrB;SAAM;QACL,KAAK,EAAE,CAAA;KACR;CACF;AAED,SAAS,KAAK;IACZ,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,kEAAkE;gBAClE,qCAAqC;gBACrC,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,yCAAyC;aAC1C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { uploadFile } from './upload'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport { runCreate } from './commands/run-create'\nimport { runVersion } from './commands/run-version'\nimport { runLogin } from './commands/run-login'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true, debug: false }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n if (processorConfig.debug === undefined) {\n processorConfig.debug = false\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n {\n name: 'debug',\n description: '(Optional) Set driver logging level to debug',\n type: Boolean,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n if (options.debug) {\n processorConfig.debug = true\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n uploadFile(processorConfig, apiOverride)\n }\n } else if (mainOptions.command === 'build') {\n buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n buildProcessor(true)\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login\\t\\t\\t\\tlogin to sentio',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.startServer = void 0;
|
|
30
|
+
const express_1 = __importDefault(require("express"));
|
|
31
|
+
const config_1 = require("../config");
|
|
32
|
+
const url_1 = __importStar(require("url"));
|
|
33
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
34
|
+
const utils_1 = require("../utils");
|
|
35
|
+
const key_1 = require("../key");
|
|
36
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
37
|
+
const os_1 = __importDefault(require("os"));
|
|
38
|
+
const crypto = __importStar(require("crypto"));
|
|
39
|
+
const app = (0, express_1.default)();
|
|
40
|
+
let server;
|
|
41
|
+
let authParams;
|
|
42
|
+
function startServer(params) {
|
|
43
|
+
authParams = params;
|
|
44
|
+
server = app.listen(params.serverPort);
|
|
45
|
+
}
|
|
46
|
+
exports.startServer = startServer;
|
|
47
|
+
app.get('/callback', async (req, res) => {
|
|
48
|
+
res.end('login success, please go back to CLI to continue');
|
|
49
|
+
const host = (0, config_1.getFinalizedHost)(authParams.sentioHost);
|
|
50
|
+
const code = req.query.code;
|
|
51
|
+
if (!code || code.length == 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// exchange token
|
|
55
|
+
const tokenResRaw = await getToken(host, code);
|
|
56
|
+
if (!tokenResRaw.ok) {
|
|
57
|
+
console.error(chalk_1.default.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const tokenRes = await tokenResRaw.json();
|
|
61
|
+
const accessToken = tokenRes['access_token'];
|
|
62
|
+
// check if the account is ready
|
|
63
|
+
const userResRaw = await getUser(host, accessToken);
|
|
64
|
+
if (!userResRaw.ok) {
|
|
65
|
+
if (userResRaw.status == 401) {
|
|
66
|
+
console.error(chalk_1.default.red('please sign up on sentio first'));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.error(chalk_1.default.red('get user error, code:', userResRaw.status, userResRaw.statusText));
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const userRes = await userResRaw.json();
|
|
74
|
+
if (!userRes.emailVerified) {
|
|
75
|
+
console.error(chalk_1.default.red('please verify your email first'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// create API key
|
|
79
|
+
const apiKeyName = `${os_1.default.hostname()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
80
|
+
const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken);
|
|
81
|
+
if (!createApiKeyResRaw.ok) {
|
|
82
|
+
console.error(chalk_1.default.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const createApiKeyRes = await createApiKeyResRaw.json();
|
|
86
|
+
const apiKey = createApiKeyRes['key'];
|
|
87
|
+
(0, key_1.WriteKey)(host, apiKey);
|
|
88
|
+
console.log(chalk_1.default.green('login success, new API key: ' + apiKey));
|
|
89
|
+
server.close();
|
|
90
|
+
});
|
|
91
|
+
async function getToken(host, code) {
|
|
92
|
+
const authConf = (0, config_1.getAuthConfig)(host);
|
|
93
|
+
const params = new url_1.default.URLSearchParams({
|
|
94
|
+
grant_type: 'authorization_code',
|
|
95
|
+
client_id: authConf.clientId,
|
|
96
|
+
code_verifier: authParams.codeVerifier,
|
|
97
|
+
code: code,
|
|
98
|
+
redirect_uri: `http://localhost:${authParams.serverPort}/callback`,
|
|
99
|
+
});
|
|
100
|
+
return (0, node_fetch_1.default)(`${authConf.domain}/oauth/token`, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
104
|
+
},
|
|
105
|
+
body: params.toString(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function createApiKey(host, name, source, accessToken) {
|
|
109
|
+
const createApiKeyUrl = new url_1.URL('/api/v1/keys', host);
|
|
110
|
+
return (0, node_fetch_1.default)(createApiKeyUrl, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
Authorization: 'Bearer ' + accessToken,
|
|
114
|
+
version: (0, utils_1.getCliVersion)(),
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
name: name,
|
|
118
|
+
scopes: ['write:project'],
|
|
119
|
+
source: source,
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async function getUser(host, accessToken) {
|
|
124
|
+
const getUserUrl = new url_1.URL('/api/v1/users', host);
|
|
125
|
+
return (0, node_fetch_1.default)(getUserUrl, {
|
|
126
|
+
method: 'GET',
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: 'Bearer ' + accessToken,
|
|
129
|
+
version: (0, utils_1.getCliVersion)(),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=login-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../src/commands/login-server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA6B;AAC7B,sCAA2D;AAC3D,2CAA8B;AAC9B,4DAA8B;AAC9B,oCAAwC;AACxC,gCAAiC;AACjC,kDAAyB;AAEzB,4CAAmB;AACnB,+CAAgC;AAQhC,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;AAErB,IAAI,MAAmB,CAAA;AACvB,IAAI,UAAsB,CAAA;AAE1B,SAAgB,WAAW,CAAC,MAAkB;IAC5C,UAAU,GAAG,MAAM,CAAA;IACnB,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AACxC,CAAC;AAHD,kCAGC;AAED,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACtC,GAAG,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAA;IAC3D,MAAM,IAAI,GAAG,IAAA,yBAAgB,EAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACpD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAA;IAC3B,IAAI,CAAC,IAAI,IAAK,IAAe,CAAC,MAAM,IAAI,CAAC,EAAE;QACzC,OAAM;KACP;IAED,iBAAiB;IACjB,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAc,CAAC,CAAA;IACxD,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,4BAA4B,EAAE,WAAW,CAAC,MAAM,EAA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AAE,IAAI,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,CAAC,eAAe,CAAC;YACzB,MAAM,EAAE,MAAM;SACf,CAAC;KACH,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,IAAY,EAAE,WAAmB;IACtD,MAAM,UAAU,GAAG,IAAI,SAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;IACjD,OAAO,IAAA,oBAAK,EAAC,UAAU,EAAE;QACvB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,GAAG,WAAW;YACtC,OAAO,EAAE,IAAA,qBAAa,GAAE;SACzB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import express from 'express'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport url, { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from '../utils'\nimport { WriteKey } from '../key'\nimport chalk from 'chalk'\nimport http from 'http'\nimport os from 'os'\nimport * as crypto from 'crypto'\n\ninterface AuthParams {\n serverPort: number\n sentioHost: string\n codeVerifier: string\n}\n\nconst app = express()\n\nlet server: http.Server\nlet authParams: AuthParams\n\nexport function startServer(params: AuthParams) {\n authParams = params\n server = app.listen(params.serverPort)\n}\n\napp.get('/callback', async (req, res) => {\n res.end('login success, please go back to CLI to continue')\n const host = getFinalizedHost(authParams.sentioHost)\n const code = req.query.code\n if (!code || (code as string).length == 0) {\n return\n }\n\n // exchange token\n const tokenResRaw = await getToken(host, code as string)\n if (!tokenResRaw.ok) {\n console.error(chalk.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText))\n return\n }\n const tokenRes = await tokenResRaw.json()\n const accessToken = tokenRes['access_token']\n\n // check if the account is ready\n const userResRaw = await getUser(host, accessToken)\n if (!userResRaw.ok) {\n if (userResRaw.status == 401) {\n console.error(chalk.red('please sign up on sentio first'))\n } else {\n console.error(chalk.red('get user error, code:', userResRaw.status, userResRaw.statusText))\n }\n return\n }\n const userRes = await userResRaw.json()\n if (!userRes.emailVerified) {\n console.error(chalk.red('please verify your email first'))\n return\n }\n\n // create API key\n const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`\n const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken)\n if (!createApiKeyResRaw.ok) {\n console.error(chalk.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText))\n return\n }\n const createApiKeyRes = await createApiKeyResRaw.json()\n const apiKey = createApiKeyRes['key']\n WriteKey(host, apiKey)\n console.log(chalk.green('login success, new API key: ' + apiKey))\n\n server.close()\n})\n\nasync function getToken(host: string, code: string) {\n const authConf = getAuthConfig(host)\n const params = new url.URLSearchParams({\n grant_type: 'authorization_code',\n client_id: authConf.clientId,\n code_verifier: authParams.codeVerifier,\n code: code,\n redirect_uri: `http://localhost:${authParams.serverPort}/callback`,\n })\n return fetch(`${authConf.domain}/oauth/token`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: params.toString(),\n })\n}\n\nasync function createApiKey(host: string, name: string, source: string, accessToken: string) {\n const createApiKeyUrl = new URL('/api/v1/keys', host)\n return fetch(createApiKeyUrl, {\n method: 'POST',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n body: JSON.stringify({\n name: name,\n scopes: ['write:project'],\n source: source,\n }),\n })\n}\n\nasync function getUser(host: string, accessToken: string) {\n const getUserUrl = new URL('/api/v1/users', host)\n return fetch(getUserUrl, {\n method: 'GET',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCreate(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const latest_version_1 = __importDefault(require("latest-version"));
|
|
13
|
+
async function runCreate(argv) {
|
|
14
|
+
const optionDefinitions = [
|
|
15
|
+
{
|
|
16
|
+
name: 'help',
|
|
17
|
+
alias: 'h',
|
|
18
|
+
type: Boolean,
|
|
19
|
+
description: 'Display this usage guide.',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'name',
|
|
23
|
+
alias: 'n',
|
|
24
|
+
defaultOption: true,
|
|
25
|
+
type: String,
|
|
26
|
+
description: 'Project name',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'directory',
|
|
30
|
+
alias: 'd',
|
|
31
|
+
description: '(Optional) The root direct new project will be created, default current working dir',
|
|
32
|
+
type: String,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'chain-type',
|
|
36
|
+
alias: 'c',
|
|
37
|
+
description: 'The type of project you want to create, can be evm, aptos, solana, raw (if you want to start from scratch and support multiple types of chains)',
|
|
38
|
+
type: String,
|
|
39
|
+
defaultValue: 'evm',
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
|
|
43
|
+
const usage = (0, command_line_usage_1.default)([
|
|
44
|
+
{
|
|
45
|
+
header: 'Create a template project',
|
|
46
|
+
content: 'sentio create <name>',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
header: 'Options',
|
|
50
|
+
optionList: optionDefinitions,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
if (options.help || !options.name) {
|
|
54
|
+
console.log(usage);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const chainType = options['chain-type'].toLowerCase();
|
|
58
|
+
switch (chainType) {
|
|
59
|
+
case 'evm':
|
|
60
|
+
break;
|
|
61
|
+
case 'aptos':
|
|
62
|
+
break;
|
|
63
|
+
case 'raw':
|
|
64
|
+
break;
|
|
65
|
+
case 'solana':
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
console.error(chalk_1.default.red('non supported chain-type for template creation, use --help for more information.'));
|
|
69
|
+
console.log(usage);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
const templateFolder = path_1.default.resolve(__dirname, '../../templates', chainType);
|
|
73
|
+
const projectName = options.name || 'default';
|
|
74
|
+
const rootDir = options.directory || process.cwd();
|
|
75
|
+
const dstFolder = path_1.default.resolve(rootDir, projectName);
|
|
76
|
+
if (fs_extra_1.default.existsSync(dstFolder)) {
|
|
77
|
+
console.error(chalk_1.default.red("can't create project '" + projectName + "', directory already existed"));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
fs_extra_1.default.copySync(templateFolder, dstFolder, {
|
|
81
|
+
filter: (src, _) => {
|
|
82
|
+
// TODO read from .gitignore to be more reliable
|
|
83
|
+
if (src.endsWith('types') ||
|
|
84
|
+
src.endsWith('dist') ||
|
|
85
|
+
src.endsWith('node_modules') ||
|
|
86
|
+
src.endsWith('.lock') ||
|
|
87
|
+
src.endsWith('dist')) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
overwrite: false,
|
|
93
|
+
});
|
|
94
|
+
if (options.name) {
|
|
95
|
+
const sentioYamlPath = path_1.default.resolve(dstFolder, 'sentio.yaml');
|
|
96
|
+
fs_extra_1.default.writeFileSync(sentioYamlPath, 'project: ' + projectName + '\n', { flag: 'w+' });
|
|
97
|
+
const packageJsonPath = path_1.default.resolve(dstFolder, 'package.json');
|
|
98
|
+
const packageJson = JSON.parse(fs_extra_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
99
|
+
const sdkVersion = '^' + (await (0, latest_version_1.default)('@sentio/sdk'));
|
|
100
|
+
packageJson.dependencies['@sentio/sdk'] = sdkVersion;
|
|
101
|
+
switch (chainType) {
|
|
102
|
+
case 'aptos':
|
|
103
|
+
packageJson.dependencies['@sentio/sdk-aptos'] = sdkVersion;
|
|
104
|
+
break;
|
|
105
|
+
case 'solana':
|
|
106
|
+
packageJson.dependencies['@sentio/sdk-solana'] = sdkVersion;
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
}
|
|
110
|
+
const cliVersion = '^' + (await (0, latest_version_1.default)('@sentio/cli'));
|
|
111
|
+
packageJson.devDependencies['@sentio/cli'] = cliVersion;
|
|
112
|
+
packageJson.name = projectName;
|
|
113
|
+
// Don't add directly to avoid deps issue
|
|
114
|
+
packageJson.scripts.postinstall = 'sentio gen';
|
|
115
|
+
fs_extra_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
116
|
+
}
|
|
117
|
+
console.log(chalk_1.default.green("successfully create project '" + projectName + "'"));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.runCreate = runCreate;
|
|
121
|
+
//# sourceMappingURL=run-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-create.js","sourceRoot":"","sources":["../../src/commands/run-create.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,gDAAuB;AACvB,wDAAyB;AACzB,kDAAyB;AACzB,oEAA0C;AAEnC,KAAK,UAAU,SAAS,CAAC,IAAc;IAC5C,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,E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c,CAAC,CAAA;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAA;YAExE,MAAM,UAAU,GAAG,GAAG,GAAG,CAAC,MAAM,IAAA,wBAAa,EAAC,aAAa,CAAC,CAAC,CAAA;YAC7D,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,UAAU,CAAA;YAEpD,QAAQ,SAAS,EAAE;gBACjB,KAAK,OAAO;oBACV,WAAW,CAAC,YAAY,CAAC,mBAAmB,CAAC,GAAG,UAAU,CAAA;oBAC1D,MAAK;gBACP,KAAK,QAAQ;oBACX,WAAW,CAAC,YAAY,CAAC,oBAAoB,CAAC,GAAG,UAAU,CAAA;oBAC3D,MAAK;gBACP,QAAQ;aACT;YAED,MAAM,UAAU,GAAG,GAAG,GAAG,CAAC,MAAM,IAAA,wBAAa,EAAC,aAAa,CAAC,CAAC,CAAA;YAC7D,WAAW,CAAC,eAAe,CAAC,aAAa,CAAC,GAAG,UAAU,CAAA;YACvD,WAAW,CAAC,IAAI,GAAG,WAAW,CAAA;YAE9B,yCAAyC;YACzC,WAAW,CAAC,OAAO,CAAC,WAAW,GAAG,YAAY,CAAA;YAE9C,kBAAE,CAAC,aAAa,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;SACxE;QACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,+BAA+B,GAAG,WAAW,GAAG,GAAG,CAAC,CAAC,CAAA;KAC9E;AACH,CAAC;AAtHD,8BAsHC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\nimport latestVersion from 'latest-version'\n\nexport async 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 defaultOption: true,\n type: String,\n description: 'Project name',\n },\n {\n name: 'directory',\n alias: 'd',\n description: '(Optional) The root direct new project will be created, default current working dir',\n type: String,\n },\n {\n name: 'chain-type',\n alias: 'c',\n description:\n 'The type of project you want to create, can be evm, aptos, solana, raw (if you want to start from scratch and support multiple types of chains)',\n type: String,\n defaultValue: 'evm',\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create <name>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help || !options.name) {\n console.log(usage)\n } else {\n const chainType: string = options['chain-type'].toLowerCase()\n switch (chainType) {\n case 'evm':\n break\n case 'aptos':\n break\n case 'raw':\n break\n case 'solana':\n break\n default:\n console.error(chalk.red('non supported chain-type for template creation, use --help for more information.'))\n console.log(usage)\n process.exit(1)\n }\n const templateFolder = path.resolve(__dirname, '../../templates', chainType)\n const projectName = options.name || 'default'\n\n const rootDir = options.directory || process.cwd()\n const dstFolder = path.resolve(rootDir, projectName)\n if (fs.existsSync(dstFolder)) {\n console.error(chalk.red(\"can't create project '\" + projectName + \"', directory already existed\"))\n process.exit(1)\n }\n\n fs.copySync(templateFolder, dstFolder, {\n filter: (src, _) => {\n // TODO read from .gitignore to be more reliable\n if (\n src.endsWith('types') ||\n src.endsWith('dist') ||\n src.endsWith('node_modules') ||\n src.endsWith('.lock') ||\n src.endsWith('dist')\n ) {\n return false\n }\n return true\n },\n overwrite: false,\n })\n if (options.name) {\n const sentioYamlPath = path.resolve(dstFolder, 'sentio.yaml')\n fs.writeFileSync(sentioYamlPath, 'project: ' + projectName + '\\n', { flag: 'w+' })\n\n const packageJsonPath = path.resolve(dstFolder, 'package.json')\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))\n\n const sdkVersion = '^' + (await latestVersion('@sentio/sdk'))\n packageJson.dependencies['@sentio/sdk'] = sdkVersion\n\n switch (chainType) {\n case 'aptos':\n packageJson.dependencies['@sentio/sdk-aptos'] = sdkVersion\n break\n case 'solana':\n packageJson.dependencies['@sentio/sdk-solana'] = sdkVersion\n break\n default:\n }\n\n const cliVersion = '^' + (await latestVersion('@sentio/cli'))\n packageJson.devDependencies['@sentio/cli'] = cliVersion\n packageJson.name = projectName\n\n // Don't add directly to avoid deps issue\n packageJson.scripts.postinstall = 'sentio gen'\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))\n }\n console.log(chalk.green(\"successfully create project '\" + projectName + \"'\"))\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runLogin(argv: string[]): void;
|