feat: include font licenses in the licenses section

This commit is contained in:
Thea Schöbl
2022-08-08 14:05:30 +00:00
committed by Rainer Killinger
parent a4de628495
commit 82479f463c
10 changed files with 113 additions and 71 deletions

8
additional-licenses.json Normal file
View File

@@ -0,0 +1,8 @@
{
"barlow": {
"repository": "https://github.com/jpt/barlow",
"licenses": "OFL-1.1",
"licenseFile": "./src/assets/fonts/barlow/OFL.txt",
"publisher": "JPT"
}
}

View File

@@ -31,7 +31,7 @@
"docker:serve": "sudo docker run -p 8100:8100 -p 35729:35729 -p 53703:53703 -v $PWD:/app -it registry.gitlab.com/openstapps/app bash -c \"npm run start:external\"",
"documentation": "compodoc -p tsconfig.json -d docs",
"e2e": "ng e2e",
"licenses": "license-checker --json > src/assets/about/licenses.json && node scripts/accumulate-licenses.mjs",
"licenses": "license-checker --json > src/assets/about/licenses.json && ts-node ./scripts/accumulate-licenses.ts",
"lint": "ng lint",
"lint:fix": "eslint --fix -c .eslintrc.json --ignore-path .eslintignore --ext .ts,.html src/",
"ng": "ng",

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {initial, mapValues, omit, pickBy, merge, last} from 'lodash-es';
import fs from 'fs';
function accumulateFile(path) {
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
const dependencies = merge(packageJson.dependencies, packageJson.devDependencies);
fs.writeFileSync(path, JSON.stringify(
mapValues(
pickBy(
JSON.parse(fs.readFileSync(path)),
(value, key) => {
const parts = key.split('@');
return dependencies[initial(parts).join('@')] === last(parts);
},
),
value => ({
licenseText: value.licenseFile && fs.readFileSync(value.licenseFile, 'utf8'),
...omit(value, 'licenseFile'),
})
)
));
}
accumulateFile('./src/assets/about/licenses.json');

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import fs from 'fs';
import {omit} from '../src/app/_helpers/collections/omit';
import {pickBy} from '../src/app/_helpers/collections/pick';
/**
* accumulate and transform licenses based on two license files
*/
function accumulateFile(path: string, additionalLicensesPath: string) {
const packageJson = JSON.parse(fs.readFileSync('./package.json').toString());
const dependencies = packageJson.dependencies;
console.log(`Accumulating licenses from ${path}`);
fs.writeFileSync(
path,
JSON.stringify(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Object.entries<any>({
...pickBy(
JSON.parse(fs.readFileSync(path).toString()),
(_, key: string) => {
const parts = key.split('@');
return (
dependencies[parts.slice(0, -1).join('@')] ===
parts[parts.length - 1]
);
},
),
...JSON.parse(fs.readFileSync(additionalLicensesPath).toString()),
})
.map(([key, value]) => ({
licenseText:
value.licenseFile && fs.readFileSync(value.licenseFile, 'utf8'),
name: key,
...omit(value, 'licenseFile', 'path'),
}))
.sort((a, b) => a.name.localeCompare(b.name)),
),
);
}
accumulateFile(
'./src/assets/about/licenses.json',
'./additional-licenses.json',
);

3
scripts/tsconfig.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": "../node_modules/@openstapps/configuration/tsconfig.json"
}

View File

@@ -27,3 +27,18 @@ export function pick<T extends object, U extends keyof T>(
return accumulator;
}, {} as Pick<T, U>);
}
/**
* Pick a set of properties from an object using a predicate function
*/
export function pickBy<T extends object, U extends keyof T>(
object: T,
predicate: (value: T[U], key: U) => boolean,
): Pick<T, U> {
return (Object.keys(object) as U[]).reduce((accumulator, key) => {
if (predicate(object[key], key)) {
accumulator[key] = object[key];
}
return accumulator;
}, {} as Pick<T, U>);
}

View File

@@ -25,7 +25,6 @@ export interface License {
publisher?: string;
email?: string;
url?: string;
path: string;
licenseText?: string;
}
@@ -58,12 +57,6 @@ export class AboutLicensesComponent implements OnInit {
}
loadLicenses(): License[] {
return Object.values(licensesFile as Record<string, object>).map(
(value, key) =>
({
name: key,
...value,
} as unknown as License),
);
return licensesFile as License[];
}
}

View File

@@ -1,21 +1,22 @@
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {SCAboutPage, SCAppConfiguration} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import packageJson from '../../../../../package.json';
@Component({
selector: 'about-page',
@@ -25,6 +26,8 @@ import {ConfigProvider} from '../../config/config.provider';
export class AboutPageComponent implements OnInit {
content: SCAboutPage;
version = packageJson.version;
constructor(
private readonly route: ActivatedRoute,
private readonly configProvider: ConfigProvider,

View File

@@ -1,16 +1,16 @@
<!--
~ Copyright (C) 2021 StApps
~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3.
~ Copyright (C) 2022 StApps
~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~ This program is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <https://www.gnu.org/licenses/>.
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <https://www.gnu.org/licenses/>.
-->
<ion-header>
@@ -32,6 +32,7 @@
</ion-toolbar>
</ion-header>
<ion-content *ngIf="content">
<pre>StApps v{{ version }}</pre>
<about-page-content
*ngFor="let element of content.content"
[content]="element"

File diff suppressed because one or more lines are too long