@blocklet/cli 1.16.33 → 1.16.34-beta-20241120-080738-bbbe036c
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/README.md +32 -25
- package/bin/blocklet.js +292 -1
- package/config.example.yml +33 -0
- package/lib/arcblock.js +53 -0
- package/lib/commands/blocklet/add.js +124 -0
- package/lib/commands/blocklet/assets/git-ignore +28 -0
- package/lib/commands/blocklet/assets/index.html +9 -0
- package/lib/commands/blocklet/assets/index.js +14 -0
- package/lib/commands/blocklet/assets/logo.png +0 -0
- package/lib/commands/blocklet/bundle/bundle.js +184 -0
- package/lib/commands/blocklet/bundle/bundlers/blocklet.js +138 -0
- package/lib/commands/blocklet/bundle/bundlers/changelog.js +100 -0
- package/lib/commands/blocklet/bundle/bundlers/logo.js +56 -0
- package/lib/commands/blocklet/bundle/bundlers/markdown.js +241 -0
- package/lib/commands/blocklet/bundle/bundlers/preference.js +50 -0
- package/lib/commands/blocklet/bundle/bundlers/readme.js +43 -0
- package/lib/commands/blocklet/bundle/bundlers/screenshots.js +94 -0
- package/lib/commands/blocklet/bundle/bundlers/simple.js +70 -0
- package/lib/commands/blocklet/bundle/compact/bundle-compact-file.js +48 -0
- package/lib/commands/blocklet/bundle/compact/bundle-merge-extra.js +66 -0
- package/lib/commands/blocklet/bundle/compact/default-external.js +5 -0
- package/lib/commands/blocklet/bundle/compact/index.js +88 -0
- package/lib/commands/blocklet/bundle/index.js +139 -0
- package/lib/commands/blocklet/bundle/pack.js +8 -0
- package/lib/commands/blocklet/bundle/parse-external-dependencies.js +97 -0
- package/lib/commands/blocklet/bundle/simple/index.js +62 -0
- package/lib/commands/blocklet/bundle/zip/archive.js +35 -0
- package/lib/commands/blocklet/bundle/zip/dependencies.js +333 -0
- package/lib/commands/blocklet/bundle/zip/index.js +165 -0
- package/lib/commands/blocklet/bundle/zip/main.js +124 -0
- package/lib/commands/blocklet/bundle/zip/node.js +59 -0
- package/lib/commands/blocklet/bundle/zip/resolve.js +93 -0
- package/lib/commands/blocklet/cleanup.js +52 -0
- package/lib/commands/blocklet/config.js +108 -0
- package/lib/commands/blocklet/connect.js +87 -0
- package/lib/commands/blocklet/create.js +38 -0
- package/lib/commands/blocklet/deploy.js +435 -0
- package/lib/commands/blocklet/dev.js +1000 -0
- package/lib/commands/blocklet/document.js +39 -0
- package/lib/commands/blocklet/exec.js +106 -0
- package/lib/commands/blocklet/init.js +300 -0
- package/lib/commands/blocklet/meta.js +22 -0
- package/lib/commands/blocklet/remove.js +35 -0
- package/lib/commands/blocklet/test.js +201 -0
- package/lib/commands/blocklet/upload.js +105 -0
- package/lib/commands/blocklet/version.js +81 -0
- package/lib/commands/server/cleanup.js +32 -0
- package/lib/commands/server/command.js +131 -0
- package/lib/commands/server/info.js +92 -0
- package/lib/commands/server/init.js +433 -0
- package/lib/commands/server/logs.js +99 -0
- package/lib/commands/server/rescue.js +71 -0
- package/lib/commands/server/start.js +821 -0
- package/lib/commands/server/status.js +107 -0
- package/lib/commands/server/stop.js +163 -0
- package/lib/commands/server/upgrade.js +123 -0
- package/lib/constant.js +21 -2
- package/lib/debug.js +20 -0
- package/lib/manager/config.js +122 -0
- package/lib/manager/deploy.js +75 -0
- package/lib/manager/index.js +23 -0
- package/lib/manager/process.js +47 -0
- package/lib/node.js +214 -0
- package/lib/port.js +19 -0
- package/lib/postinstall.js +3 -0
- package/lib/process/daemon.js +196 -0
- package/lib/process/service.js +86 -0
- package/lib/ui.js +137 -0
- package/lib/util/blocklet/config.js +78 -0
- package/lib/util/blocklet/env.js +172 -0
- package/lib/util/blocklet/meta.js +36 -0
- package/lib/util/blocklet/payment.js +88 -0
- package/lib/util/blocklet/sign.js +21 -0
- package/lib/util/blocklet/tar.js +119 -0
- package/lib/util/convert-to-nosources-sourcemap.js +37 -0
- package/lib/util/docker-status-log.js +17 -0
- package/lib/util/exit-when-server-stopped.js +44 -0
- package/lib/util/get-cli-binary-name.js +8 -0
- package/lib/util/get-download-bundle-step.js +36 -0
- package/lib/util/get-service-instance-number.js +12 -0
- package/lib/util/index.js +626 -0
- package/lib/util/print-error.js +11 -0
- package/lib/util/print.js +9 -0
- package/lib/util/what-uri.js +40 -0
- package/package.json +123 -27
- package/lib/run.d.ts +0 -2
- package/lib/run.js +0 -73
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This package contains 2 command utilities to manage Blocklet Server and Blocklets
|
|
4
4
|
|
|
5
|
-
- `blocklet`: manage
|
|
6
|
-
- `blocklet
|
|
5
|
+
- `blocklet server`: manage Blocklet Server instances, such as init/start/stop/export, designed for DevOps
|
|
6
|
+
- `blocklet`: manage blocklets, such as init/dev/bundle/deploy/publish, designed for developers
|
|
7
7
|
|
|
8
8
|
## Getting Started
|
|
9
9
|
|
|
@@ -21,15 +21,27 @@ Now your Blocklet Server is up and running.
|
|
|
21
21
|
## `blocklet server` command
|
|
22
22
|
|
|
23
23
|
```terminal
|
|
24
|
-
|
|
25
|
-
_ ____ _ _
|
|
26
|
-
/ \ _ __ ___| __ )| | ___ ___| | __
|
|
27
|
-
/ _ \ | '__/ __| _ \| |/ _ \ / __| |/ /
|
|
28
|
-
/ ___ \| | | (__| |_) | | (_) | (__| <
|
|
29
|
-
/_/ \_\_| \___|____/|_|\___/ \___|_|\_\
|
|
30
|
-
|
|
31
|
-
Blocklet CLI v1.16.32
|
|
24
|
+
Usage: blocklet server [options] [command]
|
|
32
25
|
|
|
26
|
+
Options:
|
|
27
|
+
-V, --version output the version number
|
|
28
|
+
-c --config [node-config] Blocklet Server configuration file
|
|
29
|
+
-y --yes Automatic yes to prompts (default: false)
|
|
30
|
+
(default: false)
|
|
31
|
+
-h, --help display help for command
|
|
32
|
+
|
|
33
|
+
Commands:
|
|
34
|
+
start [options] Start Blocklet Server Daemon
|
|
35
|
+
init [options] Init Blocklet Server config
|
|
36
|
+
status Show Blocklet Server and blocklet status
|
|
37
|
+
logs Show Blocklet Server and blocklet logs
|
|
38
|
+
stop [options] Stop Blocklet Server and blocklets
|
|
39
|
+
info [options] Get environment information for debugging and
|
|
40
|
+
issue reporting
|
|
41
|
+
upgrade Self-Upgrade Blocklet Server
|
|
42
|
+
export [options] Eject a Blocklet Server config that can be
|
|
43
|
+
shared with others
|
|
44
|
+
help [command] display help for command
|
|
33
45
|
|
|
34
46
|
None of the above command seems help? Consider command line utility blocklet.
|
|
35
47
|
```
|
|
@@ -42,6 +54,7 @@ Usage: blocklet [options] [command]
|
|
|
42
54
|
Options:
|
|
43
55
|
-V, --version output the version number
|
|
44
56
|
-y --yes Automatic yes to prompts (default: false)
|
|
57
|
+
(default: false)
|
|
45
58
|
-h, --help display help for command
|
|
46
59
|
|
|
47
60
|
Commands:
|
|
@@ -49,25 +62,19 @@ Commands:
|
|
|
49
62
|
Server
|
|
50
63
|
deploy [options] <folder> Deploy blocklet from local directory to
|
|
51
64
|
Blocklet Server
|
|
52
|
-
dev [options]
|
|
53
|
-
test Setup blocklet test environment
|
|
65
|
+
dev [options] [action] Develop blocklet from current directory
|
|
54
66
|
init [options] Create an empty blocklet project
|
|
55
67
|
meta Print blocklet meta from a directory
|
|
56
68
|
version [options] [newVersion] Bump blocklet version and persist to disk
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
add [options] <component> Add component to blocklet.yml
|
|
64
|
-
remove <component> Remove component from blocklet.yml
|
|
65
|
-
document Manage DID document for the blocklet or the
|
|
66
|
-
Blocklet Server
|
|
67
|
-
config [options] Manage the configuration for Blocklet CLI,
|
|
68
|
-
use blocklet config help to see detail
|
|
69
|
-
server [options]
|
|
69
|
+
migrate [options] Migrate blocklet meta to latest version for
|
|
70
|
+
a blocklet
|
|
71
|
+
publish [options] [metafile] Publish the blocklet release to registry
|
|
72
|
+
upload [options] [metafile] Upload the blocklet to registry
|
|
73
|
+
config Manage the Blocklet Server configuration
|
|
74
|
+
files, use blocklet config help to see detail
|
|
70
75
|
help [command] display help for command
|
|
76
|
+
|
|
77
|
+
None of the above command seems help? Consider command line utility blocklet server.
|
|
71
78
|
```
|
|
72
79
|
|
|
73
80
|
## Documentation
|
package/bin/blocklet.js
CHANGED
|
@@ -1,3 +1,294 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable import/order */
|
|
3
|
+
/* eslint-disable global-require */
|
|
4
|
+
const {
|
|
5
|
+
ABT_NODE_MAX_CLUSTER_SIZE,
|
|
6
|
+
CLI_MODE,
|
|
7
|
+
NODE_ENV,
|
|
8
|
+
ABT_NODE_HOME,
|
|
9
|
+
PM2_HOME,
|
|
10
|
+
ABT_NODE_CONFIG_FILE,
|
|
11
|
+
} = require('../lib/constant');
|
|
2
12
|
|
|
3
|
-
|
|
13
|
+
process.env.CLI_MODE = CLI_MODE;
|
|
14
|
+
process.env.NODE_ENV = NODE_ENV;
|
|
15
|
+
process.env.ABT_NODE_HOME = ABT_NODE_HOME;
|
|
16
|
+
process.env.PM2_HOME = PM2_HOME;
|
|
17
|
+
process.env.ABT_NODE_CONFIG_FILE = ABT_NODE_CONFIG_FILE;
|
|
18
|
+
process.env.ABT_NODE_MAX_CLUSTER_SIZE = String(ABT_NODE_MAX_CLUSTER_SIZE);
|
|
19
|
+
|
|
20
|
+
require('please-upgrade-node')(require('../package.json'));
|
|
21
|
+
|
|
22
|
+
const { Command } = require('commander');
|
|
23
|
+
const last = require('lodash/last');
|
|
24
|
+
|
|
25
|
+
const { PROCESS_NAME_UPDATER, PROCESS_NAME_SERVICE, PROCESS_NAME_EVENT_HUB } = require('@abtnode/constant');
|
|
26
|
+
const debug = require('debug')('@blocklet/cli:blocklet');
|
|
27
|
+
const { echoBrand, isNewInstalled, removeNewInstalled } = require('../lib/arcblock');
|
|
28
|
+
const { print, checkUpdate, printVersionTip } = require('../lib/util');
|
|
29
|
+
|
|
30
|
+
const { getInternalPort: getPort } = require('../lib/port');
|
|
31
|
+
|
|
32
|
+
process.env.ABT_NODE_UPDATER_PORT = getPort(PROCESS_NAME_UPDATER);
|
|
33
|
+
process.env.ABT_NODE_SERVICE_PORT = getPort(PROCESS_NAME_SERVICE);
|
|
34
|
+
process.env.ABT_NODE_EVENT_PORT = getPort(PROCESS_NAME_EVENT_HUB);
|
|
35
|
+
|
|
36
|
+
const { version } = require('../package.json');
|
|
37
|
+
const bundle = require('../lib/commands/blocklet/bundle');
|
|
38
|
+
const deploy = require('../lib/commands/blocklet/deploy');
|
|
39
|
+
const dev = require('../lib/commands/blocklet/dev');
|
|
40
|
+
const test = require('../lib/commands/blocklet/test');
|
|
41
|
+
const init = require('../lib/commands/blocklet/init');
|
|
42
|
+
const meta = require('../lib/commands/blocklet/meta');
|
|
43
|
+
const blockletVersion = require('../lib/commands/blocklet/version');
|
|
44
|
+
const upload = require('../lib/commands/blocklet/upload');
|
|
45
|
+
const config = require('../lib/commands/blocklet/config');
|
|
46
|
+
const create = require('../lib/commands/blocklet/create');
|
|
47
|
+
const connect = require('../lib/commands/blocklet/connect');
|
|
48
|
+
const exec = require('../lib/commands/blocklet/exec');
|
|
49
|
+
const add = require('../lib/commands/blocklet/add');
|
|
50
|
+
const remove = require('../lib/commands/blocklet/remove');
|
|
51
|
+
const cleanup = require('../lib/commands/blocklet/cleanup');
|
|
52
|
+
const document = require('../lib/commands/blocklet/document');
|
|
53
|
+
const ServerCommand = require('../lib/commands/server/command');
|
|
54
|
+
|
|
55
|
+
const program = new Command();
|
|
56
|
+
|
|
57
|
+
program.version(version);
|
|
58
|
+
program.option('-y --yes', 'Automatic yes to prompts', false);
|
|
59
|
+
|
|
60
|
+
const handleUnexpectedError = (error) => {
|
|
61
|
+
print();
|
|
62
|
+
console.error(error);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
process.on('uncaughtException', handleUnexpectedError).on('unhandledRejection', handleUnexpectedError);
|
|
67
|
+
|
|
68
|
+
// if it's new installed, print the brand and version
|
|
69
|
+
// else just print the version
|
|
70
|
+
if (isNewInstalled() && ['--version', '-V'].includes(last(process.argv)) === false) {
|
|
71
|
+
echoBrand({ version });
|
|
72
|
+
removeNewInstalled();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const parseOptions =
|
|
76
|
+
(handler) =>
|
|
77
|
+
async (...args) => {
|
|
78
|
+
if (isNewInstalled() === false) {
|
|
79
|
+
printVersionTip();
|
|
80
|
+
}
|
|
81
|
+
const commonOptions = program.opts();
|
|
82
|
+
const options = last(args);
|
|
83
|
+
const allOptions = { ...commonOptions, ...options };
|
|
84
|
+
debug('parse options', allOptions);
|
|
85
|
+
await handler(...args.slice(0, args.length - 1), allOptions);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
program
|
|
89
|
+
.command('bundle')
|
|
90
|
+
.description('Bundle a blocklet that can run in Blocklet Server')
|
|
91
|
+
.option('--zip', 'Bundle using zip mode, enabled by default', true)
|
|
92
|
+
.option('--simple', 'Bundle using simple mode', false)
|
|
93
|
+
.option('--compact', 'Bundle using compact mode, together with all its dependencies', false)
|
|
94
|
+
.option('--source-map', 'Create source map for bundled blocklet, only available for compact mode', false)
|
|
95
|
+
.option(
|
|
96
|
+
'--nosources-source-map <boolean>',
|
|
97
|
+
'Create a source map without including sources content, only available for compact mode',
|
|
98
|
+
false
|
|
99
|
+
)
|
|
100
|
+
.option('--minify', 'Use minify in compact mode', true)
|
|
101
|
+
.option('--no-minify', 'Do not use minify in compact mode')
|
|
102
|
+
.option(
|
|
103
|
+
'--external <items>',
|
|
104
|
+
'External dependencies to be included in bundle, use comma to separate multiple items',
|
|
105
|
+
(val, memo) => {
|
|
106
|
+
memo.push(val);
|
|
107
|
+
return memo;
|
|
108
|
+
},
|
|
109
|
+
[]
|
|
110
|
+
)
|
|
111
|
+
.option('--create-release', 'Create release tarball/meta for bundled blocklet', false)
|
|
112
|
+
.option('--monorepo', 'Bundle a blocklet that is in a monorepo', false)
|
|
113
|
+
.option('--changelog', 'Include CHANGELOG.md in blocklet bundle', true)
|
|
114
|
+
.option('--no-changelog', 'Skip including CHANGELOG.md in blocklet bundle')
|
|
115
|
+
.option('--store-url <storeUrl>', 'Default store url used when component source store is not declared')
|
|
116
|
+
.action(parseOptions(bundle.run));
|
|
117
|
+
|
|
118
|
+
program
|
|
119
|
+
.command('deploy <folder>')
|
|
120
|
+
.option('--endpoint <host>', 'The endpoint of remote Blocklet Server dashboard, such as http://127.0.0.1/admin')
|
|
121
|
+
.option('--access-key <key>', 'Access key of remote Blocklet Server')
|
|
122
|
+
.option('--access-secret <secret>', 'Access secret of remote Blocklet Server')
|
|
123
|
+
.option('--app-id <did>', 'Which app to mount to when deploy a component')
|
|
124
|
+
.option('--app-did <did>', '[Deprecated] Alias of --app-id')
|
|
125
|
+
.option('--mount-point <mountPoint>', 'Mount point to the app when deploy a component')
|
|
126
|
+
.description('Deploy blocklet from local directory to Blocklet Server')
|
|
127
|
+
.action(parseOptions(deploy.run));
|
|
128
|
+
|
|
129
|
+
program.addCommand(
|
|
130
|
+
(function makeDevCommand() {
|
|
131
|
+
const command = new Command('dev');
|
|
132
|
+
command.description('Develop blocklet from current directory');
|
|
133
|
+
command.option('--open', 'Open the browser after blocklet had been started', false);
|
|
134
|
+
command.option('--app-id <did>', 'Develop the blocklet as a component and mount it to which app');
|
|
135
|
+
command.option('--app-did <did>', '[Deprecated] Alias of --app-id');
|
|
136
|
+
command.option('--mount-point <mountPoint>', 'Mount point to the app');
|
|
137
|
+
command.option('--store-url <storeUrl>', 'Default store url used when component source store is not declared');
|
|
138
|
+
command.option('--start-all-components', 'Auto start all components in the blocklet', false);
|
|
139
|
+
command.command('install').description('Install the development mode blocklet').action(parseOptions(dev.install));
|
|
140
|
+
command
|
|
141
|
+
.command('start')
|
|
142
|
+
.description('Start developing blocklet after installed')
|
|
143
|
+
.option('--e2e', 'Start blocklet in e2e mode, must have e2eDev script', false)
|
|
144
|
+
.action(parseOptions(dev.start));
|
|
145
|
+
command.command('remove').description('Remove the development mode blocklet').action(parseOptions(dev.remove));
|
|
146
|
+
command.command('studio').description('Start the blocklet studio').action(parseOptions(dev.studio));
|
|
147
|
+
command.command('reset').alias('clear').description('Reset blocklet data').action(parseOptions(dev.reset));
|
|
148
|
+
command
|
|
149
|
+
.command('faucet')
|
|
150
|
+
.option('--host <host>', 'The host of the faucet', 'https://faucet.abtnetwork.io')
|
|
151
|
+
.option('--token <token>', 'The token symbol')
|
|
152
|
+
.description('Fund your app with test token from faucet')
|
|
153
|
+
.action(parseOptions(dev.faucet));
|
|
154
|
+
command.action(parseOptions(dev.run));
|
|
155
|
+
return command;
|
|
156
|
+
})()
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
program.addCommand(
|
|
160
|
+
(function makeTestCommand() {
|
|
161
|
+
const command = new Command('test');
|
|
162
|
+
command.description('Setup blocklet test environment');
|
|
163
|
+
command
|
|
164
|
+
.command('init')
|
|
165
|
+
.option('--app-sk <appSk>', 'The secretKey for the blocklet app')
|
|
166
|
+
.option('--owner-sk <ownerSk>', 'The secretKey for the blocklet owner')
|
|
167
|
+
.option('--app-name [appName]', 'The name for the blocklet app', 'Test App')
|
|
168
|
+
.description('Init new blocklet, skip if same appDid exist')
|
|
169
|
+
.action(parseOptions(test.init));
|
|
170
|
+
command
|
|
171
|
+
.command('start')
|
|
172
|
+
.option('--app-sk <appSk>', 'The secretKey for the blocklet app')
|
|
173
|
+
.description('Start the blocklet for testing')
|
|
174
|
+
.action(parseOptions(test.start));
|
|
175
|
+
command
|
|
176
|
+
.command('remove')
|
|
177
|
+
.option('--app-sk <appSk>', 'The secretKey for the blocklet app')
|
|
178
|
+
.description('Delete the testing blocklet completely')
|
|
179
|
+
.action(parseOptions(test.remove));
|
|
180
|
+
command
|
|
181
|
+
.command('reset')
|
|
182
|
+
.option('--app-sk <appSk>', 'The secretKey for the blocklet app')
|
|
183
|
+
.description('Reset the testing blocklet state')
|
|
184
|
+
.action(parseOptions(test.reset));
|
|
185
|
+
command.action(parseOptions(test.run));
|
|
186
|
+
return command;
|
|
187
|
+
})()
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
program
|
|
191
|
+
.command('init')
|
|
192
|
+
.option('--did [did]', 'Specify a blocklet did', '')
|
|
193
|
+
.option('-f --force', 'Initialize a blocklet project without having it ask any questions', false)
|
|
194
|
+
.option('--monikers <monikers>', 'Custom did create moniker, support array combine with comma', '')
|
|
195
|
+
.option('--connectUrl <connectUrl>', 'A connect url help to generate did', 'https://store.blocklet.dev')
|
|
196
|
+
.description('Create an empty blocklet project')
|
|
197
|
+
.action(parseOptions(init.run));
|
|
198
|
+
|
|
199
|
+
program.command('meta').description('Print blocklet meta from a directory').action(parseOptions(meta.run));
|
|
200
|
+
|
|
201
|
+
program
|
|
202
|
+
.command('version [newVersion]')
|
|
203
|
+
.option('--git-commit', 'Do a git commit after the bump')
|
|
204
|
+
.option('-f --force', 'Force bumping blocklet version')
|
|
205
|
+
.description('Bump blocklet version and persist to disk')
|
|
206
|
+
.action(parseOptions(blockletVersion.run));
|
|
207
|
+
|
|
208
|
+
program
|
|
209
|
+
.command('upload [metafile]')
|
|
210
|
+
.option('--profile <profile>', 'Your config profile', 'default')
|
|
211
|
+
.option('--access-token <accessToken>', 'Your blocklet store access token')
|
|
212
|
+
.description('Upload the blocklet to blocklet store')
|
|
213
|
+
.action(parseOptions(upload.run));
|
|
214
|
+
|
|
215
|
+
program
|
|
216
|
+
.command('exec <script>')
|
|
217
|
+
.option('--app-id <did>', "Execute component script in which app's running context")
|
|
218
|
+
.option('--timeout <timeout>', 'Max timeout in seconds for script to run')
|
|
219
|
+
.description('Execute script in blocklet running context')
|
|
220
|
+
.action(parseOptions(exec.run));
|
|
221
|
+
|
|
222
|
+
program
|
|
223
|
+
.command('connect <store-url>')
|
|
224
|
+
.option('--profile <profile>', 'Your config profile', 'default')
|
|
225
|
+
.description('Connect to blocklet store. This command will set store configuration by "blocklet config"')
|
|
226
|
+
.action(parseOptions(connect.run));
|
|
227
|
+
|
|
228
|
+
program
|
|
229
|
+
.command('create [name]')
|
|
230
|
+
.option('--did <did>', 'Specify a blocklet did')
|
|
231
|
+
.description('Bootstrap a brand new blocklet from various starter templates within minutes')
|
|
232
|
+
.action(parseOptions(create.run));
|
|
233
|
+
|
|
234
|
+
program
|
|
235
|
+
.command('add <component>')
|
|
236
|
+
.description('Add component to blocklet.yml')
|
|
237
|
+
.option('--profile <profile>', 'Your config profile', 'default')
|
|
238
|
+
.option('--store <store>', 'Which store is the component from')
|
|
239
|
+
.option('--title <title>', 'Custom title of the component')
|
|
240
|
+
.option('--mount-point <mountPoint>', 'MountPoint of the component')
|
|
241
|
+
.action(parseOptions(add.run));
|
|
242
|
+
|
|
243
|
+
program
|
|
244
|
+
.command('remove <component>')
|
|
245
|
+
.description('Remove component from blocklet.yml')
|
|
246
|
+
.action(parseOptions(remove.run));
|
|
247
|
+
|
|
248
|
+
program
|
|
249
|
+
.command('cleanup')
|
|
250
|
+
.option('--target <target>', 'Which target to cleanup, available options: cache, backup')
|
|
251
|
+
.option('--app-did <did>', 'Which blocklet to cleanup')
|
|
252
|
+
.description('Do some blocklet level cleanup work')
|
|
253
|
+
.action(parseOptions(cleanup.run));
|
|
254
|
+
|
|
255
|
+
function makeDocumentCommand() {
|
|
256
|
+
const documentCommand = new Command('document');
|
|
257
|
+
documentCommand.description('Manage DID document for the blocklet or the Blocklet Server');
|
|
258
|
+
documentCommand
|
|
259
|
+
.command('update <app-id>')
|
|
260
|
+
.description('Update DID document for the blocklet')
|
|
261
|
+
.action(parseOptions(document.update));
|
|
262
|
+
return documentCommand;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
program.addCommand(makeDocumentCommand());
|
|
266
|
+
|
|
267
|
+
function makeConfigCommand() {
|
|
268
|
+
const configCommand = new Command('config');
|
|
269
|
+
configCommand.description('Manage the configuration for Blocklet CLI, use blocklet config help to see detail');
|
|
270
|
+
configCommand.option('--profile <profile>', 'Your config profile', 'default');
|
|
271
|
+
configCommand.command('set [key] [value]').description('Set config value').action(parseOptions(config.set));
|
|
272
|
+
configCommand.command('get [key]').description('Get config value').action(parseOptions(config.get));
|
|
273
|
+
configCommand.command('delete [key]').description('Delete config value').action(parseOptions(config.delete));
|
|
274
|
+
configCommand.command('list').alias('ls').description('List config value').action(parseOptions(config.list));
|
|
275
|
+
configCommand.action(config.run);
|
|
276
|
+
return configCommand;
|
|
277
|
+
}
|
|
278
|
+
program.addCommand(makeConfigCommand());
|
|
279
|
+
|
|
280
|
+
program.addCommand(ServerCommand('server'));
|
|
281
|
+
|
|
282
|
+
if (process.argv.includes('upgrade') === false) {
|
|
283
|
+
checkUpdate();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
program.on('command:*', () => {
|
|
287
|
+
program.help();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
program.parse(process.argv);
|
|
291
|
+
|
|
292
|
+
if (program.args.length === 0) {
|
|
293
|
+
program.help();
|
|
294
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Node config
|
|
2
|
+
node:
|
|
3
|
+
# Meta
|
|
4
|
+
name: 'ABT Node'
|
|
5
|
+
description: 'Container of official ArcBlock blocklets'
|
|
6
|
+
|
|
7
|
+
# Node wallet
|
|
8
|
+
sk: '0xf80939b4ff688cd148ceab330b451683d41bb616b259507ae3e96a1188706d367efeabbebdc0cb49bcf865c77a15993d87245b124bbc5125d2c3997437d1fda3'
|
|
9
|
+
pk: '0x7efeabbebdc0cb49bcf865c77a15993d87245b124bbc5125d2c3997437d1fda3'
|
|
10
|
+
did: 'zNKgjyuEWQQqfuJcAVruPRHUaDD1PzcsAjaD'
|
|
11
|
+
|
|
12
|
+
# Where to store ABT Node data
|
|
13
|
+
dataDir: /Users/wangshijun/.abtnode
|
|
14
|
+
|
|
15
|
+
# Node dashboard
|
|
16
|
+
domain: 192.168.1.2
|
|
17
|
+
port: 5554
|
|
18
|
+
https: false
|
|
19
|
+
|
|
20
|
+
# Node dashboard session secret
|
|
21
|
+
secret: 'weilru4j2oi34u*(#U$IORQWRjk'
|
|
22
|
+
|
|
23
|
+
# Owner info
|
|
24
|
+
owner:
|
|
25
|
+
pk: ''
|
|
26
|
+
did: ''
|
|
27
|
+
|
|
28
|
+
blocklet:
|
|
29
|
+
# On which port should blocklet process listen on, multiple blocklets will use different ports incremented from this config
|
|
30
|
+
port: 5555
|
|
31
|
+
|
|
32
|
+
# Where to fetch available blocklets
|
|
33
|
+
registry: https://blocklet.arcblockio.cn
|
package/lib/arcblock.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const figlet = require('figlet');
|
|
3
|
+
const terminalLink = require('terminal-link');
|
|
4
|
+
const gradient = require('gradient-string');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const { print } = require('./util/print');
|
|
7
|
+
const { INSTALL_FILE_PATH } = require('./constant');
|
|
8
|
+
|
|
9
|
+
const { green } = chalk;
|
|
10
|
+
|
|
11
|
+
function echoBrand({ version = '' } = {}) {
|
|
12
|
+
const data = figlet.textSync('ArcBlock', { width: 44 });
|
|
13
|
+
const symbolLen = 44;
|
|
14
|
+
const indent = (symbolLen - 10) / 2;
|
|
15
|
+
const msgList = [`\n${' '.repeat(indent)}Powered By`, data];
|
|
16
|
+
if (version) {
|
|
17
|
+
msgList.push(`${' '.repeat((symbolLen - 20) / 2)}Blocklet CLI v${version}\n`);
|
|
18
|
+
}
|
|
19
|
+
const msg = gradient(['cyan', 'rgb(0, 111, 150)', 'rgb(0, 246,136)']).multiline(msgList.join('\n'));
|
|
20
|
+
print(msg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function echoDocument() {
|
|
24
|
+
const url = 'https://developer.blocklet.io/docs';
|
|
25
|
+
let msg;
|
|
26
|
+
if (terminalLink.isSupported) {
|
|
27
|
+
msg = green(terminalLink(`Documentation: ${url}`, url));
|
|
28
|
+
} else {
|
|
29
|
+
msg = green(`Check documentation in here: ${url}`);
|
|
30
|
+
}
|
|
31
|
+
print('\n', msg, '\n');
|
|
32
|
+
return msg;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isNewInstalled() {
|
|
36
|
+
return fs.existsSync(INSTALL_FILE_PATH);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function removeNewInstalled() {
|
|
40
|
+
return fs.removeSync(INSTALL_FILE_PATH);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ensureNewInstalled() {
|
|
44
|
+
return fs.ensureFileSync(INSTALL_FILE_PATH);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
echoBrand,
|
|
49
|
+
echoDocument,
|
|
50
|
+
isNewInstalled,
|
|
51
|
+
removeNewInstalled,
|
|
52
|
+
ensureNewInstalled,
|
|
53
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const { joinURL } = require('ufo');
|
|
3
|
+
const getBlockletMeta = require('@blocklet/meta/lib/parse');
|
|
4
|
+
const toBlockletDid = require('@blocklet/meta/lib/did');
|
|
5
|
+
const { select: getMetaFile, update: updateMetaFile } = require('@blocklet/meta/lib/file');
|
|
6
|
+
const urlPathFriendly = require('@blocklet/meta/lib/url-path-friendly').default;
|
|
7
|
+
const { BLOCKLET_STORE_API_BLOCKLET_PREFIX, BLOCKLET_STORE_URL } = require('@abtnode/constant');
|
|
8
|
+
const { getBlockletMetaFromUrl } = require('@blocklet/meta/lib/util-meta');
|
|
9
|
+
|
|
10
|
+
const { printSuccess, printError } = require('../../util');
|
|
11
|
+
const Config = require('../../util/blocklet/config');
|
|
12
|
+
const { fixComponents, checkCircularDependencies } = require('../../util/blocklet/meta');
|
|
13
|
+
const debug = require('../../debug')('blocklet:version');
|
|
14
|
+
|
|
15
|
+
const getMetaUrl = (store, name, version) => {
|
|
16
|
+
return joinURL(
|
|
17
|
+
store,
|
|
18
|
+
BLOCKLET_STORE_API_BLOCKLET_PREFIX,
|
|
19
|
+
toBlockletDid(name),
|
|
20
|
+
!version || version === 'latest' ? '' : version,
|
|
21
|
+
'blocklet.json'
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// eslint-disable-next-line consistent-return
|
|
26
|
+
const getMeta = async (url) => {
|
|
27
|
+
try {
|
|
28
|
+
const meta = await getBlockletMetaFromUrl(url);
|
|
29
|
+
return meta;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
printError(`Failed validate component meta: ${error.message}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const parseComponent = (text) => {
|
|
37
|
+
if (/^\w+:\/\//.test(text)) {
|
|
38
|
+
return { url: text };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const match = /(.*)@((latest)|(\d+\.\d+\.\d+))$/.exec(text);
|
|
42
|
+
const name = match ? match[1] : text;
|
|
43
|
+
const version = match ? match[2] : 'latest';
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
version,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const getSource = async (param, opts) => {
|
|
52
|
+
const { url, name, version } = parseComponent(param);
|
|
53
|
+
if (url) {
|
|
54
|
+
const componentMeta = await getMeta(url);
|
|
55
|
+
// bundleName 必须为 blocklet 的 blocklet.yml 中的 name
|
|
56
|
+
return { source: { url }, bundleName: componentMeta.name, bundleTitle: componentMeta.title || '' };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const config = new Config({
|
|
60
|
+
configFile: process.env.ABT_NODE_CONFIG_FILE,
|
|
61
|
+
section: opts.profile === 'default' ? '' : opts.profile,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
let store = opts.store || config.get('store') || config.get('registry') || BLOCKLET_STORE_URL;
|
|
65
|
+
if (!/^https?:\/\//.test(store)) {
|
|
66
|
+
store = `https://${store}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const bundleMetaUrl = getMetaUrl(store, name, version);
|
|
70
|
+
const componentMeta = await getMeta(bundleMetaUrl);
|
|
71
|
+
// NOTICE: 支持传入 blocklet-did 来进行安装
|
|
72
|
+
if (componentMeta.name !== name && componentMeta.did !== name) {
|
|
73
|
+
printError(`Failed validate component meta: invalid name. Expected ${name}, Got: ${componentMeta.name}`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
source: { store, name: componentMeta.name, version },
|
|
78
|
+
bundleName: componentMeta.name,
|
|
79
|
+
bundleTitle: componentMeta.title || '',
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.run = async (param, opts = {}) => {
|
|
84
|
+
try {
|
|
85
|
+
const dir = process.cwd();
|
|
86
|
+
const file = getMetaFile(dir);
|
|
87
|
+
const meta = getBlockletMeta(dir, { fix: false });
|
|
88
|
+
|
|
89
|
+
const { source, bundleName, bundleTitle } = await getSource(param, opts);
|
|
90
|
+
|
|
91
|
+
fixComponents(meta);
|
|
92
|
+
|
|
93
|
+
meta.components = meta.components || [];
|
|
94
|
+
|
|
95
|
+
const name = bundleName;
|
|
96
|
+
|
|
97
|
+
if (meta.components.some((x) => x.name === name)) {
|
|
98
|
+
printSuccess(`Component ${chalk.cyan(name)} already exists`);
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const component = {
|
|
103
|
+
name,
|
|
104
|
+
title: opts.title || bundleTitle,
|
|
105
|
+
mountPoint: opts.mountPoint || `/${urlPathFriendly(name, { keepSlash: false })}`,
|
|
106
|
+
source,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
debug('component config', component);
|
|
110
|
+
|
|
111
|
+
meta.components.push(component);
|
|
112
|
+
|
|
113
|
+
await checkCircularDependencies(meta);
|
|
114
|
+
|
|
115
|
+
updateMetaFile(file, meta, { fix: false });
|
|
116
|
+
printSuccess(`Component ${chalk.cyan(name)} was successfully added`);
|
|
117
|
+
|
|
118
|
+
process.exit(0);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
debug('Failed add blocklet', error);
|
|
121
|
+
printError('Failed add component: ', error.message);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
.pnp
|
|
5
|
+
.pnp.js
|
|
6
|
+
.DS_Store
|
|
7
|
+
node_modules
|
|
8
|
+
|
|
9
|
+
# testing
|
|
10
|
+
coverage
|
|
11
|
+
|
|
12
|
+
# production
|
|
13
|
+
build
|
|
14
|
+
dist
|
|
15
|
+
dist-ssr
|
|
16
|
+
.blocklet
|
|
17
|
+
|
|
18
|
+
# local env files
|
|
19
|
+
*.local
|
|
20
|
+
|
|
21
|
+
# Log files
|
|
22
|
+
logs
|
|
23
|
+
*.log
|
|
24
|
+
npm-debug.log*
|
|
25
|
+
yarn-debug.log*
|
|
26
|
+
yarn-error.log*
|
|
27
|
+
pnpm-debug.log*
|
|
28
|
+
lerna-debug.log*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
|
|
3
|
+
const server = http.createServer((req, res) => {
|
|
4
|
+
res.statusCode = 200;
|
|
5
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
6
|
+
res.end('Hello Blocklet\n');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const port = process.env.BLOCKLET_PORT || 3000;
|
|
10
|
+
|
|
11
|
+
server.listen(port, () => {
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.log(`Server running at http://127.0.0.1:${3000}/`);
|
|
14
|
+
});
|
|
Binary file
|