分发

分发的目标是使别人能轻松的安装扩展,只需把扩展放到 extensions 文件夹里即可。你不能要求他们安装某种工具或者编译什么代码——那是你作为一个开发者应该完成的工作!

所以在你打包扩展之前,需要安装好所有的 Compser 依赖项,并且编译你的 JavaScript 程序。

一个打包脚本的示例:

  1. #!/usr/bin/env bash
  2. base=${PWD}
  3. # Unzip an archive of the latest committed code
  4. # 解压 Flarum 最终版
  5. rm -rf /tmp/extension-release
  6. mkdir /tmp/extension-release
  7. git archive --format zip --worktree-attributes HEAD > /tmp/extension-release/release.zip
  8. cd /tmp/extension-release
  9. unzip release.zip -d ./
  10. rm release.zip
  11. # Install all Composer dependencies
  12. # 安装 Composer 依赖
  13. cd /tmp/extension-release/flarum
  14. composer install --prefer-dist --optimize-autoloader --ignore-platform-reqs --no-dev
  15. # Compile JavaScript
  16. # 编译 JavaScript
  17. # Assumes: npm install -g gulp flarum-gulp babel-core
  18. cd /tmp/extension-release/js
  19. for app in forum admin; do
  20. cd "/tmp/extension-release/js/${app}"
  21. npm link gulp flarum-gulp babel-core
  22. gulp --production
  23. rm -rf "/tmp/extension-release/js/${app}/node_modules"
  24. done

译者:@ttnl