@airmoney-degn/airmoney-cli 0.17.0 → 0.19.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 +12 -5
- 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 +10 -6
- package/dist/service/simulator/BaseSimulatorService.js +11 -11
- package/dist/service/simulator/SimulatorService.js +0 -1
- package/dist/types.js +9 -3
- 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 +23 -7
- package/dist/util/network.js +12 -7
- package/dist/util/remote.js +55 -0
- package/dist/util/server.js +16 -2
- package/dist/util/tarball.js +6 -5
- package/package.json +3 -2
|
@@ -10,8 +10,11 @@ const express_ws_1 = __importDefault(require("express-ws"));
|
|
|
10
10
|
const cors_1 = __importDefault(require("cors"));
|
|
11
11
|
const open_1 = __importDefault(require("open"));
|
|
12
12
|
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
13
|
+
const LogService_1 = require("../log/LogService");
|
|
14
|
+
const SIMULATOR_SERVICE_PORT = 4041;
|
|
13
15
|
class BaseSimulatorService {
|
|
14
16
|
constructor(config) {
|
|
17
|
+
this.server = null;
|
|
15
18
|
this.simulatorClient = null;
|
|
16
19
|
this.onClientConnectedCallback = null;
|
|
17
20
|
this.config = config;
|
|
@@ -30,14 +33,14 @@ class BaseSimulatorService {
|
|
|
30
33
|
return path_1.default.join(base, 'public', 'simulator');
|
|
31
34
|
}
|
|
32
35
|
setupWebSocket() {
|
|
33
|
-
this.app.ws('/ws', (ws
|
|
36
|
+
this.app.ws('/ws', (ws) => {
|
|
34
37
|
this.simulatorClient = ws;
|
|
35
38
|
// Notify callback about new connection
|
|
36
39
|
if (this.onClientConnectedCallback) {
|
|
37
40
|
this.onClientConnectedCallback(this.getClient());
|
|
38
41
|
}
|
|
39
42
|
ws.on('message', (msg) => {
|
|
40
|
-
|
|
43
|
+
(0, LogService_1.log)(String(msg)).white();
|
|
41
44
|
});
|
|
42
45
|
ws.on('close', () => {
|
|
43
46
|
this.simulatorClient = null;
|
|
@@ -47,7 +50,7 @@ class BaseSimulatorService {
|
|
|
47
50
|
}
|
|
48
51
|
});
|
|
49
52
|
ws.on('error', (error) => {
|
|
50
|
-
|
|
53
|
+
(0, LogService_1.log)(`WebSocket error: ${error}`).red();
|
|
51
54
|
this.simulatorClient = null;
|
|
52
55
|
// Notify callback about disconnection due to error
|
|
53
56
|
if (this.onClientConnectedCallback) {
|
|
@@ -76,12 +79,12 @@ class BaseSimulatorService {
|
|
|
76
79
|
}
|
|
77
80
|
async openBrowser() {
|
|
78
81
|
if (!this.config.noBrowser) {
|
|
79
|
-
const url = `http://localhost:${
|
|
82
|
+
const url = `http://localhost:${SIMULATOR_SERVICE_PORT}/simulator`;
|
|
80
83
|
try {
|
|
81
84
|
await (0, open_1.default)(url);
|
|
82
85
|
}
|
|
83
86
|
catch (err) {
|
|
84
|
-
|
|
87
|
+
(0, LogService_1.log)(`Failed to open web browser ${err}`).red();
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
}
|
|
@@ -104,17 +107,14 @@ class BaseSimulatorService {
|
|
|
104
107
|
}
|
|
105
108
|
return false;
|
|
106
109
|
}
|
|
107
|
-
setOnClientConnected(callback) {
|
|
108
|
-
this.onClientConnectedCallback = callback;
|
|
109
|
-
}
|
|
110
110
|
async start() {
|
|
111
111
|
this.setupWebSocket();
|
|
112
112
|
this.setupStaticFiles();
|
|
113
113
|
this.setupProjectFiles();
|
|
114
114
|
return new Promise(resolve => {
|
|
115
|
-
this.server = this.app.listen(
|
|
116
|
-
const url = `http://localhost:${
|
|
117
|
-
|
|
115
|
+
this.server = this.app.listen(SIMULATOR_SERVICE_PORT, () => {
|
|
116
|
+
const url = `http://localhost:${SIMULATOR_SERVICE_PORT}/simulator`;
|
|
117
|
+
(0, LogService_1.log)(`Starting simulator server at ${url}`).green();
|
|
118
118
|
this.openBrowser();
|
|
119
119
|
resolve();
|
|
120
120
|
});
|
package/dist/types.js
CHANGED
|
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createPackage = createPackage;
|
|
4
4
|
function createPackage(name, identifier) {
|
|
5
5
|
return {
|
|
6
|
-
name,
|
|
7
|
-
identifier,
|
|
6
|
+
name: name,
|
|
7
|
+
identifier: identifier,
|
|
8
|
+
displayName: '',
|
|
8
9
|
author: '',
|
|
9
|
-
version: '0.1.0',
|
|
10
10
|
maintainer: '',
|
|
11
11
|
url: '',
|
|
12
|
+
themeColor: '',
|
|
13
|
+
version: '0.0.1',
|
|
14
|
+
whatsNew: '',
|
|
15
|
+
buildNumber: '',
|
|
16
|
+
commitHash: '',
|
|
17
|
+
buildDate: '',
|
|
12
18
|
};
|
|
13
19
|
}
|
|
@@ -16,6 +16,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
16
16
|
const child_process_1 = require("child_process");
|
|
17
17
|
const env_1 = require("./env");
|
|
18
18
|
const CryptoService_1 = require("../service/crypto/CryptoService");
|
|
19
|
+
const LogService_1 = require("../service/log/LogService");
|
|
19
20
|
// Utility functions for port management
|
|
20
21
|
function isPortInUse(port) {
|
|
21
22
|
return new Promise(resolve => {
|
|
@@ -102,29 +103,29 @@ function startCryptoService() {
|
|
|
102
103
|
}, (error, stdout, stderr) => {
|
|
103
104
|
// Ignore errors if the process was intentionally killed
|
|
104
105
|
if (error && !isKilled && !hasResolved) {
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
(0, LogService_1.log)('Crypto service failed to start:').red();
|
|
107
|
+
(0, LogService_1.log)(`Error details: ${error.message}`).red();
|
|
107
108
|
// Check for specific Rust panic errors
|
|
108
109
|
if (stderr &&
|
|
109
110
|
stderr.includes('Cannot drop a runtime in a context where blocking is not allowed')) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
(0, LogService_1.log)('\n🔧 This appears to be a Rust/tokio runtime issue in the crypto service binary.').red();
|
|
112
|
+
(0, LogService_1.log)('Possible solutions:').red();
|
|
113
|
+
(0, LogService_1.log)('1. The binary may be corrupted - try rebuilding: npm run build').red();
|
|
114
|
+
(0, LogService_1.log)('2. There may be a compatibility issue with your system').red();
|
|
115
|
+
(0, LogService_1.log)('3. Try running the binary directly to see more details:').red();
|
|
116
|
+
(0, LogService_1.log)(` ${bin}`).red();
|
|
116
117
|
}
|
|
117
118
|
else if (stderr) {
|
|
118
|
-
|
|
119
|
+
(0, LogService_1.log)(`Stderr: ${stderr}`).red();
|
|
119
120
|
}
|
|
120
121
|
reject(new Error(`Crypto service failed: ${error.message}`));
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
123
124
|
if (stdout) {
|
|
124
|
-
//
|
|
125
|
+
// log(`Crypto service stdout: ${stdout}`).white();
|
|
125
126
|
}
|
|
126
127
|
if (stderr && !isKilled) {
|
|
127
|
-
|
|
128
|
+
(0, LogService_1.log)(`Crypto service stderr: ${stderr}`).red();
|
|
128
129
|
}
|
|
129
130
|
});
|
|
130
131
|
// Wait 2 seconds before resolving to ensure service is ready
|
|
@@ -153,10 +154,10 @@ function getCryptoServicePath() {
|
|
|
153
154
|
function startCryptoServiceSimple() {
|
|
154
155
|
const bin = getCryptoServicePath();
|
|
155
156
|
if (!(0, fs_1.existsSync)(bin)) {
|
|
156
|
-
|
|
157
|
+
(0, LogService_1.log)(`crypto service not found at ${bin}`).red();
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
|
-
|
|
160
|
+
(0, LogService_1.log)('Starting crypto service at http://localhost:5050').green();
|
|
160
161
|
(0, child_process_1.exec)(bin, { env: { SECURE_STORAGE: (0, env_1.configDir)(), RUST_BACKTRACE: '1' } }, (_, stdout, stderr) => {
|
|
161
162
|
// console.log("stdout", stdout);
|
|
162
163
|
// console.log("stderr", stderr);
|
|
@@ -182,17 +183,17 @@ async function withCryptoService(operation) {
|
|
|
182
183
|
startedCryptoService = true;
|
|
183
184
|
}
|
|
184
185
|
catch (error) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
186
|
+
(0, LogService_1.log)('Failed to start crypto service:').red();
|
|
187
|
+
(0, LogService_1.log)('This might be due to:').red();
|
|
188
|
+
(0, LogService_1.log)('- Missing or corrupted binary files').red();
|
|
189
|
+
(0, LogService_1.log)('- Insufficient permissions').red();
|
|
190
|
+
(0, LogService_1.log)('- System compatibility issues').red();
|
|
191
|
+
(0, LogService_1.log)('- Port conflicts').red();
|
|
192
|
+
(0, LogService_1.log)('\nTry running: npm run build').red();
|
|
192
193
|
throw error;
|
|
193
194
|
}
|
|
194
195
|
const cryptoServiceClient = new CryptoService_1.CryptoService();
|
|
195
|
-
//
|
|
196
|
+
// log('Crypto service client created').white();
|
|
196
197
|
return await operation(cryptoServiceClient);
|
|
197
198
|
}
|
|
198
199
|
catch (error) {
|
package/dist/util/env.js
CHANGED
|
@@ -35,10 +35,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.configDir = configDir;
|
|
37
37
|
exports.loadEnvFromConfig = loadEnvFromConfig;
|
|
38
|
+
exports.getDeveloperAddress = getDeveloperAddress;
|
|
39
|
+
exports.getApiKey = getApiKey;
|
|
40
|
+
exports.getRpc = getRpc;
|
|
41
|
+
exports.validateCredential = validateCredential;
|
|
38
42
|
const fs = __importStar(require("fs"));
|
|
39
43
|
const path = __importStar(require("path"));
|
|
40
44
|
const os = __importStar(require("os"));
|
|
41
45
|
const dotenv = __importStar(require("dotenv"));
|
|
46
|
+
const network_1 = require("./network");
|
|
42
47
|
function configDir() {
|
|
43
48
|
// similar to Rust's ProjectDirs::from("fun", "air", "simulator");
|
|
44
49
|
// We'll do a rough approach
|
|
@@ -54,3 +59,42 @@ function loadEnvFromConfig() {
|
|
|
54
59
|
dotenv.config({ path: envPath });
|
|
55
60
|
}
|
|
56
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the developer address from environment variables
|
|
64
|
+
*/
|
|
65
|
+
function getDeveloperAddress() {
|
|
66
|
+
return process.env.DEVELOPER_ADDRESS || '';
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the API key from environment variables
|
|
70
|
+
*/
|
|
71
|
+
function getApiKey() {
|
|
72
|
+
return process.env.API_KEY || '';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets the RPC/network from environment variables
|
|
76
|
+
*/
|
|
77
|
+
function getRpc() {
|
|
78
|
+
return process.env.RPC;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validates that credentials exist and returns them
|
|
82
|
+
* Throws error if credentials are missing
|
|
83
|
+
*/
|
|
84
|
+
function validateCredential() {
|
|
85
|
+
const userId = getDeveloperAddress();
|
|
86
|
+
const apiKey = getApiKey();
|
|
87
|
+
const rpc = getRpc();
|
|
88
|
+
if (!userId || !apiKey) {
|
|
89
|
+
throw new Error('Missing credentials. Run "airmoney-cli setup" to configure your credentials.');
|
|
90
|
+
}
|
|
91
|
+
if ((0, network_1.validateNetwork)(rpc)) {
|
|
92
|
+
return {
|
|
93
|
+
userId,
|
|
94
|
+
apiKey,
|
|
95
|
+
rpc,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
throw new Error('Invalid network. Must be "devnet" or "mainnet". Your current network is: ' +
|
|
99
|
+
rpc);
|
|
100
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Formatting utilities for CLI output
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stripAnsiCodes = stripAnsiCodes;
|
|
7
|
+
exports.padString = padString;
|
|
8
|
+
exports.printTableRow = printTableRow;
|
|
9
|
+
exports.printSeparator = printSeparator;
|
|
10
|
+
exports.shortenString = shortenString;
|
|
11
|
+
const LogService_1 = require("../service/log/LogService");
|
|
12
|
+
/**
|
|
13
|
+
* Strips ANSI color codes from a string
|
|
14
|
+
*/
|
|
15
|
+
function stripAnsiCodes(str) {
|
|
16
|
+
// Remove ANSI escape codes (CSI escape sequences)
|
|
17
|
+
return str.replace(/\x1b\[[0-9;]*m/g, '');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Formats a string to fixed width for table display
|
|
21
|
+
* Handles ANSI color codes by only counting visible characters for width calculation
|
|
22
|
+
*/
|
|
23
|
+
function padString(str, width) {
|
|
24
|
+
const s = String(str || 'N/A');
|
|
25
|
+
const visibleLength = stripAnsiCodes(s).length;
|
|
26
|
+
if (visibleLength > width) {
|
|
27
|
+
// Truncate the visible text, keeping color codes
|
|
28
|
+
const visibleText = stripAnsiCodes(s);
|
|
29
|
+
const truncated = visibleText.substring(0, width - 3) + '...';
|
|
30
|
+
// Try to preserve color codes at the beginning
|
|
31
|
+
const colorMatch = s.match(/^(\x1b\[[0-9;]*m)/);
|
|
32
|
+
const resetCode = '\x1b[0m';
|
|
33
|
+
if (colorMatch) {
|
|
34
|
+
return colorMatch[1] + truncated + resetCode;
|
|
35
|
+
}
|
|
36
|
+
return truncated;
|
|
37
|
+
}
|
|
38
|
+
// Pad with spaces, but only count visible characters
|
|
39
|
+
const padding = ' '.repeat(width - visibleLength);
|
|
40
|
+
return s + padding;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Prints a table row
|
|
44
|
+
*/
|
|
45
|
+
function printTableRow(columns, widths, isHeader = false) {
|
|
46
|
+
const row = columns.map((col, i) => padString(col, widths[i])).join(' | ');
|
|
47
|
+
if (isHeader) {
|
|
48
|
+
(0, LogService_1.log)(row).bold().white();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
(0, LogService_1.log)(row).white();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Prints a separator line
|
|
56
|
+
*/
|
|
57
|
+
function printSeparator(widths) {
|
|
58
|
+
const line = widths.map(w => '-'.repeat(w)).join('-|-');
|
|
59
|
+
(0, LogService_1.log)(line).white();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Shortens a string to show first N and last N characters with ellipsis
|
|
63
|
+
* @param str - The string to shorten
|
|
64
|
+
* @param maxLength - Maximum length before shortening (default: 14)
|
|
65
|
+
* @param prefixLength - Number of characters to show at start (default: 6)
|
|
66
|
+
* @param suffixLength - Number of characters to show at end (default: 6)
|
|
67
|
+
* @returns Shortened string or original if not long enough
|
|
68
|
+
*/
|
|
69
|
+
function shortenString(str, maxLength = 14, prefixLength = 6, suffixLength = 6) {
|
|
70
|
+
if (!str || str.length <= maxLength) {
|
|
71
|
+
return str;
|
|
72
|
+
}
|
|
73
|
+
return str.substring(0, prefixLength) + '…' + str.substring(str.length - suffixLength);
|
|
74
|
+
}
|
package/dist/util/metadata.js
CHANGED
|
@@ -38,19 +38,35 @@ exports.saveMetadata = saveMetadata;
|
|
|
38
38
|
exports.getPackageName = getPackageName;
|
|
39
39
|
const fs = __importStar(require("fs"));
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
|
-
|
|
41
|
+
const LogService_1 = require("../service/log/LogService");
|
|
42
|
+
const remote_1 = require("./remote");
|
|
43
|
+
async function loadMetadata(projectPath = '.', appUrl) {
|
|
42
44
|
try {
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
let raw;
|
|
46
|
+
if (appUrl) {
|
|
47
|
+
// Fetch from remote URL
|
|
48
|
+
const url = (0, remote_1.buildRemoteUrl)(appUrl, 'metadata.json');
|
|
49
|
+
const fetchedRaw = await (0, remote_1.fetchRemoteText)(url);
|
|
50
|
+
if (fetchedRaw === null) {
|
|
51
|
+
(0, LogService_1.log)('Error loading metadata from remote URL').red();
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
raw = fetchedRaw;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Read from local file system
|
|
58
|
+
const filePath = path.join(projectPath, 'metadata.json');
|
|
59
|
+
if (!fs.existsSync(filePath)) {
|
|
60
|
+
(0, LogService_1.log)('Please run this command in Project directory').white();
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
raw = fs.readFileSync(filePath, 'utf8');
|
|
47
64
|
}
|
|
48
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
49
65
|
const data = JSON.parse(raw);
|
|
50
66
|
return data;
|
|
51
67
|
}
|
|
52
68
|
catch (err) {
|
|
53
|
-
|
|
69
|
+
(0, LogService_1.log)('Error loading metadata').red();
|
|
54
70
|
return null;
|
|
55
71
|
}
|
|
56
72
|
}
|
package/dist/util/network.js
CHANGED
|
@@ -12,12 +12,18 @@ exports.networkToRpcUrl = networkToRpcUrl;
|
|
|
12
12
|
* @throws Error if network is invalid
|
|
13
13
|
*/
|
|
14
14
|
function validateNetwork(network) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (network) {
|
|
16
|
+
const normalized = network.toLowerCase().trim();
|
|
17
|
+
if (normalized !== 'devnet' && normalized !== 'mainnet') {
|
|
18
|
+
throw new Error(`Invalid network: ${network}. Must be "devnet" or "mainnet"`);
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
return true;
|
|
20
22
|
}
|
|
23
|
+
const networkMap = {
|
|
24
|
+
devnet: 'https://rpc-dev.air.fun/',
|
|
25
|
+
mainnet: 'https://rpc.air.fun/',
|
|
26
|
+
};
|
|
21
27
|
/**
|
|
22
28
|
* Maps network name to RPC URL
|
|
23
29
|
* Only accepts "devnet" or "mainnet"
|
|
@@ -26,11 +32,10 @@ function validateNetwork(network) {
|
|
|
26
32
|
* @throws Error if network is invalid
|
|
27
33
|
*/
|
|
28
34
|
function networkToRpcUrl(network) {
|
|
35
|
+
if (!network) {
|
|
36
|
+
return networkMap.devnet;
|
|
37
|
+
}
|
|
29
38
|
const normalized = network.toLowerCase().trim();
|
|
30
|
-
const networkMap = {
|
|
31
|
-
'devnet': 'https://rpc-dev.air.fun/',
|
|
32
|
-
'mainnet': 'https://rpc.air.fun/',
|
|
33
|
-
};
|
|
34
39
|
if (!(normalized in networkMap)) {
|
|
35
40
|
throw new Error(`Invalid network: ${network}. Must be "devnet" or "mainnet"`);
|
|
36
41
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for fetching resources from remote URLs
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
7
|
+
exports.buildRemoteUrl = buildRemoteUrl;
|
|
8
|
+
exports.fetchRemoteText = fetchRemoteText;
|
|
9
|
+
exports.fetchRemoteBase64 = fetchRemoteBase64;
|
|
10
|
+
/**
|
|
11
|
+
* Normalizes a base URL by removing trailing slashes
|
|
12
|
+
*/
|
|
13
|
+
function normalizeBaseUrl(url) {
|
|
14
|
+
return url.endsWith('/') ? url.slice(0, -1) : url;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Builds a URL by combining base URL with a path, encoding path segments
|
|
18
|
+
*/
|
|
19
|
+
function buildRemoteUrl(baseUrl, path) {
|
|
20
|
+
const normalizedBase = normalizeBaseUrl(baseUrl);
|
|
21
|
+
const pathSegments = path.split('/').map(segment => encodeURIComponent(segment));
|
|
22
|
+
return `${normalizedBase}/${pathSegments.join('/')}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetches text content from a remote URL
|
|
26
|
+
*/
|
|
27
|
+
async function fetchRemoteText(url) {
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(url);
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return await response.text();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetches binary content from a remote URL and returns as base64 string
|
|
41
|
+
*/
|
|
42
|
+
async function fetchRemoteBase64(url) {
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(url);
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
49
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
50
|
+
return buffer.toString('base64');
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/util/server.js
CHANGED
|
@@ -39,9 +39,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.displayImage = displayImage;
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
|
-
|
|
42
|
+
const remote_1 = require("./remote");
|
|
43
|
+
async function displayImage(request, appName, appUrl) {
|
|
43
44
|
const f = request.params[0].replace(new RegExp(`^${appName}\\/`), '');
|
|
44
|
-
let file
|
|
45
|
+
let file;
|
|
46
|
+
if (appUrl) {
|
|
47
|
+
// Fetch from remote URL
|
|
48
|
+
const url = (0, remote_1.buildRemoteUrl)(appUrl, f);
|
|
49
|
+
const base64Content = await (0, remote_1.fetchRemoteBase64)(url);
|
|
50
|
+
if (base64Content === null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
file = base64Content;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Read from local file system
|
|
57
|
+
file = fs.readFileSync(f, { encoding: 'base64' });
|
|
58
|
+
}
|
|
45
59
|
const fileType = path_1.default.extname(f);
|
|
46
60
|
let mime = '';
|
|
47
61
|
switch (fileType.replace('.', '')) {
|
package/dist/util/tarball.js
CHANGED
|
@@ -42,6 +42,7 @@ const path = __importStar(require("path"));
|
|
|
42
42
|
const tar = __importStar(require("tar"));
|
|
43
43
|
const md5_1 = __importDefault(require("md5")); // default import
|
|
44
44
|
const metadata_1 = require("./metadata");
|
|
45
|
+
const LogService_1 = require("../service/log/LogService");
|
|
45
46
|
/**
|
|
46
47
|
* Reproduces the `pack()` logic, creating a tar.gz from the project's assets
|
|
47
48
|
*/
|
|
@@ -63,7 +64,7 @@ async function packProject(pkg, projectPath, assetsPath) {
|
|
|
63
64
|
files.push('@assets.tar.gz');
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
|
-
|
|
67
|
+
(0, LogService_1.log)('No assets directory found.').white();
|
|
67
68
|
}
|
|
68
69
|
// this is bad, but couldn't figure out how to get files from different folders without the absolute path messing with the tar file structure
|
|
69
70
|
await tar.create({
|
|
@@ -83,14 +84,14 @@ async function packProject(pkg, projectPath, assetsPath) {
|
|
|
83
84
|
// read it in memory for MD5
|
|
84
85
|
const buffer = fs.readFileSync(absOutputPath);
|
|
85
86
|
const digest = (0, md5_1.default)(buffer);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
(0, LogService_1.log)(`MD5: ${digest}`).white();
|
|
88
|
+
(0, LogService_1.log)(`Tarball created at ${absOutputPath}`).white();
|
|
89
|
+
(0, LogService_1.log)('cleaning up...').white();
|
|
89
90
|
fs.rmSync('projectFiles.tar.gz');
|
|
90
91
|
fs.rmSync('assets.tar.gz');
|
|
91
92
|
}
|
|
92
93
|
catch (err) {
|
|
93
|
-
|
|
94
|
+
(0, LogService_1.log)(`Failed to create tarball: ${err.message}`).red();
|
|
94
95
|
if (fs.existsSync('projectFiles.tar.gz'))
|
|
95
96
|
fs.rmSync('projectFiles.tar.gz');
|
|
96
97
|
if (fs.existsSync('assets.tar.gz'))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airmoney-degn/airmoney-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "airmoney-cli is a command-line interface tool designed to facilitate the development and management of decentralized applications (DApps) for Airmoney.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"version": "changeset version",
|
|
17
17
|
"changeset": "changeset",
|
|
18
18
|
"bump": "changeset && changeset version",
|
|
19
|
-
"update-version": "node scripts/update-version.js"
|
|
19
|
+
"update-version": "node scripts/update-version.js",
|
|
20
|
+
"check-types": "tsc --noEmit"
|
|
20
21
|
},
|
|
21
22
|
"keywords": [
|
|
22
23
|
"CLI"
|