Leave a version tag when creating project (#12846)

* Leave a version tag when creating project

* Generalize .version to .metadata
This commit is contained in:
xster 2017-11-03 10:07:57 -07:00 committed by GitHub
parent b865b0eb2f
commit c17099f474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import '../ios/xcodeproj.dart';
import '../plugins.dart';
import '../runner/flutter_command.dart';
import '../template.dart';
import '../version.dart';
class CreateCommand extends FlutterCommand {
CreateCommand() {
@ -298,6 +299,8 @@ To edit platform code in an IDE see https://flutter.io/platform-plugins/#edit-co
'withPluginHook': withPluginHook,
'androidLanguage': androidLanguage,
'iosLanguage': iosLanguage,
'flutterRevision': FlutterVersion.instance.frameworkRevision,
'flutterChannel': FlutterVersion.instance.channel,
};
}

View File

@ -0,0 +1,8 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: {{flutterRevision}}
channel: {{flutterChannel}}

View File

@ -12,15 +12,21 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import '../src/common.dart';
import '../src/context.dart';
const String frameworkRevision = '12345678';
const String frameworkChannel = 'omega';
void main() {
group('create', () {
Directory temp;
Directory projectDir;
FlutterVersion mockFlutterVersion;
setUpAll(() {
Cache.disableLocking();
@ -29,6 +35,7 @@ void main() {
setUp(() {
temp = fs.systemTempDirectory.createTempSync('flutter_tools');
projectDir = temp.childDirectory('flutter_project');
mockFlutterVersion = new MockFlutterVersion();
});
tearDown(() {
@ -171,6 +178,8 @@ void main() {
// Verify content and formatting
testUsingContext('content', () async {
Cache.flutterRoot = '../..';
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
final CreateCommand command = new CreateCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command);
@ -229,6 +238,16 @@ void main() {
final File xcodeProjectFile = fs.file(fs.path.join(projectDir.path, xcodeProjectPath));
final String xcodeProject = xcodeProjectFile.readAsStringSync();
expect(xcodeProject, contains('PRODUCT_BUNDLE_IDENTIFIER = com.foo.bar.flutterProject'));
final String versionPath = fs.path.join('.metadata');
expectExists(versionPath);
final String version = fs.file(fs.path.join(projectDir.path, versionPath)).readAsStringSync();
expect(version, contains('version:'));
expect(version, contains('revision: 12345678'));
expect(version, contains('channel: omega'));
},
overrides: <Type, Generator>{
FlutterVersion: () => mockFlutterVersion,
});
// Verify that we can regenerate over an existing project.
@ -334,3 +353,5 @@ Future<Null> _analyzeProject(String workingDir, {String target}) async {
}
expect(exec.exitCode, 0);
}
class MockFlutterVersion extends Mock implements FlutterVersion {}