Skip to content

Commit

Permalink
fix: generating app-info.json updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Sep 10, 2024
1 parent 0c1c8f9 commit cfa1daa
Show file tree
Hide file tree
Showing 17 changed files with 913 additions and 488 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ coverage
libpeerconnection.log
testem.log
typings
./aas-server-config.json
reports
.nyc_output
temp
*-audit.json
swagger.json
swagger.yaml
projects/aas-server/src/app/routes
projects/ass-server/src/assets/app-info.json

# System files
.DS_Store
Thumbs.db
.VSCodeCounter
aas-server-config.json
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stages:
- deploy

tag:
image: node:20.10
image: node:alpine3.19
stage: tag
rules:
- if: '$CI_COMMIT_MESSAGE !~ /(Release)/'
Expand All @@ -15,7 +15,7 @@ tag:
- npx semantic-release

build:
image: node:lts-alpine3.19
image: node:alpine3.19
stage: build
rules:
- if: '$CI_COMMIT_MESSAGE =~ /(Release)/'
Expand All @@ -24,7 +24,7 @@ build:
- npm run build -ws

test:
image: node:lts-alpine3.19
image: node:alpine3.19
stage: test
rules:
- if: '$CI_COMMIT_MESSAGE =~ /(Release)/'
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ COPY projects/aas-server/package.json package.json
COPY projects/aas-server/src/assets assets/
RUN npm install --omit=dev
COPY --from=build /usr/src/app/projects/aas-server/dist/ /usr/src/app/
COPY --from=build /usr/src/app/projects/aas-server/app-info.json /usr/src/app/app-info.json
COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/aas-core/package.json
COPY --from=build /usr/src/app/projects/aas-portal/dist/browser/ /usr/src/app/wwwroot/
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.aas-portal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile to build server and client parts
FROM node:lts-alpine3.19 AS build
FROM node:alpine3.19 AS build
WORKDIR /usr/src/app
COPY . .
RUN npm install
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile.aas-server
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Dockerfile to build server and client parts
FROM node:lts-alpine3.19 as build
FROM node:alpine3.19 as build
WORKDIR /usr/src/app
COPY . .
# RUN apk add g++ make py3-pip
RUN npm install
RUN node --no-warnings --loader ts-node/esm create-app-info.ts
RUN npm run aas-server:build

FROM node:lts-alpine3.19 AS aas-server
FROM node:alpine3.19 AS aas-server
RUN apk upgrade --update-cache --available && apk add openssl && rm -rf /var/cache/apk/*
WORKDIR /usr/src/app
COPY projects/aas-server/package.json package.json
COPY projects/aas-server/src/assets assets/
RUN npm install --omit=dev
COPY --from=build /usr/src/app/projects/aas-server/dist/ /usr/src/app/
COPY --from=build /usr/src/app/projects/aas-server/app-info.json /usr/src/app/app-info.json
COPY --from=build /usr/src/app/projects/aas-core/dist/ /usr/src/app/node_modules/aas-core/dist/
COPY --from=build /usr/src/app/projects/aas-core/package.json /usr/src/app/node_modules/aas-core/package.json
ENV NODE_LOG=./log/debug.log
Expand Down
96 changes: 70 additions & 26 deletions create-app-info.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,",
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft",
* zur Foerderung der angewandten Forschung e.V.",
*
*****************************************************************************/

import { readFile, writeFile, readdir } from 'fs/promises';
import path from 'path';
import { existsSync } from 'fs';
Expand All @@ -12,6 +20,7 @@ interface Package {
homepage: string;
license: string;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
}

