From ff69aca121e604414a74332751b621991077c94e Mon Sep 17 00:00:00 2001 From: chenchongqiang Date: Mon, 17 Apr 2023 20:09:30 +0800 Subject: [PATCH 1/4] doc: update doc --- apps/demo/craco.config.js | 32 ++-------------------- apps/demo/package.json | 3 +- apps/doc/docs/expansion/index.mdx | 7 +++++ apps/doc/docs/get-started.mdx | 44 ++++++------------------------ apps/next_demo/src/pages/index.tsx | 25 +++++++++-------- pnpm-lock.yaml | 12 ++++++++ 6 files changed, 47 insertions(+), 76 deletions(-) diff --git a/apps/demo/craco.config.js b/apps/demo/craco.config.js index b2ef58d..dcf61ea 100644 --- a/apps/demo/craco.config.js +++ b/apps/demo/craco.config.js @@ -1,5 +1,5 @@ const cracoAlias = require("craco-alias"); -const webpack = require("webpack"); +const nodeExternals = require('webpack-node-externals'); module.exports = { style: { @@ -21,34 +21,8 @@ module.exports = { ], webpack: { configure: (webpackConfig, { env, paths }) => { - // eslint-disable-next-line no-param-reassign - webpackConfig.resolve.fallback = { - "http": require.resolve("stream-http"), - "https": require.resolve("https-browserify"), - "zlib": require.resolve("browserify-zlib"), - "stream": require.resolve("stream-browserify"), - "events": require.resolve("events/"), - "crypto": require.resolve("crypto-browserify"), - "assert": require.resolve("assert/"), - "buffer": require.resolve("buffer/"), - "util": require.resolve("util/"), - "path": require.resolve("path-browserify"), - "tty": require.resolve("tty-browserify"), - "os": require.resolve("os-browserify/browser"), - "punycode": require.resolve("punycode/"), - "fs": false, - "url": require.resolve("url/"), - "net": require.resolve("net-browserify"), - "child_process": false, - async_hooks: false, - rawBody: false, - }; - - webpackConfig.plugins.push( - new webpack.ProvidePlugin({ - Buffer: ["buffer", "Buffer"] - }) - ); + webpackConfig.externalsPresets = {node: true}; + webpackConfig.externals = [nodeExternals()]; return webpackConfig; } } diff --git a/apps/demo/package.json b/apps/demo/package.json index 1a96245..31b8c20 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -56,6 +56,7 @@ "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17", "tty-browserify": "^0.0.1", "url": "^0.11.0", - "util": "^0.12.5" + "util": "^0.12.5", + "webpack-node-externals": "^3.0.0" } } diff --git a/apps/doc/docs/expansion/index.mdx b/apps/doc/docs/expansion/index.mdx index 10571b6..5c446a8 100644 --- a/apps/doc/docs/expansion/index.mdx +++ b/apps/doc/docs/expansion/index.mdx @@ -3,3 +3,10 @@ title: 扩展 sidebar_position: 3 hide_title: true --- + +## 扩展 + +import DocCardList from '@theme/DocCardList'; + + + diff --git a/apps/doc/docs/get-started.mdx b/apps/doc/docs/get-started.mdx index a47d28e..e6c824c 100644 --- a/apps/doc/docs/get-started.mdx +++ b/apps/doc/docs/get-started.mdx @@ -15,21 +15,21 @@ import TabItem from '@theme/TabItem'; ```sh -npm install solive +npm install solive-core ``` ```sh -yarn add solive +yarn add solive-core ``` ```sh -pnpm install solive +pnpm install solive-core ``` @@ -44,42 +44,16 @@ pnpm install solive ```js // 使用craco配置: -const webpack = require("webpack"); +const nodeExternals = require('webpack-node-externals'); module.exports = { // ... webpack: { - configure: (webpackConfig, { env, paths }) => { - // eslint-disable-next-line no-param-reassign - webpackConfig.resolve.fallback = { - "http": require.resolve("stream-http"), - "https": require.resolve("https-browserify"), - "zlib": require.resolve("browserify-zlib"), - "stream": require.resolve("stream-browserify"), - "events": require.resolve("events/"), - "crypto": require.resolve("crypto-browserify"), - "assert": require.resolve("assert/"), - "buffer": require.resolve("buffer/"), - "util": require.resolve("util/"), - "path": require.resolve("path-browserify"), - "tty": require.resolve("tty-browserify"), - "os": require.resolve("os-browserify/browser"), - "punycode": require.resolve("punycode/"), - "fs": false, - "url": require.resolve("url/"), - "net": require.resolve("net-browserify"), - "child_process": false, - async_hooks: false, - rawBody: false, - }; - - webpackConfig.plugins.push( - new webpack.ProvidePlugin({ - Buffer: ["buffer", "Buffer"] - }) - ); - return webpackConfig; - } + configure: (webpackConfig, { env, paths }) => { + webpackConfig.externalsPresets = {node: true}; + webpackConfig.externals = [nodeExternals()]; + return webpackConfig; + } } }; diff --git a/apps/next_demo/src/pages/index.tsx b/apps/next_demo/src/pages/index.tsx index e0ff1b4..e78608d 100644 --- a/apps/next_demo/src/pages/index.tsx +++ b/apps/next_demo/src/pages/index.tsx @@ -1,26 +1,29 @@ -import dynamic from "next/dynamic"; +import dynamic from 'next/dynamic'; -import "solive-core/dist/index.css"; +import 'solive-core/dist/index.css'; const Editor = dynamic( - () => { - return import("solive-core"); - }, - { ssr: false } + () => import('solive-core'), + { ssr: false }, ); export default function Home() { return (
- =0.7.0 <0.9.0;\n\n/**\n * @title Storage\n * @dev Store & retrieve value in a variable\n * @custom:dev-run-script ./scripts/deploy_with_ethers.ts\n */\ncontract Storage {\n\n uint256 number;\n\n /**\n * @dev Store value in variable\n * @param num value to store\n */\n function store(uint256 num) public {\n number = num;\n }\n\n /**\n * @dev Return value \n * @return value of 'number'\n */\n function retrieve() public view returns (uint256){\n return number;\n }\n}", - language: "solidity" as any, - } + language: 'solidity' as any, + }, ] - } height="500px" /> + } + height="500px" + />
- ) + ); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e40f12c..db16739 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,6 +122,7 @@ importers: url: ^0.11.0 util: ^0.12.5 web-vitals: ^2.1.4 + webpack-node-externals: ^3.0.0 dependencies: '@craco/craco': 7.1.0_uaemxlzga3znd5u3dmtbp5hl4i '@testing-library/jest-dom': 5.16.5 @@ -157,6 +158,7 @@ importers: tty-browserify: r2.cnpmjs.org/tty-browserify/0.0.1 url: r2.cnpmjs.org/url/0.11.0 util: 0.12.5 + webpack-node-externals: r2.cnpmjs.org/webpack-node-externals/3.0.0 apps/doc: specifiers: @@ -218,6 +220,7 @@ importers: solive-core: workspace:* tailwindcss: 3.3.1 typescript: 5.0.4 + webpack-node-externals: ^3.0.0 dependencies: '@headlessui/react': 1.7.13_biqbaboplfbrettd7655fr4n2y '@heroicons/react': 2.0.17_react@18.2.0 @@ -234,6 +237,8 @@ importers: solive-core: link:../../packages/core tailwindcss: 3.3.1_postcss@8.4.21 typescript: 5.0.4 + devDependencies: + webpack-node-externals: r2.cnpmjs.org/webpack-node-externals/3.0.0 packages/compiler-utils: specifiers: @@ -21491,6 +21496,13 @@ packages: clone-deep: r2.cnpmjs.org/clone-deep/4.0.1 wildcard: r2.cnpmjs.org/wildcard/2.0.0 + r2.cnpmjs.org/webpack-node-externals/3.0.0: + resolution: {integrity: sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==, registry: https://r.cnpmjs.org/, tarball: https://r2.cnpmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz} + name: webpack-node-externals + version: 3.0.0 + engines: {node: '>=6'} + dev: true + r2.cnpmjs.org/webpack-sources/1.4.3: resolution: {integrity: sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==, registry: https://r.cnpmjs.org/, tarball: https://r2.cnpmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz} name: webpack-sources From ac7ac5485b906695e6b1c26fd4b1576c46b2e9ec Mon Sep 17 00:00:00 2001 From: chenchongqiang Date: Tue, 18 Apr 2023 09:37:24 +0800 Subject: [PATCH 2/4] fix(demo): fix demo webpack config --- apps/demo/craco.config.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/demo/craco.config.js b/apps/demo/craco.config.js index dcf61ea..b2ef58d 100644 --- a/apps/demo/craco.config.js +++ b/apps/demo/craco.config.js @@ -1,5 +1,5 @@ const cracoAlias = require("craco-alias"); -const nodeExternals = require('webpack-node-externals'); +const webpack = require("webpack"); module.exports = { style: { @@ -21,8 +21,34 @@ module.exports = { ], webpack: { configure: (webpackConfig, { env, paths }) => { - webpackConfig.externalsPresets = {node: true}; - webpackConfig.externals = [nodeExternals()]; + // eslint-disable-next-line no-param-reassign + webpackConfig.resolve.fallback = { + "http": require.resolve("stream-http"), + "https": require.resolve("https-browserify"), + "zlib": require.resolve("browserify-zlib"), + "stream": require.resolve("stream-browserify"), + "events": require.resolve("events/"), + "crypto": require.resolve("crypto-browserify"), + "assert": require.resolve("assert/"), + "buffer": require.resolve("buffer/"), + "util": require.resolve("util/"), + "path": require.resolve("path-browserify"), + "tty": require.resolve("tty-browserify"), + "os": require.resolve("os-browserify/browser"), + "punycode": require.resolve("punycode/"), + "fs": false, + "url": require.resolve("url/"), + "net": require.resolve("net-browserify"), + "child_process": false, + async_hooks: false, + rawBody: false, + }; + + webpackConfig.plugins.push( + new webpack.ProvidePlugin({ + Buffer: ["buffer", "Buffer"] + }) + ); return webpackConfig; } } From 5a8c475411ae1f26c4029137262e7ab2025bebab Mon Sep 17 00:00:00 2001 From: chenchongqiang Date: Tue, 18 Apr 2023 13:28:04 +0800 Subject: [PATCH 3/4] fix(docusaurus-plugin): fix match props error --- .changeset/rude-pears-sneeze.md | 5 +++++ .../src/theme/utils/match-props.ts | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .changeset/rude-pears-sneeze.md diff --git a/.changeset/rude-pears-sneeze.md b/.changeset/rude-pears-sneeze.md new file mode 100644 index 0000000..21be9fb --- /dev/null +++ b/.changeset/rude-pears-sneeze.md @@ -0,0 +1,5 @@ +--- +"solive-docusaurus-theme-code": patch +--- + +fix match props error diff --git a/packages/docusaurus-plugin/src/theme/utils/match-props.ts b/packages/docusaurus-plugin/src/theme/utils/match-props.ts index 856655b..ed10e0c 100644 --- a/packages/docusaurus-plugin/src/theme/utils/match-props.ts +++ b/packages/docusaurus-plugin/src/theme/utils/match-props.ts @@ -29,15 +29,18 @@ export const coerceValue = (value: string, type: TPropType) => { }; export const matchProps = (metaString: string, propsInfo: TPropsInfo): TResultProps => { - const dynamicRex = /(?[^=]+)="(?[^"]*)"/g; - const props: any = {}; + const dynamicRex = /(?[^=\s]+)=(?:"(?[^"]*)"|'(?[^']*)'|(?[^\s]*))/g; + const props: TResultProps = {}; let match; // eslint-disable-next-line no-cond-assign while ((match = dynamicRex.exec(metaString)) !== null) { - const { key, value } = match.groups as any; - const keyName = key.trim(); - if (propsInfo[keyName]) { - props[keyName] = coerceValue(value, propsInfo[keyName].type); + const { groups } = match; + if (groups) { + const key = groups.key.trim(); + const value = groups.value1 || groups.value2 || groups.value3; + if (propsInfo[key]) { + props[key] = value; + } } } From ec18ff92aa542a810255395f3ea090f947d1ebc7 Mon Sep 17 00:00:00 2001 From: chenchongqiang Date: Tue, 18 Apr 2023 13:29:41 +0800 Subject: [PATCH 4/4] doc(dome/doc): update doc --- .eslintrc.js | 2 +- .github/workflows/relesae.yaml | 2 + .../guide.mdx} | 36 +++++++++--------- .../expansion/docusaurus-plugins/props.mdx | 21 ++++++++++ apps/doc/docs/get-started.mdx | 38 ++++++++++++++++--- 5 files changed, 75 insertions(+), 24 deletions(-) rename apps/doc/docs/expansion/{docusaurus-plugins.mdx => docusaurus-plugins/guide.mdx} (85%) create mode 100644 apps/doc/docs/expansion/docusaurus-plugins/props.mdx diff --git a/.eslintrc.js b/.eslintrc.js index e188436..61b29cd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -53,7 +53,7 @@ module.exports = { 'class-methods-use-this': 'off', radix: 'off', 'guard-for-in': 'off', - 'max-len': ['error', { code: 150 }], + 'max-len': ['error', { code: 250 }], // TypeScript 相关 '@typescript-eslint/explicit-function-return-type': 'off', diff --git a/.github/workflows/relesae.yaml b/.github/workflows/relesae.yaml index a34ce61..4dcb60e 100644 --- a/.github/workflows/relesae.yaml +++ b/.github/workflows/relesae.yaml @@ -4,6 +4,8 @@ on: push: branches: - main + paths-ignore: + - 'apps/**' concurrency: ${{ github.workflow }}-${{ github.ref }} diff --git a/apps/doc/docs/expansion/docusaurus-plugins.mdx b/apps/doc/docs/expansion/docusaurus-plugins/guide.mdx similarity index 85% rename from apps/doc/docs/expansion/docusaurus-plugins.mdx rename to apps/doc/docs/expansion/docusaurus-plugins/guide.mdx index bb441fa..732c64d 100644 --- a/apps/doc/docs/expansion/docusaurus-plugins.mdx +++ b/apps/doc/docs/expansion/docusaurus-plugins/guide.mdx @@ -1,11 +1,13 @@ --- -title: Docusaurus 插件 +title: 引导 hide_title: true +slug: /docusaurus-plugins --- + ## Docusaurus 插件 -> 你可以使用 `solive-docusaurus-theme-code` 插件快速集成一个轻量级Solidity Editor嵌入你的文档. +> 你可以使用 `solive-docusaurus-theme-code` 插件快速集成一个轻量级Solidity Editor嵌入你的文档. (完善中) ### 安装 @@ -27,22 +29,22 @@ module.exports = { ### 快速使用 1. 你需要注意在代码块标记solive,和配置solive的属性: -```md - ```solidity solive height=300px +````md + ```solidity solive height=500px // your code - ```\ -``` + ``` +```` -2. 你可以在代码块中配置solive相关属性 `height`(具体参考[属性表](/docs/solive-props)): -```md +2. 你可以在代码块中配置solive相关属性 `height`(具体参考[属性表](/docs/docusaurus-plugins/props)): +````md ```solidity solive height=300px // your code - ```\ -``` + ``` +```` 3. 配置代码块文件名(可多文件): -```md - ```solidity solive height=300px +````md + ```solidity solive height=500px /** * @filename Storage.sol */ @@ -54,12 +56,12 @@ module.exports = { */ // your code - ```\ -``` + ``` +```` 3. 完整的代码块示例: ````md -```solidity solive height=300px +```solidity solive height=500px /** * @filename Storage.sol */ @@ -94,12 +96,12 @@ contract Storage { return number; } } -```\ +``` ```` ### 展示结果: -```solidity solive height=300px +```solidity solive height=500px /** * @filename Storage.sol */ diff --git a/apps/doc/docs/expansion/docusaurus-plugins/props.mdx b/apps/doc/docs/expansion/docusaurus-plugins/props.mdx new file mode 100644 index 0000000..d8e7ada --- /dev/null +++ b/apps/doc/docs/expansion/docusaurus-plugins/props.mdx @@ -0,0 +1,21 @@ +--- +title: 属性 +slug: /docusaurus-plugins/props +hide_title: true +--- + +## 属性 + +> 注意:考虑对参数匹配的准确性和文档UI适应性,部分Solive的属性默认值有所变动,并增加和变动一些新的属性 + +| 属性 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| width | string | 90% | 容器宽度 | +| height | string | 500px | 容器高度 | +| consoleOpen | boolean | true | 是否显示控制台 | +| consoleTriggerControl | boolean | false | 是否显示控制台触发按钮 | +| consoleDefaultVisible | boolean | false | 控制台默认是否可见 | +| deployOpen | boolean | true | 是否显示部署 | +| deployDefaultVisible | boolean | false | 部署默认是否可见 | +| fileNavOpen | boolean | true | 是否显示文件导航栏 | +| fileNavDefaultVisible | boolean | false | 文件导航栏默认是否可见 | diff --git a/apps/doc/docs/get-started.mdx b/apps/doc/docs/get-started.mdx index e6c824c..cdd4b1f 100644 --- a/apps/doc/docs/get-started.mdx +++ b/apps/doc/docs/get-started.mdx @@ -44,16 +44,42 @@ pnpm install solive-core ```js // 使用craco配置: -const nodeExternals = require('webpack-node-externals'); +const webpack = require("webpack"); module.exports = { // ... webpack: { - configure: (webpackConfig, { env, paths }) => { - webpackConfig.externalsPresets = {node: true}; - webpackConfig.externals = [nodeExternals()]; - return webpackConfig; - } + configure: (webpackConfig, { env, paths }) => { + // eslint-disable-next-line no-param-reassign + webpackConfig.resolve.fallback = { + "http": require.resolve("stream-http"), + "https": require.resolve("https-browserify"), + "zlib": require.resolve("browserify-zlib"), + "stream": require.resolve("stream-browserify"), + "events": require.resolve("events/"), + "crypto": require.resolve("crypto-browserify"), + "assert": require.resolve("assert/"), + "buffer": require.resolve("buffer/"), + "util": require.resolve("util/"), + "path": require.resolve("path-browserify"), + "tty": require.resolve("tty-browserify"), + "os": require.resolve("os-browserify/browser"), + "punycode": require.resolve("punycode/"), + "fs": false, + "url": require.resolve("url/"), + "net": require.resolve("net-browserify"), + "child_process": false, + async_hooks: false, + rawBody: false, + }; + + webpackConfig.plugins.push( + new webpack.ProvidePlugin({ + Buffer: ["buffer", "Buffer"] + }) + ); + return webpackConfig; + } } };