Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
49ba9747
Commit
49ba9747
authored
Sep 26, 2017
by
Sarah Zakarias
Committed by
GitHub
Sep 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out flutter manifest logic (#12237)
parent
a08b5e00
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
617 additions
and
181 deletions
+617
-181
asset.dart
packages/flutter_tools/lib/src/asset.dart
+102
-172
flutter_manifest.dart
packages/flutter_tools/lib/src/flutter_manifest.dart
+170
-0
asset_bundle_package_fonts_test.dart
...s/flutter_tools/test/asset_bundle_package_fonts_test.dart
+9
-9
flutter_manifest_test.dart
packages/flutter_tools/test/flutter_manifest_test.dart
+336
-0
No files found.
packages/flutter_tools/lib/src/asset.dart
View file @
49ba9747
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/flutter_manifest.dart
0 → 100644
View file @
49ba9747
// Copyright 2017 The Chromium Authors. 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:flutter_tools/src/globals.dart'
;
import
'package:json_schema/json_schema.dart'
;
import
'package:yaml/yaml.dart'
;
import
'base/file_system.dart'
;
import
'cache.dart'
;
/// A wrapper around the `flutter` section in the `pubspec.yaml` file.
class
FlutterManifest
{
FlutterManifest
.
_
();
/// Returns null on missing or invalid manifest
static
Future
<
FlutterManifest
>
createFromPath
(
String
path
)
async
{
return
_createFromYaml
(
await
_loadFlutterManifest
(
path
));
}
/// Returns null on missing or invalid manifest
static
Future
<
FlutterManifest
>
createFromString
(
String
manifest
)
async
{
return
_createFromYaml
(
loadYaml
(
manifest
));
}
static
Future
<
FlutterManifest
>
_createFromYaml
(
Object
yamlDocument
)
async
{
final
FlutterManifest
pubspec
=
new
FlutterManifest
.
_
();
if
(
yamlDocument
==
null
||
!
await
_validate
(
yamlDocument
))
return
null
;
pubspec
.
_descriptor
=
yamlDocument
;
pubspec
.
_flutterDescriptor
=
pubspec
.
_descriptor
[
'flutter'
]
??
<
String
,
dynamic
>{};
return
pubspec
;
}
/// A map representation of the entire `pubspec.yaml` file.
Map
<
String
,
dynamic
>
_descriptor
;
/// A map representation of the `flutter` section in the `pubspec.yaml` file.
Map
<
String
,
dynamic
>
_flutterDescriptor
;
String
get
appName
=>
_descriptor
[
'name'
];
bool
get
usesMaterialDesign
{
return
_flutterDescriptor
[
'uses-material-design'
]
??
false
;
}
List
<
Map
<
String
,
dynamic
>>
get
fontsDescriptor
{
return
_flutterDescriptor
[
'fonts'
]
??
const
<
Map
<
String
,
dynamic
>>[];
}
List
<
String
>
get
assets
{
return
_flutterDescriptor
[
'assets'
]
??
const
<
String
>[];
}
List
<
Font
>
_fonts
;
List
<
Font
>
get
fonts
{
_fonts
??=
_extractFonts
();
return
_fonts
;
}
List
<
Font
>
_extractFonts
()
{
if
(!
_flutterDescriptor
.
containsKey
(
'fonts'
))
return
<
Font
>[];
final
List
<
Font
>
fonts
=
<
Font
>[];
for
(
Map
<
String
,
dynamic
>
fontFamily
in
_flutterDescriptor
[
'fonts'
])
{
final
List
<
Map
<
String
,
dynamic
>>
fontFiles
=
fontFamily
[
'fonts'
];
final
String
familyName
=
fontFamily
[
'family'
];
if
(
familyName
==
null
)
{
printError
(
'Warning: Missing family name for font.'
,
emphasis:
true
);
continue
;
}
if
(
fontFiles
==
null
)
{
printError
(
'Warning: No fonts specified for font
$familyName
'
,
emphasis:
true
);
continue
;
}
final
List
<
FontAsset
>
fontAssets
=
<
FontAsset
>[];
for
(
Map
<
String
,
dynamic
>
fontFile
in
fontFiles
)
{
final
String
asset
=
fontFile
[
'asset'
];
if
(
asset
==
null
)
{
printError
(
'Warning: Missing asset in fonts for
$familyName
'
,
emphasis:
true
);
continue
;
}
fontAssets
.
add
(
new
FontAsset
(
asset
,
weight:
fontFile
[
'weight'
],
style:
fontFile
[
'style'
],
));
}
if
(
fontAssets
.
isNotEmpty
)
fonts
.
add
(
new
Font
(
fontFamily
[
'family'
],
fontAssets
));
}
return
fonts
;
}
}
class
Font
{
Font
(
this
.
familyName
,
this
.
fontAssets
)
{
assert
(
familyName
!=
null
);
assert
(
fontAssets
!=
null
);
assert
(
fontAssets
.
isNotEmpty
);
}
final
String
familyName
;
final
List
<
FontAsset
>
fontAssets
;
Map
<
String
,
dynamic
>
get
descriptor
{
return
<
String
,
dynamic
>{
'family'
:
familyName
,
'fonts'
:
fontAssets
.
map
((
FontAsset
a
)
=>
a
.
descriptor
).
toList
(),
};
}
@override
String
toString
()
=>
'
$runtimeType
(family:
$familyName
, assets:
$fontAssets
)'
;
}
class
FontAsset
{
FontAsset
(
this
.
asset
,
{
this
.
weight
,
this
.
style
})
{
assert
(
asset
!=
null
);
}
final
String
asset
;
final
int
weight
;
final
String
style
;
Map
<
String
,
dynamic
>
get
descriptor
{
final
Map
<
String
,
dynamic
>
descriptor
=
<
String
,
dynamic
>{};
if
(
weight
!=
null
)
descriptor
[
'weight'
]
=
weight
;
if
(
style
!=
null
)
descriptor
[
'style'
]
=
style
;
descriptor
[
'asset'
]
=
asset
;
return
descriptor
;
}
@override
String
toString
()
=>
'
$runtimeType
(asset:
$asset
, weight;
$weight
, style:
$style
)'
;
}
Future
<
dynamic
>
_loadFlutterManifest
(
String
manifestPath
)
async
{
if
(
manifestPath
==
null
||
!
fs
.
isFileSync
(
manifestPath
))
return
null
;
final
String
manifestDescriptor
=
await
fs
.
file
(
manifestPath
).
readAsString
();
return
loadYaml
(
manifestDescriptor
);
}
Future
<
bool
>
_validate
(
Object
manifest
)
async
{
final
String
schemaPath
=
fs
.
path
.
join
(
fs
.
path
.
absolute
(
Cache
.
flutterRoot
),
'packages'
,
'flutter_tools'
,
'schema'
,
'pubspec_yaml.json'
,
);
final
Schema
schema
=
await
Schema
.
createSchemaFromUrl
(
fs
.
path
.
toUri
(
schemaPath
).
toString
());
final
Validator
validator
=
new
Validator
(
schema
);
if
(
validator
.
validate
(
manifest
))
{
return
true
;
}
else
{
printStatus
(
'Error detected in pubspec.yaml:'
,
emphasis:
true
);
printError
(
validator
.
errors
.
join
(
'
\n
'
));
return
false
;
}
}
\ No newline at end of file
packages/flutter_tools/test/asset_bundle_package_fonts_test.dart
View file @
49ba9747
...
...
@@ -180,8 +180,8 @@ $fontsSection
writeFontAsset
(
'p/p/'
,
font
);
final
String
expectedFontManifest
=
'[{"f
onts":[{"asset":"packages/test_package/a/bar"}]
,'
'"f
amily":"packages/test_package/foo"
}]'
;
'[{"f
amily":"packages/test_package/foo"
,'
'"f
onts":[{"asset":"packages/test_package/a/bar"}]
}]'
;
await
buildAndVerifyFonts
(
<
String
>[],
<
String
>[
font
],
...
...
@@ -211,8 +211,8 @@ $fontsSection
writeFontAsset
(
'p2/p/lib/'
,
font
);
final
String
expectedFontManifest
=
'[{"f
onts":[{"asset":"packages/test_package2/bar"}]
,'
'"f
amily":"packages/test_package/foo"
}]'
;
'[{"f
amily":"packages/test_package/foo"
,'
'"f
onts":[{"asset":"packages/test_package2/bar"}]
}]'
;
await
buildAndVerifyFonts
(
<
String
>[],
<
String
>[
font
],
...
...
@@ -243,8 +243,8 @@ $fontsSection
writeFontAsset
(
'p/p/'
,
font
);
final
String
expectedFontManifest
=
'[{"f
onts":[{"weight":400,"style":"italic","asset":"packages/test_package/a/bar"}]
,'
'"f
amily":"packages/test_package/foo"
}]'
;
'[{"f
amily":"packages/test_package/foo"
,'
'"f
onts":[{"weight":400,"style":"italic","asset":"packages/test_package/a/bar"}]
}]'
;
await
buildAndVerifyFonts
(
<
String
>[],
<
String
>[
font
],
...
...
@@ -278,9 +278,9 @@ $fontsSection
writeFontAsset
(
'p/p/'
,
font
);
final
String
expectedFontManifest
=
'[{"fonts":[{"asset":"
packages/test_package/a/bar"}]
,'
'
"family":"packages/test_package/foo"}
,'
'
{"fonts":[{"asset":"a/bar"}],"family":"foo"
}]'
;
'[{"fonts":[{"asset":"
a/bar"}],"family":"foo"}
,'
'
{"family":"packages/test_package/foo"
,'
'
"fonts":[{"asset":"packages/test_package/a/bar"}]
}]'
;
await
buildAndVerifyFonts
(
<
String
>[
font
],
<
String
>[
font
],
...
...
packages/flutter_tools/test/flutter_manifest_test.dart
0 → 100644
View file @
49ba9747
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment