Skip to content

Commit

Permalink
added licenses back
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jan 26, 2024
1 parent 9c2b096 commit 2cc6fa9
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 197 deletions.
40 changes: 40 additions & 0 deletions Website/licensefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");
const package = require(path.resolve(__dirname, "package.json"));

const NODE_MODULES_PATH = path.resolve(__dirname, "node_modules");
const OUTPUT = path.resolve(__dirname, "src", "util", "licenses.json");
const allDependencies = [];

Object.keys(package.dependencies).forEach((dependency) => {
const depPackage = require(path.resolve(__dirname, NODE_MODULES_PATH, dependency, "package.json"));

if (depPackage) {
function getSource() {
if (depPackage.repository) {
return depPackage.repository.url ? depPackage.repository.url : null;
} else {
return null;
}
}

function getAuthor() {
if (depPackage.author) {
return depPackage.author.name ? depPackage.author.name : null;
} else {
return null;
}
}

allDependencies.push({
name: depPackage.name,
author: getAuthor(),
license: depPackage.license,
description: depPackage.description,
version: depPackage.version,
source: `https://www.npmjs.com/package/${depPackage.name}`,
});
}
});

fs.writeFileSync(OUTPUT, JSON.stringify(allDependencies, null, 2));
11 changes: 6 additions & 5 deletions Website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
"author": "Der_Googler",
"license": "GPL-3.0",
"scripts": {
"start:dev": "webpack-dev-server --open --config webpack.dev.ts",
"start:prod": "webpack-dev-server --open --config webpack.prod.ts",
"start:dev": "npm run licensefix && webpack-dev-server --open --config webpack.dev.ts",
"start:prod": "npm run licensefix && webpack-dev-server --open --config webpack.prod.ts",
"web:dev": "webpack --config webpack.dev.ts",
"web:prod": "webpack --config webpack.prod.ts",
"web:dev-app": "npm run web:dev && npm run assetfix:android-clean && npm run assetfix:android-build",
"web:prod-app": "npm run web:prod && npm run assetfix:android-clean && npm run assetfix:android-build",
"web:dev-app": "npm run licensefix && npm run web:dev && npm run assetfix:android-clean && npm run assetfix:android-build",
"web:prod-app": "npm run licensefix && npm run web:prod && npm run assetfix:android-clean && npm run assetfix:android-build",
"assetfix:android-build": "node assetfix.js android --build",
"assetfix:android-clean": "node assetfix.js android --clean",
"assetfix:web-build": "node assetfix.js web --build",
"assetfix:web-clean": "node assetfix.js web --clean"
"assetfix:web-clean": "node assetfix.js web --clean",
"licensefix": "node licensefix.js"
},
"resolutions": {
"react": "^18.2.0",
Expand Down
125 changes: 125 additions & 0 deletions Website/src/activitys/LicensesActivity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { Page } from "@Components/onsenui/Page";
import { Toolbar } from "@Components/onsenui/Toolbar";
import { useActivity } from "@Hooks/useActivity";
import { useStrings } from "@Hooks/useStrings";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import Card from "@mui/material/Card";
import Stack from "@mui/material/Stack";
import { useSettings } from "@Hooks/useSettings";
import FlatList from "flatlist-react";

import li from "@Util/licenses.json";
import { os } from "@Native/Os";
import { useTheme } from "@Hooks/useTheme";
import FetchTextActivity from "./FetchTextActivity";

const DepCard = (props: { dep: (typeof li)[0] }) => {
const { theme } = useTheme();
const { strings } = useStrings();
const { context } = useActivity();
const dep = props.dep;

const handleOpenSource = () => {
os.open(dep.source, {
target: "_blank",
features: {
color: theme.palette.primary.main,
},
});
};

const handleOpenLicense = () => {
fetch(`https://spdx.org/licenses/${dep.license}.json`)
.then((res) => {
if (res.status === 200) {
return res.json();
} else {
throw new Error("Fetching license failed");
}
})
.then((json: LicenseSPX) => {
context.pushPage({
component: FetchTextActivity,
key: "license_" + dep.license,
extra: {
raw_data: json.licenseText,
modulename: json.name,
},
});
})
.catch((err) => {
os.toast(err, Toast.LENGTH_SHORT);
});
};

return (
<Card sx={{ p: 2 }}>
<Stack direction="column" justifyContent="center" alignItems="stretch" spacing={0}>
<Stack direction="row" justifyContent="space-between" alignItems="center" spacing={2}>
<Typography variant="caption" display="block">
{dep.author}
</Typography>
<Typography variant="overline" display="block">
{dep.license}
</Typography>
</Stack>
<Stack direction="column" justifyContent="center" alignItems="flex-start" spacing={0.5}>
<Typography variant="h5" gutterBottom>
{dep.name}
</Typography>
<Typography variant="caption" display="block">
{dep.version}
</Typography>
<Typography variant="subtitle2" gutterBottom>
{dep.description}
</Typography>
</Stack>
</Stack>
<Stack direction="row" justifyContent="flex-start" alignItems="center" spacing={1} mt={1}>
<Button disableElevation variant="contained" size="small" onClick={handleOpenLicense}>
{strings("license")}
</Button>
<Button disableElevation variant="outlined" size="small" onClick={handleOpenSource}>
{strings("source")}
</Button>
</Stack>
</Card>
);
};

const LicensesActivity = () => {
const { strings } = useStrings();
const { settings } = useSettings();
const { context } = useActivity();
const { theme } = useTheme();

const renderToolbar = () => {
return (
<Toolbar modifier="noshadow">
<Toolbar.Left>
<Toolbar.BackButton onClick={context.popPage} />
</Toolbar.Left>
<Toolbar.Center>{strings("licenses")}</Toolbar.Center>
</Toolbar>
);
};

return (
<Page renderToolbar={renderToolbar}>
<Page.RelativeContent zeroMargin>
<FlatList
list={li}
renderItem={(dep) => <DepCard dep={dep} />}
renderOnScroll
display={{
row: true,
rowGap: "8px",
}}
/>
</Page.RelativeContent>
</Page>
);
};

export default LicensesActivity;
11 changes: 4 additions & 7 deletions Website/src/activitys/fragments/DrawerFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { configureSample } from "@Util/configure-sample";
import { dapiSample } from "@Util/dapi-sample";
import ModConfActivity from "@Activitys/ModConfActivity";
import ConfigurePlaygroundActivity from "@Activitys/ConfigurePlaygroundActivity";
import LicensesActivity from "@Activitys/LicensesActivity";

type Props = {
renderToolbar: () => JSX.Element;
Expand Down Expand Up @@ -122,22 +123,18 @@ export const DrawerFragment = (props: Props) => {
hide();
}}
>
<StyledListItemText primary={"About"} />
<StyledListItemText primary={strings("about")} />
</ListItemButton>
<ListItemButton
onClick={() => {
pushPage({
component: FetchTextActivity,
component: LicensesActivity,
key: "license",
extra: {
title: "License",
url: "https://raw.githubusercontent.com/wiki/DerGoogler/MMRL/License.md",
},
});
hide();
}}
>
<StyledListItemText primary={"License"} />
<StyledListItemText primary={strings("licenses")} />
</ListItemButton>
<ListItemButton
onClick={() => {
Expand Down
1 change: 1 addition & 0 deletions Website/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"search": "Suche",
"updates": "Updates",
"versions": "Versionen",
"licenses": "Lizenzen",
"license": "Lizenz",
"search_modules": "Module durchsuchen",
"settings": "Einstellungen",
Expand Down
1 change: 1 addition & 0 deletions Website/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"search": "Search",
"updates": "Updates",
"versions": "Versions",
"licenses": "Licenses",
"license": "License",
"search_modules": "Search modules",
"settings": "Settings",
Expand Down
24 changes: 24 additions & 0 deletions Website/src/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,30 @@ declare global {
changelog: string;
}

export interface LicenseSPX {
isDeprecatedLicenseId: boolean
isFsfLibre: boolean
licenseText: string
standardLicenseTemplate: string
name: string
licenseId: string
crossRef: CrossRef[]
seeAlso: string[]
isOsiApproved: boolean
licenseTextHtml: string
}

export interface CrossRef {
match: string
url: string
isValid: boolean
isLive: boolean
timestamp: string
isWayBackLink: boolean
order: number
}


// OnsenUI Types
/**
* @extends {Event}
Expand Down
Loading

0 comments on commit 2cc6fa9

Please sign in to comment.