Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/epam/ketcher into #2460-s…
Browse files Browse the repository at this point in the history
…tructure-on-canvas-becomes-undefined-when-atom-is-hovered-and-functional-group-selected-using-hotkey
  • Loading branch information
Nitvex committed May 16, 2023
2 parents 64a89c2 + 19f51b2 commit 7d216b6
Show file tree
Hide file tree
Showing 66 changed files with 3,128 additions and 711 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug, feature request
labels: bug
assignees: Nitvex

---
Expand Down
13 changes: 13 additions & 0 deletions .github/auto_assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
addReviewers: true
numberOfReviewers: 1
useReviewGroups: true
addAssignees: author
reviewGroups:
core:
- nitvex
- yuleicul
- KonstantinEpam23
developers:
- VasilevDO
- AnastasiiaPlyako
- gairon
12 changes: 12 additions & 0 deletions .github/workflows/choose-reviewers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Choose reviewers
on:
pull_request:
types: [opened]

jobs:
add-reviews:
runs-on: ubuntu-latest
steps:
- uses: kentaro-m/auto-assign-action@v1.2.5
with:
configuration-path: '.github/auto_assign.yml'
16 changes: 15 additions & 1 deletion DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ The latest version of Ketcher is based on npm workspaces. So before starting dev
npm install
```

After that component library and application should be started separately. First should be started ketcher-core package.
Then start a Vite dev server in example:

```sh
cd example

# Standalone
npm run dev:standalone

