Skip to content

Commit b184e1c

Browse files
committed
extra
1 parent 09f92b7 commit b184e1c

File tree

6 files changed

+300
-0
lines changed

6 files changed

+300
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
targets:
2+
angular_components:
3+
sources:
4+
exclude: ["lib/builder.dart"]
5+
builders:
6+
sass_builder|sass_builder:
7+
enabled: False
8+
angular_components|scss_builder:
9+
enabled: True
10+
scss_builder:
11+
sources: ["lib/builder.dart"]
12+
dependencies:
13+
- build
14+
- sass_builder
15+
16+
17+
builders:
18+
scss_builder:
19+
target: "scss_builder"
20+
import: "package:angular_components/builder.dart"
21+
builder_factories: ["scssBuilder"]
22+
build_to: cache
23+
build_extensions:
24+
.scss: [".scss.css"]
25+
.sass: [".scss.css"]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
targets:
2+
$default:
3+
builders:
4+
angular:
5+
generate_for:
6+
exclude:
7+
- "lib/builder.dart"
8+
- "lib/src/compiler/**"
9+
- "lib/src/source_gen/**"
10+
11+
builders:
12+
angular:
13+
import: "package:angular/builder.dart"
14+
builder_factories:
15+
- templatePlaceholder
16+
- templateCompiler
17+
- stylesheetCompiler
18+
auto_apply: none
19+
applies_builders:
20+
- "angular|placeholder_cleanup"
21+
- "angular|component_source_cleanup"
22+
# See https://github.com/dart-lang/angular/issues/988.
23+
is_optional: true
24+
required_inputs:
25+
- ".css"
26+
build_extensions:
27+
.css:
28+
- ".css.dart"
29+
- ".css.shim.dart"
30+
.dart:
31+
- ".template.dart"
32+
post_process_builders:
33+
placeholder_cleanup:
34+
import: "package:angular/builder.dart"
35+
builder_factory: "placeholderCleanup"
36+
component_source_cleanup:
37+
import: "package:angular/builder.dart"
38+
builder_factory: "componentSourceCleanup"
39+
defaults:
40+
generate_for: ["lib/**"]
41+
release_options:
42+
enabled: true
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// ignore_for_file: annotate_overrides
6+
7+
import 'package:json_annotation/json_annotation.dart';
8+
import 'package:meta/meta.dart';
9+
10+
part 'build_config.g.dart';
11+
12+
@JsonSerializable()
13+
class Config extends Object with _$ConfigSerializerMixin {
14+
final Map<String, Builder> builders;
15+
16+
Config({@required this.builders});
17+
18+
factory Config.fromJson(Map map) => _$ConfigFromJson(map);
19+
}
20+
21+
@JsonSerializable(includeIfNull: false)
22+
class Builder extends Object with _$BuilderSerializerMixin {
23+
@JsonKey(nullable: true)
24+
final String target;
25+
final String import;
26+
27+
@JsonKey(name: 'is_optional')
28+
final bool isOptional;
29+
30+
@JsonKey(name: 'auto_apply', toJson: _toJson, fromJson: _fromJson)
31+
final AutoApply autoApply;
32+
33+
@JsonKey(name: 'builder_factories')
34+
final List<String> builderFactories;
35+
36+
@JsonKey(name: 'applies_builders')
37+
final List<String> appliesBuilders;
38+
39+
@JsonKey(name: 'required_inputs')
40+
final List<String> requiredInputs;
41+
42+
@JsonKey(name: 'build_extensions')
43+
final Map<String, List<String>> buildExtentions;
44+
45+
Builder({
46+
@required this.import,
47+
this.target,
48+
this.isOptional,
49+
this.autoApply,
50+
this.builderFactories,
51+
this.appliesBuilders,
52+
this.requiredInputs,
53+
this.buildExtentions,
54+
});
55+
56+
factory Builder.fromJson(Map map) => _$BuilderFromJson(map);
57+
}
58+
59+
enum AutoApply { none, dependents, allPackages, rootPackage }
60+
61+
//TODO: remove all of this and annotate the fields on the enum once we have
62+
//pkg:analyzer with github.com/dart-lang/sdk/commit/74db253d34
63+
AutoApply _fromJson(String input) {
64+
var value = _autoApplyConvert[input];
65+
if (value == null) {
66+
var allowed = _autoApplyConvert.keys.map((e) => '"$e"').join(', ');
67+
throw new ArgumentError.value(
68+
input, 'autoApply', '"$input" is not in the supported set: $allowed.');
69+
}
70+
return value;
71+
}
72+
73+
String _toJson(AutoApply value) {
74+
if (value == null) {
75+
return null;
76+
}
77+
var string = _autoApplyConvert.entries
78+
.singleWhere((e) => e.value == value, orElse: () => null)
79+
?.key;
80+
81+
if (string == null) {
82+
throw new ArgumentError.value(value, 'autoApply', 'Unsupported value.');
83+
}
84+
return string;
85+
}
86+
87+
const _autoApplyConvert = const {
88+
'none': AutoApply.none,
89+
'dependents': AutoApply.dependents,
90+
'all_packages': AutoApply.allPackages,
91+
'root_package': AutoApply.rootPackage
92+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// GENERATED CODE - DO NOT MODIFY BY HAND
6+
7+
part of 'build_config.dart';
8+
9+
// **************************************************************************
10+
// Generator: JsonSerializableGenerator
11+
// **************************************************************************
12+
13+
Config _$ConfigFromJson(Map json) => $wrapNew(
14+
'Config',
15+
json,
16+
const {'builders': 'builders'},
17+
(json) => new Config(
18+
builders: $wrapConvert(
19+
json,
20+
'builders',
21+
(m, g) => (m[g] as Map)?.map((k, e) => new MapEntry(k as String,
22+
e == null ? null : new Builder.fromJson(e as Map))))));
23+
24+
abstract class _$ConfigSerializerMixin {
25+
Map<String, Builder> get builders;
26+
Map<String, dynamic> toJson() => <String, dynamic>{'builders': builders};
27+
}
28+
29+
Builder _$BuilderFromJson(Map json) => $wrapNew(
30+
'Builder',
31+
json,
32+
const {
33+
'import': 'import',
34+
'target': 'target',
35+
'isOptional': 'is_optional',
36+
'autoApply': 'auto_apply',
37+
'builderFactories': 'builder_factories',
38+
'appliesBuilders': 'applies_builders',
39+
'requiredInputs': 'required_inputs',
40+
'buildExtentions': 'build_extensions'
41+
},
42+
(json) => new Builder(
43+
import: $wrapConvert(json, 'import', (m, g) => m[g] as String),
44+
target: $wrapConvert(json, 'target', (m, g) => m[g] as String),
45+
isOptional: $wrapConvert(json, 'is_optional', (m, g) => m[g] as bool),
46+
autoApply: $wrapConvert(json, 'auto_apply',
47+
(m, g) => m[g] == null ? null : _fromJson(m[g] as String)),
48+
builderFactories: $wrapConvert(json, 'builder_factories',
49+
(m, g) => (m[g] as List)?.map((e) => e as String)?.toList()),
50+
appliesBuilders: $wrapConvert(json, 'applies_builders',
51+
(m, g) => (m[g] as List)?.map((e) => e as String)?.toList()),
52+
requiredInputs: $wrapConvert(json, 'required_inputs',
53+
(m, g) => (m[g] as List)?.map((e) => e as String)?.toList()),
54+
buildExtentions: $wrapConvert(
55+
json,
56+
'build_extensions',
57+
(m, g) => (m[g] as Map)?.map((k, e) => new MapEntry(k as String,
58+
(e as List)?.map((e) => e as String)?.toList())))));
59+
60+
abstract class _$BuilderSerializerMixin {
61+
String get target;
62+
String get import;
63+
bool get isOptional;
64+
AutoApply get autoApply;
65+
List<String> get builderFactories;
66+
List<String> get appliesBuilders;
67+
List<String> get requiredInputs;
68+
Map<String, List<String>> get buildExtentions;
69+
Map<String, dynamic> toJson() {
70+
var val = <String, dynamic>{};
71+
72+
void writeNotNull(String key, dynamic value) {
73+
if (value != null) {
74+
val[key] = value;
75+
}
76+
}
77+
78+
writeNotNull('target', target);
79+
writeNotNull('import', import);
80+
writeNotNull('is_optional', isOptional);
81+
writeNotNull('auto_apply', autoApply == null ? null : _toJson(autoApply));
82+
writeNotNull('builder_factories', builderFactories);
83+
writeNotNull('applies_builders', appliesBuilders);
84+
writeNotNull('required_inputs', requiredInputs);
85+
writeNotNull('build_extensions', buildExtentions);
86+
return val;
87+
}
88+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
builders:
2+
# The regular builder config, creates `.tar.gz` files.
3+
regular_builder:
4+
import: "package:my_package/builder.dart"
5+
builder_factories: ["myBuilder"]
6+
build_extensions: {".dart": [".tar.gz"]}
7+
auto_apply: root_package
8+
apply_builders: ["|archive_extract_builder"]
9+
post_process_builders:
10+
# The post process builder config, extracts `.tar.gz` files.
11+
extract_archive_builder:
12+
import: "package:my_package/extract_archive_builder.dart"
13+
builder_factory: "myExtractArchiveBuilder"
14+
input_extensions: [".tar.gz"]

json_serializable/test/yaml_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:json_annotation/json_annotation.dart';
8+
import 'package:path/path.dart' as p;
9+
import 'package:test/test.dart';
10+
import 'package:yaml/yaml.dart' as yaml;
11+
12+
import 'config/build_config.dart';
13+
14+
import 'test_utils.dart';
15+
16+
final _root = p.join('test', 'config');
17+
18+
List<String> _getTests() => new Directory(_root)
19+
.listSync()
20+
.where((fse) => fse is File && p.extension(fse.path) == '.yaml')
21+
.map((fse) => fse.path)
22+
.toList();
23+
24+
void main() {
25+
for (var filePath in _getTests()) {
26+
test(p.basenameWithoutExtension(filePath), () {
27+
var content = new File(filePath).readAsStringSync();
28+
var yamlContent =
29+
yaml.loadYaml(content, sourceUrl: filePath) as yaml.YamlMap;
30+
31+
try {
32+
var config = new Config.fromJson(yamlContent);
33+
print(loudEncode(config));
34+
} on SerializationConvertException catch (e) {
35+
prettyPrintSerializationConvertException(e);
36+
}
37+
});
38+
}
39+
}

0 commit comments

Comments
 (0)