Merge pubspec.yaml and flutter.yaml. (#7605)
This commit is contained in:
@@ -20,7 +20,7 @@ import 'globals.dart';
|
||||
class AssetBundle {
|
||||
final Map<String, DevFSContent> entries = <String, DevFSContent>{};
|
||||
|
||||
static const String defaultManifestPath = 'flutter.yaml';
|
||||
static const String defaultManifestPath = 'pubspec.yaml';
|
||||
static const String _kAssetManifestJson = 'AssetManifest.json';
|
||||
static const String _kFontManifestJson = 'FontManifest.json';
|
||||
static const String _kFontSetMaterial = 'material';
|
||||
@@ -31,7 +31,7 @@ class AssetBundle {
|
||||
DateTime _lastBuildTimestamp;
|
||||
|
||||
/// Constructs an [AssetBundle] that gathers the set of assets from the
|
||||
/// flutter.yaml manifest.
|
||||
/// pubspec.yaml manifest.
|
||||
AssetBundle();
|
||||
|
||||
/// Constructs an [AssetBundle] with a fixed set of assets.
|
||||
@@ -77,9 +77,9 @@ class AssetBundle {
|
||||
packagesPath ??= path.absolute(PackageMap.globalPackagesPath);
|
||||
Object manifest;
|
||||
try {
|
||||
manifest = _loadFlutterYamlManifest(manifestPath);
|
||||
manifest = _loadFlutterManifest(manifestPath);
|
||||
} catch (e) {
|
||||
printStatus('Error detected in flutter.yaml:', emphasis: true);
|
||||
printStatus('Error detected in pubspec.yaml:', emphasis: true);
|
||||
printError(e);
|
||||
return 1;
|
||||
}
|
||||
@@ -89,12 +89,12 @@ class AssetBundle {
|
||||
return 0;
|
||||
}
|
||||
if (manifest != null) {
|
||||
int result = await _validateFlutterYamlManifest(manifest);
|
||||
int result = await _validateFlutterManifest(manifest);
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
Map<String, dynamic> manifestDescriptor = manifest;
|
||||
assert(manifestDescriptor != null);
|
||||
manifestDescriptor = manifestDescriptor['flutter'] ?? <String, dynamic>{};
|
||||
String assetBasePath = path.dirname(path.absolute(manifestPath));
|
||||
|
||||
_lastBuildTimestamp = new DateTime.now();
|
||||
@@ -112,6 +112,7 @@ class AssetBundle {
|
||||
return 1;
|
||||
|
||||
final bool usesMaterialDesign = (manifestDescriptor != null) &&
|
||||
manifestDescriptor.containsKey('uses-material-design') &&
|
||||
manifestDescriptor['uses-material-design'];
|
||||
|
||||
for (_Asset asset in assetVariants.keys) {
|
||||
@@ -321,8 +322,8 @@ DevFSContent _createFontManifest(Map<String, dynamic> manifestDescriptor,
|
||||
return new DevFSStringContent(JSON.encode(fonts));
|
||||
}
|
||||
|
||||
/// Given an assetBase location and a flutter.yaml manifest, return a map of
|
||||
/// assets to asset variants.
|
||||
/// Given an assetBase location and a pubspec.yaml Flutter manifest, return a
|
||||
/// map of assets to asset variants.
|
||||
///
|
||||
/// Returns `null` on missing assets.
|
||||
Map<_Asset, List<_Asset>> _parseAssets(
|
||||
@@ -344,7 +345,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
||||
|
||||
if (!baseAsset.assetFileExists) {
|
||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||
printError('Error: unable to locate asset entry in pubspec.yaml: "$asset".');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -389,7 +390,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
||||
if (!baseAsset.assetFileExists) {
|
||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||
printError('Error: unable to locate asset entry in pubspec.yaml: "$asset".');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -427,23 +428,23 @@ _Asset _resolveAsset(
|
||||
return new _Asset(base: assetBase, relativePath: asset);
|
||||
}
|
||||
|
||||
dynamic _loadFlutterYamlManifest(String manifestPath) {
|
||||
dynamic _loadFlutterManifest(String manifestPath) {
|
||||
if (manifestPath == null || !fs.isFileSync(manifestPath))
|
||||
return null;
|
||||
String manifestDescriptor = fs.file(manifestPath).readAsStringSync();
|
||||
return loadYaml(manifestDescriptor);
|
||||
}
|
||||
|
||||
Future<int> _validateFlutterYamlManifest(Object manifest) async {
|
||||
Future<int> _validateFlutterManifest(Object manifest) async {
|
||||
String schemaPath = path.join(path.absolute(Cache.flutterRoot),
|
||||
'packages', 'flutter_tools', 'schema', 'flutter_yaml.json');
|
||||
'packages', 'flutter_tools', 'schema', 'pubspec_yaml.json');
|
||||
Schema schema = await Schema.createSchemaFromUrl('file://$schemaPath');
|
||||
|
||||
Validator validator = new Validator(schema);
|
||||
if (validator.validate(manifest)) {
|
||||
return 0;
|
||||
} else {
|
||||
printStatus('Error detected in flutter.yaml:', emphasis: true);
|
||||
printStatus('Error detected in pubspec.yaml:', emphasis: true);
|
||||
printError(validator.errors.join('\n'));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ const String _kDefaultAndroidManifestPath = 'android/AndroidManifest.xml';
|
||||
const String _kDefaultResourcesPath = 'android/res';
|
||||
const String _kDefaultAssetsPath = 'android/assets';
|
||||
|
||||
const String _kFlutterManifestPath = 'flutter.yaml';
|
||||
const String _kFlutterManifestPath = 'pubspec.yaml';
|
||||
const String _kPackagesStatusPath = '.packages';
|
||||
|
||||
// Alias of the key provided in the Chromium debug keystore
|
||||
|
||||
@@ -19,7 +19,7 @@ import 'zip.dart';
|
||||
|
||||
const String defaultMainPath = 'lib/main.dart';
|
||||
const String defaultAssetBasePath = '.';
|
||||
const String defaultManifestPath = 'flutter.yaml';
|
||||
const String defaultManifestPath = 'pubspec.yaml';
|
||||
String get defaultFlxOutputPath => path.join(getBuildDirectory(), 'app.flx');
|
||||
String get defaultSnapshotPath => path.join(getBuildDirectory(), 'snapshot_blob.bin');
|
||||
String get defaultDepfilePath => path.join(getBuildDirectory(), 'snapshot_blob.bin.d');
|
||||
|
||||
@@ -208,9 +208,28 @@ abstract class FlutterCommand extends Command<Null> {
|
||||
if (!PackageMap.isUsingCustomPackagesPath) {
|
||||
// Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path.
|
||||
if (!fs.isFileSync('pubspec.yaml')) {
|
||||
throw new ToolExit('Error: No pubspec.yaml file found.\n'
|
||||
throw new ToolExit(
|
||||
'Error: No pubspec.yaml file found.\n'
|
||||
'This command should be run from the root of your Flutter project.\n'
|
||||
'Do not run this command from the root of your git clone of Flutter.');
|
||||
'Do not run this command from the root of your git clone of Flutter.'
|
||||
);
|
||||
}
|
||||
if (fs.isFileSync('flutter.yaml')) {
|
||||
throw new ToolExit(
|
||||
'Please merge your flutter.yaml into your pubspec.yaml.\n\n'
|
||||
'We have changed from having separate flutter.yaml and pubspec.yaml\n'
|
||||
'files to having just one pubspec.yaml file. Transitioning is simple:\n'
|
||||
'add a line that just says "flutter:" to your pubspec.yaml file, and\n'
|
||||
'move everything from your current flutter.yaml file into the\n'
|
||||
'pubspec.yaml file, below that line, with everything indented by two\n'
|
||||
'extra spaces compared to how it was in the flutter.yaml file. Then, if\n'
|
||||
'you had a "name:" line, move that to the top of your "pubspec.yaml"\n'
|
||||
'file (you may already have one there), so that there is only one\n'
|
||||
'"name:" line. Finally, delete the flutter.yaml file.\n\n'
|
||||
'For an example of what a new-style pubspec.yaml file might look like,\n'
|
||||
'check out the Flutter Gallery pubspec.yaml:\n'
|
||||
'https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/pubspec.yaml\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import 'dart/package_map.dart';
|
||||
import 'android/android_sdk.dart';
|
||||
import 'globals.dart';
|
||||
|
||||
const String _kFlutterManifestPath = 'flutter.yaml';
|
||||
const String _kFlutterManifestPath = 'pubspec.yaml';
|
||||
const String _kFlutterServicesManifestPath = 'flutter_services.yaml';
|
||||
|
||||
dynamic _loadYamlFile(String path) {
|
||||
@@ -24,7 +24,7 @@ dynamic _loadYamlFile(String path) {
|
||||
return loadYaml(manifestString);
|
||||
}
|
||||
|
||||
/// Loads all services specified in `flutter.yaml`. Parses each service config file,
|
||||
/// Loads all services specified in `pubspec.yaml`. Parses each service config file,
|
||||
/// storing meta data in [services] and the list of jar files in [jars].
|
||||
Future<Null> parseServiceConfigs(
|
||||
List<Map<String, String>> services, { List<File> jars }
|
||||
@@ -40,8 +40,9 @@ Future<Null> parseServiceConfigs(
|
||||
dynamic manifest;
|
||||
try {
|
||||
manifest = _loadYamlFile(_kFlutterManifestPath);
|
||||
manifest = manifest['flutter'];
|
||||
} catch (e) {
|
||||
printStatus('Error detected in flutter.yaml:', emphasis: true);
|
||||
printStatus('Error detected in pubspec.yaml:', emphasis: true);
|
||||
printError(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "flutter.yaml",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"uses-material-design": { "type": "boolean" },
|
||||
"assets": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"services": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"family": { "type": "string" },
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"asset": { "type": "string" },
|
||||
"weight": { "type": "integer" },
|
||||
"style": { "enum": [ "normal", "italic" ] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
packages/flutter_tools/schema/pubspec_yaml.json
Normal file
46
packages/flutter_tools/schema/pubspec_yaml.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "pubspec.yaml",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"flutter": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"uses-material-design": { "type": "boolean" },
|
||||
"assets": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"services": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"family": { "type": "string" },
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"asset": { "type": "string" },
|
||||
"weight": { "enum": [ 100, 200, 300, 400, 500, 600, 700, 800, 900 ] },
|
||||
"style": { "enum": [ "normal", "italic" ] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
name: {{projectName}}
|
||||
uses-material-design: true
|
||||
@@ -1,5 +1,6 @@
|
||||
name: {{projectName}}
|
||||
description: {{description}}
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
@@ -8,3 +9,37 @@ dev_dependencies:
|
||||
flutter_driver:
|
||||
sdk: flutter
|
||||
{{/withDriverTest}}
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://www.dartlang.org/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter.
|
||||
flutter:
|
||||
|
||||
# The following line ensures that the Material Icons font is
|
||||
# included with your application, so that you can use the icons in
|
||||
# the Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section here, in
|
||||
# this "flutter" section, as in:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# To add custom fonts to your application, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
|
||||
Reference in New Issue
Block a user