Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] propsParser в production-сборке и под флагом #2151

Merged
merged 5 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. Склонировать репозиторий и перейти в созданную директорию.
2. Установить зависимости: `yarn install`.
3. Поднять локально документацию с лайврелоадом: `yarn styleguide`.
3. Поднять локально документацию с лайврелоадом: `yarn styleguide`. Свойства и методы компонента в режиме разработки по умолчанию не генерируются; если они вам нужны, используйте команду `yarn styleguide:props`.

Документация будет доступна на `http://localhost:6060`. В ней ведётся вся разработка. Для удобства можно сразу перейти на страницу разрабатываемого компонента (`http://localhost:6060/#/UsersStack`)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"size": "yarn clear && concurrently 'yarn:babel' 'yarn:postcss' && size-limit",
"size:ci": "yarn install --frozen-lockfile --ignore-scripts && yarn build:no-types",
"styleguide": "cross-env NODE_ENV=development styleguidist server --config=styleguide/config.js",
"styleguide:props": "cross-env NODE_ENV=development VKUI_STYLEGUIDE_PROPSPARSER=1 styleguidist server --config=styleguide/config.js",
"styleguide:build": "cross-env NODE_ENV=production styleguidist build --config=styleguide/config.js",
"dev": "yarn clear && concurrently \"yarn:tsc-dev\" \"yarn:babel-dev\" \"yarn:postcss-dev\"",
"dev-cjs": "yarn clear && concurrently \"yarn:tsc-cjs-dev\" \"yarn:babel-cjs-dev\" \"yarn:postcss-dev\"",
Expand Down
16 changes: 15 additions & 1 deletion styleguide/Components/ReactComponent/ReactComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const ReactComponent = ({ component, exampleMode }) => {
const { name, visibleName, pathLine } = component;
const { description = "", examples = [] } = component.props || {};

const showPropsPlaceholder =
process.env.NODE_ENV === "development" &&
process.env.VKUI_STYLEGUIDE_PROPSPARSER !== 1;

return (
<div className="ReactComponent">
<Link
Expand All @@ -36,7 +40,17 @@ const ReactComponent = ({ component, exampleMode }) => {
<SectionSubheading href={`#/${name}?id=props`}>
Свойства и методы
</SectionSubheading>
<Slot name="docsTabs" props={component} />
{showPropsPlaceholder ? (
<blockquote className="Blockquote">
<Text>
В режиме разработки свойства и методы не генерируются по умолчанию.
Если они вам необходимы, воспользуйтесь командой{" "}
<span className="Code">yarn styleguide:props</span>.
</Text>
</blockquote>
) : (
<Slot name="docsTabs" props={component} />
)}
</div>
);
};
Expand Down
17 changes: 14 additions & 3 deletions styleguide/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require("path");
const { argv } = require("yargs");
const { tsPropsParser } = require("./docgen-typescript.config");
const { reactDocgenTypescript } = require("./propsParser.config");

module.exports = {
const baseConfig = {
title: "VKUI styleguide",
styleguideDir: path.join(__dirname, `../${argv.dist || "docs"}`),
styleguideComponents: {
Expand Down Expand Up @@ -92,7 +92,7 @@ module.exports = {
},
},
},
propsParser: tsPropsParser,
propsParser: () => ({}),
exampleMode: "expand",
assetsDir: path.join(__dirname, `assets`),
sections: [
Expand Down Expand Up @@ -336,3 +336,14 @@ module.exports = {
],
webpackConfig: require("./webpack.config"),
};

const prodConfig = {
...baseConfig,
propsParser: reactDocgenTypescript,
};

module.exports =
process.env.NODE_ENV === "development" &&
process.env.VKUI_STYLEGUIDE_PROPSPARSER !== 1
? baseConfig
: prodConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function createServiceHost(compilerOptions, files) {
}

module.exports = {
tsPropsParser: (file, source) => {
reactDocgenTypescript: (file, source) => {
filesCache.set(file, {
text: source,
version: 0,
Expand Down
7 changes: 7 additions & 0 deletions styleguide/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const path = require("path");
const webpackConfig = require("../webpack.config");
const { DefinePlugin } = require("webpack");
const merge = require("webpack-merge");

module.exports = merge(webpackConfig, {
plugins: [
new DefinePlugin({
"process.env.VKUI_STYLEGUIDE_PROPSPARSER":
process.env.VKUI_STYLEGUIDE_PROPSPARSER,
}),
],
resolve: {
alias: {
"@rsg-components": path.resolve(
Expand Down