命令行
WinJS 提供了很多内置的命令行用于启动,构建项目,另外还有一些辅助开发的命令,如生成器等。
要获取可用的命令列表,你可以在项目目录中运行 help 命令:
win help
你应该能看到类似如下的日志:
Usage: win <command> [options]
Commands:
build build app for production
config win config cli
cache manage win cache
dev dev server for development
help show commands help
info print debugging information about your environment
lint lint source code using eslint and stylelint
setup setup project
see generate possessing by SEE platform
ftp FTP uploads local files to the target server
deadcode check dead code
version show win version
v show win version
plugin inspect win plugins
verify-commit verify the commit message, which is usually used with husky.
preview locally preview production build
zip compress the package to zip package
run run the script commands, support for ts and zx
generate generate code snippets quickly
g generate code snippets quickly
Run `win help <command>` for more information of specific commands.
Visit https://winjs-dev.github.io/winjs-docs/ to learn more about WinJS.
为方便查找,以下命令通过字母排序。
build
构建项目,适用于生产环境的部署。
$ win build
config
通过命令行快速查看和修改配置。
查看配置,可以用 list
或 get
。
$ win config list
- [key: polyfill] false
- [key: externals] { esbuild: true }
$ win config get mfsu
- [key: externals] { esbuild: true }
修改配置,可以用 set
或 remove
。
$ win config set polyfill false
set config:polyfill on /private/tmp/sorrycc-wsYpty/.winrc.ts
$ win config remove polyfill
remove config:polyfill on /private/tmp/sorrycc-wsYpty/.winrc.ts
cache
WinJS 将 node_modules/.cache
作为缓存目录,有时候需要手动清除缓存,例如改了 node_modules
里的文件想验证结果,或者 mf 报错清了缓存就好了。可以执行此命令清除缓存。
$ win cache clean
也支持输出缓存目录树及大小,显示缓存文件夹信息,--depth
表示层数可选,默认值为 1 层,cache层为第 0 层
执行以下命令:
win cache ls [--depth]
info - [win cache] dir info
└─ [40.71 MB] node_modules/.cache
├─ [16.52 MB] bundler-webpack-eager
├─ [166 KB] logger
├─ [4.50 MB] mfsu
└─ [19.53 MB] mfsu-deps
deadcode
用于查找 src 目录下未被引用的文件,并在根目录输出文件。
$ win deadcode
- Preparing...
- begin check deadCode
- write file /examples/win-run/DeadCodeList-{timeStamp}.txt
- check dead code end, please be careful if you want to remove them
dev
启动本地开发服务器,进行项目的开发与调试。
$ win dev
╔═════════════════════════════════════════════════════╗
║ App listening at: ║
║ > Local: https://127.0.0.1:8001 ║
ready - ║ > Network: https://192.168.1.1:8001 ║
║ ║
║ Now you can open browser with the above addresses👆 ║
╚═════════════════════════════════════════════════════╝
event - compiled successfully in 1051 ms (416 modules)
ftp
通过 FTP 工具将本地文件上传到目标服务器。通常在 package.json 的 scripts.ftp
里设置。
默认读取 .winrc.ts
配置中的 ftpOptions 属性,该属性配置具体可以参考配置 ftpOptions。
{
"scripts": { "ftp": "win ftp" }
}
generate
用于增量生成文件或启用功能,命令行别名是 g
。
不加任何参数时会给交互式的生成器选择。
$ win g
# 或
$ win generate
? Pick generator type › - Use arrow-keys. Return to submit.
❯ Create Pages -- Create a win page by page name
Enable Tailwind CSS -- Setup Tailwind CSS configuration
Enable Uno CSS -- Setup Uno CSS configuration
Generate Component -- Generate component boilerplate code
Generate mock -- Generate mock boilerplate code
Enable E2E Testing with Cypress -- Setup Cypress Configuration
Generator api -- Generate api route boilerplate code
Generate Precommit -- Generate precommit boilerplate code
Generate huipro -- Generate subsystem build tool for hui 1.0 pro
也可以指定参数。
# 生成路由文件
$ win g page index --typescript --less
help
查看帮助。
$ win help
Usage: win <command> [options]
Commands:
build build app for production
config win config cli
dev dev server for development
help show commands help
setup setup project
see generate possessing by SEE platform
version show win version
plugin inspect win plugins
generate generate code snippets quickly
Run `win help <command>` for more information of specific commands.
Visit https://winjs-dev.github.io/winjs-docs/ to learn more about WinJS.
也可指定命令,查看特定命令的详细帮助。
$ win help build
Usage: win build [options]
build app for production.
Details:
win build
# build without compression
COMPRESS=none win build
# clean and build
win build --clean
info
打印有关环境的调试信息
$ win info
Usage: win info
System:
OS: macOS 11.4
CPU: (8) arm64 Apple M1
Binaries:
Node: 18.16.0 - ~/Library/Caches/fnm_multishells/13409_1689559164099/bin/node
npm: 9.6.7 - ~/Library/Caches/fnm_multishells/13409_1689559164099/bin/npm
Browsers:
Chrome: 114.0.5735.198
Edge: Not Found
Safari: 14.1.1
npmPackages:
vue: Not Found
vue-router: Not Found
win: workspace:* => 0.0.13
npmGlobalPackages:
win: Not Found
lint
用于检查及修正代码是否符合规则。
$ win lint
Usage: win lint
# automatically fix, where possible
win lint --fix
# disable reporting on warnings
win lint --quiet
# generate a report
win lint --report
# scan the directory
win lint --include src
mfsu
win mfsu
命令可以查看 MFSU 依赖信息、重新构建 MFSU 依赖和清除 MFSU 依赖。
获取 MFSU 命令帮忙
$ win mfsu
获取 MFSU 依赖列表
$ win mfsu ls
warning@0.0.3
regenerator-runtime/runtime.js@0.13.11
react/jsx-dev-runtime@18.1.0
react-intl@3.12.1
react-error-overlay/lib/index.js@6.0.9
react@18.1.0
qiankun@2.8.4
lodash/noop@4.17.21
lodash/mergeWith@4.17.21
lodash/concat@4.17.21
...
重新构建 MFSU 依赖
$ win mfsu build
info - Preparing...
info - MFSU eager strategy enabled
warn - Invalidate webpack cache since mfsu cache is missing
info - [MFSU] buildDeps since cacheDependency has changed
...
info - [plugin: @winner-fed/preset-win/dist/commands/mfsu/mfsu] [MFSU][eager] build success
清除 MFSU 依赖
$ # 删除依赖信息列表
$ win mfsu remove
$ # 删除依赖信息列表和产物文件
$ win mfsu remove --all
plugin
插件相关操作,目前只支持 list
子命令。
列出所有插件。
$ win plugin list
- @winner-fed/core/dist/service/servicePlugin
- @winner-fed/preset-win (from preset)
- @winner-fed/preset-win/dist/registerMethods (from preset)
- @winner-fed/preset-win/dist/features/appData/appData (from preset)
- @winner-fed/preset-win/dist/features/check/check (from preset)
- @winner-fed/preset-win/dist/features/configPlugins/configPlugins (from preset)
- virtual: config-styles
- virtual: config-scripts
- virtual: config-routes
- virtual: config-plugins
...
preview
win preview
命令会在本地启动一个静态 Web 服务器,将 dist 文件夹运行在 http://127.0.0.1:4172, 用于预览构建后产物, 支持 proxy、mock 等设置。
你可以通过 --port
参数来配置服务的运行端口。
$ win preview --port 9527
现在 preview
命令会将服务器运行在 http://127.0.0.1:9527.
通过 --host
参数来指定 配置服务运行的 hostname。
以下用户配置在 preview
时也会生效
注意 dist
目录会随着配置 outputPath
的变更而变更。
run
win run
命令可以让你像 node 运行 js 一样来运行 TypeScript 和 ESM 文件。你可以搭配 zx 来更好的使用脚本命令。
$ win run ./script.ts
setup
初始化项目,会做临时文件的生成等操作。通常在 package.json 的 scripts.postinstall
里设置。
{
"scripts": { "postinstall": "win setup" }
}
see
将构建后的静态资源生成 SEE 平台发布物。通常在 package.json 的 scripts.see
里设置。
提示
该命令只会以构建后输出目录下现有的静态资源做包,不会执行源码编译。
默认读取 .winrc.ts
配置中的 seeOptions 属性,该属性配置具体可以参考配置 seeOptions。
{
"scripts": { "see": "win see" }
}
verify-commit
验证 commit message 信息,通常和 husky 搭配使用。
比如在 .husky/commit-msg
做如下配置,
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install win verify-commit $1
version
查看 win
版本,等同于 win -v
。
$ win version
0.0.3
zip
将指定的目录压缩成 zip 包。通常在 package.json 的 scripts.zip
里设置。
默认读取 .winrc.ts
配置中的 zipOptions 属性,该属性配置具体可以参考配置 zipOptions。
{
"scripts": { "zip": "win zip" }
}
$ win zip
info - Win v0.0.4
Building examplesample-v1001687759573867.zip...
info - Zip successfully! At /Users/liwenbo/Desktop/xxx/winjs/examples/sample/dist-zip/examplesample-v1001687759573867.zip