From 033c425c4f02f11f6c571066b3b381fc39583947 Mon Sep 17 00:00:00 2001 From: cipchk Date: Sat, 9 Dec 2023 14:01:41 +0800 Subject: [PATCH 1/5] ci: save yarn.lock to assets --- src/app/core/code/code.service.ts | 37 ++++++++++++------- .../yarn.lock.ts => assets/yarn.lock.txt} | 3 +- src/index.html | 1 + 3 files changed, 25 insertions(+), 16 deletions(-) rename src/{app/core/code/files/yarn.lock.ts => assets/yarn.lock.txt} (99%) diff --git a/src/app/core/code/code.service.ts b/src/app/core/code/code.service.ts index bf45d7241f..ef39dc8f43 100644 --- a/src/app/core/code/code.service.ts +++ b/src/app/core/code/code.service.ts @@ -1,5 +1,7 @@ import { DOCUMENT } from '@angular/common'; -import { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Injectable, inject } from '@angular/core'; +import { lastValueFrom } from 'rxjs'; import sdk from '@stackblitz/sdk'; import { getParameters } from 'codesandbox/lib/api/define'; @@ -16,13 +18,14 @@ import readme from './files/readme-cli'; import sandboxConfigJSON from './files/sandbox'; import startupServiceTS from './files/startup.service'; import tsconfigJSON from './files/tsconfig.json'; -import yarnLock from './files/yarn.lock'; import pkg from '../../../../package.json'; import { AppService } from '../app.service'; @Injectable({ providedIn: 'root' }) export class CodeService { - private document: Document; + private appSrv = inject(AppService); + private http = inject(HttpClient); + private document = inject(DOCUMENT); private get themePath(): string { return `node_modules/@delon/theme/${this.appSrv.theme}.css`; @@ -85,13 +88,6 @@ export class CodeService { return res; } - constructor( - private appSrv: AppService, - @Inject(DOCUMENT) document: NzSafeAny - ) { - this.document = document; - } - private get genStartupService(): string { return startupServiceTS({ ajvVersion: pkg.dependencies.ajv.substring(1) }); } @@ -132,7 +128,20 @@ export class CodeService { return `${code.replace(`@Component({`, `@Component({\n standalone: true,\n`)}`; } - openOnStackBlitz(title: string, appComponentCode: string): void { + private yarnLock?: string; + private async getYarnLock(): Promise { + if (this.yarnLock != null) return this.yarnLock; + try { + const res = await lastValueFrom(this.http.get('./assets/yarn.lock.txt', { responseType: 'text' })); + this.yarnLock = res; + return res; + } catch (ex) { + console.warn(`Unable to load yarn.lock file: ${ex}`); + } + return ''; + } + + async openOnStackBlitz(title: string, appComponentCode: string): Promise { appComponentCode = this.attachStandalone(appComponentCode); const res = this.parseCode(appComponentCode); const json = deepCopy(angularJSON); @@ -161,7 +170,7 @@ export class CodeService { null, 2 ), - 'yarn.lock': yarnLock, + 'yarn.lock': await this.getYarnLock(), 'angular.json': `${JSON.stringify(json, null, 2)}`, 'tsconfig.json': `${JSON.stringify(tsconfigJSON, null, 2)}`, 'package.json': `${JSON.stringify(packageJson, null, 2)}`, @@ -181,7 +190,7 @@ export class CodeService { ); } - openOnCodeSandbox(title: string, appComponentCode: string, includeCli: boolean = false): void { + async openOnCodeSandbox(title: string, appComponentCode: string, includeCli: boolean = false): Promise { appComponentCode = this.attachStandalone(appComponentCode); const res = this.parseCode(appComponentCode); const mockObj = this.genMock; @@ -241,7 +250,7 @@ export class CodeService { isBinary: false }, 'yarn.lock': { - content: yarnLock, + content: await this.getYarnLock(), isBinary: false } }; diff --git a/src/app/core/code/files/yarn.lock.ts b/src/assets/yarn.lock.txt similarity index 99% rename from src/app/core/code/files/yarn.lock.ts rename to src/assets/yarn.lock.txt index 5d0846e6ca..bb90fab0c5 100644 --- a/src/app/core/code/files/yarn.lock.ts +++ b/src/assets/yarn.lock.txt @@ -1,4 +1,4 @@ -export default `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 @@ -8043,4 +8043,3 @@ zrender@5.4.4: integrity sha512-0VxCNJ7AGOMCWeHVyTrGzUgrK4asT4ml9PEkeGirAkKNYXYzoPJCLvmyfdoOXcjTHPs10OZVMfD1Rwg16AZyYw== dependencies: tslib "2.3.0" -`; diff --git a/src/index.html b/src/index.html index 8b7a4a0af8..a2ca1933b6 100644 --- a/src/index.html +++ b/src/index.html @@ -14,6 +14,7 @@ + From 5c4e3e1e2d609be2238f756bf226fae461168964 Mon Sep 17 00:00:00 2001 From: cipchk Date: Sat, 9 Dec 2023 14:05:43 +0800 Subject: [PATCH 2/5] chore: fix --- src/app/core/code/files/yarn.lock.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/app/core/code/files/yarn.lock.ts diff --git a/src/app/core/code/files/yarn.lock.ts b/src/app/core/code/files/yarn.lock.ts new file mode 100644 index 0000000000..14e46f6d5f --- /dev/null +++ b/src/app/core/code/files/yarn.lock.ts @@ -0,0 +1 @@ +// removed From 01989407da2ccd9fa0e1682b00bcd4d5d0051ff7 Mon Sep 17 00:00:00 2001 From: cipchk Date: Sat, 9 Dec 2023 14:06:37 +0800 Subject: [PATCH 3/5] chore: remove yarn.lock.ts --- src/app/core/code/files/yarn.lock.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/app/core/code/files/yarn.lock.ts diff --git a/src/app/core/code/files/yarn.lock.ts b/src/app/core/code/files/yarn.lock.ts deleted file mode 100644 index 14e46f6d5f..0000000000 --- a/src/app/core/code/files/yarn.lock.ts +++ /dev/null @@ -1 +0,0 @@ -// removed From b802413ffcb5275c850f085addc013f18df62ef0 Mon Sep 17 00:00:00 2001 From: cipchk Date: Sat, 9 Dec 2023 14:07:15 +0800 Subject: [PATCH 4/5] chore: fix --- src/app/core/code/files/yarn.lock.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/app/core/code/files/yarn.lock.ts diff --git a/src/app/core/code/files/yarn.lock.ts b/src/app/core/code/files/yarn.lock.ts new file mode 100644 index 0000000000..14e46f6d5f --- /dev/null +++ b/src/app/core/code/files/yarn.lock.ts @@ -0,0 +1 @@ +// removed From 1beeab36f9b593d64993c48762ccbd7ade2e730f Mon Sep 17 00:00:00 2001 From: cipchk Date: Sat, 9 Dec 2023 14:07:43 +0800 Subject: [PATCH 5/5] chore: remove --- src/app/core/code/files/yarn.lock.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/app/core/code/files/yarn.lock.ts diff --git a/src/app/core/code/files/yarn.lock.ts b/src/app/core/code/files/yarn.lock.ts deleted file mode 100644 index 14e46f6d5f..0000000000 --- a/src/app/core/code/files/yarn.lock.ts +++ /dev/null @@ -1 +0,0 @@ -// removed