From 880494e155d9935374c0cad7a2b07cb683eaffac Mon Sep 17 00:00:00 2001 From: Christian Badura <93912698+cbadura@users.noreply.github.com> Date: Sat, 3 Aug 2024 15:19:20 +0200 Subject: [PATCH] fix: improve theme export name, bump deps, improve package.json scripts (#196) Co-authored-by: Christian Badura --- .eslintrc.json | 2 +- .gitignore | 1 + package-lock.json | 24 +++++++++---------- package.json | 12 +++++----- src/app/shared/utils.ts | 15 ++++++++++++ .../theme-detail.component.spec.ts | 7 ++++-- .../theme-detail/theme-detail.component.ts | 7 ++++-- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8a7fd2b..112ecbd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -61,7 +61,7 @@ ], "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none" }], - "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/ban-types": [ "error", { diff --git a/.gitignore b/.gitignore index bf766ec..2f1a578 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ speed-measure-plugin*.json # misc .angular/cache .sass-cache +.eslintcache .gitlab* .scannerwork connect.lock diff --git a/package-lock.json b/package-lock.json index b3edc8b..6dde43c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,13 +31,13 @@ "@onecx/angular-accelerator": "^5.2.0", "@onecx/angular-auth": "^5.2.0", "@onecx/angular-integration-interface": "^5.2.0", - "@onecx/angular-remote-components": "^5.2.0", - "@onecx/angular-testing": "^5.2.0", + "@onecx/angular-remote-components": "^5.3.0", + "@onecx/angular-testing": "^5.3.0", "@onecx/angular-webcomponents": "^5.2.0", "@onecx/integration-interface": "^5.2.0", "@onecx/keycloak-auth": "^5.2.0", "@onecx/portal-integration-angular": "^5.2.0", - "@onecx/portal-layout-styles": "^5.2.0", + "@onecx/portal-layout-styles": "^5.3.0", "@webcomponents/webcomponentsjs": "^2.8.0", "file-saver": "^2.0.5", "i18n-iso-countries": "^7.11.3", @@ -6746,9 +6746,9 @@ } }, "node_modules/@onecx/angular-remote-components": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@onecx/angular-remote-components/-/angular-remote-components-5.2.0.tgz", - "integrity": "sha512-CJWP+RYMhYITdHrIYUgCB6zHI+9J2nn+uT8N9cdF3nAmJNPpGkv01v75xlom2QPTDLJ0MgzqhBo8Gtp83r58lw==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@onecx/angular-remote-components/-/angular-remote-components-5.3.0.tgz", + "integrity": "sha512-k6LtLLw4ojsHjcm+8HO4/ubWdib7FfilmPvireVtjSZvJrdQKVO4mXlWee2wgk1cG5LICFiHdES55AJXM4A1lQ==", "dependencies": { "tslib": "^2.3.0" }, @@ -6763,9 +6763,9 @@ } }, "node_modules/@onecx/angular-testing": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@onecx/angular-testing/-/angular-testing-5.2.0.tgz", - "integrity": "sha512-e5I4JdECB6VPRsP+rc2AQP0SK/+XoxjJVMY9R99Gas10pFsSHvxZtViU/xE31Il+DE1RiggjAFfDI2N0Rh0pmA==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@onecx/angular-testing/-/angular-testing-5.3.0.tgz", + "integrity": "sha512-x9XgCZRPOcr10j9bCCp7F/8TTZv0f5xG7Rk5pACVzozuitJvJ1C3D+BFOnB7ZPxbsPmm1R+rKaR2Uw4GPWmNlA==", "dependencies": { "tslib": "^2.3.0" }, @@ -6853,9 +6853,9 @@ } }, "node_modules/@onecx/portal-layout-styles": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@onecx/portal-layout-styles/-/portal-layout-styles-5.2.0.tgz", - "integrity": "sha512-/eieVUV8UsqZWkrhieE4/qozqgMET+KAMDuT2Ls/OIkSW8KMC+URA+7IP2KVqQq5PlAjbWxPMPu72pHPnEHlzw==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@onecx/portal-layout-styles/-/portal-layout-styles-5.3.0.tgz", + "integrity": "sha512-n0Bc9DUXy2p0ECaf8mgW3iCZxpyAiqJgJEjjrXf71Bur4BoDpER3B3e0JOp0T/xD5r6n88o6EaVju3l9mES77g==", "peerDependencies": { "tslib": "^2.6.3" } diff --git a/package.json b/package.json index 5f8c6e1..aed8bf3 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ }, "scripts": { "build": "ng build", - "clean": "npm cache clean --force && npm run clean-angular", + "clean": "npm cache clean --force && npm run clean-angular && ng cache clean && rm .eslintcache", "clean-angular": "ng cache clean", "start": "ng serve --configuration=development --proxy-config=proxy.conf.js", - "prepare": "husky install", - "lint": "ng lint", + "prepare": "husky", + "lint": "ng lint --cache=true", "eslint": "eslint --quiet --ext .js,.ts src", "format": "ng lint --fix", "browsers": "npx browserslist", @@ -57,13 +57,13 @@ "@onecx/angular-accelerator": "^5.2.0", "@onecx/angular-auth": "^5.2.0", "@onecx/angular-integration-interface": "^5.2.0", - "@onecx/angular-remote-components": "^5.2.0", + "@onecx/angular-remote-components": "^5.3.0", "@onecx/angular-webcomponents": "^5.2.0", - "@onecx/angular-testing": "^5.2.0", + "@onecx/angular-testing": "^5.3.0", "@onecx/integration-interface": "^5.2.0", "@onecx/keycloak-auth": "^5.2.0", "@onecx/portal-integration-angular": "^5.2.0", - "@onecx/portal-layout-styles": "^5.2.0", + "@onecx/portal-layout-styles": "^5.3.0", "@webcomponents/webcomponentsjs": "^2.8.0", "file-saver": "^2.0.5", "i18n-iso-countries": "^7.11.3", diff --git a/src/app/shared/utils.ts b/src/app/shared/utils.ts index 84ac116..33c7e02 100644 --- a/src/app/shared/utils.ts +++ b/src/app/shared/utils.ts @@ -47,3 +47,18 @@ export function prepareUrlPath(url?: string, path?: string): string { export function bffImageUrl(basePath: string | undefined, name: string | undefined, refType: RefType): string { return !name ? '' : basePath + '/images/' + name + '/' + refType } + +/** + * Date & time + */ +export function getCurrentDateTime(): string { + const now = new Date() + const year = now.getFullYear() + const month = String(now.getMonth() + 1).padStart(2, '0') + const day = String(now.getDate()).padStart(2, '0') + const hours = String(now.getHours()).padStart(2, '0') + const minutes = String(now.getMinutes()).padStart(2, '0') + const seconds = String(now.getSeconds()).padStart(2, '0') + + return `${year}-${month}-${day}_${hours}${minutes}${seconds}` +} diff --git a/src/app/theme/theme-detail/theme-detail.component.spec.ts b/src/app/theme/theme-detail/theme-detail.component.spec.ts index 08e7b8a..9b60536 100644 --- a/src/app/theme/theme-detail/theme-detail.component.spec.ts +++ b/src/app/theme/theme-detail/theme-detail.component.spec.ts @@ -13,7 +13,7 @@ import { ConfigurationService, PortalMessageService, UserService } from '@onecx/ import { RefType, Theme, ThemesAPIService } from 'src/app/shared/generated' import { ThemeDetailComponent } from './theme-detail.component' -import { bffImageUrl } from 'src/app/shared/utils' +import { bffImageUrl, getCurrentDateTime } from 'src/app/shared/utils' describe('ThemeDetailComponent', () => { let component: ThemeDetailComponent @@ -404,7 +404,10 @@ describe('ThemeDetailComponent', () => { null, 2 ) - expect(FileSaver.saveAs).toHaveBeenCalledOnceWith(jasmine.any(Blob), 'themeName_Theme.json') + expect(FileSaver.saveAs).toHaveBeenCalledOnceWith( + jasmine.any(Blob), + `onecx-theme_themeName_${getCurrentDateTime()}.json` + ) }) it('should display error on theme export fail', () => { diff --git a/src/app/theme/theme-detail/theme-detail.component.ts b/src/app/theme/theme-detail/theme-detail.component.ts index 5f15e38..7f0748e 100644 --- a/src/app/theme/theme-detail/theme-detail.component.ts +++ b/src/app/theme/theme-detail/theme-detail.component.ts @@ -6,7 +6,7 @@ import FileSaver from 'file-saver' import { Action, PortalMessageService, UserService } from '@onecx/portal-integration-angular' -import { sortByLocale, bffImageUrl } from 'src/app/shared/utils' +import { sortByLocale, bffImageUrl, getCurrentDateTime } from 'src/app/shared/utils' import { ExportThemeRequest, ImagesInternalAPIService, @@ -164,7 +164,10 @@ export class ThemeDetailComponent implements OnInit { .subscribe({ next: (data) => { const themeJSON = JSON.stringify(data, null, 2) - FileSaver.saveAs(new Blob([themeJSON], { type: 'text/json' }), `${this.theme?.name + '_Theme'}.json`) + FileSaver.saveAs( + new Blob([themeJSON], { type: 'text/json' }), + `onecx-theme_${this.theme?.name}_${getCurrentDateTime()}.json` + ) }, error: (err) => { console.log(err)