interface ApplicationInfo {
Expand All @@ -34,21 +43,37 @@ interface Library {
}

const __dirname = dirname(fileURLToPath(import.meta.url));
const nodeModulesFolder = join(__dirname, 'node_modules');

const replacements = new Map<string, string>([
['@angular/animations', 'oss/@angular/LICENSE.txt'],
['@angular/common', 'oss/@angular/LICENSE.txt'],
['@angular/compiler', 'oss/@angular/LICENSE.txt'],
['@angular/compiler-cli', 'oss/@angular/LICENSE.txt'],
['@angular/core', 'oss/@angular/LICENSE.txt'],
['@angular/forms', 'oss/@angular/LICENSE.txt'],
['@angular/localize', 'oss/@angular/LICENSE.txt'],
['@angular/platform-browser', 'oss/@angular/LICENSE.txt'],
['@angular/platform-browser-dynamic', 'oss/@angular/LICENSE.txt'],
['@angular/router', 'oss/@angular/LICENSE.txt'],
['@ngx-translate/core', 'oss/@ngx-translate/core/LICENSE.txt'],
['@ngx-translate/http-loader', 'oss/@ngx-translate/http-loader/LICENSE.txt'],
]);

const exclude = new Set(['aas-core', 'aas-lib', 'aas-portal', 'aas-server', 'fhg-jest']);

await main();

async function main(): Promise<void> {
const project: Package = await read(resolve(__dirname, 'package.json'));
const file = resolve(__dirname, 'projects/aas-server/app-info.json');
const file = resolve(__dirname, 'projects/aas-server/src/assets/app-info.json');
const appInfo = await read<ApplicationInfo>(file);

appInfo.name = project.name;
appInfo.version = project.version;
appInfo.description = project.description;
appInfo.author = project.author;
appInfo.homepage = project.homepage;
appInfo.license = project.license;

appInfo.libraries = await readLibrariesAsync(project);

await write(file, appInfo);
Expand All @@ -64,41 +89,60 @@ function write(file: string, data: object): Promise<void> {

async function readLibrariesAsync(project: Package): Promise<Library[]> {
const libraries: Library[] = [];
const nodeModulesFolder = join(__dirname, 'node_modules');
if (existsSync(nodeModulesFolder)) {
for (const name in project.dependencies) {
const packageFile = join(nodeModulesFolder, name, 'package.json');
if (existsSync(packageFile)) {
try {
const pkg = JSON.parse((await readFile(packageFile)).toString());
libraries.push({
name: pkg.name,
version: pkg.version,
description: pkg.description,
license: pkg.license,
licenseText: await loadLicenseText(nodeModulesFolder, name),
homepage: pkg.homepage,
});
} catch (error) {
console.error(error);
}
}
await readLibraryAsync(name, libraries);
}

for (const name in project.devDependencies) {
await readLibraryAsync(name, libraries);
}
}

libraries.sort((a, b) => a.name.localeCompare(b.name));

return libraries;
}

async function readLibraryAsync(name: string, libraries: Library[]): Promise<void> {
if (exclude.has(name)) {
return;
}

const packageFile = join(nodeModulesFolder, name, 'package.json');
if (existsSync(packageFile)) {
try {
const pkg = JSON.parse((await readFile(packageFile)).toString());
libraries.push({
name: pkg.name,
version: pkg.version,
description: pkg.description,
license: pkg.license,
licenseText: await loadLicenseText(nodeModulesFolder, name),
homepage: pkg.homepage,
});
} catch (error) {
console.error(error);
}
}
}

async function loadLicenseText(nodeModulesFolder: string, packageName: string): Promise<string> {
packageName = packageName.split('/')[0];
const folder = join(nodeModulesFolder, packageName);
for (const file of await readdir(folder, { withFileTypes: true, recursive: true })) {
if (file.isFile()) {
if (path.basename(file.name, path.extname(file.name)).toLowerCase() === 'license') {
return (await readFile(join(file.parentPath, file.name))).toString();
const value = replacements.get(packageName);
if (value) {
return (await readFile(join(__dirname, value))).toString();
} else {
const folder = join(nodeModulesFolder, packageName);
for (const file of await readdir(folder, { withFileTypes: true, recursive: true })) {
if (file.isFile()) {
if (path.basename(file.name, path.extname(file.name)).toLowerCase() === 'license') {
return (await readFile(join(file.parentPath, file.name))).toString();
}
}
}
}

console.warn(`${packageName} has no license file.`);

return '';
}
21 changes: 21 additions & 0 deletions oss/@angular/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010-2024 Google LLC. https://angular.io/license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions oss/@ngx-translate/core/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2023 Olivier Combe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions oss/@ngx-translate/http-loader/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2018 Olivier Combe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Web-based visualization and control of asset administration shells.",
"type": "module",
"scripts": {
"tsoa": "npm run tsoa -w aas-server",
"create-app-info": "node --no-warnings --loader ts-node/esm create-app-info.ts",
"tsoa": "npm run tsoa -w=ass-server",
"start": "docker build -f Dockerfile -t aasportal . && docker run -d --name AASPortal -p 80:80 --restart=always aasportal",
"header": "node --no-warnings --loader ts-node/esm copyright-header.ts",
"coverage": "node --no-warnings --loader ts-node/esm coverage-summary.ts",
Expand All @@ -15,14 +16,13 @@
"tsc": "npm run tsc -ws",
"build": "npm run build -ws",
"build:debug": "npm run build:debug -ws",
"lib:build": "npm run build -w aas-core -w aas-lib",
"lib:build:debug": "npm run build:debug -w aas-core -w aas-lib",
"aas-portal:build": "npm run build -w aas-core -w aas-lib -w aas-portal",
"aas-portal:build:debug": "npm run build:build -w aas-core -w aas-lib -w aas-portal",
"aas-server:build": "npm run build -w aas-core -w aas-server",
"aas-server:build:debug": "npm run build:debug -w aas-core -w aas-server",
"serve": "npm run build && node --env-file projects/aas-server/.env projects/aas-server/dist/aas-server.js",
"create-app-info": "node --no-warnings --loader ts-node/esm create-app-info.ts"
"lib:build": "npm run build -w=ass-core -w=ass-lib",
"lib:build:debug": "npm run build:debug -w=ass-core -w=ass-lib",
"aas-portal:build": "npm run build -w=ass-core -w=ass-lib -w=ass-portal",
"aas-portal:build:debug": "npm run build:build -w=ass-core -w=ass-lib -w=ass-portal",
"aas-server:build": "npm run build -w=ass-core -w=ass-server",
"aas-server:build:debug": "npm run build:debug -w=ass-core -w=ass-server",
"serve": "npm run build && node --env-file projects/aas-server/.env projects/aas-server/dist/aas-server.js"
},
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions projects/aas-core/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ export interface ErrorData {
/** Provides information about a 3rd-party package. */
export interface Library {
name: string;
version?: string;
description?: string;
license?: string;
version: string;
description: string;
license: string;
licenseText: string;
homepage?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,9 @@
!
!---------------------------------------------------------------------------->

<table class="table table-sm table-striped table-borderless">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" translate>COLUMN_PACKAGE</th>
<th scope="col" translate>COLUMN_VERSION</th>
<th scope="col" translate>COLUMN_LICENSE</th>
<th scope="col" translate>COLUMN_DESCRIPTION</th>
</tr>
</thead>
<tbody>
<div>
@for (library of libraries(); track library.name) {
<tr>
<th scope="row">{{library.id}}</th>
<td [noWrap]="true">
@if (library.homepage) {
<a target="_blank" [href]="library.homepage">{{library.name}}</a>
} @else {
<div class="text-nowrap">{{library.name}}</div>
}
</td>
<td [noWrap]="true">{{library.version}}</td>
<td [noWrap]="true">{{library.license}}</td>
<td [noWrap]="true">{{library.description}}</td>
</tr>
<h3>{{library.name}}</h3>
<pre>{{library.licenseText}}</pre>
}
</tbody>
<tbody>
<td [colSpan]="5">
@if (pageSize() > 0 && size > pageSize) {
<div class="d-flex align-items-start">
<ngb-pagination [collectionSize]="size()" [(page)]="page" [pageSize]="pageSize()" size="sm">
</ngb-pagination>
</div>
}
</td>
</tbody>
</table>
</div>
Loading

0 comments on commit cfa1daa

Please sign in to comment.