@blocklet/cli 1.16.43-beta-20250505-062139-b156e7da → 1.16.43-beta-20250507-124320-c405ab23
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/commands/blocklet/deploy.js +46 -49
- package/package.json +15 -15
|
@@ -4,17 +4,13 @@ require('dotenv-flow').config({ silent: true, node_env: 'development' });
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const expandTilde = require('expand-tilde');
|
|
7
|
-
const tar = require('tar');
|
|
8
7
|
const chalk = require('chalk');
|
|
9
|
-
const slugify = require('slugify');
|
|
10
8
|
const { joinURL } = require('ufo');
|
|
11
9
|
|
|
12
10
|
const { isValid: isValidDid, toAddress } = require('@arcblock/did');
|
|
13
11
|
const Client = require('@abtnode/client');
|
|
14
12
|
const hashFiles = require('@abtnode/util/lib/hash-files');
|
|
15
13
|
const { default: axios } = require('axios');
|
|
16
|
-
const isPathPrefixEqual = require('@abtnode/util/lib/is-path-prefix-equal');
|
|
17
|
-
const getBlockletMeta = require('@blocklet/meta/lib/parse');
|
|
18
14
|
const validateBlockletEntry = require('@blocklet/meta/lib/entry');
|
|
19
15
|
const { hasMountPoint } = require('@blocklet/meta/lib/engine');
|
|
20
16
|
const { BLOCKLET_BUNDLE_FOLDER } = require('@blocklet/constant');
|
|
@@ -27,6 +23,7 @@ const makeFormData = require('@abtnode/util/lib/make-from-data');
|
|
|
27
23
|
const { createConnect } = require('@blocklet/store');
|
|
28
24
|
const open = require('open');
|
|
29
25
|
const inquirer = require('inquirer');
|
|
26
|
+
const { createRelease } = require('@abtnode/util/lib/create-blocklet-release');
|
|
30
27
|
|
|
31
28
|
const Config = require('../../util/blocklet/config');
|
|
32
29
|
const {
|
|
@@ -42,10 +39,23 @@ const { wrapSpinner } = require('../../ui');
|
|
|
42
39
|
const { getNode } = require('../../node');
|
|
43
40
|
const { checkRunning, deployManager } = require('../../manager');
|
|
44
41
|
const { version } = require('../../../package.json');
|
|
45
|
-
const debug = require('../../debug')('blocklet:deploy');
|
|
46
42
|
|
|
47
43
|
const { signWithAccessKey, validateAccessKey } = Client;
|
|
48
|
-
const {
|
|
44
|
+
const { printDeployFileInfo } = deployManager;
|
|
45
|
+
|
|
46
|
+
function getFilename(input) {
|
|
47
|
+
try {
|
|
48
|
+
if (input.startsWith('http://') || input.startsWith('https://') || input.startsWith('file://')) {
|
|
49
|
+
const url = new URL(input);
|
|
50
|
+
return path.basename(url.pathname);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// ignore invalid URL parsing
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 处理本地路径或文件名
|
|
57
|
+
return path.basename(input);
|
|
58
|
+
}
|
|
49
59
|
|
|
50
60
|
async function confirmOpenConnectPage(
|
|
51
61
|
message = 'No access key found, do you need to open the connect page to generate access key?'
|
|
@@ -68,6 +78,32 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
68
78
|
bundleDir = path.join(dir, BLOCKLET_BUNDLE_FOLDER);
|
|
69
79
|
}
|
|
70
80
|
|
|
81
|
+
const releaseMetaPath = path.join(bundleDir, '..', 'release', 'blocklet.json');
|
|
82
|
+
if (!fs.existsSync(releaseMetaPath)) {
|
|
83
|
+
printInfo('No release found, create release...');
|
|
84
|
+
await createRelease(path.join(bundleDir, '..'));
|
|
85
|
+
if (!fs.existsSync(releaseMetaPath)) {
|
|
86
|
+
throw new Error('Failed to create release meta');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// get local blocklet meta
|
|
91
|
+
let localMeta;
|
|
92
|
+
try {
|
|
93
|
+
localMeta = JSON.parse(fs.readFileSync(releaseMetaPath, 'utf-8'));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new Error(`Get blocklet meta failed: ${error.message}`);
|
|
96
|
+
}
|
|
97
|
+
// build tarFile
|
|
98
|
+
const tarFile = path.join(bundleDir, '..', 'release', getFilename(localMeta.dist.tarball));
|
|
99
|
+
if (!fs.existsSync(tarFile)) {
|
|
100
|
+
printInfo('No release found, create release...');
|
|
101
|
+
await createRelease(path.join(bundleDir, '..'));
|
|
102
|
+
if (!fs.existsSync(releaseMetaPath)) {
|
|
103
|
+
throw new Error('Failed to create release meta');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
71
107
|
const rootDid = appDid || appId;
|
|
72
108
|
|
|
73
109
|
const fullEndpoint = joinURL(endpoint, '/api/gql');
|
|
@@ -104,15 +140,6 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
104
140
|
);
|
|
105
141
|
}
|
|
106
142
|
|
|
107
|
-
// get local blocklet meta
|
|
108
|
-
let localMeta;
|
|
109
|
-
try {
|
|
110
|
-
localMeta = getBlockletMeta(bundleDir);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
debug('get blocklet error', error);
|
|
113
|
-
throw new Error(`Get blocklet meta failed: ${error.message}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
143
|
printInfo(
|
|
117
144
|
`Try to deploy ${chalk.cyan(`${localMeta.title}@${localMeta.version}`)} from`,
|
|
118
145
|
`${chalk.cyan(bundleDir)} to ${chalk.cyan(app.meta.title)} in server ${chalk.cyan(endpoint)}.`
|
|
@@ -187,19 +214,7 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
187
214
|
hasBlocklet: hasDiff,
|
|
188
215
|
version: serverVersion,
|
|
189
216
|
} = blockletDiff.blockletDiff || {};
|
|
190
|
-
const diffList = hasDiff ? [...addSet, ...changeSet] : null;
|
|
191
|
-
|
|
192
|
-
// if no diff and mountPoint not changed, stop deploy
|
|
193
|
-
if (hasDiff && localMeta.version === serverVersion && !addSet.length && !changeSet.length && !deleteSet.length) {
|
|
194
|
-
let needNotDeploy = true;
|
|
195
|
-
const child = app.children.find((x) => x.meta.did === localMeta.did);
|
|
196
|
-
needNotDeploy = isPathPrefixEqual(mountPoint, child.mountPoint);
|
|
197
217
|
|
|
198
|
-
if (needNotDeploy) {
|
|
199
|
-
print(`${localMeta.title}@${localMeta.version} already exists in ${app.meta.title}`);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
218
|
printInfo(`Name: ${chalk.cyan(localMeta.name)}`);
|
|
204
219
|
printInfo(`DID: ${chalk.cyan(localMeta.did)}`);
|
|
205
220
|
printInfo(`Version: ${chalk.cyan(localMeta.version)}`);
|
|
@@ -210,22 +225,6 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
210
225
|
printDeployFileInfo(Object.keys(files));
|
|
211
226
|
}
|
|
212
227
|
|
|
213
|
-
// build tarFile
|
|
214
|
-
const tarFile = path.join(process.cwd(), `${slugify(localMeta.name)}-${localMeta.version}.tgz`);
|
|
215
|
-
|
|
216
|
-
await tar.c(
|
|
217
|
-
{
|
|
218
|
-
file: tarFile,
|
|
219
|
-
cwd: bundleDir,
|
|
220
|
-
filter: (f) =>
|
|
221
|
-
!diffList ||
|
|
222
|
-
fileFilter(f.replace(/^\.\//, ''), {
|
|
223
|
-
diffList,
|
|
224
|
-
}),
|
|
225
|
-
},
|
|
226
|
-
['.']
|
|
227
|
-
);
|
|
228
|
-
|
|
229
228
|
// do upload
|
|
230
229
|
const { form } = makeFormData({
|
|
231
230
|
tarFile,
|
|
@@ -235,6 +234,10 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
235
234
|
deleteSet,
|
|
236
235
|
mountPoint,
|
|
237
236
|
rootDid,
|
|
237
|
+
dist: {
|
|
238
|
+
tarball: localMeta.dist.tarball,
|
|
239
|
+
integrity: localMeta.dist.integrity,
|
|
240
|
+
},
|
|
238
241
|
});
|
|
239
242
|
try {
|
|
240
243
|
const timestamp = Date.now();
|
|
@@ -272,18 +275,12 @@ const deploy = async (dir, { endpoint, accessKey, accessSecret, appDid, appId, m
|
|
|
272
275
|
error.errors = res.data.errors;
|
|
273
276
|
throw error;
|
|
274
277
|
}
|
|
275
|
-
if (fs.existsSync(tarFile)) {
|
|
276
|
-
fs.unlinkSync(tarFile);
|
|
277
|
-
}
|
|
278
278
|
printSuccess(
|
|
279
279
|
`${chalk.cyan(localMeta.title)}@${chalk.cyan(localMeta.version)} was successfully deployed to ${chalk.cyan(
|
|
280
280
|
app.meta.title
|
|
281
281
|
)} in server ${chalk.cyan(endpoint)}.`
|
|
282
282
|
);
|
|
283
283
|
} catch (error) {
|
|
284
|
-
if (fs.existsSync(tarFile)) {
|
|
285
|
-
fs.unlinkSync(tarFile);
|
|
286
|
-
}
|
|
287
284
|
throw new Error(`Blocklet deploy failed when uploading: ${formatGQLError(error)}`);
|
|
288
285
|
}
|
|
289
286
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/cli",
|
|
3
|
-
"version": "1.16.43-beta-
|
|
3
|
+
"version": "1.16.43-beta-20250507-124320-c405ab23",
|
|
4
4
|
"description": "Command line tools to manage Blocklet Server",
|
|
5
5
|
"homepage": "https://github.com/ArcBlock/blocklet-server#readme",
|
|
6
6
|
"bin": {
|
|
@@ -35,25 +35,25 @@
|
|
|
35
35
|
"url": "https://github.com/ArcBlock/blocklet-server/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@abtnode/blocklet-services": "1.16.43-beta-
|
|
39
|
-
"@abtnode/client": "1.16.43-beta-
|
|
40
|
-
"@abtnode/constant": "1.16.43-beta-
|
|
41
|
-
"@abtnode/core": "1.16.43-beta-
|
|
42
|
-
"@abtnode/logger": "1.16.43-beta-
|
|
43
|
-
"@abtnode/router-provider": "1.16.43-beta-
|
|
44
|
-
"@abtnode/util": "1.16.43-beta-
|
|
45
|
-
"@abtnode/webapp": "1.16.43-beta-
|
|
38
|
+
"@abtnode/blocklet-services": "1.16.43-beta-20250507-124320-c405ab23",
|
|
39
|
+
"@abtnode/client": "1.16.43-beta-20250507-124320-c405ab23",
|
|
40
|
+
"@abtnode/constant": "1.16.43-beta-20250507-124320-c405ab23",
|
|
41
|
+
"@abtnode/core": "1.16.43-beta-20250507-124320-c405ab23",
|
|
42
|
+
"@abtnode/logger": "1.16.43-beta-20250507-124320-c405ab23",
|
|
43
|
+
"@abtnode/router-provider": "1.16.43-beta-20250507-124320-c405ab23",
|
|
44
|
+
"@abtnode/util": "1.16.43-beta-20250507-124320-c405ab23",
|
|
45
|
+
"@abtnode/webapp": "1.16.43-beta-20250507-124320-c405ab23",
|
|
46
46
|
"@arcblock/did": "1.20.4",
|
|
47
47
|
"@arcblock/event-hub": "1.20.4",
|
|
48
48
|
"@arcblock/ipfs-only-hash": "^0.0.2",
|
|
49
49
|
"@arcblock/jwt": "1.20.4",
|
|
50
50
|
"@arcblock/ws": "1.20.4",
|
|
51
|
-
"@blocklet/constant": "1.16.43-beta-
|
|
51
|
+
"@blocklet/constant": "1.16.43-beta-20250507-124320-c405ab23",
|
|
52
52
|
"@blocklet/form-collector": "^0.1.8",
|
|
53
|
-
"@blocklet/images": "1.16.43-beta-
|
|
54
|
-
"@blocklet/meta": "1.16.43-beta-
|
|
55
|
-
"@blocklet/resolver": "1.16.43-beta-
|
|
56
|
-
"@blocklet/store": "1.16.43-beta-
|
|
53
|
+
"@blocklet/images": "1.16.43-beta-20250507-124320-c405ab23",
|
|
54
|
+
"@blocklet/meta": "1.16.43-beta-20250507-124320-c405ab23",
|
|
55
|
+
"@blocklet/resolver": "1.16.43-beta-20250507-124320-c405ab23",
|
|
56
|
+
"@blocklet/store": "1.16.43-beta-20250507-124320-c405ab23",
|
|
57
57
|
"@blocklet/theme-builder": "^0.1.13",
|
|
58
58
|
"@ocap/client": "1.20.4",
|
|
59
59
|
"@ocap/mcrypto": "1.20.4",
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"engines": {
|
|
153
153
|
"node": ">=14"
|
|
154
154
|
},
|
|
155
|
-
"gitHead": "
|
|
155
|
+
"gitHead": "4e5087dfaa52788676f313d23bfdd3ac68d63503",
|
|
156
156
|
"devDependencies": {
|
|
157
157
|
"@types/fs-extra": "^11.0.4",
|
|
158
158
|
"@types/jest": "^29.5.13"
|