Validate flutter.yaml against a JSON schema
This commit is contained in:
@@ -1,4 +1,2 @@
|
||||
name: stocks
|
||||
version: 0.0.2
|
||||
update-url: http://localhost:9888/
|
||||
uses-material-design: true
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flx/bundle.dart';
|
||||
import 'package:flx/signing.dart';
|
||||
import 'package:json_schema/json_schema.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
@@ -108,6 +109,20 @@ dynamic _loadManifest(String manifestPath) {
|
||||
return loadYaml(manifestDescriptor);
|
||||
}
|
||||
|
||||
Future<int> _validateManifest(Object manifest) async {
|
||||
String schemaPath = path.join(path.absolute(ArtifactStore.flutterRoot),
|
||||
'packages', 'flutter_tools', 'schema', 'flutter_yaml.json');
|
||||
Schema schema = await Schema.createSchemaFromUrl('file://$schemaPath');
|
||||
|
||||
Validator validator = new Validator(schema);
|
||||
if (validator.validate(manifest))
|
||||
return 0;
|
||||
|
||||
printError('Error in flutter.yaml:');
|
||||
printError(validator.errors.join('\n'));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ZipEntry _createAssetEntry(_Asset asset) {
|
||||
String source = asset.source ?? asset.key;
|
||||
File file = new File('${asset.base}/$source');
|
||||
@@ -184,7 +199,14 @@ Future<int> build(
|
||||
String workingDirPath: defaultWorkingDirPath,
|
||||
bool precompiledSnapshot: false
|
||||
}) async {
|
||||
Map<String, dynamic> manifestDescriptor = _loadManifest(manifestPath);
|
||||
Object manifest = _loadManifest(manifestPath);
|
||||
if (manifest != null) {
|
||||
int result = await _validateManifest(manifest);
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
Map<String, dynamic> manifestDescriptor = manifest;
|
||||
|
||||
String assetBasePath = path.dirname(path.absolute(manifestPath));
|
||||
|
||||
File snapshotFile;
|
||||
|
||||
@@ -14,6 +14,7 @@ dependencies:
|
||||
crypto: ^0.9.2
|
||||
den_api: ^0.1.0
|
||||
file: ^0.1.0
|
||||
json_schema: ^1.0.3
|
||||
mustache4dart: ^1.0.0
|
||||
path: ^1.3.0
|
||||
pub_semver: ^1.0.0
|
||||
|
||||
36
packages/flutter_tools/schema/flutter_yaml.json
Normal file
36
packages/flutter_tools/schema/flutter_yaml.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$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" }
|
||||
},
|
||||
"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" ] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user