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