写了一个代码生成的Dart包,根据官方文档进行发布。
package已经写好了routes_generator是一个路由生成的现在需要发布。
检查
发布之前需要检查,运行以下命令进行检查
$ pub publish --dry-run
Publishing routes_generator 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- LICENSE
|-- README.md
|-- build.yaml
|-- lib
| '-- routes_generator.dart
'-- pubspec.yaml
Package validation found the following potential issues:
* Your pubspec.yaml includes an "author" section which is no longer used and may be removed.
* Please add a`CHANGELOG.md` to your package. See https://dart.dev/tools/pub/publishing#important-files.
按照提示修正对应的问题知道显示以下信息
$ pub publish --dry-run
Publishing routes_generator 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- build.yaml
|-- lib
| '-- routes_generator.dart
'-- pubspec.yaml
Package has 0 warnings.
发布
检查没有问题就可以正式发布了
$ Publishing routes_generator 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- build.yaml
|-- lib
| '-- routes_generator.dart
'-- pubspec.yaml
Uploads to pub.dev are subject to https://pub.dev/policy
Do you want to publish routes_generator 0.0.1 (y/N)? y
Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A61334&code_challenge=rCRJ6nfSujdbQBiNDVR8NSRS4pnrDXwSkUNFuxVqdM8&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".
会出现以下提示
Do you want to publish routes_generator 0.0.1 (y/N)? y
输入y之后继续,会出现以下链接
Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?....
Then click "Allow access".
Waiting for your authorization...
在浏览器中打开控制台的中链接,用Goole账号登录之后进行授权之后浏览器会出现以下提示
Pub Authorized Successfully
The pub client has been successfully authorized. You may now use it to upload packages and perform other tasks.
同时在控制台中会出现
Authorization received, processing...
等待一段时间出现
It looks like accounts.google.com is having some trouble.
Pub will wait for a while before trying to connect again.
是因为发布到国内的镜像仓库https://pub.flutter-io.cn了,最初在开发的时候设置了变量
export PUB_HOSTED_URL=https://pub.flutter-io.cn
可以指定官方的地址,先检查以下
$ pub publish --dry-run --server=https://pub.dartlang.org
Publishing routes_generator 0.0.1 to https://pub.dartlang.org:
|-- .gitignore
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- build.yaml
|-- lib
| '-- routes_generator.dart
'-- pubspec.yaml
等待很长时间没有出现Package has 0 warnings.提示,是因为国内无法访问,可以配置代理
$ export https_proxy=http://127.0.0.1:1087
$ export http_proxy=http://127.0.0.1:1087
再次检查
$ pub publish --dry-run --server=https://pub.dartlang.org
Publishing routes_generator 0.0.1 to https://pub.dartlang.org:
|-- .gitignore
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- build.yaml
|-- lib
| '-- routes_generator.dart
'-- pubspec.yaml
Package has 0 warnings.
确认没有问题就可以进行发布了
$ pub publish --server=https://pub.dartlang.org
....
Waiting for your authorization...
Authorization received, processing...
Successfully authorized.
Uploading... (7.3s)
Successfully uploaded package.
发布成功
本文详细介绍了如何使用Dart的pub工具发布一个包至官方仓库的过程,包括代码检查、问题修正、授权流程及代理配置等关键步骤。
2745

被折叠的 条评论
为什么被折叠?



