Skip to content

Commit

Permalink
add license banner for ui packages (#184)
Browse files Browse the repository at this point in the history
* feat: add license banner for translators/dashboard/terminal/xterm-addon-overlay/xterm-addon-zmodem

Signed-off-by: warjiang <[email protected]>

* chore: ignore license check for node_modules、husky

Signed-off-by: warjiang <[email protected]>

* ci: switch to turbo build

Signed-off-by: warjiang <[email protected]>

---------

Signed-off-by: warjiang <[email protected]>
  • Loading branch information
warjiang authored Feb 5, 2025
1 parent a69df28 commit be1beb1
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
echo "Start build"
pnpm --version
cd ui
pnpm install --filter @karmada/dashboard
pnpm run dashboard:build
pnpm install
pnpm turbo build
build-bin:
name: build-bin
runs-on: ubuntu-22.04
Expand Down
15 changes: 15 additions & 0 deletions hack/karmada-license.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright {{year}} The Karmada Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2 changes: 2 additions & 0 deletions hack/verify-license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ missing_license_header_files="$($ADDLICENSE_BIN \
-ignore "**/*.yml" \
-ignore "**/*.json" \
-ignore ".idea/**" \
-ignore "**/*/node_modules/**" \
-ignore "ui/.husky/**" \
.)" || true

if [[ "$missing_license_header_files" ]]; then
Expand Down
5 changes: 3 additions & 2 deletions ui/apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
]
},
"dependencies": {
"@karmada/dashboard": "link:",
"@karmada/i18n-tool": "link:",
"@karmada/i18n-tool": "workspace:*",
"@karmada/utils": "workspace:*",
"@monaco-editor/react": "^4.6.0",
"@tanstack/react-query": "^5.59.8",
"@uidotdev/usehooks": "^2.4.1",
Expand Down Expand Up @@ -65,6 +65,7 @@
"tailwindcss": "^3.4.13",
"typescript": "^5.6.3",
"vite": "^5.4.8",
"vite-plugin-banner": "^0.8.0",
"vite-plugin-dynamic-base": "^1.1.0",
"vite-plugin-svgr": "^4.2.0"
}
Expand Down
5 changes: 5 additions & 0 deletions ui/apps/dashboard/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import path from 'path';
import { dynamicBase } from 'vite-plugin-dynamic-base';
import banner from 'vite-plugin-banner';
import { getLicense } from '@karmada/utils';

const replacePathPrefixPlugin = (): Plugin => {
return {
Expand All @@ -34,10 +36,13 @@ const replacePathPrefixPlugin = (): Plugin => {

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const license = getLicense();

const env = loadEnv(mode, process.cwd(), '');
return {
base: process.env.NODE_ENV === 'development' ? '' : '/static',
plugins: [
banner(license) as Plugin,
react(),
svgr(),
replacePathPrefixPlugin(),
Expand Down
1 change: 1 addition & 0 deletions ui/packages/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@karmada/xterm-addon-overlay": "workspace:*",
"@karmada/xterm-addon-zmodem": "workspace:*",
"@karmada/utils": "workspace:*",
"@xterm/addon-canvas": "^0.7.0",
"@xterm/addon-clipboard": "^0.1.0",
"@xterm/addon-fit": "^0.10.0",
Expand Down
10 changes: 9 additions & 1 deletion ui/packages/terminal/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ limitations under the License.
*/

import { defineConfig } from 'tsup';
import { getLicense } from '@karmada/utils';

const license = getLicense();

export default defineConfig({
entry: ['src/index.tsx'],
Expand All @@ -23,5 +26,10 @@ export default defineConfig({
clean: true,
format: ['cjs', 'esm'],
// external: ['react'],
dts: true,
dts: {
banner: license,
},
banner: {
js: license,
},
});
3 changes: 2 additions & 1 deletion ui/packages/translators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"got": "^14.4.2",
"openai": "^4.63.0"
"openai": "^4.63.0",
"@karmada/utils": "workspace:*"
}
}
5 changes: 5 additions & 0 deletions ui/packages/translators/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ limitations under the License.
*/

import { defineConfig } from 'tsup';
import {getLicense} from '@karmada/utils';

const license = getLicense()
export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
clean: true,
format: ['cjs', 'esm'],
dts: false,
banner: {
js: license
}
});
5 changes: 5 additions & 0 deletions ui/packages/utils/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
build
coverage
dist
pnpm-*
7 changes: 7 additions & 0 deletions ui/packages/utils/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"endOfLine": "auto"
}
27 changes: 27 additions & 0 deletions ui/packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@karmada/utils",
"version": "1.0.0",
"publishConfig": {
"access": "public"
},
"description": "",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
},
"types": "dist/index.d.ts",
"scripts": {
"prepublish": "tsup --config ./tsup.config.ts",
"build": "tsup --config ./tsup.config.ts"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,json,css,md}": [
"prettier --write"
]
},
"keywords": [],
"author": "",
"license": "ISC"
}
41 changes: 41 additions & 0 deletions ui/packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2025 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import * as path from 'path';
import * as fs from 'fs';
import { fileURLToPath } from 'url';

/**
* return karmada license content according to year.
* @param year optional, if not set year, use currentYear instead
*/
export function getLicense(year: string = ''): string {
const __filename = fileURLToPath(import.meta.url);
const currentDir = path.dirname(__filename);
// __filename in dist dir
const workspaceRootDir = path.resolve(currentDir, '../../../../');
const licenseTplPath = path.join(
workspaceRootDir,
'./hack/karmada-license.tpl',
);
const tplContent = fs.readFileSync(licenseTplPath).toString();

let _year = year;
if (_year === '') {
_year = new Date().getFullYear().toString();
}
return tplContent.replace(/\{\{year\}\}/g, _year);
}
25 changes: 25 additions & 0 deletions ui/packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions ui/packages/utils/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
26 changes: 26 additions & 0 deletions ui/packages/utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2025 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
clean: true,
dts: true,
format: ['cjs', 'esm'],
});
3 changes: 3 additions & 0 deletions ui/packages/xterm-addon-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
],
"author": "",
"license": "ISC",
"dependencies": {
"@karmada/utils": "workspace:*"
},
"peerDependencies": {
"@xterm/xterm": "^5.0.0"
}
Expand Down
9 changes: 8 additions & 1 deletion ui/packages/xterm-addon-overlay/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ limitations under the License.
*/

import { defineConfig } from 'tsup';
import { getLicense } from '@karmada/utils';

const license = getLicense();
export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
clean: true,
format: ['cjs', 'esm'],
dts: true,
dts: {
banner: license,
},
banner: {
js: license,
},
});
2 changes: 1 addition & 1 deletion ui/packages/xterm-addon-zmodem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@karmada/xterm-addon-zmodem": "link:",
"@karmada/utils": "workspace:*",
"file-saver": "^2.0.5",
"trzsz": "^1.1.5",
"zmodem.js": "^0.1.10"
Expand Down
10 changes: 9 additions & 1 deletion ui/packages/xterm-addon-zmodem/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ limitations under the License.
*/

import { defineConfig } from 'tsup';
import { getLicense } from '@karmada/utils';

const license = getLicense();

export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: true,
clean: true,
format: ['cjs', 'esm'],
dts: true,
dts: {
banner: license,
},
banner: {
js: license,
},
});
Loading

0 comments on commit be1beb1

Please sign in to comment.