diff --git a/Dockerfile.mce.prow b/Dockerfile.mce.prow index 5c05d49612b..105fa28dc6f 100644 --- a/Dockerfile.mce.prow +++ b/Dockerfile.mce.prow @@ -8,8 +8,11 @@ RUN npm run build:plugin:mce FROM registry.ci.openshift.org/stolostron/builder:nodejs20-linux as backend WORKDIR /app/backend -COPY ./backend . +# Copy only package.json and package-lock.json so that the docker layer cache only changes if those change +# This will cause the npm ci to only rerun if the package.json or package-lock.json changes +COPY ./backend/package.json ./backend/package-lock.json ./ RUN npm ci --omit=optional +COPY ./backend . RUN npm run build FROM registry.ci.openshift.org/stolostron/builder:nodejs20-linux as production diff --git a/Dockerfile.prow b/Dockerfile.prow index d526b7d1171..46ae2373dd8 100644 --- a/Dockerfile.prow +++ b/Dockerfile.prow @@ -1,14 +1,9 @@ # Copyright Contributors to the Open Cluster Management project -FROM registry.ci.openshift.org/stolostron/builder:nodejs20-linux as frontend-packages +FROM registry.ci.openshift.org/stolostron/builder:nodejs20-linux as dynamic-plugin WORKDIR /app/frontend -# Copy only package.json and package-lock.json so that the docker cache hash only changes if those change -# This will cause the npm ci to only rerun if the package.json or package-lock.json changes -COPY ./frontend/package.json ./frontend/package-lock.json ./ -RUN npm ci --legacy-peer-deps COPY ./frontend . - -FROM frontend-packages as dynamic-plugin +RUN npm ci --legacy-peer-deps RUN npm run build:plugin:acm FROM registry.ci.openshift.org/stolostron/builder:nodejs20-linux as backend diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 26e24cc8179..7e4f957c281 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "frontend", "version": "0.0.1", + "workspaces": [ + "packages/*" + ], "dependencies": { "@apollo/client": "3.10.8", "@babel/runtime": "7.18.9", @@ -6940,6 +6943,14 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@stolostron/multicluster-sdk": { + "resolved": "packages/multicluster-sdk", + "link": true + }, + "node_modules/@stolostron/prettier-config": { + "resolved": "packages/prettier-config", + "link": true + }, "node_modules/@stolostron/react-data-view": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@stolostron/react-data-view/-/react-data-view-2.4.0.tgz", @@ -28100,6 +28111,7 @@ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, @@ -34095,6 +34107,22 @@ "dependencies": { "zen-observable": "0.8.15" } + }, + "packages/multicluster-sdk": { + "name": "@stolostron/multicluster-sdk", + "version": "0.1.0", + "license": "Apache-2.0", + "devDependencies": { + "prettier": "^3.2.5", + "typescript": "^5.6.3" + }, + "peerDependencies": { + "@openshift-console/dynamic-plugin-sdk": "1.0.0" + } + }, + "packages/prettier-config": { + "name": "@stolostron/prettier-config", + "version": "0.0.0" } }, "dependencies": { @@ -38822,6 +38850,16 @@ "@sinonjs/commons": "^3.0.0" } }, + "@stolostron/multicluster-sdk": { + "version": "file:packages/multicluster-sdk", + "requires": { + "prettier": "^3.2.5", + "typescript": "^5.6.3" + } + }, + "@stolostron/prettier-config": { + "version": "file:packages/prettier-config" + }, "@stolostron/react-data-view": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@stolostron/react-data-view/-/react-data-view-2.4.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 60ed658f115..b13fa5bf148 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,6 +13,7 @@ "build:plugin": "./scripts/checkPlugin.sh && cd plugins/${PLUGIN} && node ../../scripts/generatePluginPackage.js && TS_NODE_PROJECT=../../webpack.tsconfig.json webpack -c ../../webpack.plugin.ts --env plugin=$PLUGIN --mode production", "build:plugin:acm": "PLUGIN=acm npm run build:plugin", "build:plugin:mce": "PLUGIN=mce npm run build:plugin", + "build:workspaces": "npm run build --workspaces --if-present", "check": "npm run i18n && npm run prettier && npm run lint && npm run tsc", "check:fix": "npm run i18n:fix && npm run prettier:fix && npm run lint:fix && npm run tsc", "clean": "rm -rf coverage build", @@ -21,6 +22,7 @@ "jest:update-snapshot": "jest --updateSnapshot", "lint": "eslint src --ext .js,.jsx,.ts,.tsx --max-warnings=0", "lint:fix": "npm run lint -- --fix", + "postinstall": "npm run build:workspaces", "prettier": "prettier --check src public", "prettier:fix": "prettier --write src public", "i18n": "i18next --fail-on-warnings && git diff --exit-code public/locales/en/translation.json", @@ -364,11 +366,8 @@ "last 1 safari version" ] }, - "prettier": { - "printWidth": 120, - "tabWidth": 2, - "semi": false, - "singleQuote": true, - "trailingComma": "es5" - } + "prettier": "@stolostron/prettier-config", + "workspaces": [ + "packages/*" + ] } diff --git a/frontend/packages/multicluster-sdk/.gitignore b/frontend/packages/multicluster-sdk/.gitignore new file mode 100644 index 00000000000..7951405f85a --- /dev/null +++ b/frontend/packages/multicluster-sdk/.gitignore @@ -0,0 +1 @@ +lib \ No newline at end of file diff --git a/frontend/packages/multicluster-sdk/package.json b/frontend/packages/multicluster-sdk/package.json new file mode 100644 index 00000000000..d06baf2d59c --- /dev/null +++ b/frontend/packages/multicluster-sdk/package.json @@ -0,0 +1,40 @@ +{ + "name": "@stolostron/multicluster-sdk", + "version": "0.1.0", + "description": "Provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management.", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "files": [ + "lib" + ], + + "repository": { + "type": "git", + "url": "git+https://github.com/stolostron/console.git" + }, + "keywords": [ + "multicluster", + "RHACM", + "ACM", + "SDK", + "OpenShift", + "dynamic plugin", + "Red Hat" + ], + "license": "Apache-2.0", + "homepage": "https://github.com/stolostron/console/tree/main/frontend/packages/multicluster-sdk#readme", + "scripts": { + "build": "tsc --build", + "tsc": "tsc --no-emit", + "prettier": "prettier --check src", + "prettier:fix": "prettier --write src" + }, + "peerDependencies": { + "@openshift-console/dynamic-plugin-sdk": "1.x" + }, + "devDependencies": { + "prettier": "^3.2.5", + "typescript": "^5.6.3" + }, + "prettier": "@stolostron/prettier-config" +} diff --git a/frontend/src/plugin-extensions/extensions/ApplicationAction.ts b/frontend/packages/multicluster-sdk/src/extensions/ApplicationAction.ts similarity index 100% rename from frontend/src/plugin-extensions/extensions/ApplicationAction.ts rename to frontend/packages/multicluster-sdk/src/extensions/ApplicationAction.ts diff --git a/frontend/src/plugin-extensions/extensions/ApplicationListPageColumn.ts b/frontend/packages/multicluster-sdk/src/extensions/ApplicationListPageColumn.ts similarity index 100% rename from frontend/src/plugin-extensions/extensions/ApplicationListPageColumn.ts rename to frontend/packages/multicluster-sdk/src/extensions/ApplicationListPageColumn.ts diff --git a/frontend/src/plugin-extensions/extensions/OverviewTab.ts b/frontend/packages/multicluster-sdk/src/extensions/OverviewTab.ts similarity index 100% rename from frontend/src/plugin-extensions/extensions/OverviewTab.ts rename to frontend/packages/multicluster-sdk/src/extensions/OverviewTab.ts diff --git a/frontend/src/plugin-extensions/extensions/index.ts b/frontend/packages/multicluster-sdk/src/extensions/index.ts similarity index 100% rename from frontend/src/plugin-extensions/extensions/index.ts rename to frontend/packages/multicluster-sdk/src/extensions/index.ts diff --git a/frontend/packages/multicluster-sdk/src/index.ts b/frontend/packages/multicluster-sdk/src/index.ts new file mode 100644 index 00000000000..f5a51dae390 --- /dev/null +++ b/frontend/packages/multicluster-sdk/src/index.ts @@ -0,0 +1,3 @@ +/* Copyright Contributors to the Open Cluster Management project */ +export * from './extensions' +export * from './properties' diff --git a/frontend/src/plugin-extensions/properties/addActionProps.ts b/frontend/packages/multicluster-sdk/src/properties/addActionProps.ts similarity index 100% rename from frontend/src/plugin-extensions/properties/addActionProps.ts rename to frontend/packages/multicluster-sdk/src/properties/addActionProps.ts diff --git a/frontend/src/plugin-extensions/properties/addListColumnProps.ts b/frontend/packages/multicluster-sdk/src/properties/addListColumnProps.ts similarity index 100% rename from frontend/src/plugin-extensions/properties/addListColumnProps.ts rename to frontend/packages/multicluster-sdk/src/properties/addListColumnProps.ts diff --git a/frontend/src/plugin-extensions/properties/index.ts b/frontend/packages/multicluster-sdk/src/properties/index.ts similarity index 100% rename from frontend/src/plugin-extensions/properties/index.ts rename to frontend/packages/multicluster-sdk/src/properties/index.ts diff --git a/frontend/src/plugin-extensions/properties/overviewTabProps.ts b/frontend/packages/multicluster-sdk/src/properties/overviewTabProps.ts similarity index 100% rename from frontend/src/plugin-extensions/properties/overviewTabProps.ts rename to frontend/packages/multicluster-sdk/src/properties/overviewTabProps.ts diff --git a/frontend/packages/multicluster-sdk/tsconfig.json b/frontend/packages/multicluster-sdk/tsconfig.json new file mode 100644 index 00000000000..bf9f2760b4c --- /dev/null +++ b/frontend/packages/multicluster-sdk/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib", + "noEmit": false + }, + "include": ["src"] +} diff --git a/frontend/packages/prettier-config/index.js b/frontend/packages/prettier-config/index.js new file mode 100644 index 00000000000..0ac47f97961 --- /dev/null +++ b/frontend/packages/prettier-config/index.js @@ -0,0 +1,12 @@ +/** + * @type {import("prettier").Config} + */ +const config = { + "printWidth": 120, + "tabWidth": 2, + "semi": false, + "singleQuote": true, + "trailingComma": "es5", +}; + +export default config; \ No newline at end of file diff --git a/frontend/packages/prettier-config/package.json b/frontend/packages/prettier-config/package.json new file mode 100644 index 00000000000..8d7dff43fa0 --- /dev/null +++ b/frontend/packages/prettier-config/package.json @@ -0,0 +1,8 @@ +{ + "name": "@stolostron/prettier-config", + "version": "0.0.0", + "private": true, + "type": "module", + "exports": "./index.js", + "license": "Apache-2.0" +} diff --git a/frontend/src/plugin-extensions/handler.ts b/frontend/src/plugin-extensions/handler.ts index 24bf6a74f94..85046f036d6 100644 --- a/frontend/src/plugin-extensions/handler.ts +++ b/frontend/src/plugin-extensions/handler.ts @@ -1,7 +1,7 @@ /* Copyright Contributors to the Open Cluster Management project */ import { useResolvedExtensions } from '@openshift-console/dynamic-plugin-sdk' -import { isApplicationAction, isApplicationListColumn, isOverviewTab } from './extensions' -import { ApplicationActionProps, ApplicationListColumnProps } from './properties' +import { isApplicationAction, isApplicationListColumn, isOverviewTab } from '@stolostron/multicluster-sdk' +import { ApplicationActionProps, ApplicationListColumnProps } from '@stolostron/multicluster-sdk' import { AcmExtension } from './types' // Type guards diff --git a/frontend/src/plugin-extensions/types.ts b/frontend/src/plugin-extensions/types.ts index 9cc110e595d..ef49686e39b 100644 --- a/frontend/src/plugin-extensions/types.ts +++ b/frontend/src/plugin-extensions/types.ts @@ -1,7 +1,7 @@ /* Copyright Contributors to the Open Cluster Management project */ import { ResolvedExtension } from '@openshift-console/dynamic-plugin-sdk' -import { ApplicationActionProps, ApplicationListColumnProps } from './properties' -import { OverviewTab } from './extensions' +import { ApplicationActionProps, ApplicationListColumnProps } from '@stolostron/multicluster-sdk' +import { OverviewTab } from '@stolostron/multicluster-sdk' export type AcmExtension = Partial<{ applicationAction: ApplicationActionProps[] diff --git a/frontend/src/routes/Applications/Application.sharedmocks.tsx b/frontend/src/routes/Applications/Application.sharedmocks.tsx index fa93e4b7ac0..4b1256bd4e0 100644 --- a/frontend/src/routes/Applications/Application.sharedmocks.tsx +++ b/frontend/src/routes/Applications/Application.sharedmocks.tsx @@ -41,7 +41,7 @@ import { SubscriptionOperatorKind, } from '../../resources' import { AcmExtension } from '../../plugin-extensions/types' -import { ApplicationActionProps } from '../../plugin-extensions/properties' +import { ApplicationActionProps } from '@stolostron/multicluster-sdk' import { IResultStatuses } from '../../lib/useAggregates' export const mockArgoCD: IResource = { diff --git a/frontend/src/routes/Applications/ApplicationDetails/ApplicationDetails.test.tsx b/frontend/src/routes/Applications/ApplicationDetails/ApplicationDetails.test.tsx index dfcc5632582..a05aae68d31 100644 --- a/frontend/src/routes/Applications/ApplicationDetails/ApplicationDetails.test.tsx +++ b/frontend/src/routes/Applications/ApplicationDetails/ApplicationDetails.test.tsx @@ -20,7 +20,7 @@ import { import { nockIgnoreApiPaths, nockIgnoreRBAC, nockSearch } from '../../../lib/nock-util' import { defaultPlugin, PluginContext } from '../../../lib/PluginContext' import { waitForText } from '../../../lib/test-util' -import { ApplicationActionProps } from '../../../plugin-extensions/properties' +import { ApplicationActionProps } from '@stolostron/multicluster-sdk' import { AcmExtension } from '../../../plugin-extensions/types' import { GetMessagesDocument, SearchSchemaDocument } from '../../Search/search-sdk/search-sdk' import { diff --git a/scripts/copyright.ts b/scripts/copyright.ts index f69caa7e1ef..edd60200738 100644 --- a/scripts/copyright.ts +++ b/scripts/copyright.ts @@ -2,7 +2,7 @@ import { lstat, readdir, readFile, writeFile } from 'fs/promises' import { join } from 'path' -const ignoreDirectories = ['.git', 'node_modules', 'coverage', 'build', 'dist'] +const ignoreDirectories = ['.git', 'node_modules', 'coverage', 'build', 'dist', 'lib'] const extensions = ['.ts', '.tsx', '.js'] export type CopyrightAction = (path: string) => Promise