Skip to content

Commit

Permalink
perf: reduce release info for now (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored May 3, 2024
1 parent 1e35b09 commit 3e494c1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
4 changes: 3 additions & 1 deletion scripts/src/generate-release-file.mts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ type FakeResultObject = ResultObject & { fake: true }
const RELEASE_FILE = join(getRepositoryRootDir(), 'release.json')

async function writeToReleaseFile(result: object) {
const { nextRelease, fake, preview } = result as FakeResultObject &
PreviewResultObject
Log.info("Writing to file '%s'", RELEASE_FILE)
writeFileSync(RELEASE_FILE, objectToJson(result))
writeFileSync(RELEASE_FILE, objectToJson({ nextRelease, fake, preview }))
}

if (isMain(import.meta.url)) {
Expand Down
20 changes: 0 additions & 20 deletions src/app/common/injection-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { InjectionToken } from '@angular/core'
import RELEASE_OBJECT from '../../../release.json'
import { environment, Environment } from '../../environments'
import { METADATA as METADATA_OBJECT, Metadata } from '../metadata'
import {
ReleaseInfo,
ReleaseInfoSummary,
} from '../release-info/semantic-release'

/* istanbul ignore next */
export const ENVIRONMENT = new InjectionToken<Environment>(
Expand All @@ -21,18 +16,3 @@ export const METADATA = new InjectionToken<Metadata>('Metadata object', {
export const WINDOW = new InjectionToken<Window>('Global window object', {
factory: () => window,
})
export const RELEASE = new InjectionToken<ReleaseInfoSummary>(
'Release object',
{
// Have to manually cast as strings are not checked against the union type
// https://github.com/microsoft/TypeScript/issues/26552
// Adding just picked properties because full object may increase a lot the bundle size.
// Also, if we want to generate this file on older commits, like tagged ones, this may need to be mocked
factory: () =>
({
nextRelease: RELEASE_OBJECT.nextRelease,
fake: (RELEASE_OBJECT as ReleaseInfo).fake,
preview: (RELEASE_OBJECT as ReleaseInfo).preview,
}) as ReleaseInfoSummary,
},
)
2 changes: 1 addition & 1 deletion src/app/release-info/release-info.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<pre>{{ releaseAsJsonString }}</pre>
<pre>{{ _jsonString }}</pre>
22 changes: 8 additions & 14 deletions src/app/release-info/release-info.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Inject } from '@angular/core'
import { RELEASE } from '@/common/injection-tokens'
import { Component } from '@angular/core'
import RELEASE_JSON from '../../../release.json'
import { ReleaseInfoSummary } from './semantic-release'

@Component({
Expand All @@ -9,16 +9,10 @@ import { ReleaseInfoSummary } from './semantic-release'
standalone: true,
})
export class ReleaseInfoComponent {
constructor(@Inject(RELEASE) private release: ReleaseInfoSummary) {}

protected get releaseAsJsonString() {
const nextRelease = this.release.nextRelease
const summary = {
...nextRelease,
notes: undefined,
preview: this.release.preview,
fake: this.release.fake,
}
return JSON.stringify(summary, null, 2)
}
protected _jsonString = JSON.stringify({
...RELEASE_JSON.nextRelease,
notes: undefined,
preview: (RELEASE_JSON as ReleaseInfoSummary).preview,
fake: (RELEASE_JSON as ReleaseInfoSummary).fake,
})
}

0 comments on commit 3e494c1

Please sign in to comment.