Wednesday, July 24, 2013

Getting Started with Dart Pub Deploy for Applications

I was quite pleased with yesterday's simple Bash script to “de-cache” Dart packages for deployment to my simple GitHub pages site. It seemed a nice, concise solution to a problem in need of a bit of automation. I was almost proud. And then Kasper Lund told me about pub deploy.

In my defense, I did know of pub deploy, but after brief examination, had decided it was not likely a good candidate for my use-case. But I did not actually try it to make sure. Tonight I do so.

On the GitHub pages web site, I have two sub-directories: ice and ice-beta. These contain different versions of the ICE Code Editor at and Both of these sub-directories are nearly identical with an index.html page, a main.dart script that starts the application, and a bunch of Dart packages in the packages sub-directory created by the Dart Pub tool:
➜  ice-beta git:(gh-pages) ✗ tree . -P 'index*|*.dart' -l -L 2
├── index.html
├── main.dart
└── packages
    ├── browser -> /home/chris/.pub-cache/hosted/
    ├── crypto -> /home/chris/.pub-cache/hosted/
    ├── ice_code_editor -> /home/chris/.pub-cache/hosted/
    ├── js -> /home/chris/.pub-cache/hosted/
    ├── meta -> /home/chris/.pub-cache/hosted/
    └── unittest -> /home/chris/.pub-cache/hosted/

7 directories, 2 files
There is other stuff in there as well, but that (I think) is the most important bit for tonight. The index.html needs to reside there because it enables GitHub pages to serve up a page when the directory is accessed (e.g. The main.dart is important because it imports the ICE package:
import 'package:ice_code_editor/ice.dart' as ICE;

main()=> new ICE.Full();
Last night's converted the symbolic links in the packages sub-directory into local copies so that they will still work once pushed to GitHub (GitHub pages do not work with symbolic links).

So will pub deploy work with this?

As is, the answer would seem to be “no”:
➜  ice-beta git:(gh-pages) ✗ pub deploy
There is no '/home/chris/repos/gamingjs/ice-beta/web' directory.
This error would seem to refer to the pub layout convention for Dart web applications.

Perhaps if I copy the index.html file into a web sub-directory?
➜  ice-beta git:(gh-pages) ✗ mkdir web
➜  ice-beta git:(gh-pages) ✗ cp index.html web
➜  ice-beta git:(gh-pages) ✗ pub install
Resolving dependencies.........
Dependencies installed!
➜  ice-beta git:(gh-pages) ✗ pub deploy
Finding entrypoints...
Copying   web/ → deploy/
➜  ice-beta git:(gh-pages) ✗ ls deploy
That did not seem to do anything useful. Perhaps if I also place my main.dart entry point in there?
➜  ice-beta git:(gh-pages) ✗ cp main.dart web
➜  ice-beta git:(gh-pages) ✗ pub deploy
Finding entrypoints...
Copying   web/          → deploy/
Compiling web/main.dart → deploy/main.dart.js
➜  ice-beta git:(gh-pages) ✗ ls deploy
index.html  main.dart  main.dart.js
Ah, that is pretty nice. Compiling my application to JavaScript and moving it into the deploy directory is quite useful. But not in my particular use-case.

I need to have the main entry point for ICE directly in the ice sub-directory. I even need this locally so that I can test things out with a local Jekyll server. Placing my index.html application page and the associated main.dart entry point down a level are not going to serve the correct URLs. So I think I have a handle on pub deploy, but I think my custom built will still be of use.

Day #822

1 comment:

  1. One option you could try is to put another entrypoint in web/ that just imports your "real" entrypoint in the "ice" directory and then invokes main() on it. That would let pub deploy find it while still leaving it where you want it.