diff --git a/build.yaml b/build.yaml index 536519e0..5fa3e905 100644 --- a/build.yaml +++ b/build.yaml @@ -8,6 +8,8 @@ targets: - lib/** - templates/** builders: + build_version: + enabled: true stagehand: generate_for: - lib/src/cli_app.dart diff --git a/lib/src/cli_app.dart b/lib/src/cli_app.dart index 500c4328..a79f7ae3 100644 --- a/lib/src/cli_app.dart +++ b/lib/src/cli_app.dart @@ -14,7 +14,7 @@ import 'package:stagehand/src/common.dart'; import 'package:stagehand/stagehand.dart'; import 'package:usage/usage_io.dart'; -part 'cli_app.g.dart'; +import 'version.dart'; const String appName = 'stagehand'; @@ -38,7 +38,7 @@ class CliApp { assert(generators != null); assert(logger != null); - analytics = new AnalyticsIO(_gaTrackingId, appName, appVersion) + analytics = new AnalyticsIO(_gaTrackingId, appName, packageVersion) // These `cdX` values MUST be tightly coordinated with Analytics config // DO NOT modify unless you're certain what you're doing. // Contact kevmoo@ if you have questions @@ -85,10 +85,10 @@ class CliApp { } if (options['version']) { - _out('$appName version: $appVersion'); + _out('$appName version: $packageVersion'); return http.get(appPubInfo).then((response) { List versions = jsonDecode(response.body)['versions']; - if (appVersion != versions.last) { + if (packageVersion != versions.last) { _out('Version ${versions.last} is available! Run `pub global activate' ' $appName` to get the latest.'); } diff --git a/lib/src/cli_app.g.dart b/lib/src/cli_app.g.dart deleted file mode 100644 index a43fd4b1..00000000 --- a/lib/src/cli_app.g.dart +++ /dev/null @@ -1,9 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'cli_app.dart'; - -// ************************************************************************** -// VersionGenerator -// ************************************************************************** - -const appVersion = '3.1.3-dev'; diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 00000000..bc0149e8 --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1,2 @@ +// Generated code. Do not modify. +const packageVersion = '3.1.3-dev'; diff --git a/pubspec.yaml b/pubspec.yaml index afd47e7a..8c903291 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dev_dependencies: build: ^0.12.6 build_config: ^0.3.0 build_runner: ^0.10.0 + build_version: ^1.0.0 glob: ^1.1.5 grinder: ^0.8.0 source_gen: ^0.9.0 diff --git a/tool/builder.dart b/tool/builder.dart index 088b04a8..48320d4a 100644 --- a/tool/builder.dart +++ b/tool/builder.dart @@ -6,9 +6,7 @@ import 'package:source_gen/source_gen.dart'; import 'package:build/build.dart'; import 'src/code_generator.dart'; -import 'src/version_generator.dart'; Builder stagehandBuilder([_]) => new PartBuilder([ - new VersionGenerator(), new DataGenerator(), ], '.g.dart'); diff --git a/tool/src/version_generator.dart b/tool/src/version_generator.dart deleted file mode 100644 index 7dada567..00000000 --- a/tool/src/version_generator.dart +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:async'; - -import 'package:build/build.dart'; -import 'package:source_gen/source_gen.dart'; -import 'package:yaml/yaml.dart'; - -class VersionGenerator extends Generator { - @override - FutureOr generate(LibraryReader library, BuildStep buildStep) async { - if (buildStep.inputId.pathSegments.last != 'cli_app.dart') { - return null; - } - - var content = await buildStep - .readAsString(new AssetId(buildStep.inputId.package, 'pubspec.yaml')); - - var yaml = loadYaml(content) as Map; - - var versionString = yaml['version'] as String; - - return ''' -const appVersion = '$versionString'; -'''; - } -} diff --git a/tool/version-check.sh b/tool/version-check.sh index 34a4607b..c5cd74d7 100755 --- a/tool/version-check.sh +++ b/tool/version-check.sh @@ -15,8 +15,8 @@ VERS_FROM_PUB=$(grep '^version:' pubspec.yaml | awk '{ print $2 }') echo "Version of stagehand from pubspec.yaml: $VERS_FROM_PUB" -VERSION_FILE=lib/src/cli_app.g.dart -if grep -qe "appVersion = '$VERS_FROM_PUB';" $VERSION_FILE; then +VERSION_FILE=lib/src/version.dart +if grep -qe "packageVersion = '$VERS_FROM_PUB';" $VERSION_FILE; then echo "✔ $VERSION_FILE has same version as pubspec." else EXIT_CODE=2