Skip to content

Commit 8a4ce4d

Browse files
hanslKeen Yee Liau
authored and
Keen Yee Liau
committed
refactor(@schematics/update): add automated JSON schema generation
1 parent a07f836 commit 8a4ce4d

File tree

6 files changed

+25
-43
lines changed

6 files changed

+25
-43
lines changed

packages/schematics/update/BUILD

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ licenses(["notice"]) # MIT
77

88
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
99
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
10+
load("//tools:ts_json_schema.bzl", "ts_json_schema")
1011

1112
package(default_visibility = ["//visibility:public"])
1213

@@ -20,12 +21,9 @@ ts_library(
2021
"**/*_benchmark.ts",
2122
],
2223
),
23-
data = [
24-
"collection.json",
25-
"migrate/schema.json",
26-
"update/schema.json",
27-
],
2824
deps = [
25+
":migrate_schema",
26+
":update_schema",
2927
"//packages/angular_devkit/core",
3028
"//packages/angular_devkit/schematics",
3129
"//packages/angular_devkit/schematics:tasks",
@@ -35,6 +33,16 @@ ts_library(
3533
],
3634
)
3735

36+
ts_json_schema(
37+
name = "update_schema",
38+
src = "update/schema.json",
39+
)
40+
41+
ts_json_schema(
42+
name = "migrate_schema",
43+
src = "migrate/schema.json",
44+
)
45+
3846
ts_library(
3947
name = "update_test_lib",
4048
srcs = glob(

packages/schematics/update/migrate/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
externalSchematic,
1616
} from '@angular-devkit/schematics';
1717
import * as semver from 'semver';
18-
import { PostUpdateSchema } from './schema';
18+
import { Schema as PostUpdateSchema } from './schema';
1919

2020

2121
/**

packages/schematics/update/migrate/schema.ts

-13
This file was deleted.

packages/schematics/update/update/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as semver from 'semver';
2020
import { getNpmPackageJson } from './npm';
2121
import { NpmRepositoryPackageJson } from './npm-package-json';
2222
import { Dependency, JsonSchemaForNpmPackageJsonFiles } from './package-json';
23-
import { UpdateSchema } from './schema';
23+
import { Schema as UpdateSchema } from './schema';
2424

2525
type VersionRange = string & { __VERSION_RANGE: void; };
2626
type PeerVersionTransform = string | ((range: string) => string);
@@ -758,9 +758,11 @@ export default function(options: UpdateSchema): Rule {
758758
// We cannot just return this because we need to fetch the packages from NPM still for the
759759
// help/guide to show.
760760
options.packages = [];
761-
} else if (typeof options.packages == 'string') {
762-
// If a string, then we should split it and make it an array.
763-
options.packages = options.packages.split(/,/g);
761+
} else {
762+
// We split every packages by commas to allow people to pass in multiple and make it an array.
763+
options.packages = options.packages.reduce((acc, curr) => {
764+
return acc.concat(curr.split(','));
765+
}, [] as string[]);
764766
}
765767

766768
if (options.migrateOnly && options.from) {
@@ -852,9 +854,9 @@ export default function(options: UpdateSchema): Rule {
852854
logger.createChild(''),
853855
'warn',
854856
);
855-
_validateUpdatePackages(infoMap, options.force, sublog);
857+
_validateUpdatePackages(infoMap, !!options.force, sublog);
856858

857-
return _performUpdate(tree, context, infoMap, logger, options.migrateOnly);
859+
return _performUpdate(tree, context, infoMap, logger, !!options.migrateOnly);
858860
} else {
859861
return _usageMessage(options, infoMap, logger);
860862
}

packages/schematics/update/update/schema.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,7 @@
5454
}
5555
]
5656
}
57-
}
57+
},
58+
"required": [
59+
]
5860
}

packages/schematics/update/update/schema.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)