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

Add automatic JS license generation #11810

Merged
merged 9 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 0 additions & 2 deletions integrations/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func TestLinksNoLogin(t *testing.T) {
"/user/forgot_password",
"/api/swagger",
"/api/v1/swagger",
// TODO: follow this page and test every link
"/vendor/librejs.html",
}

for _, link := range links {
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ user_profile_and_more = Profile and Settings…
signed_in_as = Signed in as
enable_javascript = This website works better with JavaScript.
toc = Table of Contents
licenses = Licenses

username = Username
email = Email Address
Expand Down
113 changes: 106 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"jquery": "3.5.1",
"jquery.are-you-sure": "1.9.0",
"less-loader": "6.1.0",
"license-webpack-plugin": "2.2.0",
"mini-css-extract-plugin": "0.9.0",
"monaco-editor": "0.20.0",
"monaco-editor-webpack-plugin": "1.9.0",
Expand All @@ -48,7 +49,8 @@
"webpack-fix-style-only-entries": "0.4.0",
"workbox-routing": "5.1.3",
"workbox-strategies": "5.1.3",
"worker-loader": "2.0.0"
"worker-loader": "2.0.0",
"wrap-ansi": "7.0.0"
},
"devDependencies": {
"eslint": "7.2.0",
Expand Down
126 changes: 0 additions & 126 deletions public/vendor/librejs.html

This file was deleted.

2 changes: 1 addition & 1 deletion templates/base/footer_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{end}}
</div>
</div>
<a href="{{StaticUrlPrefix}}/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a>
<a href="{{StaticUrlPrefix}}/js/licenses.txt">{{.i18n.Tr "licenses"}}</a>
{{if .EnableSwagger}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}}
<a target="_blank" rel="noopener noreferrer" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
{{template "custom/extra_links_footer" .}}
Expand Down
2 changes: 1 addition & 1 deletion templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
THE SOFTWARE.
---
Licensing information for additional javascript libraries can be found at:
{{StaticUrlPrefix}}/vendor/librejs.html
{{StaticUrlPrefix}}/js/licenses.txt

@licend The above is the entire license notice
for the JavaScript code in this page.
Expand Down
30 changes: 30 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cssnano = require('cssnano');
const fastGlob = require('fast-glob');
const wrapAnsi = require('wrap-ansi');
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
Expand All @@ -11,6 +12,7 @@ const TerserPlugin = require('terser-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const {statSync} = require('fs');
const {resolve, parse} = require('path');
const {LicenseWebpackPlugin} = require('license-webpack-plugin');
const {SourceMapDevToolPlugin} = require('webpack');

const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
Expand Down Expand Up @@ -241,6 +243,34 @@ module.exports = {
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].worker.js',
}),
new LicenseWebpackPlugin({
outputFilename: 'js/licenses.txt',
perChunkOutput: false,
addBanner: false,
skipChildCompilers: true,
modulesDirectories: [
resolve(__dirname, 'node_modules'),
],
additionalModules: [
{
name: 'fomantic-ui',
directory: resolve(__dirname, 'node_modules/fomantic-ui'),
},
],
renderLicenses: (modules) => {
const line = '-'.repeat(80);
return modules.map((module) => {
const {name, version} = module.packageJson;
const {licenseId, licenseText} = module;
const body = wrapAnsi(licenseText || '', 80);
return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
}).join('\n');
},
stats: {
warnings: false,
errors: true,
},
}),
],
performance: {
hints: false,
Expand Down