diff --git a/.dumirc.ts b/.dumirc.ts new file mode 100644 index 0000000..221cb46 --- /dev/null +++ b/.dumirc.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'dumi'; +const isGitPagesSite = process.env.GITHUB_ACTIONS; + +export default defineConfig({ + favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], + themeConfig: { + name: 'rc-overflow', + logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', + }, + exportStatic: {}, + outputPath: 'docs-dist', + base: isGitPagesSite ? `/rc-overflow/` : ``, + publicPath: isGitPagesSite ? `/rc-overflow/` : ``, + styles: [ + ` + .markdown table { + width: auto !important; + } + `, + ], +}); diff --git a/.fatherrc.js b/.fatherrc.js deleted file mode 100644 index 912aa0a..0000000 --- a/.fatherrc.js +++ /dev/null @@ -1,9 +0,0 @@ -export default { - cjs: 'babel', - esm: { type: 'babel', importLibToEs: true }, - preCommit: { - eslint: true, - prettier: true, - }, - runtimeHelpers: true, -}; diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 0000000..96268ae --- /dev/null +++ b/.fatherrc.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + plugins: ['@rc-component/father-plugin'], +}); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 432a3fb..b0a4263 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-node@v1 with: - node-version: '12' + node-version: '18' - name: cache package-lock.json uses: actions/cache@v2 @@ -24,7 +24,7 @@ jobs: key: lock-${{ github.sha }} - name: create package-lock.json - run: npm i --package-lock-only + run: npm i --package-lock-only --ignore-scripts - name: hack for singe file run: | diff --git a/.gitignore b/.gitignore index dfa72e1..d222701 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.storybook *.iml *.log .idea/ @@ -29,5 +28,10 @@ yarn.lock package-lock.json coverage/ .doc -.umi -dist/ \ No newline at end of file +dist/ + +# dumi +.dumi/tmp +.dumi/tmp-test +.dumi/tmp-production +.env.local diff --git a/.umirc.ts b/.umirc.ts deleted file mode 100644 index a15b3dd..0000000 --- a/.umirc.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { defineConfig } from 'dumi'; - -export default defineConfig({ - title: 'rc-overflow', - favicon: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - logo: - 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - exportStatic: {}, - outputPath: 'docs-dist', - resolve: { - examples: ['none'], - }, - styles: [ - ` - .markdown table { - width: auto !important; - } - `, - ] -}); diff --git a/docs/demo/base.md b/docs/demo/base.md deleted file mode 100644 index 3d1c229..0000000 --- a/docs/demo/base.md +++ /dev/null @@ -1,3 +0,0 @@ -## base - - diff --git a/docs/demo/basic.md b/docs/demo/basic.md new file mode 100644 index 0000000..edb9e62 --- /dev/null +++ b/docs/demo/basic.md @@ -0,0 +1,8 @@ +--- +title: basic +nav: + title: Demo + path: /demo +--- + + diff --git a/docs/demo/blink.md b/docs/demo/blink.md index 7362231..778c112 100644 --- a/docs/demo/blink.md +++ b/docs/demo/blink.md @@ -1,3 +1,8 @@ -## blink +--- +title: blink +nav: + title: Demo + path: /demo +--- - + diff --git a/docs/demo/fill-width.md b/docs/demo/fill-width.md index acf87dd..b9b3935 100644 --- a/docs/demo/fill-width.md +++ b/docs/demo/fill-width.md @@ -1,3 +1,8 @@ -## fill-width +--- +title: fill-width +nav: + title: Demo + path: /demo +--- - + diff --git a/docs/demo/raw-render.md b/docs/demo/raw-render.md index 0b2479d..204a6dd 100644 --- a/docs/demo/raw-render.md +++ b/docs/demo/raw-render.md @@ -1,3 +1,8 @@ -## Raw Render +--- +title: raw-render +nav: + title: Demo + path: /demo +--- - + diff --git a/docs/index.md b/docs/index.md index e99bdf3..9bb192a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,7 @@ --- -title: rc-overflow +hero: + title: rc-overflow + description: React Overflow Component --- - + diff --git a/jest.config.js b/jest.config.js index 9a92751..86627c3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,4 @@ module.exports = { setupFiles: ['./tests/setup.js'], snapshotSerializers: [require.resolve('enzyme-to-json/serializer')], - setupFilesAfterEnv: ['/tests/setupFilesAfterEnv.ts'] }; diff --git a/now.json b/now.json index 01a4be8..7b2f649 100644 --- a/now.json +++ b/now.json @@ -4,11 +4,8 @@ "builds": [ { "src": "package.json", - "use": "@now/static-build", + "use": "@vercel/static-build", "config": { "distDir": "docs-dist" } } - ], - "routes": [ - { "src": "/(.*)", "dest": "/dist/$1" } ] } \ No newline at end of file diff --git a/package.json b/package.json index ca02002..bbd61bf 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,12 @@ "start": "dumi dev", "docs:build": "dumi build", "docs:deploy": "gh-pages -d docs-dist", - "compile": "father-build", + "compile": "father build", + "prepare": "dumi setup", "deploy": "npm run docs:build && npm run docs:deploy", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", - "test": "father test", - "test:coverage": "umi-test --coverage", + "test": "rc-test", + "test:coverage": "rc-test --coverage", "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish", "lint": "eslint src/ --ext .tsx,.ts", "lint:tsc": "tsc -p tsconfig.json --noEmit", @@ -49,6 +50,7 @@ "rc-util": "^5.37.0" }, "devDependencies": { + "@rc-component/father-plugin": "^1.0.0", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^12.0.0", "@types/classnames": "^2.2.9", @@ -56,21 +58,23 @@ "@types/jest": "^26.0.23", "@types/react": "^16.14.2", "@types/react-dom": "^16.9.10", - "@umijs/fabric": "^2.0.8", + "@umijs/fabric": "^3.0.0", + "glob": "^10.0.0", "cross-env": "^7.0.2", - "dumi": "^1.1.10", + "dumi": "^2.0.0", "enzyme": "^3.0.0", "enzyme-adapter-react-16": "^1.0.1", "enzyme-to-json": "^3.4.0", "eslint": "^7.0.0", - "father": "^2.13.4", - "father-build": "^1.19.1", + "father": "^4.0.0", "less": "^3.10.3", "np": "^7.0.0", "prettier": "^2.0.5", + "rc-test": "^7.0", "react": "^16.0.0", "react-dom": "^16.0.0", - "regenerator-runtime": "^0.13.7" + "regenerator-runtime": "^0.13.7", + "typescript": "^5.0.0" }, "peerDependencies": { "react": ">=16.9.0", @@ -82,4 +86,4 @@ "tnpm": { "mode": "npm" } -} +} \ No newline at end of file diff --git a/script/update-content.js b/script/update-content.js new file mode 100644 index 0000000..60452da --- /dev/null +++ b/script/update-content.js @@ -0,0 +1,34 @@ +/* + 用于 dumi 改造使用, + 可用于将 examples 的文件批量修改为 demo 引入形式, + 其他项目根据具体情况使用。 +*/ + +const fs = require('fs'); +const glob = require('glob'); + +const paths = glob.sync('./examples/*.tsx'); + +paths.forEach(path => { + const name = path.split('/').pop().split('.')[0]; + fs.writeFile( + `./docs/demo/${name}.md`, + `--- +title: ${name} +nav: + title: Demo + path: /demo +--- + + +`, + 'utf8', + function(error) { + if(error){ + console.log(error); + return false; + } + console.log(`${name} 更新成功~`); + } + ) +}); diff --git a/tests/setup.js b/tests/setup.js index 511c8ef..1d5b617 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -11,22 +11,20 @@ Enzyme.configure({ adapter: new Adapter() }); Object.assign(Enzyme.ReactWrapper.prototype, { triggerResize(clientWidth) { + const target = this.find('ResizeObserver').first() + target.invoke('onResize')({}, { clientWidth }) act(() => { - this.find('ResizeObserver').first().props().onResize({}, { clientWidth }); jest.runAllTimers(); - this.update(); - }); + }) + this.update() }, triggerItemResize(index, offsetWidth) { + const target = this.find('Item').at(index).find('ResizeObserver') + target.invoke('onResize')({ offsetWidth }); act(() => { - this.find('Item') - .at(index) - .find('ResizeObserver') - .props() - .onResize({ offsetWidth }); jest.runAllTimers(); - this.update(); - }); + }) + this.update() }, initSize(width, itemWidth) { this.triggerResize(width); diff --git a/tests/setupFilesAfterEnv.ts b/tests/setupFilesAfterEnv.ts deleted file mode 100644 index 7b0828b..0000000 --- a/tests/setupFilesAfterEnv.ts +++ /dev/null @@ -1 +0,0 @@ -import '@testing-library/jest-dom'; diff --git a/tests/wrapper.ts b/tests/wrapper.ts index 24739d8..8a52aa6 100644 --- a/tests/wrapper.ts +++ b/tests/wrapper.ts @@ -1,4 +1,5 @@ -import { mount as enzymeMount, ReactWrapper } from 'enzyme'; +import type { ReactWrapper } from 'enzyme'; +import { mount as enzymeMount } from 'enzyme'; export type MountParam = Parameters; diff --git a/tsconfig.json b/tsconfig.json index 1248088..168ea06 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,13 +3,13 @@ "target": "esnext", "moduleResolution": "node", "baseUrl": "./", - "jsx": "preserve", + "jsx": "react", "declaration": true, "skipLibCheck": true, "esModuleInterop": true, "paths": { "@/*": ["src/*"], - "@@/*": ["src/.umi/*"], + "@@/*": [".dumi/tmp/*"], "rc-overflow": ["src/index.tsx"] } }