Skip to content

Instantly share code, notes, and snippets.

@damondouglas
Last active December 16, 2015 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save damondouglas/5493601 to your computer and use it in GitHub Desktop.
Save damondouglas/5493601 to your computer and use it in GitHub Desktop.
Chained webui compiler.
library hop_runner;
import 'dart:async';
import 'dart:io';
import 'package:hop/hop.dart';
import 'package:hop/hop_tasks.dart';
void main() {
final String out = "out";
final String entryPointDir = "web";
final String entryPoint = "webui_chained_hop";
Task dwc = createWebuiCompilerTask("$entryPointDir/$entryPoint.html",output:out);
addTask('webui', dwc);
Task d2js = createDart2JsTask(["$out/$entryPoint.html_bootstrap.dart"], liveTypeAnalysis: true, rejectDeprecatedFeatures: true);
addTask('dart2js', d2js);
addTask('w2d2js',dwc.chain("webui").and("dart2js", d2js));
runHop();
}
Task createWebuiCompilerTask(String entryPoint,{String output:"web/out"}){
final entryPointFile = new File(entryPoint);
final packageDir = new Directory('packages');
assert(packageDir.existsSync());
assert(entryPointFile.existsSync() && entryPoint.endsWith(".html"));
final args = ["--package-root=${packageDir.path}/",
"packages/web_ui/dwc.dart",
"--out",
"$output/",
"$entryPoint"
];
return new Task.async((TaskContext context){
return _dwc(context, output, entryPoint).whenComplete((){
context.info("completed");
});
});
}
Future<bool> _dwc(TaskContext ctx, String output, String entryPoint){
final packageDir = new Directory('packages');
assert(packageDir.existsSync());
final args = ["--package-root=${packageDir.path}/",
"packages/web_ui/dwc.dart",
"--out",
"$output/",
"$entryPoint"
];
return Process.start("dart", args)
.then((process) {
return pipeProcess(process,
stdOutWriter: ctx.info,
stdErrWriter: ctx.severe);
}).then((int exitCode){
return exitCode==1;
});
}
//courtesy https://github.com/kevmoo/hop.dart
String _getPlatformBin(String binName) {
if(Platform.operatingSystem == 'windows') {
return '${binName}.bat';
} else {
return binName;
}
}
@damondouglas
Copy link
Author

Import hop in pubspec.yaml from pub package. However, as of this comment, I had to supply the bleeding edge git repository. People typically put this file in /tool/hop_runner.dart. Run as dart tool/hop_runner.dart.

@adam-singer
Copy link

I just tried to dump this into a project and it silently fails. Could you upload a full example on github??

@adam-singer
Copy link

$ dart tool/hop_runner.dart --log-level all webui
webui: Started at 2013-05-02 14:47:32.330
webui: completed
webui: Finished at 2013-05-02 14:47:33.438
webui: Run time: 0:00:01.108000

@adam-singer
Copy link

actually, ignore my comment, my fork was old and I ran the wrong task.

@damondouglas
Copy link
Author

Thank you for giving it a go. I will convert this to a library with a full example.

@kevmoo
Copy link

kevmoo commented May 4, 2013

You might want to tweak this sample to use:

  addChainedTask('analyze_all', ['analyze_libs', 'analyze_test_libs']);

@damondouglas
Copy link
Author

Thank you, @kevmoo. I'll add that code to the library I created: https://github.com/damondouglas/webui_tasks.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment