Skip to content

Commit 069f792

Browse files
Merge pull request #275 from Workiva/v2_prep
AF-2759 V2 Prep: deprecate docs, examples, saucelabs; add dart1-only and dart2-only
2 parents 9321335 + 5570d05 commit 069f792

File tree

16 files changed

+355
-19
lines changed

16 files changed

+355
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ test_reports/
2323
/test_fixtures/coverage/functional_test/test/functional/simple_test.dart.temp.html
2424
/test_fixtures/coverage/non_test_file/coverage/
2525
/test_fixtures/coverage/vm/coverage/
26+
/test_fixtures/dart_x_only/doc/api/
2627
/test_fixtures/docs/docs/doc/api/
2728
/test_fixtures/format/changes_needed_temp/

README.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
1010
---
1111

12-
#### Looking for the 2.0.0 Alpha?
13-
14-
https://github.com/Workiva/dart_dev/blob/2.0.0-alpha/README.md
15-
16-
---
17-
1812
- [**Motivation**](#motivation)
1913
- [**Supported Tasks**](#supported-tasks)
2014
- [**Getting Started**](#getting-started)
@@ -91,8 +85,8 @@ local tasks.
9185
- **Coverage:** collects coverage over test suites (unit, integration, and functional) and generates a report. Uses the [`coverage` package](https://github.com/dart-lang/coverage).
9286
- **Code Formatting:** runs the [`dartfmt` tool from the `dart_style` package](https://github.com/dart-lang/dart_style) over source code.
9387
- **Static Analysis:** runs the [`dartanalyzer`](https://www.dartlang.org/tools/analyzer/) over source code.
94-
- **Documentation Generation:** runs the tool from [the `dartdoc` package](https://github.com/dart-lang/dartdoc) to generate docs.
95-
- **Serving Examples:** uses [`pub serve`](https://www.dartlang.org/tools/pub/cmd/pub-serve.html) to serve the project examples.
88+
- (DEPRECATED) **Documentation Generation:** runs the tool from [the `dartdoc` package](https://github.com/dart-lang/dartdoc) to generate docs.
89+
- (DEPRECATED) **Serving Examples:** uses [`pub serve`](https://www.dartlang.org/tools/pub/cmd/pub-serve.html) to serve the project examples.
9690
- **Applying a License to Source Files:** copies a LICENSE file to all applicable files.
9791
- **Generate a test runner file:** that allows for faster test execution.
9892
- **Running dart unit tests on Sauce Labs:** compiles dart unit tests that can be run in the browser and executes them on various platforms using Sauce Labs.
@@ -247,23 +241,23 @@ running any of the following tasks:
247241
ddev analyze
248242
ddev copy-license
249243
ddev coverage
250-
ddev docs
251-
ddev examples
244+
ddev docs # (DEPRECATED)
245+
ddev examples # (DEPRECATED)
252246
ddev format
253247
ddev gen-test-runner
254-
ddev saucelabs
248+
ddev saucelabs # (DEPRECATED)
255249
ddev task-runner
256250
ddev test
257251
258252
# without the alias
259253
pub run dart_dev analyze
260254
pub run dart_dev copy-license
261255
pub run dart_dev coverage
262-
pub run dart_dev docs
263-
pub run dart_dev examples
256+
pub run dart_dev docs # (DEPRECATED)
257+
pub run dart_dev examples # (DEPRECATED)
264258
pub run dart_dev format
265259
pub run dart_dev gen-test-runner
266-
pub run dart_dev saucelabs
260+
pub run dart_dev saucelabs # (DEPRECATED)
267261
pub run dart_dev task-runner
268262
pub run dart_dev test
269263
```
@@ -272,6 +266,33 @@ Add the `-h` flag to any of the above commands to receive additional help
272266
information specific to that task.
273267

274268

269+
#### Convenience Tasks for Targeting Dart1 and/or Dart2
270+
271+
To help with the transition from Dart1 to Dart2, you can leverage the `dart1-only`
272+
and `dart2-only` tasks to conditionally run another dart_dev task or any executable.
273+
274+
```bash
275+
# Run a dart_dev task only on Dart1:
276+
$ ddev dart1-only test
277+
278+
# Run a dart_dev task with additional args only on Dart1:
279+
$ ddev dart1-only -- format --check
280+
281+
# Run an shell script only on Dart1:
282+
$ ddev dart1-only ./example.sh
283+
284+
# Run an executable with additional args only on Dart1:
285+
$ ddev dart1-only -- pub serve web --port 8080
286+
287+
# The `dart2-only` task works exactly the same, but only runs on Dart2:
288+
$ ddev dart2-only test
289+
$ ddev dart2-only -- format --check
290+
$ ddev dart2-only ./example.sh
291+
$ ddev dart2-only -- pub run build_runner serve web:8080
292+
```
293+
294+
295+
275296
## Project Configuration
276297
Project configuration occurs in the `tool/dev.dart` file where the `config`
277298
instance is imported from the `dart_dev` package. The bare minimum for this file

lib/api.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ library dart_dev.api;
1616

1717
export 'package:dart_dev/src/tasks/analyze/api.dart' show AnalyzeTask, analyze;
1818
export 'package:dart_dev/src/tasks/examples/api.dart'
19-
show ExamplesTask, serveExamples;
19+
show
20+
// ignore: deprecated_member_use
21+
ExamplesTask,
22+
// ignore: deprecated_member_use
23+
serveExamples;
2024
export 'package:dart_dev/src/tasks/format/api.dart'
2125
show FilesToFormat, FormatTask, format, getFilesToFormat;
2226
export 'package:dart_dev/src/tasks/init/api.dart' show InitTask, init;

lib/src/dart_dev_cli.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'package:dart_dev/src/tasks/analyze/cli.dart';
2727
import 'package:dart_dev/src/tasks/bash_completion/cli.dart';
2828
import 'package:dart_dev/src/tasks/copy_license/cli.dart';
2929
import 'package:dart_dev/src/tasks/coverage/cli.dart';
30+
import 'package:dart_dev/src/tasks/dart_x_only/cli.dart';
3031
import 'package:dart_dev/src/tasks/docs/cli.dart';
3132
import 'package:dart_dev/src/tasks/examples/cli.dart';
3233
import 'package:dart_dev/src/tasks/export_config/cli.dart';
@@ -59,12 +60,15 @@ dev(List<String> args) async {
5960
registerTask(new BashCompletionCli(), config.bashCompletion);
6061
registerTask(new CopyLicenseCli(), config.copyLicense);
6162
registerTask(new CoverageCli(), config.coverage);
63+
// ignore: deprecated_member_use
6264
registerTask(new DocsCli(), config.docs);
65+
// ignore: deprecated_member_use
6366
registerTask(new ExamplesCli(), config.examples);
6467
registerTask(new ExportConfigCli(), new TaskConfig());
6568
registerTask(new FormatCli(), config.format);
6669
registerTask(new GenTestRunnerCli(), config.genTestRunner);
6770
registerTask(new InitCli(), config.init);
71+
// ignore: deprecated_member_use
6872
registerTask(new SauceRunnerCli(), config.saucelabs);
6973
registerTask(new TaskRunnerCli(), config.taskRunner);
7074
registerTask(new TestCli(), config.test);
@@ -80,6 +84,12 @@ dev(List<String> args) async {
8084
exit(exitCode);
8185
}
8286

87+
// Register these tasks after the rest of the tasks have been registered
88+
// because they depend on the list of other available dart_dev tasks.
89+
final availableTasks = _cliTasks.keys.toSet();
90+
registerTask(new Dart1OnlyCli(availableTasks), config.dart1Only);
91+
registerTask(new Dart2OnlyCli(availableTasks), config.dart2Only);
92+
8393
await _run(args);
8494
exit(exitCode);
8595
}

lib/src/tasks/config.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:dart_dev/src/tasks/analyze/config.dart';
1818
import 'package:dart_dev/src/tasks/bash_completion/config.dart';
1919
import 'package:dart_dev/src/tasks/copy_license/config.dart';
2020
import 'package:dart_dev/src/tasks/coverage/config.dart';
21+
import 'package:dart_dev/src/tasks/dart_x_only/config.dart';
2122
import 'package:dart_dev/src/tasks/docs/config.dart';
2223
import 'package:dart_dev/src/tasks/examples/config.dart';
2324
import 'package:dart_dev/src/tasks/format/config.dart';
@@ -35,13 +36,32 @@ class Config {
3536
BashCompletionConfig bashCompletion = new BashCompletionConfig();
3637
CopyLicenseConfig copyLicense = new CopyLicenseConfig();
3738
CoverageConfig coverage = new CoverageConfig();
39+
Dart1OnlyConfig dart1Only = new Dart1OnlyConfig();
40+
Dart2OnlyConfig dart2Only = new Dart2OnlyConfig();
41+
42+
/// Deprecated: 1.10.0
43+
/// To be removed: 2.0.0
44+
/// Use the `dartdoc` executable instead.
45+
@deprecated
3846
DocsConfig docs = new DocsConfig();
47+
48+
/// Deprecated 1.10.0
49+
/// To be removed: 2.0.0
50+
/// Use `pub serve example` or `pub run build_runner serve example:8080`
51+
/// instead.
52+
@deprecated
3953
ExamplesConfig examples = new ExamplesConfig();
54+
4055
LocalConfig local = new LocalConfig();
4156
FormatConfig format = new FormatConfig();
4257
GenTestRunnerConfig genTestRunner = new GenTestRunnerConfig();
4358
InitConfig init = new InitConfig();
59+
60+
/// Deprecated 1.10.0
61+
/// To be removed: 2.0.0
62+
@deprecated
4463
SaucelabsConfig saucelabs = new SaucelabsConfig();
64+
4565
TaskRunnerConfig taskRunner = new TaskRunnerConfig();
4666
TestConfig test = new TestConfig();
4767

@@ -50,12 +70,15 @@ class Config {
5070
'bashCompletion': bashCompletion,
5171
'copyLicense': copyLicense,
5272
'coverage': coverage,
73+
// ignore: deprecated_member_use
5374
'docs': docs,
75+
// ignore: deprecated_member_use
5476
'examples': examples,
5577
'local': local,
5678
'format': format,
5779
'genTestRunner': genTestRunner,
5880
'init': init,
81+
// ignore: deprecated_member_use
5982
'saucelabs': saucelabs,
6083
'taskRunner': taskRunner,
6184
'test': test,

lib/src/tasks/dart_x_only/cli.dart

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2015 Workiva Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
library dart_dev.src.tasks.dart1_only.cli;
16+
17+
import 'dart:async';
18+
19+
import 'package:args/args.dart';
20+
21+
import 'package:dart_dev/util.dart' show TaskProcess, reporter;
22+
23+
import 'package:dart_dev/src/tasks/cli.dart';
24+
import 'package:dart_dev/src/util.dart';
25+
26+
class Dart1OnlyCli extends DartXOnlyCli {
27+
@override
28+
final String command = 'dart1-only';
29+
30+
Dart1OnlyCli(Iterable<String> availableTasks) : super(availableTasks);
31+
32+
@override
33+
bool get shouldRun => dartMajorVersion == 1;
34+
}
35+
36+
class Dart2OnlyCli extends DartXOnlyCli {
37+
@override
38+
final String command = 'dart2-only';
39+
40+
Dart2OnlyCli(Iterable<String> availableTasks) : super(availableTasks);
41+
42+
@override
43+
bool get shouldRun => dartMajorVersion == 2;
44+
}
45+
46+
abstract class DartXOnlyCli extends TaskCli {
47+
@override
48+
final ArgParser argParser = new ArgParser();
49+
50+
final Iterable<String> _availableTasks;
51+
52+
bool get shouldRun;
53+
54+
@override
55+
String get usage => '${super.usage} <task or executable> [args]';
56+
57+
DartXOnlyCli(Iterable<String> availableTasks)
58+
: _availableTasks = availableTasks;
59+
60+
@override
61+
Future<CliResult> run(ArgResults parsedArgs, {bool color: true}) async {
62+
if (parsedArgs.rest.isEmpty) {
63+
return new CliResult.fail('A task or executable is required.');
64+
}
65+
66+
if (!shouldRun) {
67+
return new CliResult.success('Skipped (Dart $dartMajorVersion)');
68+
}
69+
70+
final target = parsedArgs.rest.first;
71+
final targetArgs = parsedArgs.rest.sublist(1);
72+
73+
String executable;
74+
List<String> args;
75+
if (_availableTasks.contains(target)) {
76+
executable = 'pub';
77+
args = <String>['run', 'dart_dev', target]..addAll(targetArgs);
78+
} else {
79+
executable = target;
80+
args = targetArgs;
81+
}
82+
83+
final process = new TaskProcess(executable, args);
84+
reporter.logGroup('$executable ${args.join(' ')}',
85+
outputStream: process.stdout, errorStream: process.stderr);
86+
await process.done;
87+
return await process.exitCode == 0
88+
? new CliResult.success()
89+
: new CliResult.fail();
90+
}
91+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 Workiva Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
library dart_dev.src.tasks.dart_x_only.config;
16+
17+
import 'package:dart_dev/src/tasks/config.dart';
18+
19+
class Dart1OnlyConfig extends TaskConfig {}
20+
21+
class Dart2OnlyConfig extends TaskConfig {}

lib/src/tasks/docs/cli.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ class DocsCli extends TaskCli {
3535

3636
@override
3737
Future<CliResult> run(ArgResults parsedArgs, {bool color: true}) async {
38+
reporter.warning('''
39+
---- DEPRECATION NOTICE ----
40+
The docs task is deprecated and will be removed in dart_dev v2.0.0.
41+
Use `dartdoc` instead.
42+
----------------------------''');
43+
3844
if (!hasImmediateDependency('dartdoc'))
3945
return new CliResult.fail(
4046
'Package "dartdoc" must be an immediate dependency in order to run its executables.');

lib/src/tasks/examples/api.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ bool hasExamples() {
2727
return exampleDir.existsSync();
2828
}
2929

30+
/// Deprecated 1.10.0
31+
/// To be removed: 2.0.0
32+
/// Use `pub serve example` or `pub run build_runner serve example:8080`
33+
/// instead.
34+
@deprecated
3035
ExamplesTask serveExamples(
3136
{String hostname: defaultHostname, int port: defaultPort}) {
3237
if (!hasExamples())
@@ -64,6 +69,10 @@ ExamplesTask serveExamples(
6469
return task;
6570
}
6671

72+
/// Deprecated: 1.10.0
73+
/// To be removed: 2.0.0
74+
/// Use the `dartdoc` executable instead.
75+
@deprecated
6776
class ExamplesTask extends Task {
6877
@override
6978
final Future<Null> done;

lib/src/tasks/examples/cli.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ class ExamplesCli extends TaskCli {
3939

4040
@override
4141
Future<CliResult> run(ArgResults parsedArgs, {bool color: true}) async {
42+
reporter.warning('''
43+
---- DEPRECATION NOTICE ----
44+
The examples task is deprecated and will be removed in dart_dev v2.0.0.
45+
Run `pub serve example` or `pub run build_runner serve example:8080` instead.
46+
----------------------------''');
47+
4248
String hostname =
49+
// ignore: deprecated_member_use
4350
TaskCli.valueOf('hostname', parsedArgs, config.examples.hostname);
51+
// ignore: deprecated_member_use
4452
var port = TaskCli.valueOf('port', parsedArgs, config.examples.port);
4553
if (port is String) {
4654
port = int.parse(port);
@@ -49,6 +57,7 @@ class ExamplesCli extends TaskCli {
4957
if (!hasExamples())
5058
return new CliResult.fail('This project does not have any examples.');
5159

60+
// ignore: deprecated_member_use
5261
ExamplesTask task = serveExamples(hostname: hostname, port: port);
5362
reporter.logGroup(task.pubServeCommand,
5463
outputStream: task.pubServeStdOut, errorStream: task.pubServeStdErr);

0 commit comments

Comments
 (0)