脚手架部署与更新 - Kit

steamer-plugin-kit

starter kit 管理命令

NPM Version Travis AppVeyor Deps Coverage

内置

steamer-plugin-kit 已经默认作为 steamerjs 的内置插件,全局安装 steamerjs 后即可使用。如果你额外安装 steamer-plugin-kit,则会优先使用这个额外安装的包。

安装

以下命令全局安装 steamerjssteamer-plugin-kit,使用时如遇到问题,可先参见文档[常见问题],可能是没设置好 NODE_PATH

  1. // 必须
  2. npm i -g steamerjs
  3. // v2.0 已经内置到 steamerjs,因此可不安装
  4. npm i -g steamer-plugin-kit

设置 NODE_PATH

由于 steamerjs 的命令或脚手架都需要全局安装,尽管steamerjs会尝试兼容,但在某些使用场景下会仍然找到不全局安装的位置,因此推荐设置环境变量 NODE_PATH

常见问题 - NODE_PATH设置

更新

  1. npm i -g steamer-plugin-kit@latest
  2. // 或者
  3. steamer update

添加脚手架

  1. // 添加最新版本
  2. steamer kit --add https://github.com/steamerjs/steamer-react.git
  3. // 添加指定tag版本
  4. steamer kit --add https://github.com/steamerjs/steamer-react.git --tag v3.0.7

基于脚手架初始化项目

  1. // 运行命令,并进行选择
  2. steamer kit
  3. ? Which starterkit do you wanna install: (Use arrow keys)
  4. steamer-react - alloyteam react starterkit
  5. steamer-vue - alloyteam vue starterkit
  6. steamer-simple - alloyteam frameworkless starterkit
  7. ? Which version do you need: (Use arrow keys)
  8. 3.0.8
  9. 3.0.5
  10. ? Which folder is your project in: (./)

更新脚手架

  1. steamer kit --update --global
  2. ? Which starterkit do you wanna update: (Use arrow keys)
  3. all starterkits
  4. steamer-react - alloyteam react starterkit
  5. steamer-vue - alloyteam vue starterkit
  6. steamer-simple - alloyteam frameworkless starterkit

更新项目使用的脚手架

  1. cd project
  2. steamer kit --update

查看可用脚手架

  1. steamer kit --list
  2. // 或
  3. steamer kit -l
  4. You can use following starterkits:
  5. * steamer-react
  6. - ver: 3.0.8
  7. - des: alloyteam react starterkit
  8. - url: https://github.com/steamerjs/steamer-react.git
  9. * steamer-vue
  10. - ver: 3.0.5
  11. - des: alloyteam vue starterkit
  12. - url: https://github.com/steamerjs/steamer-vue.git
  13. * steamer-simple
  14. - ver: 3.0.3
  15. - des: alloyteam frameworkless starterkit
  16. - url: https://github.com/steamerjs/steamer-simple.git

脚手架数据

  1. // 添加脚手架后,数据会存放在 $HOME/.steamer/starterkits/ 下面,脚手架的相关信息也会存放在 starterkit.js 中
  2. // 示例信息如下:
  3. kits = {
  4. list: {
  5. 'steamer-react': {
  6. latestVersion: '3.0.8',
  7. currentVersion: '3.0.8',
  8. description: '',
  9. versions: [
  10. '3.0.8',
  11. '3.0.5'
  12. ],
  13. url: ''
  14. }
  15. },
  16. timestamp: ''
  17. };

基于模板生成页面

  1. steamer kit --template
  2. // or
  3. steamer kit -t
  4. // 初次使用时做好配置,然后选择模板
  5. ? type the template source folder: ./tools/template
  6. ? type your template destination folder: ./src/page
  7. ? type your npm command(npm|tnpm|cnpm etc): npm
  8. ? which template do you like: (Use arrow keys)
  9. preact-list
  10. react-simple-mobx
  11. react-simple-redux
  12. react-spa-mobx
  13. react-spa-redux
  14. react-typescript

脚手架生命周期

3.0.0 版本后,新增脚手架生命周期,例如,如果脚手架叫做 steamer-example,则在脚手架相关配置文件 .steamer/steamer-example.js 中可以写如下生命周期:

  1. const path = require("path");
  2. const fs = require("fs");
  3. module.exports = {
  4. /**
  5. * some other codes here
  6. */
  7. // 初始化脚手架时,在拷贝文件发生前
  8. beforeInstallCopy: function (answers, folderPath) {
  9. console.log('====beforeInstallCopy====');
  10. },
  11. // 初始化脚手架时,在拷贝文件发生后
  12. afterInstallCopy: function (answers, folderPath) {
  13. console.log('====afterInstallCopy====');
  14. },
  15. // 初始化脚手架时,在安装依赖发生前
  16. beforeInstallDep: function (answers, folderPath) {
  17. console.log('====afterInstallDep====');
  18. },
  19. // 初始化脚手架时,在安装依赖发生后
  20. afterInstallDep: function (answers, folderPath) {
  21. console.log('====afterInstallDep====');
  22. },
  23. // 更新本地项目脚手架时,在拷贝文件发生前
  24. beforeUpdateCopy: function (answers, folderPath) {
  25. console.log('====beforeUpdateCopy====');
  26. },
  27. // 更新本地项目脚手架时,在拷贝文件发生后
  28. afterUpdateCopy: function (answers, folderPath) {
  29. console.log('====afterUpdateCopy====');
  30. },
  31. // 更新本地项目脚手架时,在更新依赖发生前
  32. beforeUpdateDep: function (answers, folderPath) {
  33. console.log('====beforeUpdateDep====');
  34. },
  35. // 更新本地项目脚手架时,在更新依赖发生后
  36. afterUpdateDep: function (answers, folderPath) {
  37. console.log('====afterUpdateDep====');
  38. },
  39. };

Starter Kit 的例子

符合 steamer 规范的 Starter Kit,可以参考 steamer-example,并仿照规范,进行接入。如何想开发,可以使用下面命令初始化:

  1. steamer develop -k [kit name]

官方 Starter Kit:

开发脚手架

在使用 steamer develop -k [kit name] 初始脚手架并开发了一定程序之外,若要在本地测试,可使用以下命令:

  1. cd [starterkit path]
  2. steamer kit --develop
  3. // or
  4. steamer kit -d
  5. // 如果想用别名,则用
  6. steamer kit --develop [alias name]
  7. // or
  8. steamer kit -d [alias name]