Continuing on the chain of phonegap_from_scratch, this post goes over buildtool and libraries.
Took an afternoon to look into using buildtool for helping call dart2js on save within the DartEditor. Minor modifications was needed to redirect the generated javascript code to the cordova www
directory in the project. This tool is still in the works and future versions will be more robust.
The trend with dart currently is to use pub
with github or to publish on pub.dartlang.org. A great feature with pub
is if you want to make modifications to an existing project on github, fork+branch
is an easy way to get hacking with modifications to an existing package. buildtool
’s quick hack was added to the pubspec.yaml file as follows.
1 2 3 4 5 6 7 8 9 10 |
|
This pubspec.yaml pulls in the branch diroverride
from a cloned version of buildtool
from my github. Awesome solution for modifications that might not be upstreamed and needed quickly for testing.
Moving along, the DartEditor will look for a build.dart
file in the root directory of a projects folder. When that file is found it will execute on file changes within the project. buildtool
currently provides a client/server architecture for building or transforming dart projects. The particular task I was interested in is Dart2JSTask
which calls the dart2js compiler on modified dart files. With my modifications it now outputs the generated javascript code into the directory specified in the Dart2JSTask.withOutDir
constructor.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The way that I’ve approached running the server side of the buildtool
was to launch a ./build.dart --server
process before opening the project in the DartEditor.
1 2 3 4 5 6 7 |
|
On each save in the project the server side will generate javascript code via Dart2JSTask
.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
This solution saves me having to run the ./build.sh
from command line and launching the iOS simulator on each launch.
The other changes to this project was to refactor the single app.dart
into a collection of dart library files. Seems that each of the API categories have been implemented as singletons. At some point I may make this similar to gap where each category of API is a singleton and instantiated at the top level of a dart library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
New classes added Connection
, CordovaEvents
, Notification
, Splashscreen
and Globalization
. Globalization
is presenting a problem with knowing the proper ways to parse date strings within the javascript implementation dependent scenarios. For now I might just skip them, different javascript engines parse Date
strings different ways and my goal was not to cover all of them. app.dart
is now importing the libraries directly at some point a single lib/cordova.dart
library should be provided.
This is where my journey for tonight has ended, Contacts
might be the next exciting class of API to cover.
The code for phonegap_from_scratch can be found on github