pub init and pub add

Created on 23 Mar 2018  路  9Comments  路  Source: dart-lang/pub

Would be nice to have something like other package mangers to seamlessly start a new project:

# uses current folder for name
pub init

# adds latest stable releases to dependencies and runs pub get
pub add angular angular_components

# adds latest stable releases to dev_dependencies and runs pub get
pub add --dev build_runner build_web_compilers
not planned

Most helpful comment

Hm, not exactly what I meant, stagehand and pub init will play different roles. pub init will not bootstrap an entire application, it will just create a pubspec.yaml file with name, version and description required fields only no pre-defined dependencies; like any other init in various package managers: dep init, npm init, yarn init, composer init, pod init, opam init and probably more...

pub init
  --name # defaults to current dirname
  --version # defaults to 0.1.0 (semver initial version)
  --description #defaults to 'My awesome Dart application' (or something like that)
pubspec.yaml
name: pub_issues
version: 0.1.0
description: My awesome Dart application

It is a companion for something like pub add:
Which is currently, at least for me, a hassle to always switch to the web-browser (even opening one, if it is not already running) and searching for the deps just to copy-and-past its latest stable version.

All 9 comments

For something like pub init, I think a dedicated app like stagehand is a better place than pub.

In the past I've been skeptical of the idea of things like pub add modifying the user's files, but I've come around to it as a way of encouraging users to default to reasonable version constraints without a lot of extra explanation on the part of package authors.

The main barrier here is making changes without breaking the existing YAML structure of the user's pubspec. I believe @seaneagan did some work there at some point, but I don't know how robust it is. I'd want pub add to be really smooth not just in terms of preserving the existing YAML structure, but in matching the style of other dependencies in the pubspec as much as possible.

@leocavalcante We are moving away from having pub have any knowledge of client types (including templates), and will have other tools - https://github.com/dart-lang/webdev - to bootstrap your web application (the build_* packages, etc).

Hm, not exactly what I meant, stagehand and pub init will play different roles. pub init will not bootstrap an entire application, it will just create a pubspec.yaml file with name, version and description required fields only no pre-defined dependencies; like any other init in various package managers: dep init, npm init, yarn init, composer init, pod init, opam init and probably more...

pub init
  --name # defaults to current dirname
  --version # defaults to 0.1.0 (semver initial version)
  --description #defaults to 'My awesome Dart application' (or something like that)
pubspec.yaml
name: pub_issues
version: 0.1.0
description: My awesome Dart application

It is a companion for something like pub add:
Which is currently, at least for me, a hassle to always switch to the web-browser (even opening one, if it is not already running) and searching for the deps just to copy-and-past its latest stable version.

Many other package managers include init and some sort of add command. Anyone coming from those ecosystems (npm, yarn, lerna, rails, gradle, etc) generally expect commands like these. Adding these commands would go a long way towards making a good initial impression given that the pub CLI is one of the first Dart tools you interact with when trying out the language. This is especially true for an ecosystem that markets itself as "batteries included".

@matanlurey Even if we don't support pub init (which I agree with), I want to keep this open to track pub add.

Just want to add this to the conversation. There are init and install commands here, more or less modeled after those in NPM:

https://github.com/thosakwe/dart_scripts

I feel that pub init as described by @leocavalcante would be a great addition.
I came here to create a feature request and now see that it is also something that other devs want.

I am creating my first dart app and with out thinking I ran pub init to create a pubspec.yaml for my project only to find that command didn't exist. Instead I've had to look at other projects to find a pubspec.yaml to copy. Now that I have done this I find that there is no pub add command to add new dependencies.

This seems very odd to me. I also feel that this goes against what has been advertised as a _batteries included_ language. I am learning about dart and pub. Introducing another tool like stagehand is getting overwhelming.

This is something that should definitely be considered by the team behind dart and pub. I feel the lack of this will hinder adoption. I was all up for trying out dart and learning about it. But now I am a bit put off as the ecosystem feels awkward.

@leocavalcante We are moving away from having pub have any knowledge of client types (including templates), and will have other tools - https://github.com/dart-lang/webdev - to bootstrap your web application (the build_* packages, etc).

A lot of times I just want to run a script to know how the package works. With pub I did copy/paste a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  72Comments

wh120 picture wh120  路  24Comments

Andersmholmgren picture Andersmholmgren  路  45Comments

paulyoung picture paulyoung  路  21Comments

jayoung-lee picture jayoung-lee  路  38Comments