forge blocklet:init The command can initialize a Blocklet project. During the initialization process, several variables need to be set:
- name: Blocklet name
- description: Blocklet description
- group: classification of blocklet, currently optional
dApp | starter | contract
- color: Select the color theme of the blocklet.
primary | secondary | error
- templates: specify the template code directory, if there are multiple, use a comma (
After the command is successfully executed, the following files and directories are generated:
This file is the core file of the blocklet, and the analysis of the blocklet is based on this file.
This file provides the blocklet's
作者And other meta-information, as well as the scripts needed to create an application based on the blocklet (see below for details)
在 blocklet.json 中设置执行脚本one period).
This file will be displayed as the Blocklet detail page of the official website by default, so it is recommended to include the following in the document:
- What is this Blocklet?
- What features are provided?
- External dependencies using the blocklet
Because Blocklets are now packaged via npm, this file is required.
In addition, for
package.json All supported fields if
blocklet.json No settings in the official website or CLI will be used when parsing
package.json Fields, such as description information and so on.
This directory is some screenshots of the dApp generated by the Blocklet, which will be displayed on the Blocklet details page on the official website, so that other developers can easily see what features are available.
This directory is the source code needed to use this Blocklet to generate dApps. The directory where the code is stored in the example is
Of course, this can also be an array.
A dApp created through a blocklet may require the support of a chain or a database at runtime. How can a dApp set these configurations?
Available through the CLI
钩子脚本 to realise. The CLI divides these scripts into two parts: the scripts that the blocklet itself needs to execute, and the scripts that the generated dApp needs. These two configuration items are in
hooks Two nodes are set.
The execution timing of the script for this node is
复制Before template code, before
hooksExecute; so,If the Blocklet itself has dependencies that need to be installed, you can put it here.
The following four phases are currently supported in hooks
This stage is at
复制模板代码前Executed, so if you want to do some preparation before copying the code, you can do it by defining a script here.
This stage is at
复制模板代码后Executed, so if you want to do something after copying the code, such as installing dependencies, initializing the git repository, etc.
This phase is the key phase of creating a project based on blocklets. It is recommended that configuration item scripts required by the project be executed in this phase. For example, for a dAPP, you need an available chain, and possibly database support, so you can put the chain and database settings at this stage.
This is the last stage. After completing the previous steps, you can now start the project if it is successful, so you can put the command to start this project here, for example:
In this way, developers can easily start this project.
forge blocklet:use --local-blocklet <blocklet directory> Directive to test a local Blocklet project:
--local-blocklet Parameter to specify a local blocklet project to test the project you just created.
How to publish the Blocklet project to our after completing development and testing Official websiteHow about it?
Currently, all our blocklets must be published in
NPM On, at the same time, you must alsoPublished to NPM Add the Blocklet on our official warehouse, the specific process is as follows:
Now we can only supportManual reviewWay, you need to publish by submitting PR.
- Publish the project to NPM
- Fork this project https://github.com/ArcBlock/blocklets
- And then modify the
register.yml, Put your own Github project address:
- Then submit a PR.
- After passing the manual review, we will merge this PR into the master branch. After the build is complete, you can see your Blocklet project on the official website.