Last active
December 16, 2015 20:39
-
-
Save damondouglas/5493601 to your computer and use it in GitHub Desktop.
Chained webui compiler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
I just tried to dump this into a project and it silently fails. Could you upload a full example on github??
$ 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
actually, ignore my comment, my fork was old and I ran the wrong task.
Thank you for giving it a go. I will convert this to a library with a full example.
You might want to tweak this sample to use:
addChainedTask('analyze_all', ['analyze_libs', 'analyze_test_libs']);
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
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 asdart tool/hop_runner.dart
.