Skip to content

Instantly share code, notes, and snippets.

@adam-singer
Forked from Gubaer/build.dart
Created March 7, 2013 01:54
Show Gist options
  • Save adam-singer/5104936 to your computer and use it in GitHub Desktop.
Save adam-singer/5104936 to your computer and use it in GitHub Desktop.
/*
* Deployes dart packages.
*
* Takes the dart packages in directory
* /source/dir/packages/...
* which is configured in the configuration files build.json,
* i.e.
* {"packages-dir": "/source/dir(packages"}
*
* and copies them to the directory
* ./packages
* by resolving any symlinks
*/
import "dart:async";
import "dart:io";
import "dart:json" as json;
var _OPTIONS;
readOptions() {
var config = new File("build.json");
if (!config.existsSync()) {
print("fatal: configuration file 'build.json' missing.");
exit(1);
}
_OPTIONS = json.parse(
config.readAsStringSync()
);
}
/// represents a dart package
class Package {
/// the package name, i.e. "meta"
final String name;
/// the absolute path to the local package repository
final String repo;
Package(this.name, this.repo);
}
/// replies a stream of package infos
Stream<Package> packages() {
var controller = new StreamController();
var dir = new Directory(_OPTIONS["packages-dir"]);
dir.list().where((e) => e is Directory).listen((d) {
var name = new Path(d.path).filename;
// resolve symlinks
Process.run("/bin/readlink", ["-f", d.path]).then((result) {
var repo = result.stdout.trim();
controller.sink.add(new Package(name, repo));
});
});
return controller.stream;
}
recreatePackagesDir() {
var packages = new Directory("packages");
if (packages.existsSync()) {
print("'packages': deleting ...");
packages.deleteSync(recursive: true);
}
print("'packages': creating ...");
packages.createSync();
}
deployPackage(package) {
var dir = new Directory("packages/${package.name}");
print("creating package dir '$dir.path' ...");
dir.createSync(recursive:true);
print("copying package: ${package.repo} -> packages/${package.name} ...");
Process.run("cp", ["-R", package.repo, "packages/${package.name}"]).then((result){});
}
main() {
readOptions();
var packages = packages();
recreatePackagesDir();
packages.listen((p) {
deployPackage(p);
});
}
{
"packages-dir": "/loccal/package/source/dir/packages"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment