Skip to content

Commit

Permalink
fix: improve theme export name, bump deps, improve package.json scrip…
Browse files Browse the repository at this point in the history
…ts (#196)

Co-authored-by: Christian Badura <[email protected]>
  • Loading branch information
cbadura and Christian Badura authored Aug 3, 2024
1 parent e901950 commit 880494e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ speed-measure-plugin*.json
# misc
.angular/cache
.sass-cache
.eslintcache
.gitlab*
.scannerwork
connect.lock
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
7 changes: 5 additions & 2 deletions src/app/theme/theme-detail/theme-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/theme/theme-detail/theme-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 880494e

Please sign in to comment.