【Phoenix】 Mix 命令
可根据 mix help 查询
mix # Runs the default task (current: "mix run")
mix app.config # Configures all registered apps
mix app.start # Starts all registered apps
mix app.tree # Prints the application tree
mix arc.g # For Arc definition generation code
mix archive # Lists installed archives
mix archive.build # Archives this project into a .ez file
mix archive.install # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean # Deletes generated application files
mix cmd # Executes the given command
mix compile # Compiles source files
mix deps # Lists dependencies and their status
mix deps.clean # Deletes the given dependencies' files
mix deps.compile # Compiles dependencies
mix deps.get # Gets all out of date dependencies
mix deps.tree # Prints the dependency tree
mix deps.unlock # Unlocks the given dependencies
mix deps.update # Updates the given dependencies
mix distillery.gen.appup # Generate appup files for hot upgrades and downgrades
mix distillery.init # initialize a new release configuration
mix distillery.release # Build a release for the current mix application
mix distillery.release.clean # Clean up any release-related files
mix do # Executes the tasks separated by comma
mix docs # Generate documentation for the project
mix ecto # Prints Ecto help information
mix ecto.create # Creates the repository storage
mix ecto.drop # Drops the repository storage
mix ecto.dump # Dumps the repository database structure
mix ecto.gen.migration # Generates a new migration for the repo
mix ecto.gen.repo # Generates a new repository
mix ecto.load # Loads previously dumped database structure
mix ecto.migrate # Runs the repository migrations
mix ecto.migrations # Displays the repository migration status
mix ecto.reset # Alias defined in mix.exs
mix ecto.rollback # Rolls back the repository migrations
mix ecto.setup # Alias defined in mix.exs
mix escript # Lists installed escripts
mix escript.build # Builds an escript for the project
mix escript.install # Installs an escript locally
mix escript.uninstall # Uninstalls escripts
mix ex_oauth2_provider # Prints ExOauth2Provider help information
mix ex_oauth2_provider.gen.migration # Generates ExOauth2Provider migration file
mix ex_oauth2_provider.gen.schemas # Generates ExOauth2Provider schema files
mix ex_oauth2_provider.install # Installs ExOauth2Provider
mix format # Formats the given files/patterns
mix gettext.extract # Extracts translations from source code
mix gettext.merge # Merge template files into translation files
mix guardian.db.gen.migration # Generates Guardian.DB's migration
mix guardian.gen.secret # Generates a secret
mix help # Prints help information for tasks
mix hex # Prints Hex help information
mix hex.audit # Shows retired Hex deps for the current project
mix hex.build # Builds a new package version locally
mix hex.config # Reads, updates or deletes local Hex config
mix hex.docs # Fetches or opens documentation of a package
mix hex.info # Prints Hex information
mix hex.organization # Manages Hex.pm organizations
mix hex.outdated # Shows outdated Hex deps for the current project
mix hex.owner # Manages Hex package ownership
mix hex.package # Fetches or diffs packages
mix hex.publish # Publishes a new package version
mix hex.registry # Manages local Hex registries
mix hex.repo # Manages Hex repositories
mix hex.retire # Retires a package version
mix hex.search # Searches for package names
mix hex.sponsor # Show Hex packages accepting sponsorships
mix hex.user # Manages your Hex user account
mix loadconfig # Loads and persists the given configuration
mix local # Lists local tasks
mix local.hex # Installs Hex locally
mix local.public_keys # Manages public keys
mix local.rebar # Installs Rebar locally
mix new # Creates a new Elixir project
mix nimble_parsec.compile # Compiles a parser and injects its content into the parser file
mix phx # Prints Phoenix help information
mix phx.digest # Digests and compresses static files
mix phx.digest.clean # Removes old versions of static assets.
mix phx.gen.cert # Generates a self-signed certificate for HTTPS testing
mix phx.gen.channel # Generates a Phoenix channel
mix phx.gen.context # Generates a context with functions around an Ecto schema
mix phx.gen.embedded # Generates an embedded Ecto schema file
mix phx.gen.html # Generates controller, views, and context for an HTML resource
mix phx.gen.json # Generates controller, views, and context for a JSON resource
mix phx.gen.live # Generates LiveView, templates, and context for a resource
mix phx.gen.presence # Generates a Presence tracker
mix phx.gen.schema # Generates an Ecto schema and migration file
mix phx.gen.secret # Generates a secret
mix phx.routes # Prints all routes
mix phx.server # Starts applications and their servers
mix profile.cprof # Profiles the given file or expression with cprof
mix profile.eprof # Profiles the given file or expression with eprof
mix profile.fprof # Profiles the given file or expression with fprof
mix release # Assembles a self-contained release
mix release.init # Generates sample files for releases
mix run # Starts and runs the current application
mix test # Alias defined in mix.exs
mix test # Runs a project's tests
mix test.coverage # Build report from exported test coverage
mix xref # Prints cross reference information
iex -S mix # Starts IEx and runs the default task
mix phx.gen.html 命令生成模板
# 其中 name 和 age 是 schema 字段名称,后面跟的是类型
# 下面这样的写法,会生成 controller 和 service 层的,但是我们通常不需要生成 service 层面的结构
mix phx.gen.html Account User users [name:string age:integer]
# 这样就能生成没有 schema 结构的 HTML 控制:
mix phx.gen.html Account User users --no-context
# 但是有时候我们又要把它放在之前生成过的结构下面,方法如下:
# 把 user 放在了之前生成的 Merchant 目录下面,当做是 user 的子目录
mix phx.gen.html Account User users --no-context --web Merchant
# 如果不生成 schema 的话,基本 Account 和 students 是随便填的。
# Account 和 students 随便填,会导致 生成的文件中的名称,不对应。这点需要自己改
# Account 是 会查询到服务中有 Account 的模块
# students 是 表名
# 下面是把 Student 放在 Merchant/User/ 下面的文件名
mix phx.gen.html Account Student students --no-context --web Merchant.User
mix phx.gen.json 生成 json 交互命令
# Account: 依赖的 service 模块名
# User: 依赖的 schema 模块名
# users: 依赖的表名
# --Web: 生成路径:
# **/controllers/api/v1/user_controller.ex
# **/views/api/v1/user_view.ex
mix phx.gen.json Account User users --no-context --no-schema --web Api.V1
mix ecto.gen.migration 版本控制
# migration文件名
# 生成 migration 文件
mix phx.gen.schema
# 生成 schema,默认生成 migration 文件
# Blog.Post:生成的模块名,如果是这样两层的,会生成 blog 文件夹,然后把 post 放在里面
# blog_posts: 表名
# blog_posts 后面的[可选]: 后面是字段名,和类型
mix phx.gen.schema Blog.Post blog_posts title:string views:integer
# 不要生成 migration, 带上参数 --no-migration
mix phx.gen.schema Blog.Post blog_posts --no-migration
mix phx.gen.contenxt
# 生成 处理数据库查询 API 的模块
# Accounts: 文件名,同时也是模块名称,会自动带上根目录的模块名称
# User: schema 的名称
# users: 表名
# users 后面的是字段名[可选]
mix phx.gen.context Accounts User users name:string age:integer
# 有时候我们已经生成了 schema, 就不需要再让它生成 schema 了。用戏码的参数
# 默认生成 context 外,还有单元测试的文件 在 test 里面
mix phx.gen.context Accounts User users --no-schema
其他
- mix ecto.migrate: migrate 数据库结构
- mix ecto.rollback: 回退上一次 migrate
- mix phx.routes: # Prints all routes, 打印所有路由
- mix clean: # Deletes generated application files, 删除生成的 应用文件
- mix phx.server: # Starts applications and their servers, 启动应用和它的服务
- mix deps.get: # Gets all out of date dependencies, 获取所有过期依赖项
- iex -S mix: # Starts IEx and runs the default task, 启动IEx并运行默认任务
# Ps: mix help: 显示所有 mix 命令
mix help 命令: 查看命令的详细帮助,比如 mix help phx.gen.html
命令与它们默认生成的文件
mix phx.digest # Digests and compresses static files
mix phx.digest.clean # Removes old versions of static assets.
mix phx.gen.cert # Generates a self-signed certificate for HTTPS testing
mix phx.gen.channel # Generates a Phoenix channel
mix phx.gen.context # Generates a context with functions around an Ecto schema
mix phx.gen.embedded # Generates an embedded Ecto schema file
mix phx.gen.html # Generates controller, views, and context for an HTML resource
mix phx.gen.json # Generates controller, views, and context for a JSON resource
mix phx.gen.presence # Generates a Presence tracker
mix phx.gen.schema # Generates an Ecto schema and migration file
mix phx.gen.secret # Generates a secret
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律