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 _buildExampleDir = new Directory('build/example'); | 11 final Directory _buildExampleDir = new Directory('build/example'); |
12 | 12 |
13 main(List<String> args) => grind(args); | 13 main(List<String> args) => grind(args); |
14 | 14 |
15 @Task('Do any necessary build set up') | 15 @Task() |
16 void init() { | 16 void init() => _buildExampleDir.createSync(recursive: true); |
17 // Verify we're running in the project root. | |
18 if (!getDir('lib').existsSync() || !getFile('pubspec.yaml').existsSync()) { | |
19 context.fail('This script must be run from the project root.'); | |
20 } | |
21 | |
22 _buildExampleDir.createSync(recursive: true); | |
23 } | |
24 | 17 |
25 @Task() | 18 @Task() |
26 @Depends(init) | 19 @Depends(init) |
27 void build() { | 20 void build() { |
28 // Compile `test/web_test.dart` to the `build/test` dir; measure its size. | 21 // Compile `test/web_test.dart` to the `build/test` dir; measure its size. |
29 File srcFile = new File('example/example.dart'); | 22 File srcFile = new File('example/example.dart'); |
30 Dart2js.compile(srcFile, outDir: _buildExampleDir, minify: true); | 23 Dart2js.compile(srcFile, |
| 24 outDir: _buildExampleDir, |
| 25 minify: true, |
| 26 extraArgs: ['--conditional-directives']); |
31 File outFile = joinFile(_buildExampleDir, ['example.dart.js']); | 27 File outFile = joinFile(_buildExampleDir, ['example.dart.js']); |
32 | 28 |
33 context.log('${outFile.path} compiled to ${_printSize(outFile)}'); | 29 log('${outFile.path} compiled to ${_printSize(outFile)}'); |
34 } | 30 } |
35 | 31 |
36 @Task('Delete all generated artifacts') | 32 @Task() |
37 void clean() { | 33 void clean() => delete(buildDir); |
38 // Delete the build/ dir. | |
39 delete(buildDir); | |
40 } | |
41 | 34 |
42 String _printSize(File file) => '${(file.lengthSync() + 1023) ~/ 1024}k'; | 35 String _printSize(File file) => '${(file.lengthSync() + 1023) ~/ 1024}k'; |
OLD | NEW |