@airmoney-degn/airmoney-cli 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/create.js +48 -58
- package/dist/cli/dapp.js +97 -0
- package/dist/cli/demo.js +34 -28
- package/dist/cli/setup.js +17 -104
- package/dist/cli/upload.js +69 -64
- package/dist/cli/wallet.js +46 -30
- package/dist/config.json +1 -1
- package/dist/index.js +20 -41
- package/dist/service/airmoney/AirmoneyService.js +3 -2
- package/dist/service/dapp/DappService.js +162 -0
- package/dist/service/log/LogService.js +85 -0
- package/dist/service/port/PortManager.js +5 -4
- package/dist/service/serve/ServeOrchestrator.js +2 -1
- package/dist/service/simulator/BaseSimulatorService.js +5 -4
- package/dist/util/cryptoProcess.js +22 -21
- package/dist/util/env.js +44 -0
- package/dist/util/format.js +74 -0
- package/dist/util/metadata.js +3 -2
- package/dist/util/network.js +12 -7
- package/dist/util/tarball.js +6 -5
- package/package.json +3 -2
package/dist/cli/create.js
CHANGED
|
@@ -38,41 +38,27 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const types_1 = require("../types");
|
|
40
40
|
const child_process_1 = require("child_process");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// if (!ignoreEnvValidation) {
|
|
58
|
-
// console.log(`Using .env user: ${userId}`);
|
|
59
|
-
// }
|
|
60
|
-
const folderName = locationFolder || name;
|
|
61
|
-
const projectPath = path.join(process.cwd(), folderName);
|
|
62
|
-
if (template) {
|
|
63
|
-
console.log('cloning project');
|
|
64
|
-
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/Air-Money/airmoney-dapp-quickstart ${folderName}`);
|
|
65
|
-
if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
|
|
66
|
-
fs.rmdirSync(path.join(projectPath, '.git'));
|
|
41
|
+
const LogService_1 = require("../service/log/LogService");
|
|
42
|
+
async function createCommand({ name, template, locationFolder, quiet, }) {
|
|
43
|
+
try {
|
|
44
|
+
const identifier = `com.degn.${name}`;
|
|
45
|
+
(0, LogService_1.log)(`Initializing project: ${name}`).white();
|
|
46
|
+
const folderName = locationFolder || name;
|
|
47
|
+
const projectPath = path.join(process.cwd(), folderName);
|
|
48
|
+
if (template) {
|
|
49
|
+
(0, LogService_1.log)('cloning project').white();
|
|
50
|
+
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/Air-Money/airmoney-dapp-quickstart ${folderName}`);
|
|
51
|
+
if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
|
|
52
|
+
fs.rmdirSync(path.join(projectPath, '.git'));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fs.rmSync(path.join(projectPath, '.git'));
|
|
56
|
+
}
|
|
67
57
|
}
|
|
68
58
|
else {
|
|
69
|
-
fs.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
else {
|
|
73
|
-
fs.mkdirSync(projectPath, { recursive: true });
|
|
74
|
-
// replicate Rust logic
|
|
75
|
-
const indexHtml = `
|
|
59
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
60
|
+
// replicate Rust logic
|
|
61
|
+
const indexHtml = `
|
|
76
62
|
<html>
|
|
77
63
|
<head>
|
|
78
64
|
<title>Sample ${name}</title>
|
|
@@ -82,32 +68,36 @@ async function createCommand({ name, template, locationFolder, quiet,
|
|
|
82
68
|
</body>
|
|
83
69
|
</html>
|
|
84
70
|
`.trim();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
// metadata
|
|
93
|
-
const pkg = (0, types_1.createPackage)(name, identifier);
|
|
94
|
-
const metaStr = JSON.stringify(pkg, null, 2);
|
|
95
|
-
fs.writeFileSync(path.join(projectPath, 'metadata.json'), metaStr, 'utf8');
|
|
96
|
-
console.log(`Project '${name}' created successfully.`);
|
|
97
|
-
if (!quiet) {
|
|
98
|
-
console.log(`\nNext steps:`);
|
|
99
|
-
console.log(` cd ${name}`);
|
|
100
|
-
if (template) {
|
|
101
|
-
console.log(' npm install');
|
|
102
|
-
console.log('\n- Development mode:');
|
|
103
|
-
console.log(' npm run dev');
|
|
104
|
-
console.log(' airmoney-cli serve -u http://localhost:5173');
|
|
105
|
-
console.log('\n- Production build:');
|
|
106
|
-
console.log(' npm run build');
|
|
107
|
-
console.log(' airmoney-cli serve -f dist');
|
|
71
|
+
fs.writeFileSync(path.join(projectPath, 'index.html'), indexHtml, 'utf8');
|
|
72
|
+
// assets
|
|
73
|
+
const assetsDir = path.join(projectPath, 'assets');
|
|
74
|
+
fs.mkdirSync(assetsDir, { recursive: true });
|
|
75
|
+
fs.writeFileSync(path.join(assetsDir, 'main.js'), '// sample main.js\n', 'utf8');
|
|
76
|
+
fs.writeFileSync(path.join(assetsDir, 'style.css'), '/* sample style.css */\n', 'utf8');
|
|
108
77
|
}
|
|
109
|
-
|
|
110
|
-
|
|
78
|
+
// metadata
|
|
79
|
+
const pkg = (0, types_1.createPackage)(name, identifier);
|
|
80
|
+
const metaStr = JSON.stringify(pkg, null, 2);
|
|
81
|
+
fs.writeFileSync(path.join(projectPath, 'metadata.json'), metaStr, 'utf8');
|
|
82
|
+
(0, LogService_1.log)(`Project '${name}' created successfully.`).green();
|
|
83
|
+
if (!quiet) {
|
|
84
|
+
(0, LogService_1.log)(`\nNext steps:`).white();
|
|
85
|
+
(0, LogService_1.log)(` cd ${name}`).white();
|
|
86
|
+
if (template) {
|
|
87
|
+
(0, LogService_1.log)(' npm install').white();
|
|
88
|
+
(0, LogService_1.log)('\n- Development mode:').white();
|
|
89
|
+
(0, LogService_1.log)(' npm run dev').white();
|
|
90
|
+
(0, LogService_1.log)(' airmoney-cli serve -u http://localhost:5173').white();
|
|
91
|
+
(0, LogService_1.log)('\n- Production build:').white();
|
|
92
|
+
(0, LogService_1.log)(' npm run build').white();
|
|
93
|
+
(0, LogService_1.log)(' airmoney-cli serve -f dist').white();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
(0, LogService_1.log)(' airmoney-cli serve').white();
|
|
97
|
+
}
|
|
111
98
|
}
|
|
112
99
|
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
102
|
+
}
|
|
113
103
|
}
|
package/dist/cli/dapp.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dappStatusCommand = dappStatusCommand;
|
|
4
|
+
const env_1 = require("../util/env");
|
|
5
|
+
const format_1 = require("../util/format");
|
|
6
|
+
const LogService_1 = require("../service/log/LogService");
|
|
7
|
+
const DappService_1 = require("../service/dapp/DappService");
|
|
8
|
+
async function dappStatusCommand() {
|
|
9
|
+
try {
|
|
10
|
+
const { userId, apiKey, rpc } = (0, env_1.validateCredential)();
|
|
11
|
+
(0, LogService_1.log)(`User: ${(0, format_1.shortenString)(userId)}`).white();
|
|
12
|
+
(0, LogService_1.log)(`Network: ${rpc || ''}`).white();
|
|
13
|
+
const dappService = new DappService_1.DappService(userId, apiKey, rpc);
|
|
14
|
+
await dappService.validateApiKey();
|
|
15
|
+
// Fetch dapp list
|
|
16
|
+
const dapps = await dappService.fetchDappList();
|
|
17
|
+
if (dapps.length === 0) {
|
|
18
|
+
(0, LogService_1.log)('You have not registered any dapps yet').green();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
(0, LogService_1.log)(`Found ${dapps.length} dapp(s)`).green();
|
|
22
|
+
// Fetch details for each dapp
|
|
23
|
+
for (let i = 0; i < dapps.length; i++) {
|
|
24
|
+
const dappName = dapps[i];
|
|
25
|
+
// log(`\nDapp ${i + 1}: ${dappName}`)
|
|
26
|
+
// .bold()
|
|
27
|
+
// .white();
|
|
28
|
+
// log('─'.repeat(80)).white();
|
|
29
|
+
try {
|
|
30
|
+
// Fetch versions/builds with metadata
|
|
31
|
+
const buildsWithMeta = await dappService.fetchDappDetails(dappName);
|
|
32
|
+
if (buildsWithMeta.length === 0) {
|
|
33
|
+
(0, LogService_1.log)(' No builds found for this dapp').italic().white();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Define column widths (Status needs to be wider to accommodate "Waiting", "Pending", etc.)
|
|
37
|
+
const widths = [20, 10, 15, 20, 15, 16, 15];
|
|
38
|
+
const headers = [
|
|
39
|
+
'Name',
|
|
40
|
+
'Version',
|
|
41
|
+
'Author',
|
|
42
|
+
'Identifier',
|
|
43
|
+
'Maintainer',
|
|
44
|
+
'Digest',
|
|
45
|
+
'Status',
|
|
46
|
+
];
|
|
47
|
+
// Print table header
|
|
48
|
+
// log('').white();
|
|
49
|
+
(0, format_1.printTableRow)(headers, widths, true);
|
|
50
|
+
(0, format_1.printSeparator)(widths);
|
|
51
|
+
// Print table rows
|
|
52
|
+
buildsWithMeta.forEach(build => {
|
|
53
|
+
const digest = build.package_digest || 'N/A';
|
|
54
|
+
const shortenedDigest = (0, format_1.shortenString)(digest);
|
|
55
|
+
// Color code status
|
|
56
|
+
const status = build.status || 'N/A';
|
|
57
|
+
let statusText = status;
|
|
58
|
+
let statusColor = '';
|
|
59
|
+
let statusReset = '';
|
|
60
|
+
if (status === 'Active') {
|
|
61
|
+
statusColor = '\x1b[32m'; // Green
|
|
62
|
+
statusReset = '\x1b[0m';
|
|
63
|
+
}
|
|
64
|
+
else if (status === 'Pending') {
|
|
65
|
+
statusColor = '\x1b[33m'; // Yellow
|
|
66
|
+
statusReset = '\x1b[0m';
|
|
67
|
+
}
|
|
68
|
+
else if (status === 'Waiting') {
|
|
69
|
+
statusColor = '\x1b[36m'; // Cyan
|
|
70
|
+
statusReset = '\x1b[0m';
|
|
71
|
+
}
|
|
72
|
+
else if (status === 'Rejected') {
|
|
73
|
+
statusColor = '\x1b[31m'; // Red
|
|
74
|
+
statusReset = '\x1b[0m';
|
|
75
|
+
}
|
|
76
|
+
const row = [
|
|
77
|
+
build.name || 'N/A',
|
|
78
|
+
build.version || 'N/A',
|
|
79
|
+
build.author || 'N/A',
|
|
80
|
+
build.identifier || 'N/A',
|
|
81
|
+
build.maintainer || 'N/A',
|
|
82
|
+
shortenedDigest,
|
|
83
|
+
statusColor + statusText + statusReset,
|
|
84
|
+
];
|
|
85
|
+
(0, format_1.printTableRow)(row, widths);
|
|
86
|
+
});
|
|
87
|
+
// log('').white();
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
(0, LogService_1.log)(`Error fetching versions: ${err instanceof Error ? err.message : String(err)}`).red();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/cli/demo.js
CHANGED
|
@@ -38,35 +38,41 @@ const path = __importStar(require("path"));
|
|
|
38
38
|
const child_process_1 = require("child_process");
|
|
39
39
|
const create_1 = require("./create");
|
|
40
40
|
const serve_1 = require("./serve");
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const folderName = appPath || projectName;
|
|
44
|
-
const projectPath = path.join(process.cwd(), folderName);
|
|
45
|
-
await (0, create_1.createCommand)({
|
|
46
|
-
name: projectName,
|
|
47
|
-
template: true,
|
|
48
|
-
locationFolder: appPath,
|
|
49
|
-
quiet: true,
|
|
50
|
-
// ignoreEnvValidation: true,
|
|
51
|
-
});
|
|
41
|
+
const LogService_1 = require("../service/log/LogService");
|
|
42
|
+
async function demoCommand({ name = "degn-demo", appPath }) {
|
|
52
43
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
const projectName = name;
|
|
45
|
+
const folderName = appPath || projectName;
|
|
46
|
+
const projectPath = path.join(process.cwd(), folderName);
|
|
47
|
+
await (0, create_1.createCommand)({
|
|
48
|
+
name: projectName,
|
|
49
|
+
template: true,
|
|
50
|
+
locationFolder: appPath,
|
|
51
|
+
quiet: true,
|
|
52
|
+
// ignoreEnvValidation: true,
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
(0, LogService_1.log)('Installing dependencies...').white();
|
|
56
|
+
(0, child_process_1.execSync)('npm install', { cwd: projectPath, stdio: 'inherit' });
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
(0, LogService_1.log)('Failed to install dependencies').red();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
(0, LogService_1.log)('Starting dev server...').white();
|
|
63
|
+
const devProc = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
|
|
64
|
+
cwd: projectPath,
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
shell: process.platform === 'win32',
|
|
67
|
+
});
|
|
68
|
+
devProc.on('error', err => {
|
|
69
|
+
(0, LogService_1.log)(`Failed to start dev server: ${err}`).red();
|
|
70
|
+
});
|
|
71
|
+
// Give the dev server a moment to boot; default Vite port is 5173
|
|
72
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
73
|
+
await (0, serve_1.serveCommand)({ noBrowser: false, locationFolder: undefined, appUrl: 'http://localhost:5173' });
|
|
55
74
|
}
|
|
56
|
-
catch (
|
|
57
|
-
|
|
58
|
-
return;
|
|
75
|
+
catch (err) {
|
|
76
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
59
77
|
}
|
|
60
|
-
console.log('Starting dev server...');
|
|
61
|
-
const devProc = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
|
|
62
|
-
cwd: projectPath,
|
|
63
|
-
stdio: 'inherit',
|
|
64
|
-
shell: process.platform === 'win32',
|
|
65
|
-
});
|
|
66
|
-
devProc.on('error', err => {
|
|
67
|
-
console.error('Failed to start dev server:', err);
|
|
68
|
-
});
|
|
69
|
-
// Give the dev server a moment to boot; default Vite port is 5173
|
|
70
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
71
|
-
await (0, serve_1.serveCommand)({ noBrowser: false, locationFolder: undefined, appUrl: 'http://localhost:5173' });
|
|
72
78
|
}
|
package/dist/cli/setup.js
CHANGED
|
@@ -32,122 +32,35 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.setupCommand = setupCommand;
|
|
40
|
-
exports.statusCommand = statusCommand;
|
|
41
37
|
const fs = __importStar(require("fs"));
|
|
42
38
|
const path = __importStar(require("path"));
|
|
43
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
39
|
const env_1 = require("../util/env");
|
|
45
|
-
const
|
|
40
|
+
const LogService_1 = require("../service/log/LogService");
|
|
46
41
|
async function setupCommand({ network, userId, apiKey, }) {
|
|
47
|
-
const dir = (0, env_1.configDir)();
|
|
48
|
-
if (!dir)
|
|
49
|
-
return;
|
|
50
|
-
// ensure directory
|
|
51
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
52
|
-
const envPath = path.join(dir, '.env');
|
|
53
42
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
console.error(`error when writing .env to ${envPath}`);
|
|
59
|
-
console.error(err);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async function statusCommand() {
|
|
64
|
-
// Read environment variables (already loaded by loadEnvFromConfig at startup)
|
|
65
|
-
const userId = process.env.DEVELOPER_ADDRESS || '';
|
|
66
|
-
const apiKey = process.env.API_KEY || '';
|
|
67
|
-
const rpc = process.env.RPC || 'devnet';
|
|
68
|
-
// Validate that we have both userId and apiKey
|
|
69
|
-
if (!userId || !apiKey) {
|
|
70
|
-
console.log('\x1b[31mRun "airmoney-cli setup" to configure your credentials\x1b[0m');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
console.log('User:', userId);
|
|
74
|
-
console.log('Network:', rpc);
|
|
75
|
-
console.log('');
|
|
76
|
-
// Check API key validity
|
|
77
|
-
// RPC should already be a URL (stored from setup), but handle network names for backward compatibility
|
|
78
|
-
let apiUrl = (0, network_1.networkToRpcUrl)(rpc);
|
|
79
|
-
const body = JSON.stringify({
|
|
80
|
-
jsonrpc: '2.0',
|
|
81
|
-
id: 1,
|
|
82
|
-
method: 'checkApiKey',
|
|
83
|
-
params: [userId, apiKey],
|
|
84
|
-
});
|
|
85
|
-
try {
|
|
86
|
-
const res = await (0, node_fetch_1.default)(apiUrl, {
|
|
87
|
-
method: 'POST',
|
|
88
|
-
body,
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
if (!res.ok) {
|
|
94
|
-
console.log('\x1b[31mError: Failed to connect to API\x1b[0m');
|
|
95
|
-
console.log(`\x1b[31mMessage: HTTP ${res.status} - ${await res.text()}\x1b[0m`);
|
|
43
|
+
const dir = (0, env_1.configDir)();
|
|
44
|
+
if (!dir)
|
|
96
45
|
return;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (json.error.message) {
|
|
105
|
-
errorMessageParts.push(json.error.message);
|
|
106
|
-
}
|
|
107
|
-
// Parse and add data field if it exists and is different from message
|
|
108
|
-
if (json.error.data !== undefined) {
|
|
109
|
-
let dataMessage = '';
|
|
110
|
-
if (typeof json.error.data === 'string') {
|
|
111
|
-
try {
|
|
112
|
-
const parsed = JSON.parse(json.error.data);
|
|
113
|
-
dataMessage = parsed;
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
dataMessage = json.error.data.replace(/^"|"$/g, '');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
dataMessage = String(json.error.data);
|
|
121
|
-
}
|
|
122
|
-
// Only add data if it's different from message
|
|
123
|
-
if (dataMessage && dataMessage !== json.error.message) {
|
|
124
|
-
errorMessageParts.push(dataMessage);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Combine into final error message
|
|
128
|
-
const combinedMessage = errorMessageParts.length > 0
|
|
129
|
-
? errorMessageParts.join(' - ')
|
|
130
|
-
: 'Invalid API key';
|
|
131
|
-
console.log(`\x1b[31mMessage: ${combinedMessage}\x1b[0m`);
|
|
132
|
-
if (json.error.code === -32602) {
|
|
133
|
-
console.log('');
|
|
134
|
-
console.log('\x1b[3mPlease visit https://dash-devnet.degn.com/ to get a valid API key\x1b[0m');
|
|
46
|
+
// ensure directory
|
|
47
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
48
|
+
const envPath = path.join(dir, '.env');
|
|
49
|
+
try {
|
|
50
|
+
let envContent = `DEVELOPER_ADDRESS=${userId}\nAPI_KEY=${apiKey}\n`;
|
|
51
|
+
if (network) {
|
|
52
|
+
envContent += `RPC=${network}\n`;
|
|
135
53
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (json.result === true) {
|
|
139
|
-
console.log('\x1b[32mStatus: Credentials are valid\x1b[0m');
|
|
140
|
-
console.log('\x1b[32mMessage: Your API key is active and ready to use\x1b[0m');
|
|
54
|
+
fs.writeFileSync(envPath, envContent, 'utf8');
|
|
55
|
+
(0, LogService_1.log)(`.env created at ${envPath}`).white();
|
|
141
56
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
57
|
+
catch (err) {
|
|
58
|
+
(0, LogService_1.log)(`error when writing .env to ${envPath}`).red();
|
|
59
|
+
(0, LogService_1.log)(String(err)).red();
|
|
60
|
+
process.exit(1);
|
|
145
61
|
}
|
|
146
62
|
}
|
|
147
63
|
catch (err) {
|
|
148
|
-
|
|
149
|
-
console.log(`\x1b[31mMessage: ${err instanceof Error ? err.message : String(err)}\x1b[0m`);
|
|
150
|
-
console.log('');
|
|
151
|
-
console.log('\x1b[3mPlease check your internet connection and try again\x1b[0m');
|
|
64
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
152
65
|
}
|
|
153
66
|
}
|
package/dist/cli/upload.js
CHANGED
|
@@ -43,77 +43,82 @@ const md5_1 = __importDefault(require("md5")); // default import fixes TS call
|
|
|
43
43
|
const metadata_1 = require("../util/metadata");
|
|
44
44
|
const tarball_1 = require("../util/tarball");
|
|
45
45
|
const network_1 = require("../util/network");
|
|
46
|
+
const env_1 = require("../util/env");
|
|
47
|
+
const LogService_1 = require("../service/log/LogService");
|
|
46
48
|
const path_1 = __importDefault(require("path"));
|
|
47
49
|
async function uploadCommand({ network, locationFolder, buttonImages, }) {
|
|
48
|
-
console.log('Loading metadata...');
|
|
49
|
-
const userId = process.env.DEVELOPER_ADDRESS || '';
|
|
50
|
-
const apiKey = process.env.API_KEY || '';
|
|
51
|
-
console.log('User ID:', userId);
|
|
52
|
-
if (!userId || !apiKey) {
|
|
53
|
-
console.error("Missing user or API key from env. Did you run 'airmoney-cli setup'?");
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
let projectPath = process.cwd();
|
|
57
|
-
if (locationFolder != undefined) {
|
|
58
|
-
projectPath = path_1.default.join(projectPath, locationFolder);
|
|
59
|
-
}
|
|
60
|
-
if (buttonImages === undefined) {
|
|
61
|
-
buttonImages = 'assets';
|
|
62
|
-
}
|
|
63
|
-
console.log(buttonImages);
|
|
64
|
-
const meta = (0, metadata_1.loadMetadata)();
|
|
65
|
-
if (!meta) {
|
|
66
|
-
console.error('No metadata.json found. Aborting.');
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const pkgName = (0, metadata_1.getPackageName)(meta);
|
|
70
|
-
console.log(`Packing ${pkgName}...`);
|
|
71
|
-
await (0, tarball_1.packProject)(meta, projectPath, buttonImages);
|
|
72
|
-
const pkgPath = path_1.default.join(process.cwd(), pkgName);
|
|
73
|
-
// read tar
|
|
74
|
-
const fileBuffer = fs.readFileSync(pkgPath);
|
|
75
|
-
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
76
|
-
console.log('Package Hash:', fileHash);
|
|
77
|
-
console.log('Publishing package to DEGN Dapp Store...');
|
|
78
|
-
// encode base64
|
|
79
|
-
const encoded = Buffer.from(fileBuffer).toString('base64');
|
|
80
|
-
// In Rust, we do a JSON-RPC call. Let's replicate:
|
|
81
|
-
const metaJson = JSON.stringify(meta);
|
|
82
|
-
const body = JSON.stringify({
|
|
83
|
-
jsonrpc: '2.0',
|
|
84
|
-
id: 1,
|
|
85
|
-
method: 'uploadPackage',
|
|
86
|
-
params: [userId, apiKey, metaJson, encoded],
|
|
87
|
-
});
|
|
88
50
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
console.error('Error uploding package');
|
|
108
|
-
if (json.error.code == -32602) {
|
|
109
|
-
console.error('invalid api key, please visit https://dash-devnet.air.fun/ and setup env with the new key');
|
|
51
|
+
if ((0, network_1.validateNetwork)(network)) {
|
|
52
|
+
(0, LogService_1.log)('Loading metadata...').white();
|
|
53
|
+
const credentials = (0, env_1.validateCredential)();
|
|
54
|
+
const { userId, apiKey } = credentials;
|
|
55
|
+
(0, LogService_1.log)(`User ID: ${userId}`).white();
|
|
56
|
+
let projectPath = process.cwd();
|
|
57
|
+
if (locationFolder != undefined) {
|
|
58
|
+
projectPath = path_1.default.join(projectPath, locationFolder);
|
|
59
|
+
}
|
|
60
|
+
if (buttonImages === undefined) {
|
|
61
|
+
buttonImages = 'assets';
|
|
62
|
+
}
|
|
63
|
+
(0, LogService_1.log)(buttonImages).white();
|
|
64
|
+
const meta = (0, metadata_1.loadMetadata)();
|
|
65
|
+
if (!meta) {
|
|
66
|
+
(0, LogService_1.log)('No metadata.json found. Aborting.').red();
|
|
110
67
|
return;
|
|
111
68
|
}
|
|
112
|
-
|
|
113
|
-
|
|
69
|
+
const pkgName = (0, metadata_1.getPackageName)(meta);
|
|
70
|
+
(0, LogService_1.log)(`Packing ${pkgName}...`).white();
|
|
71
|
+
await (0, tarball_1.packProject)(meta, projectPath, buttonImages);
|
|
72
|
+
const pkgPath = path_1.default.join(process.cwd(), pkgName);
|
|
73
|
+
// read tar
|
|
74
|
+
const fileBuffer = fs.readFileSync(pkgPath);
|
|
75
|
+
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
76
|
+
(0, LogService_1.log)(`Package Hash: ${fileHash}`).white();
|
|
77
|
+
(0, LogService_1.log)('Publishing package to DEGN Dapp Store...').white();
|
|
78
|
+
// encode base64
|
|
79
|
+
const encoded = Buffer.from(fileBuffer).toString('base64');
|
|
80
|
+
// In Rust, we do a JSON-RPC call. Let's replicate:
|
|
81
|
+
const metaJson = JSON.stringify(meta);
|
|
82
|
+
const body = JSON.stringify({
|
|
83
|
+
jsonrpc: '2.0',
|
|
84
|
+
id: 1,
|
|
85
|
+
method: 'uploadPackage',
|
|
86
|
+
params: [userId, apiKey, metaJson, encoded],
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const rpcUrl = (0, network_1.networkToRpcUrl)(network);
|
|
90
|
+
const res = await (0, node_fetch_1.default)(rpcUrl, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
body,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/json',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
if (!res.ok) {
|
|
98
|
+
(0, LogService_1.log)(`Error uploading package: ${await res.text()}`).red();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const json = await res.json();
|
|
102
|
+
if (json.result === true) {
|
|
103
|
+
(0, LogService_1.log)('Package uploaded successfully').green();
|
|
104
|
+
(0, LogService_1.log)('Open : https://dash-devnet.air.fun/').white();
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, LogService_1.log)('Error uploding package').red();
|
|
108
|
+
if (json.error.code == -32602) {
|
|
109
|
+
(0, LogService_1.log)('invalid api key, please visit https://dash-devnet.air.fun/ and setup env with the new key').red();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
(0, LogService_1.log)('unknow error, please contact support').red();
|
|
113
|
+
(0, LogService_1.log)(JSON.stringify(json.error)).red();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
(0, LogService_1.log)(`Error: ${err}`).red();
|
|
118
|
+
}
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
catch (err) {
|
|
117
|
-
|
|
122
|
+
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
118
123
|
}
|
|
119
124
|
}
|