From c6fe1fdba1aac8c1df41d0082e73e9176ce85e72 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Mon, 20 Jul 2020 10:16:46 +0000 Subject: [PATCH] ci(bazel): Bazelify tile component. Build and test tile component with bazel. --- angular.json | 9 -- libs/barista-components/tile/BUILD.bazel | 72 +++++++++++++++- libs/barista-components/tile/jest.config.js | 10 --- libs/barista-components/tile/jest.config.json | 8 ++ .../tile/src/chart-colors.ts | 82 ------------------- libs/barista-components/tile/tsconfig.json | 2 +- .../barista-components/tile/tsconfig.lib.json | 8 -- 7 files changed, 80 insertions(+), 111 deletions(-) delete mode 100644 libs/barista-components/tile/jest.config.js create mode 100644 libs/barista-components/tile/jest.config.json delete mode 100644 libs/barista-components/tile/src/chart-colors.ts diff --git a/angular.json b/angular.json index 5c46c04ca5..00a37e9b4c 100644 --- a/angular.json +++ b/angular.json @@ -2773,15 +2773,6 @@ "!libs/barista-components/tile/**/*" ] } - }, - "test": { - "builder": "@nrwl/jest:jest", - "options": { - "jestConfig": "libs/barista-components/tile/jest.config.js", - "tsConfig": "libs/barista-components/tile/tsconfig.spec.json", - "setupFile": "libs/barista-components/tile/src/test-setup.ts", - "passWithNoTests": true - } } }, "schematics": {} diff --git a/libs/barista-components/tile/BUILD.bazel b/libs/barista-components/tile/BUILD.bazel index bfd00d2228..f99920618e 100644 --- a/libs/barista-components/tile/BUILD.bazel +++ b/libs/barista-components/tile/BUILD.bazel @@ -1,4 +1,6 @@ -load("//tools/bazel_rules:index.bzl", "stylelint") +load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library") +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("//tools/bazel_rules:index.bzl", "jest", "ng_module_view_engine", "stylelint") package(default_visibility = ["//visibility:public"]) @@ -16,7 +18,75 @@ filegroup( ]), ) +ng_module_view_engine( + name = "compile", + srcs = glob( + include = ["**/*.ts"], + exclude = [ + "**/*.spec.ts", + "src/test-setup.ts", + ], + ), + angular_assets = [ + ":styles", + ":src/tile.html", + ], + module_name = "@dynatrace/barista-components/tile", + tsconfig = "tsconfig_lib", + deps = [ + "//libs/barista-components/core:compile", + "@npm//@angular/core", + "@npm//@angular/common", + "@npm//@angular/cdk", + ], +) + +sass_library( + name = "theme", + srcs = glob( + ["src/_tile-theme.scss"], + ), +) + +sass_binary( + name = "styles", + src = "src/tile.scss", + deps = [":theme"], +) + +jest( + name = "test", + srcs = glob(include = ["**/*.spec.ts"]), + jest_config = ":jest.config.json", + setup_file = ":src/test-setup.ts", + ts_config = ":tsconfig_test", + deps = [ + ":compile", + "//libs/testing/browser", + "@npm//@angular/platform-browser", + "@npm//@angular/core", + ], +) + stylelint( name = "stylelint", srcs = glob(["**/*.scss"]), ) + +ts_config( + name = "tsconfig_lib", + src = "tsconfig.lib.json", + deps = [ + "tsconfig.json", + "//libs/barista-components:tsconfig", + ], +) + +ts_config( + name = "tsconfig_test", + src = "tsconfig.spec.json", + deps = [ + "tsconfig.json", + "//libs/barista-components:tsconfig", + ], +) diff --git a/libs/barista-components/tile/jest.config.js b/libs/barista-components/tile/jest.config.js deleted file mode 100644 index d67b4e3652..0000000000 --- a/libs/barista-components/tile/jest.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - name: 'tile', - preset: '../../../jest.config.js', - coverageDirectory: '../../../coverage/components/tile', - snapshotSerializers: [ - 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js', - 'jest-preset-angular/build/AngularSnapshotSerializer.js', - 'jest-preset-angular/build/HTMLCommentSerializer.js', - ], -}; diff --git a/libs/barista-components/tile/jest.config.json b/libs/barista-components/tile/jest.config.json new file mode 100644 index 0000000000..94fb71fe6e --- /dev/null +++ b/libs/barista-components/tile/jest.config.json @@ -0,0 +1,8 @@ +{ + "name": "tile", + "snapshotSerializers": [ + "jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js", + "jest-preset-angular/build/AngularSnapshotSerializer.js", + "jest-preset-angular/build/HTMLCommentSerializer.js" + ] +} diff --git a/libs/barista-components/tile/src/chart-colors.ts b/libs/barista-components/tile/src/chart-colors.ts deleted file mode 100644 index 9c61cac7ec..0000000000 --- a/libs/barista-components/tile/src/chart-colors.ts +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @license - * Copyright 2020 Dynatrace LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { DtColors } from './colors'; -import { DtTheme } from './theme'; - -// Threshold to determine the color palette used -const DT_CHART_THEME_COLOR_MAX_LENGTH = 3; - -export const DT_CHART_COLOR_PALETTE_ORDERED: string[] = [ - DtColors.PURPLE_600 /* 1 */, - DtColors.YELLOW_200 /* 2 */, - DtColors.TURQUOISE_400 /* 3 */, - DtColors.PURPLE_200 /* 4 */, - DtColors.ORANGE_500 /* 5 */, - DtColors.YELLOW_500 /* 6 */, - DtColors.ROYALBLUE_600 /* 7 */, - DtColors.ORANGE_300 /* 8 */, - DtColors.PURPLE_400 /* 9 */, - DtColors.ORANGE_200 /* 10 */, - DtColors.TURQUOISE_600 /* 11 */, - DtColors.ROYALBLUE_300 /* 12 */, - DtColors.YELLOW_700 /* 13 */, - DtColors.TURQUOISE_200 /* 14 */, - DtColors.ROYALBLUE_400 /* 15 */, -]; - -/** Chart colors for the purple theme up to 3 metrics */ -const DT_COLOR_PALETTE_PURPLE: string[] = [ - DtColors.PURPLE_700, - DtColors.PURPLE_200, - DtColors.PURPLE_400, -]; - -/** Chart colors for the royalblue theme up to 3 metrics */ -const DT_COLOR_PALETTE_ROYALBLUE: string[] = [ - DtColors.ROYALBLUE_800, - DtColors.ROYALBLUE_200, - DtColors.ROYALBLUE_400, -]; - -/** Chart colors for the blue theme up to 3 metrics */ -const DT_COLOR_PALETTE_BLUE: string[] = [ - DtColors.BLUE_700, - DtColors.BLUE_200, - DtColors.BLUE_400, -]; - -export const DT_CHART_COLOR_PALETTES = { - purple: DT_COLOR_PALETTE_PURPLE, - royalblue: DT_COLOR_PALETTE_ROYALBLUE, - blue: DT_COLOR_PALETTE_BLUE, -}; - -/** Return correct color palette depending on the number of metrics */ -export function getDtChartColorPalette( - nrOfMetrics: number, - theme?: DtTheme, -): string[] { - let palette = DT_CHART_COLOR_PALETTE_ORDERED; - - if (theme && theme.name && DT_CHART_COLOR_PALETTES[theme.name]) { - palette = DT_CHART_COLOR_PALETTES[theme.name]; - } - - return nrOfMetrics <= DT_CHART_THEME_COLOR_MAX_LENGTH - ? palette - : DT_CHART_COLOR_PALETTE_ORDERED; -} diff --git a/libs/barista-components/tile/tsconfig.json b/libs/barista-components/tile/tsconfig.json index 08c7db8c96..9a8a899ff5 100644 --- a/libs/barista-components/tile/tsconfig.json +++ b/libs/barista-components/tile/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.json", + "extends": "../tsconfig.json", "compilerOptions": { "types": ["node", "jest"] }, diff --git a/libs/barista-components/tile/tsconfig.lib.json b/libs/barista-components/tile/tsconfig.lib.json index 1c600457d3..e0fe2089dc 100644 --- a/libs/barista-components/tile/tsconfig.lib.json +++ b/libs/barista-components/tile/tsconfig.lib.json @@ -8,13 +8,5 @@ "types": [], "lib": ["dom", "es2018"] }, - "angularCompilerOptions": { - "annotateForClosureCompiler": true, - "skipTemplateCodegen": true, - "strictMetadataEmit": true, - "fullTemplateTypeCheck": true, - "strictInjectionParameters": true, - "enableResourceInlining": true - }, "exclude": ["src/test-setup.ts", "**/*.spec.ts"] }