blocklet-development-guide
Version:
Blocklet development guide, a help documentation for quickly get started to develop a blocklet.
1 lines • 8.41 kB
JSON
{"componentChunkName":"component---node-modules-arcblock-gatsby-theme-docs-src-templates-documentation-js","path":"/en/developer/blocklet-hooks","result":{"data":{"file":{"changeTime":"5 minutes ago","childMarkdownRemark":{"frontmatter":{"author":"wangshijun","category":"","date":null,"description":"Blocklet Hooks","draft":null,"keywords":"abtnode, blocklet","language":"en","layout":"documentation","path":"/en/developer/blocklet-hooks","tags":["abtnode"],"title":"Blocklet Hooks"},"htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Currently AbtNode supports the following hooks:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pre-deploy"}]},{"type":"text","value":": Usually execute various builds locally, when deploying from local to ABT Node Daemon. If the exit code is non-zero, quit deployment"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"post-install"}]},{"type":"text","value":": Do something at the end of installation. If the exit code is non-zero, the installation will be failed"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pre-stop"}]},{"type":"text","value":": Do something before stopping, such as exiting the related process started by the blocklet. If the exit code is non-zero, continue to stop, but print the error log"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pre-install"}]},{"type":"text","value":": Can be used to check whether the system environment meets the installation requirements. If the exit code is non-zero, the installation will be failed"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pre-start"}]},{"type":"text","value":": Do something before start, for example, check whether the dependent blocklet has been started. If the exit code is non-zero, then it is not allowed to start"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"pre-uninstall"}]},{"type":"text","value":": Do something before uninstall, for example, check whether the dependent blocklet is running. If the exit code is non-zero, continue to uninstall, but print the error log"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"hook-files","style":"position:relative;"},"children":[{"type":"element","tagName":"a","properties":{"href":"#hook-files","ariaLabel":"hook files permalink","className":["anchor","before"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Hook Files"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If the hooks depend on the files in the project, define the relative paths of these files in the "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"hookFiles"}]},{"type":"text","value":" field in "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"blocklet.json"}]},{"type":"text","value":"(or "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"blocklet.hookFiles"}]},{"type":"text","value":" in "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"package.json"}]},{"type":"text","value":")."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{"id":"error-handler","style":"position:relative;"},"children":[{"type":"element","tagName":"a","properties":{"href":"#error-handler","ariaLabel":"error handler permalink","className":["anchor","before"]},"children":[{"type":"element","tagName":"svg","properties":{"ariaHidden":"true","focusable":"false","height":"16","version":"1.1","viewBox":"0 0 16 16","width":"16"},"children":[{"type":"element","tagName":"path","properties":{"fillRule":"evenodd","d":"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"},"children":[]}]}]},{"type":"text","value":"Error Handler"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If there is an error in the blocklet, "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"write it to stderr"}]},{"type":"text","value":", so that "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"ABT Node"}]},{"type":"text","value":" can handle it gracefully."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"And if your hook is written by Node.js, we provide a utility "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"abtnode/js-util"}]},{"type":"text","value":" to catch "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"unhandledRejection"}]},{"type":"text","value":" and "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"unhandledRejection"}]},{"type":"text","value":" error, just import to your code:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"pre","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"],"js":""},"children":[{"type":"text","value":"require('@abtnode/util/lib/error-handler');\n"}]}]}],"data":{"quirksMode":false}}}}},"pageContext":{"site":{"title":"Development Guide","description":"Blocklet Development Guide","siteUrl":"https://docs.arcblock.io","logoUrl":"/","sidebarWidth":360,"disableI18n":false,"showGetStarted":false,"defaultBanner":""},"id":"402ffeb0-ad27-5973-92d6-d6d05efe4faf","language":"en","locale":"en","languages":[{"value":"en","text":"English"},{"value":"zh","text":"简体中文"}],"headings":[{"value":"Hook Files","depth":3},{"value":"Error Handler","depth":3}],"navItems":[{"group":"/home/runner/work/development-guide/development-guide/src","title":"Development Guide","priority":999,"link":"/"}],"version":"v0.0.4","official":true,"originalPath":"/en/developer/blocklet-hooks","sidebarContent":[{"url":"/en/developer","title":"Developer Guide","pages":[{"title":"Blocklet Specification","path":"/en/developer/blocklet-spec"},{"title":"Create Static Blocklets","path":"/en/developer/static-blocklet"},{"title":"Create DApp Blocklet","path":"/en/developer/dapp-blocklet"},{"title":"Blocklet Hooks","path":"/en/developer/blocklet-hooks"},{"title":"Bundle Blocklet","path":"/en/developer/bundle-blocklet"},{"title":"Publish Blocklet","path":"/en/developer/publish-blocklet"}]}],"communityPath":"https://community.arcblockio.cn","githubUrl":"https://github.com/blocklet/development-guide/tree/master/src/developer/blocklet-hooks/index.md"}},"staticQueryHashes":["1358860651","1619896071","1812186216","2194038815"]}