Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pub should support build scripts #1674

Closed
thosakwe opened this issue Jul 26, 2017 · 1 comment
Closed

Pub should support build scripts #1674

thosakwe opened this issue Jul 26, 2017 · 1 comment

Comments

@thosakwe
Copy link

This isn't a high-priority issue, or even an issue at all, but a suggestion for feature that I feel would be helpful.

The idea: Just like how NPM supports scripts, i.e. postinstall, prepublish, it would be nice if Pub did as well. This would make it possible to do things such as compiling native extensions after installing them from Pub.

Pubspec Change

IMO, it would be best to just include scripts in the pubspec.yaml file:

name: my_package
scripts:
  greet: echo Hello World
  install: 
    - echo This is a postinstall script!!!
    - pub run-script greet

Command

Pub already has a run command, so it might make more sense to support scripts via something like run-script.

Supported Scripts

I think that Pub would only need to support about three scenarios:

  • install - Runs after a new version of the current package is installed, whether after the initial pub get, or a pub upgrade. Since Pub packages are cached, users wouldn't have to re-run the scripts each time they used a cache version of the package.
  • get - Runs after pub get. This script will only be run when developing the package; not if it is downloaded from Pub or another source.
  • upgrade - Same as get, except for that it would run after pub upgrade. Personally, I don't think it would even be necessary.

How it Works

In my head, the process would be something like the following:

  1. User runs pub get.
  2. For each package with an install script, the script is run. It might make sense to show the user the commands that will run, and allow them to opt out.
  3. If the local package has a get script, it is run as well. There probably won't need to be an opt-out feature here.

It might also be a good idea to include a flag to automatically run all scripts, i.e. --run-all-scripts.

Anyways, hopefully this is considered. I'm more than willing to send in a PR.

@nex3
Copy link
Member

nex3 commented Jul 26, 2017

Duplicate of #1192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants