OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library usage.grind; |
| 6 |
| 7 import 'dart:io'; |
| 8 |
| 9 import 'package:grinder/grinder.dart'; |
| 10 |
| 11 final Directory BUILD_DIR = new Directory('build'); |
| 12 final Directory BUILD_TEST_DIR = new Directory('build/test'); |
| 13 |
| 14 void main(List<String> args) { |
| 15 task('init', init); |
| 16 task('build', build, ['init']); |
| 17 task('clean', clean); |
| 18 |
| 19 startGrinder(args); |
| 20 } |
| 21 |
| 22 /// Do any necessary build set up. |
| 23 void init(GrinderContext context) { |
| 24 // Verify we're running in the project root. |
| 25 if (!getDir('lib').existsSync() || !getFile('pubspec.yaml').existsSync()) { |
| 26 context.fail('This script must be run from the project root.'); |
| 27 } |
| 28 |
| 29 BUILD_TEST_DIR.createSync(recursive: true); |
| 30 } |
| 31 |
| 32 void build(GrinderContext context) { |
| 33 // Compile `test/web_test.dart` to the `build/test` dir; measure its size. |
| 34 File srcFile = new File('test/web_test.dart'); |
| 35 Dart2js.compile(context, srcFile, outDir: BUILD_TEST_DIR, minify: true); |
| 36 File outFile = joinFile(BUILD_TEST_DIR, ['web_test.dart.js']); |
| 37 |
| 38 context.log('${outFile.path} compiled to ${_printSize(outFile)}'); |
| 39 } |
| 40 |
| 41 /// Delete all generated artifacts. |
| 42 void clean(GrinderContext context) { |
| 43 // Delete the build/ dir. |
| 44 deleteEntity(BUILD_DIR, context); |
| 45 } |
| 46 |
| 47 String _printSize(File file) => '${(file.lengthSync() + 1023) ~/ 1024}k'; |
OLD | NEW |