Skip to content

Commit 91bcc60

Browse files
committed
Upgrade to Dart 2.0
1 parent 7f70813 commit 91bcc60

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Files and directories created by pub
2+
.dart_tool
23
.packages
34
.pub/
45
build/

bin/dscript.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ main(List<String> arguments) async {
77
exit(0);
88
}
99

10-
final options = new Args.parse(arguments);
10+
final options = Args.parse(arguments);
1111

12-
final DetectedDartSdk sdk = new DartSdk.detect();
12+
final DetectedDartSdk sdk = DartSdk.detect();
1313

1414
if (options.verbose) {
1515
stderr.writeln(
@@ -23,7 +23,7 @@ main(List<String> arguments) async {
2323
stderr.writeln(
2424
'dscript: Embedded pubspec not found in script. Providing defualt pubspec');
2525
}
26-
pubspec = new UnmodifiableListView<String>(<String>['name: a_dart_script']);
26+
pubspec = UnmodifiableListView<String>(<String>['name: a_dart_script']);
2727
} else {
2828
if (options.verbose) {
2929
stderr.writeln('dscript: Embedded pubspec found in script');
@@ -55,7 +55,7 @@ main(List<String> arguments) async {
5555
stderr.writeln('dscript: Deleting project');
5656
}
5757
try {
58-
await new Directory(runner.tempProjectDir).delete(recursive: true);
58+
await Directory(runner.tempProjectDir).delete(recursive: true);
5959
} finally {}
6060
}
6161

lib/src/args.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,37 @@ class Args {
3838
bool verbose = false;
3939
bool deleteProject = true;
4040
String script;
41-
UnmodifiableListView<String> args = new UnmodifiableListView<String>([]);
41+
UnmodifiableListView<String> args = UnmodifiableListView<String>([]);
4242

4343
for (int i = 0; i < arguments.length; i++) {
4444
final String argument = arguments[i];
4545

4646
if (argument.startsWith('-')) {
4747
if (argument == '-v' || argument == '--verbose') {
4848
if (isRedundant.containsKey('-v'))
49-
throw new DuplicateOptionsException('--verbose');
49+
throw DuplicateOptionsException('--verbose');
5050
verbose = true;
5151
isRedundant['-v'] = true;
5252
} else if (argument == '-k' || argument == '--keep-project') {
5353
if (isRedundant.containsKey('-k'))
54-
throw new DuplicateOptionsException('--keep-project');
54+
throw DuplicateOptionsException('--keep-project');
5555
deleteProject = false;
5656
isRedundant['-k'] = true;
5757
} else {
58-
throw new UnknownOption(argument);
58+
throw UnknownOption(argument);
5959
}
6060
continue;
6161
}
6262

6363
script = argument;
6464
if (i != (arguments.length - 1)) {
65-
args = new UnmodifiableListView<String>(arguments.sublist(i + 1));
65+
args = UnmodifiableListView<String>(arguments.sublist(i + 1));
6666
}
6767
break;
6868
}
6969

70-
if (script == null) throw new Exception('Script not provided!');
70+
if (script == null) throw Exception('Script not provided!');
7171

72-
return new Args(script, args,
73-
verbose: verbose, deleteProject: deleteProject);
72+
return Args(script, args, verbose: verbose, deleteProject: deleteProject);
7473
}
7574
}

lib/src/dart_sdk.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:path/path.dart' as p;
44
import 'dart:convert';
55

66
abstract class DartSdk {
7-
factory DartSdk.detect() => new DetectedDartSdk.detect();
7+
factory DartSdk.detect() => DetectedDartSdk.detect();
88

99
FutureOr<PubGetResult> pubGet({String workingDir});
1010

@@ -28,11 +28,11 @@ class DetectedDartSdk implements DartSdk {
2828

2929
if (!executable.contains(s)) {
3030
if (Platform.isLinux) {
31-
executable = new Link("/proc/$pid/exe").resolveSymbolicLinksSync();
31+
executable = Link("/proc/$pid/exe").resolveSymbolicLinksSync();
3232
}
3333
}
3434

35-
final file = new File(executable);
35+
final file = File(executable);
3636
if (!file.existsSync()) {
3737
throw dartSdkNotFound;
3838
}
@@ -42,11 +42,11 @@ class DetectedDartSdk implements DartSdk {
4242

4343
final String sdkPath = parent.path;
4444
final String dartApi = "$sdkPath${s}include${s}dart_api.h";
45-
if (!new File(dartApi).existsSync()) {
46-
throw new Exception('Cannot find Dart SDK!');
45+
if (!File(dartApi).existsSync()) {
46+
throw Exception('Cannot find Dart SDK!');
4747
}
4848

49-
return new DetectedDartSdk(sdkPath);
49+
return DetectedDartSdk(sdkPath);
5050
}
5151

5252
String get dartPath => p.join(sdkPath, 'bin', 'dart');
@@ -61,17 +61,17 @@ class DetectedDartSdk implements DartSdk {
6161
final ProcessResult res =
6262
await pub(<String>['get'], workingDir: workingDir);
6363
if (res.exitCode == 0) {
64-
return new PubGetResult(res.stdout);
64+
return PubGetResult(res.stdout);
6565
} else {
66-
throw new PubGetException(res.exitCode, res.stdout, res.stderr);
66+
throw PubGetException(res.exitCode, res.stdout, res.stderr);
6767
}
6868
}
6969

7070
Future<String> get versionString async {
7171
final ProcessResult res =
7272
await Process.run(dartPath, <String>['--version']);
7373
if (res.exitCode != 0) {
74-
throw new Exception('Failed!');
74+
throw Exception('Failed!');
7575
}
7676
return res.stderr;
7777
}
@@ -84,7 +84,7 @@ class DetectedDartSdk implements DartSdk {
8484
}
8585
}
8686

87-
final Exception dartSdkNotFound = new Exception('Dart SDK not found!');
87+
final Exception dartSdkNotFound = Exception('Dart SDK not found!');
8888

8989
class DepInfo {
9090
final String name;
@@ -99,20 +99,20 @@ class PubGetResult {
9999

100100
PubGetResult(this.outlog);
101101

102-
List<DepInfo> get added => new LineSplitter()
102+
List<DepInfo> get added => LineSplitter()
103103
.convert(outlog)
104104
.where((String line) => line.startsWith('+ '))
105105
.map((String line) => line.split(' '))
106106
.where((List<String> parts) => parts.length == 3)
107-
.map((List<String> parts) => new DepInfo(parts[1], parts[2]))
107+
.map((List<String> parts) => DepInfo(parts[1], parts[2]))
108108
.toList();
109109

110-
List<DepInfo> get removed => new LineSplitter()
110+
List<DepInfo> get removed => LineSplitter()
111111
.convert(outlog)
112112
.where((String line) => line.startsWith('- '))
113113
.map((String line) => line.split(' '))
114114
.where((List<String> parts) => parts.length == 3)
115-
.map((List<String> parts) => new DepInfo(parts[1], parts[2]))
115+
.map((List<String> parts) => DepInfo(parts[1], parts[2]))
116116
.toList();
117117
}
118118

lib/src/project_creator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ProjectCreator {
2424

2525
/// If directory named [projectDir] does not exist, create it.
2626
Future createProjectDir() async {
27-
final directory = new Directory(projectDir);
27+
final directory = Directory(projectDir);
2828

2929
if (await directory.exists()) {
3030
return;
@@ -34,20 +34,20 @@ class ProjectCreator {
3434
}
3535

3636
Future createLibDir() async {
37-
final directory = new Directory("lib");
37+
final directory = Directory("lib");
3838

3939
if (!await directory.exists()) {
4040
return;
4141
}
4242

4343
final String libDirPath = p.join(projectDir, 'lib');
44-
final link = new Link(libDirPath);
44+
final link = Link(libDirPath);
4545
await link.create(directory.absolute.path);
4646
}
4747

4848
Future createPubspec() async {
4949
final String filePath = p.join(projectDir, "pubspec.yaml");
50-
final file = new File(filePath);
50+
final file = File(filePath);
5151
await file.writeAsString(pubspec.join('\n'));
5252
}
5353
}

lib/src/runner.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class ScriptRunner {
2222
{this.workingDir, this.tempProjectDir});
2323

2424
Future createProject() async {
25-
final creator = new ProjectCreator(tempProjectDir, pubspec);
25+
final creator = ProjectCreator(tempProjectDir, pubspec);
2626
await creator.exec();
2727

28-
final project = new Project(tempProjectDir);
28+
final project = Project(tempProjectDir);
2929
await project.pubGet(withSdk: sdk);
3030
}
3131

@@ -69,7 +69,7 @@ class ScriptRunner {
6969
workingDir ??= Directory.current.path;
7070
tempProjectDir ??= Directory.systemTemp.createTempSync().path;
7171

72-
return new ScriptRunner._(options, sdk, pubspec,
72+
return ScriptRunner._(options, sdk, pubspec,
7373
workingDir: workingDir, tempProjectDir: tempProjectDir);
7474
}
7575
}

lib/src/script_parser.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ enum _State {
1313
/// Extracts pubspec embedded in dscript
1414
Future<UnmodifiableListView<String>> extractPubspec(
1515
String scriptFilename) async {
16-
final file = new File(scriptFilename);
16+
final file = File(scriptFilename);
1717

1818
if (!file.existsSync()) {
19-
throw new Exception('Script file $scriptFilename not found!');
19+
throw Exception('Script file $scriptFilename not found!');
2020
}
2121

2222
// Read script file as lines
23-
final Stream<String> lines = await file
24-
.openRead()
25-
.transform(UTF8.decoder)
26-
.transform(new LineSplitter());
23+
final Stream<String> lines =
24+
await file.openRead().transform(utf8.decoder).transform(LineSplitter());
2725

2826
List<String> pubspec;
2927
_State state = _State.notFound;
@@ -67,5 +65,5 @@ Future<UnmodifiableListView<String>> extractPubspec(
6765

6866
if (pubspec == null) return null;
6967

70-
return new UnmodifiableListView<String>(pubspec);
68+
return UnmodifiableListView<String>(pubspec);
7169
}

pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: dscript
22
description: Execute standalone Dart shell scripts
3-
version: 1.0.3
3+
version: 2.0.0
44
homepage: https://github.com/tejainece/dscript
55
author: Ravi Teja Gudapati <[email protected]>
66

77
environment:
8-
sdk: '>=1.20.1 <2.0.0'
8+
sdk: '>=2.0.0 <3.0.0'
99

1010
executables:
1111
dscript:
1212

1313
dependencies:
14-
path: ^1.5.1
14+
path: ^1.6.2
1515

1616
dev_dependencies:
17-
test: ^0.12.0
17+
test: ^1.5.0

0 commit comments

Comments
 (0)