Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ cpu.out
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
/VERSION
/.air
/.go-licenses

# Snapcraft
snap/.snapcraft/
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GO_LICENSES_PACKAGE ?= github.com/google/[email protected]

DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
Expand Down Expand Up @@ -114,13 +115,16 @@ SVG_DEST_DIR := public/img/svg

AIR_TMP_DIR := .air

GO_LICENSE_TMP_DIR := .go-licenses
GO_LICENSE_FILE := assets/go-licenses.json

TAGS ?=
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags

TEST_TAGS ?= sqlite sqlite_unlock_notify

TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR)
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR)

GO_DIRS := cmd tests models modules routers build services tools

Expand Down Expand Up @@ -199,6 +203,7 @@ help:
@echo " - generate-swagger generate the swagger spec from code comments"
@echo " - swagger-validate check if the swagger spec is valid"
@echo " - golangci-lint run golangci-lint linter"
@echo " - go-licenses regenerate go-licenses.txt"
@echo " - vet examines Go source code and reports suspicious constructs"
@echo " - tidy run go mod tidy"
@echo " - test[\#TestSpecificName] run unit test"
Expand Down Expand Up @@ -407,6 +412,12 @@ tidy-check: tidy
exit 1; \
fi

.PHONY: go-licenses
go-licenses:
-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path="$(GO_LICENSE_TMP_DIR)"
node build/generate-go-licenses.js "$(GO_LICENSE_TMP_DIR)" "$(GO_LICENSE_FILE)"
rm -rf "$(GO_LICENSE_TMP_DIR)"

generate-ini-sqlite:
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
Expand Down
762 changes: 762 additions & 0 deletions assets/go-licenses.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions build/generate-go-licenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node
import fastGlob from 'fast-glob';
import {fileURLToPath} from 'url';
import {readFileSync, writeFileSync} from 'fs';
import wrapAnsi from 'wrap-ansi';
import {join, dirname} from 'path';

const base = process.argv[2];
const out = process.argv[3];

function exit(err) {
if (err) console.error(err);
process.exit(err ? 1 : 0);
}

async function main() {
const data = fastGlob.sync('**/*', {
cwd: fileURLToPath(new URL(`../${base}`, import.meta.url)),
}).filter((path) => {
return /\/((UN)?LICEN(S|C)E|COPYING|NOTICE)/i.test(path);
}).sort().map((path) => {
return {
name: dirname(path),
body: wrapAnsi(readFileSync(join(base, path), 'utf8') || '', 80)
};
});
writeFileSync(out, JSON.stringify(data, null, 2));
}

main().then(exit).catch(exit);
13 changes: 10 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import EsBuildLoader from 'esbuild-loader';
import {parse, dirname} from 'path';
import webpack from 'webpack';
import {fileURLToPath} from 'url';
import {readFileSync} from 'fs';

const {VueLoaderPlugin} = VueLoader;
const {ESBuildMinifyPlugin} = EsBuildLoader;
Expand Down Expand Up @@ -205,10 +206,16 @@ export default {
outputFilename: 'js/licenses.txt',
outputWriter: ({dependencies}) => {
const line = '-'.repeat(80);
return dependencies.map((module) => {
const {name, version, licenseName, licenseText} = module;
const goModules = JSON.parse(readFileSync('assets/go-licenses.json', 'utf8'));
const jsModules = dependencies.map(({name, version, licenseName, licenseText}) => {
const body = wrapAnsi(licenseText || '', 80);
return `${line}\n${name}@${version} - ${licenseName}\n${line}\n${body}`;
return {name, version, licenseName, body};
});

const modules = [...goModules, ...jsModules].sort((a, b) => a.name.localeCompare(b.name));
return modules.map(({name, version, licenseName, body}) => {
const title = licenseName ? `${name}@${version} - ${licenseName}` : name;
return `${line}\n${title}\n${line}\n${body}`;
}).join('\n');
},
override: {
Expand Down