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 http://gamingjs.com GitHub pages web site, I have two sub-directories: ice and ice-beta. These contain different versions of the ICE Code Editor at http://gamingjs.com/ice/ and http://gamingjs.com/ice-beta/. 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/pub.dartlang.org/browser-0.6.5/lib
    ├── crypto -> /home/chris/.pub-cache/hosted/pub.dartlang.org/crypto-0.6.5/lib
    ├── ice_code_editor -> /home/chris/.pub-cache/hosted/pub.dartlang.org/ice_code_editor-0.0.9/lib
    ├── js -> /home/chris/.pub-cache/hosted/pub.dartlang.org/js-0.0.24/lib
    ├── meta -> /home/chris/.pub-cache/hosted/pub.dartlang.org/meta-0.6.5/lib
    └── unittest -> /home/chris/.pub-cache/hosted/pub.dartlang.org/unittest-0.6.5/lib

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. http://gamingjs.com/ice-beta/). 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 decache.sh 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
index.html
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 decache.sh 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.

    ReplyDelete