I created a new Dart app like this:
dart create hello
I can run the app like this:
dart run hello/bin/hello.dart
I try to activate the app like this:
dart pub global activate --source path hello
But I can't run the file like I would expect:
hello
zsh: command not found: hello
The .pub-cache/bin folder is in my cache but pub global activate didn't put it there.
This does work:
dart pub global run hello
Hello world!
But I'd like to be able to run the script without typing dart pub global run every time.
If I do a package from pub.dev it works ok:
dart pub global activate webdev
It puts a webdev executable inside the .pub-cache/bin folder and I can run it.
webdev --version
2.7.4
So is there another step I need to do to make my hello app get into the executable folder?
I also tried compiling it:
dart compile exe hello/bin/hello.dart
And activating it again:
dart pub global activate --source path hello
But there is still no binary in the .pub-cache/bin folder. Any suggestions?
Update
After getting Kevin's answer below, I added the following to pubspec.yaml:
executables:
hello:
Then I ran the following command:
dart pub global activate --source path hello
which gave the following result (username modified):
Resolving dependencies...
Got dependencies!
Package hello is currently active at path "/Users/suragch/Dev/DartProjects/hello".
Installed executable hello.
Activated hello 1.0.0 at path "/Users/suragch/Dev/DartProjects/hello".
But if I run this:
hello
I get the following error:
/Users/suragch/.pub-cache/bin/hello: line 7: pub: command not found
Running this still works, though:
dart pub global run hello
Hello world!