@airmoney-degn/airmoney-cli 0.19.1 → 0.19.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/dist/cli/create.js +1 -1
- package/dist/cli/upload.js +123 -73
- package/dist/config.json +1 -1
- package/dist/index.js +84 -51
- package/dist/util/tarball.js +92 -47
- package/package.json +1 -1
package/dist/cli/create.js
CHANGED
|
@@ -47,7 +47,7 @@ async function createCommand({ name, template, locationFolder, quiet, }) {
|
|
|
47
47
|
const projectPath = path.join(process.cwd(), folderName);
|
|
48
48
|
if (template) {
|
|
49
49
|
(0, LogService_1.log)('cloning project').white();
|
|
50
|
-
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/
|
|
50
|
+
(0, child_process_1.execSync)(`git clone --separate-git-dir=$(mktemp -u) https://github.com/airmoney-degn/airmoney-dapp-quickstart ${folderName}`);
|
|
51
51
|
if (fs.lstatSync(path.join(projectPath, '.git')).isDirectory()) {
|
|
52
52
|
fs.rmdirSync(path.join(projectPath, '.git'));
|
|
53
53
|
}
|
package/dist/cli/upload.js
CHANGED
|
@@ -39,86 +39,136 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.uploadCommand = uploadCommand;
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
|
-
const md5_1 = __importDefault(require("md5"));
|
|
42
|
+
const md5_1 = __importDefault(require("md5"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
43
44
|
const metadata_1 = require("../util/metadata");
|
|
44
45
|
const tarball_1 = require("../util/tarball");
|
|
45
46
|
const network_1 = require("../util/network");
|
|
46
47
|
const env_1 = require("../util/env");
|
|
47
48
|
const LogService_1 = require("../service/log/LogService");
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Gets the project path based on location folder
|
|
51
|
+
*/
|
|
52
|
+
function getProjectPath(locationFolder) {
|
|
53
|
+
if (!locationFolder) {
|
|
54
|
+
return process.cwd();
|
|
55
|
+
}
|
|
56
|
+
return path_1.default.join(process.cwd(), locationFolder);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Loads and validates metadata
|
|
60
|
+
*/
|
|
61
|
+
async function loadAndValidateMetadata(locationFolder) {
|
|
62
|
+
(0, LogService_1.log)('Loading metadata...').white();
|
|
63
|
+
const meta = await (0, metadata_1.loadMetadata)(locationFolder);
|
|
64
|
+
if (!meta) {
|
|
65
|
+
throw new Error('No metadata.json found. Aborting.');
|
|
66
|
+
}
|
|
67
|
+
return meta;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Prepares the package by packing and reading it
|
|
71
|
+
*/
|
|
72
|
+
async function preparePackage(meta, projectPath) {
|
|
73
|
+
const pkgName = (0, metadata_1.getPackageName)(meta);
|
|
74
|
+
(0, LogService_1.log)(`Packing ${pkgName}...`).white();
|
|
75
|
+
await (0, tarball_1.packProject)(meta, projectPath);
|
|
76
|
+
const pkgPath = path_1.default.join(process.cwd(), pkgName);
|
|
77
|
+
if (!fs.existsSync(pkgPath)) {
|
|
78
|
+
throw new Error(`Package file not found at ${pkgPath}`);
|
|
79
|
+
}
|
|
80
|
+
const fileBuffer = fs.readFileSync(pkgPath);
|
|
81
|
+
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
82
|
+
(0, LogService_1.log)(`Package Hash: ${fileHash}`).white();
|
|
83
|
+
return { fileBuffer, fileHash, pkgPath };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates the JSON-RPC request body for upload
|
|
87
|
+
*/
|
|
88
|
+
function createUploadRequestBody(userId, apiKey, meta, encodedFile) {
|
|
89
|
+
const metaJson = JSON.stringify(meta);
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
jsonrpc: '2.0',
|
|
92
|
+
id: 1,
|
|
93
|
+
method: 'uploadPackage',
|
|
94
|
+
params: [userId, apiKey, metaJson, encodedFile],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Handles the upload response
|
|
99
|
+
*/
|
|
100
|
+
function handleUploadResponse(json) {
|
|
101
|
+
if (json.result === true) {
|
|
102
|
+
(0, LogService_1.log)('Package uploaded successfully').green();
|
|
103
|
+
(0, LogService_1.log)('Open : https://dash-devnet.degn.com/').white();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
(0, LogService_1.log)('Error uploding package').red();
|
|
107
|
+
if (json.error?.code === -32602) {
|
|
108
|
+
(0, LogService_1.log)('invalid api key, please visit https://dash-devnet.degn.com/ and setup env with the new key').red();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
(0, LogService_1.log)('unknow error, please contact support').red();
|
|
112
|
+
(0, LogService_1.log)(JSON.stringify(json.error)).red();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Uploads the package to the server
|
|
116
|
+
*/
|
|
117
|
+
async function uploadPackageToServer(network, body) {
|
|
118
|
+
const rpcUrl = (0, network_1.networkToRpcUrl)(network);
|
|
119
|
+
const res = await (0, node_fetch_1.default)(rpcUrl, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
body,
|
|
122
|
+
headers: {
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
const errorText = await res.text();
|
|
128
|
+
(0, LogService_1.log)(`Error uploading package: ${errorText}`).red();
|
|
129
|
+
throw new Error(`Upload failed: ${errorText}`);
|
|
130
|
+
}
|
|
131
|
+
const json = await res.json();
|
|
132
|
+
handleUploadResponse(json);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Cleans up the package file
|
|
136
|
+
*/
|
|
137
|
+
function cleanupPackageFile(pkgPath) {
|
|
138
|
+
if (fs.existsSync(pkgPath)) {
|
|
139
|
+
fs.rmSync(pkgPath);
|
|
140
|
+
(0, LogService_1.log)('Cleaned up package file').white();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Main upload command
|
|
145
|
+
*/
|
|
146
|
+
async function uploadCommand({ network, locationFolder, }) {
|
|
147
|
+
let packageData = null;
|
|
50
148
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const meta = await (0, metadata_1.loadMetadata)();
|
|
65
|
-
if (!meta) {
|
|
66
|
-
(0, LogService_1.log)('No metadata.json found. Aborting.').red();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
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
|
-
}
|
|
119
|
-
}
|
|
149
|
+
(0, network_1.validateNetwork)(network);
|
|
150
|
+
const effectiveNetwork = (network || 'devnet');
|
|
151
|
+
(0, LogService_1.log)(`Using network: ${effectiveNetwork}`).white();
|
|
152
|
+
const credentials = (0, env_1.validateCredential)();
|
|
153
|
+
const { userId, apiKey } = credentials;
|
|
154
|
+
(0, LogService_1.log)(`User ID: ${userId}`).white();
|
|
155
|
+
const projectPath = getProjectPath(locationFolder);
|
|
156
|
+
const meta = await loadAndValidateMetadata(locationFolder);
|
|
157
|
+
packageData = await preparePackage(meta, projectPath);
|
|
158
|
+
(0, LogService_1.log)('Publishing package to DEGN Dapp Store...').white();
|
|
159
|
+
const encoded = Buffer.from(packageData.fileBuffer).toString('base64');
|
|
160
|
+
const body = createUploadRequestBody(userId, apiKey, meta, encoded);
|
|
161
|
+
await uploadPackageToServer(effectiveNetwork, body);
|
|
120
162
|
}
|
|
121
163
|
catch (err) {
|
|
122
|
-
|
|
164
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
165
|
+
(0, LogService_1.log)(`Upload failed: ${errorMessage}`).red();
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
// Clean up package file if it was created
|
|
170
|
+
if (packageData) {
|
|
171
|
+
cleanupPackageFile(packageData.pkgPath);
|
|
172
|
+
}
|
|
123
173
|
}
|
|
124
174
|
}
|
package/dist/config.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -25,9 +25,14 @@ program
|
|
|
25
25
|
.requiredOption('-u, --user <string>', 'developer user')
|
|
26
26
|
.requiredOption('-k, --key <string>', 'API key')
|
|
27
27
|
.option('-n, --network <string>', 'network devnet|mainnet')
|
|
28
|
-
.action(opts => {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
.action(async (opts) => {
|
|
29
|
+
try {
|
|
30
|
+
const { user, key, network } = opts;
|
|
31
|
+
await (0, setup_1.setupCommand)({ network, userId: user, apiKey: key });
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
31
36
|
});
|
|
32
37
|
program
|
|
33
38
|
.command('create')
|
|
@@ -35,9 +40,14 @@ program
|
|
|
35
40
|
.requiredOption('-N, --name <string>', 'Project name')
|
|
36
41
|
.option('-f, --app-path <string>', 'path where project will be created')
|
|
37
42
|
.option('--template', 'initialize project based on git quickstart')
|
|
38
|
-
.action(opts => {
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
.action(async (opts) => {
|
|
44
|
+
try {
|
|
45
|
+
const { name, appPath, template } = opts;
|
|
46
|
+
await (0, create_1.createCommand)({ name, template, locationFolder: appPath });
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
41
51
|
});
|
|
42
52
|
program
|
|
43
53
|
.command('serve')
|
|
@@ -45,20 +55,25 @@ program
|
|
|
45
55
|
.option('-f, --index-app-path <string>', 'path for the index.html', './')
|
|
46
56
|
.option('--no-browser', 'stop browser from being open')
|
|
47
57
|
.option('-u, --app-url <string>', 'url where the app is running')
|
|
48
|
-
.action(opts => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
indexAppPath
|
|
58
|
+
.action(async (opts) => {
|
|
59
|
+
try {
|
|
60
|
+
let { indexAppPath, browser, appUrl } = opts;
|
|
61
|
+
if (indexAppPath == './') {
|
|
62
|
+
indexAppPath = undefined;
|
|
63
|
+
}
|
|
64
|
+
if (indexAppPath && appUrl) {
|
|
65
|
+
(0, LogService_1.log)('both --index-app-path and --app-url must not be used simuntaniusly').red();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await (0, serve_1.serveCommand)({
|
|
69
|
+
noBrowser: !browser,
|
|
70
|
+
locationFolder: indexAppPath,
|
|
71
|
+
appUrl,
|
|
72
|
+
});
|
|
52
73
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return;
|
|
74
|
+
catch (err) {
|
|
75
|
+
process.exit(1);
|
|
56
76
|
}
|
|
57
|
-
(0, serve_1.serveCommand)({
|
|
58
|
-
noBrowser: !browser,
|
|
59
|
-
locationFolder: indexAppPath,
|
|
60
|
-
appUrl,
|
|
61
|
-
});
|
|
62
77
|
});
|
|
63
78
|
program
|
|
64
79
|
.command('wallet')
|
|
@@ -72,27 +87,32 @@ program
|
|
|
72
87
|
.option('-gd, --get-default', 'get default wallet')
|
|
73
88
|
.option('-c, --chain [evm | svm | btc]', 'chain name ', 'evm')
|
|
74
89
|
.action(async (opts) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
try {
|
|
91
|
+
const { list, delete: del, import: importWallet, export: exportWallet, generate, setDefault, getDefault, chain, } = opts;
|
|
92
|
+
if (list) {
|
|
93
|
+
await (0, wallet_1.listWallet)(chain);
|
|
94
|
+
}
|
|
95
|
+
else if (del) {
|
|
96
|
+
await (0, wallet_1.deleteWallet)(del, chain);
|
|
97
|
+
}
|
|
98
|
+
else if (importWallet) {
|
|
99
|
+
await (0, wallet_1.importWalletSk)(importWallet, chain);
|
|
100
|
+
}
|
|
101
|
+
else if (exportWallet) {
|
|
102
|
+
await (0, wallet_1.exportWalletSk)(exportWallet, chain);
|
|
103
|
+
}
|
|
104
|
+
else if (generate) {
|
|
105
|
+
await (0, wallet_1.generateWallet)(chain);
|
|
106
|
+
}
|
|
107
|
+
else if (setDefault) {
|
|
108
|
+
await (0, wallet_1.setDefaultWallet)(setDefault, chain);
|
|
109
|
+
}
|
|
110
|
+
else if (getDefault) {
|
|
111
|
+
await (0, wallet_1.getDefaultWallet)(chain);
|
|
112
|
+
}
|
|
84
113
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else if (generate) {
|
|
89
|
-
await (0, wallet_1.generateWallet)(chain);
|
|
90
|
-
}
|
|
91
|
-
else if (setDefault) {
|
|
92
|
-
await (0, wallet_1.setDefaultWallet)(setDefault, chain);
|
|
93
|
-
}
|
|
94
|
-
else if (getDefault) {
|
|
95
|
-
await (0, wallet_1.getDefaultWallet)(chain);
|
|
114
|
+
catch (err) {
|
|
115
|
+
process.exit(1);
|
|
96
116
|
}
|
|
97
117
|
});
|
|
98
118
|
program
|
|
@@ -100,24 +120,32 @@ program
|
|
|
100
120
|
.description('Publish the app to the DEGN Dapp Store')
|
|
101
121
|
.option('-n, --network <string>', 'network devnet|mainnet')
|
|
102
122
|
.option('-f, --index-app-path <string>', 'path for the index.html', './')
|
|
103
|
-
.
|
|
104
|
-
|
|
105
|
-
let { network, indexAppPath, buttonImage } = opts;
|
|
123
|
+
.action(async (opts) => {
|
|
124
|
+
let { network, indexAppPath } = opts;
|
|
106
125
|
if (indexAppPath == './') {
|
|
107
126
|
indexAppPath = undefined;
|
|
108
127
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
try {
|
|
129
|
+
await (0, upload_1.uploadCommand)({
|
|
130
|
+
network,
|
|
131
|
+
locationFolder: indexAppPath,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
114
137
|
});
|
|
115
138
|
program
|
|
116
139
|
.command('dapp')
|
|
117
140
|
.description('Manage dapps')
|
|
118
141
|
.option('-s, --status', 'show all dapps list')
|
|
119
|
-
.action(() => {
|
|
120
|
-
|
|
142
|
+
.action(async () => {
|
|
143
|
+
try {
|
|
144
|
+
await (0, dapp_1.dappStatusCommand)();
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
121
149
|
});
|
|
122
150
|
program
|
|
123
151
|
.command('demo')
|
|
@@ -125,8 +153,13 @@ program
|
|
|
125
153
|
.option('-f, --app-path <string>', 'path where project will be created')
|
|
126
154
|
.description('serve the built-in demo app')
|
|
127
155
|
.action(async (opts) => {
|
|
128
|
-
|
|
129
|
-
|
|
156
|
+
try {
|
|
157
|
+
const { name = 'degn-demo', appPath } = opts;
|
|
158
|
+
await (0, demo_1.demoCommand)({ name, appPath });
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
130
163
|
});
|
|
131
|
-
program.addHelpText('after', 'for more help access https://dash-devnet.
|
|
164
|
+
program.addHelpText('after', 'for more help access https://dash-devnet.degn.com/');
|
|
132
165
|
program.parse(process.argv);
|
package/dist/util/tarball.js
CHANGED
|
@@ -40,64 +40,109 @@ exports.packProject = packProject;
|
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const tar = __importStar(require("tar"));
|
|
43
|
-
const md5_1 = __importDefault(require("md5"));
|
|
43
|
+
const md5_1 = __importDefault(require("md5"));
|
|
44
44
|
const metadata_1 = require("./metadata");
|
|
45
45
|
const LogService_1 = require("../service/log/LogService");
|
|
46
|
+
const REQUIRED_FILES = ['metadata.json', 'dapp-logo.png', 'index.html'];
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
+
* Validates that the project path exists
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
function validateProjectPath(projectPath) {
|
|
51
|
+
if (!fs.existsSync(projectPath)) {
|
|
52
|
+
throw new Error(`Project path does not exist: ${projectPath}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validates that all required files exist at the root of the project
|
|
57
|
+
*/
|
|
58
|
+
function validateRequiredFiles(projectPath) {
|
|
59
|
+
const missingFiles = [];
|
|
60
|
+
REQUIRED_FILES.forEach(file => {
|
|
61
|
+
const filePath = path.join(projectPath, file);
|
|
62
|
+
if (!fs.existsSync(filePath)) {
|
|
63
|
+
missingFiles.push(file);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (missingFiles.length > 0) {
|
|
67
|
+
throw new Error(`Missing required files at root: ${missingFiles.join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Recursively gets all files from a directory
|
|
72
|
+
*/
|
|
73
|
+
function getAllFiles(dir, baseDir, fileList = []) {
|
|
74
|
+
const items = fs.readdirSync(dir);
|
|
75
|
+
items.forEach(item => {
|
|
76
|
+
const fullPath = path.join(dir, item);
|
|
77
|
+
const stat = fs.statSync(fullPath);
|
|
78
|
+
if (stat.isDirectory()) {
|
|
79
|
+
getAllFiles(fullPath, baseDir, fileList);
|
|
65
80
|
}
|
|
66
81
|
else {
|
|
67
|
-
|
|
82
|
+
const relativePath = path.relative(baseDir, fullPath);
|
|
83
|
+
fileList.push(relativePath);
|
|
68
84
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
});
|
|
86
|
+
return fileList;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Collects all files from the project directory
|
|
90
|
+
*/
|
|
91
|
+
function collectProjectFiles(projectPath) {
|
|
92
|
+
const allFiles = getAllFiles(projectPath, projectPath);
|
|
93
|
+
if (allFiles.length === 0) {
|
|
94
|
+
throw new Error(`No files found in ${projectPath}`);
|
|
95
|
+
}
|
|
96
|
+
return allFiles;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates the tarball file
|
|
100
|
+
*/
|
|
101
|
+
async function createTarball(outputPath, projectPath, files) {
|
|
102
|
+
// Clean up any existing output file
|
|
103
|
+
if (fs.existsSync(outputPath)) {
|
|
104
|
+
fs.rmSync(outputPath);
|
|
105
|
+
}
|
|
106
|
+
await tar.create({
|
|
107
|
+
file: outputPath,
|
|
108
|
+
gzip: true,
|
|
109
|
+
cwd: projectPath,
|
|
110
|
+
prefix: '',
|
|
111
|
+
portable: true,
|
|
112
|
+
}, files);
|
|
113
|
+
if (!fs.existsSync(outputPath)) {
|
|
114
|
+
throw new Error('Tarball was not created successfully');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Calculates and logs the MD5 hash of the tarball
|
|
119
|
+
*/
|
|
120
|
+
function logTarballHash(outputPath) {
|
|
121
|
+
const buffer = fs.readFileSync(outputPath);
|
|
122
|
+
const digest = (0, md5_1.default)(buffer);
|
|
123
|
+
(0, LogService_1.log)(`MD5: ${digest}`).white();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Main function to pack a project into a tarball
|
|
127
|
+
*/
|
|
128
|
+
async function packProject(pkg, projectPath) {
|
|
129
|
+
const outputFilename = (0, metadata_1.getPackageName)(pkg);
|
|
130
|
+
const absOutputPath = path.join(process.cwd(), outputFilename);
|
|
131
|
+
try {
|
|
132
|
+
validateProjectPath(projectPath);
|
|
133
|
+
validateRequiredFiles(projectPath);
|
|
134
|
+
const allFiles = collectProjectFiles(projectPath);
|
|
135
|
+
(0, LogService_1.log)(`Found ${allFiles.length} files to pack`).white();
|
|
136
|
+
(0, LogService_1.log)('Creating tarball...').white();
|
|
137
|
+
await createTarball(absOutputPath, projectPath, allFiles);
|
|
138
|
+
logTarballHash(absOutputPath);
|
|
88
139
|
(0, LogService_1.log)(`Tarball created at ${absOutputPath}`).white();
|
|
89
|
-
(0, LogService_1.log)('cleaning up...').white();
|
|
90
|
-
fs.rmSync('projectFiles.tar.gz');
|
|
91
|
-
fs.rmSync('assets.tar.gz');
|
|
92
140
|
}
|
|
93
141
|
catch (err) {
|
|
94
142
|
(0, LogService_1.log)(`Failed to create tarball: ${err.message}`).red();
|
|
95
|
-
if (fs.existsSync(
|
|
96
|
-
fs.rmSync('projectFiles.tar.gz');
|
|
97
|
-
if (fs.existsSync('assets.tar.gz'))
|
|
98
|
-
fs.rmSync('assets.tar.gz');
|
|
99
|
-
if (fs.existsSync(absOutputPath))
|
|
143
|
+
if (fs.existsSync(absOutputPath)) {
|
|
100
144
|
fs.rmSync(absOutputPath);
|
|
101
|
-
|
|
145
|
+
}
|
|
146
|
+
throw err;
|
|
102
147
|
}
|
|
103
148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airmoney-degn/airmoney-cli",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
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"
|