Skip to content
Snippets Groups Projects
Unverified Commit 31250f97 authored by Kevin Moore's avatar Kevin Moore Committed by GitHub
Browse files

Migrate version logic to pkg:build_version (#579)

parent 39d9a187
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ targets:
- lib/**
- templates/**
builders:
build_version:
enabled: true
stagehand:
generate_for:
- 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.');
}
......
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'cli_app.dart';
// **************************************************************************
// VersionGenerator
// **************************************************************************
const appVersion = '3.1.3-dev';
// Generated code. Do not modify.
const packageVersion = '3.1.3-dev';
......@@ -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
......
......@@ -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');
// 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<String> 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';
''';
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment