Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: save yarn.lock to assets #1729

Merged
merged 5 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/app/core/code/code.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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`;
Expand Down Expand Up @@ -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) });
}
Expand Down Expand Up @@ -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<string> {
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<void> {
appComponentCode = this.attachStandalone(appComponentCode);
const res = this.parseCode(appComponentCode);
const json = deepCopy(angularJSON);
Expand Down Expand Up @@ -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)}`,
Expand All @@ -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<void> {
appComponentCode = this.attachStandalone(appComponentCode);
const res = this.parseCode(appComponentCode);
const mockObj = this.genMock;
Expand Down Expand Up @@ -241,7 +250,7 @@ export class CodeService {
isBinary: false
},
'yarn.lock': {
content: yarnLock,
content: await this.getYarnLock(),
isBinary: false
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -8043,4 +8043,3 @@ [email protected]:
integrity sha512-0VxCNJ7AGOMCWeHVyTrGzUgrK4asT4ml9PEkeGirAkKNYXYzoPJCLvmyfdoOXcjTHPs10OZVMfD1Rwg16AZyYw==
dependencies:
tslib "2.3.0"
`;
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<link rel="dns-prefetch" href="https://www.google-analytics.com">
<link rel="preconnect" href="https://cdn.jsdelivr.net">
<link rel="preconnect" href="https://api.github.com">
<link rel="prefetch" href="./assets/yarn.lock.txt">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="translucent">
Expand Down