# Or remote
npm run dev:remote
```

**NB!** We use Vite for development and react-app-rewired(Webpack based) for build. To make sure your implementation has consistent behavior both in development and production, after you finish developing with Vite, you'd better check your implementation with react-app-rewired before creating a new PR. Please follow the following steps:

Component libraries and application should be started separately. First should be started ketcher-core package.

#### Build ketcher-core package

Expand Down
17 changes: 9 additions & 8 deletions example/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const GitRevisionPlugin = require('git-revision-webpack-plugin')

const gitRevisionPlugin = new GitRevisionPlugin()
const applicationVersion = gitRevisionPlugin.version().split('-')[0]
const envVariables = {
MODE: process.env.MODE,
API_PATH: process.env.REACT_APP_API_PATH,
ENABLE_POLYMER_EDITOR: !!process.env.ENABLE_POLYMER_EDITOR,
KETCHER_ENABLE_REDUX_LOGGER: JSON.stringify(false)
}

module.exports = override(
addBundleVisualizer({}, true),
Expand All @@ -19,14 +25,7 @@ module.exports = override(
loader: 'source-map-loader',
exclude: /node_modules/
}),
addWebpackPlugin(
new webpack.EnvironmentPlugin({
MODE: process.env.MODE,
API_PATH: process.env.REACT_APP_API_PATH,
ENABLE_POLYMER_EDITOR: !!process.env.ENABLE_POLYMER_EDITOR,
KETCHER_ENABLE_REDUX_LOGGER: JSON.stringify(false)
})
),
addWebpackPlugin(new webpack.EnvironmentPlugin(envVariables)),
addWebpackPlugin(
new HtmlReplaceWebpackPlugin([
{
Expand All @@ -36,3 +35,5 @@ module.exports = override(
])
)
)

module.exports.envVariables = envVariables
8 changes: 8 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev:standalone": "cross-env MODE=standalone vite",
"dev:remote": "cross-env MODE=remote vite",
"start:standalone": "cross-env MODE=standalone react-app-rewired start",
"start:remote": "cross-env MODE=remote react-app-rewired start",
"init:build": "shx mkdir -p build",
Expand Down Expand Up @@ -40,13 +42,15 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.2",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.12",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"@vitejs/plugin-react": "^4.0.0",
"@welldone-software/why-did-you-render": "^4.3.1",
"cross-env": "^7.0.3",
"customize-cra": "^1.0.0",
Expand All @@ -62,6 +66,10 @@
"source-map-loader": "^3.0.1",
"stylelint": "13.13.1",
"typescript": "^4.5.2",
"vite": "^4.3.1",
"vite-plugin-html": "^3.2.0",
"vite-plugin-raw": "^1.0.3",
"vite-plugin-svgr": "^2.4.0",
"webpack-bundle-analyzer": "^4.8.0"
},
"browserslist": {
Expand Down
201 changes: 201 additions & 0 deletions example/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import replace from '@rollup/plugin-replace'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { createLogger, defineConfig, loadEnv } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import vitePluginRaw from 'vite-plugin-raw'
import svgr from 'vite-plugin-svgr'
import ketcherCoreTSConfig from '../packages/ketcher-core/tsconfig.json'
import { valuesToReplace as polymerEditorValues } from '../packages/ketcher-polymer-editor-react/rollup.config'
import polymerEditorTSConfig from '../packages/ketcher-polymer-editor-react/tsconfig.json'
import { valuesToReplace as ketcherReactValues } from '../packages/ketcher-react/rollup.config'
import ketcherReactTSConfig from '../packages/ketcher-react/tsconfig.json'
import ketcherStandaloneTSConfig from '../packages/ketcher-standalone/tsconfig.json'
import { envVariables as exampleEnv } from './config/webpack.config'

const dotEnv = loadEnv('development', '.', '')
Object.assign(process.env, dotEnv, exampleEnv)

/**
* To resolve alias in the range of the specific package,
* notice that it can't be an arrow function,
* see: https://github.com/rollup/plugins/blob/master/packages/alias/src/index.ts
*/
function resolver(source, importer, options) {
const packageName = importer.match(/packages\/(.*?)\//)[1]
const updatedId = source.replace('%packageName%', packageName)

return this.resolve(
updatedId,
importer,
Object.assign({ skipSelf: true }, options)
).then((resolved) => resolved || { id: updatedId })
}

const getTSConfigByPackage = (packageName) => {
return {
'ketcher-core': ketcherCoreTSConfig,
'ketcher-polymer-editor-react': polymerEditorTSConfig,
'ketcher-react': ketcherReactTSConfig,
'ketcher-standalone': ketcherStandaloneTSConfig
}[packageName]
}

const getAliasesByPackage = (packageName) => {
const aliases = getTSConfigByPackage(packageName).compilerOptions.paths || []
return Object.keys(aliases).map((alias) => {
const find = alias.replace('/*', '')
return {
find,
replacement: resolve(__dirname, `../packages/%packageName%/src/${find}`),
customResolver: resolver
}
})
}

const HtmlReplaceVitePlugin = () => {
return {
name: 'ketcher-html-transform',
transformIndexHtml(html) {
return html
.replaceAll('%PUBLIC_URL%/', process.env.PUBLIC_URL)
.replaceAll(
'@@version',
JSON.parse(ketcherReactValues['process.env.HELP_LINK']).split(
'-'
)[0] + ' (Vite)'
)
}
}
}

const logger = createLogger()
const loggerWarn = logger.warn
logger.warn = (msg, options) => {
if (
// This warning occurs when entry html is not at the root path
msg.includes('files in the public directory are served at the root path.')
) {
return
}
loggerWarn(msg, options)
}

export default defineConfig({
server: {
open: true
},
esbuild: {
tsconfigRaw: {
compilerOptions: {
// doc: https://vitejs.dev/guide/features.html#usedefineforclassfields
useDefineForClassFields: false
}
}
},
css: {
devSourcemap: true
},
plugins: [
react(),
svgr({
exportAsDefault: true
}),
vitePluginRaw({
match: /\.sdf/
}),
replace({
include: '**/ketcher-react/src/**',
preventAssignment: true,
values: ketcherReactValues
}),
replace({
include: '**/ketcher-polymer-editor-react/src/**',
preventAssignment: true,
values: polymerEditorValues
}),
replace({
include: '**/example/src/**',
preventAssignment: true,
values: {
require: 'await import'
}
}),
createHtmlPlugin({
entry: '/src/index.tsx',
template: 'public/index.html',
inject: {
tags: [
{
/**
* HACK: https://github.com/bevacqua/dragula/issues/602#issuecomment-1109840139
* Fix: global is not defined
*/
injectTo: 'body',
tag: 'script',
children: 'var global = global || window'
}
]
}
}),
HtmlReplaceVitePlugin()
],
define: {
'process.env': process.env
},
resolve: {
alias: [
{
// HACK: to ignore dist/index.css, you can set any file as replacement
find: 'ketcher-react/dist/index.css',
replacement: resolve(
__dirname,
'../packages/ketcher-react/src/index.less'
)
},
{
find: 'ketcher-react',
replacement: resolve(
__dirname,
'../packages/ketcher-react/src/index.tsx'
)
},
{
find: 'ketcher-core',
replacement: resolve(__dirname, '../packages/ketcher-core/src/index.ts')
},
{
find: 'ketcher-standalone',
replacement: resolve(
__dirname,
'../packages/ketcher-standalone/src/index.ts'
)
},
{
find: 'ketcher-polymer-editor-react',
replacement: resolve(
__dirname,
'../packages/ketcher-polymer-editor-react/src/index.tsx'
)
},

/** Get aliases from packages' tsconfig.json */
...getAliasesByPackage('ketcher-core'),
...getAliasesByPackage('ketcher-react'),
...getAliasesByPackage('ketcher-polymer-editor-react'),
...getAliasesByPackage('ketcher-standalone'),
{
find: 'src', // every package has this implicit alias
replacement: resolve(__dirname, `../packages/%packageName%/src`),
customResolver: resolver
},

/** Web worker in ketcher-standalone */
{
find: 'web-worker:./indigoWorker',
replacement: './indigoWorker?worker'
}
]
},
customLogger: logger
})
Loading

0 comments on commit 7d216b6

Please sign in to comment.