Skip to content

Commit

Permalink
Revert "chore(flat-components): remove rollup and add alias (#870)" (#…
Browse files Browse the repository at this point in the history
…871)

This reverts commit b91a9b2.
  • Loading branch information
BlackHole1 committed Aug 16, 2021
1 parent b91a9b2 commit 8fc00d8
Show file tree
Hide file tree
Showing 50 changed files with 1,949 additions and 5,748 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
if: steps.yarn-cache.outputs.cache-hit == 'true'

- name: Build Storybook
run: yarn workspace flat-components build
run: yarn workspace flat-components build-storybook

- name: Deploy Storybook
uses: peaceiris/actions-gh-pages@v3
Expand Down
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ yarn run start

部分 Flat 组件 UI 可通过 Storybook 快速查看与开发([线上地址][flat-storybook])。

- 项目根执行 `yarn run storybook` 可在本地运行 Storybook。
- 项目根执行 `yarn --cwd packages/flat-components storybook` 可在本地运行 Storybook。

## 环境变量值参考

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ yarn run start

Many Flat components UI can be quickly viewed and developed via Storybook ([Online address][flat-storybook]).

- Run `yarn run storybook` at project root to run Storybook locally.
- Run `yarn --cwd packages/flat-components storybook` at project root to run Storybook locally.

## Environment Variables Reference

Expand Down
2 changes: 0 additions & 2 deletions cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ module.exports = {
"Variatio",
"Clav",
"webfonts",
"browserslist",
"estree",
],
flagWords: ["fuck", "bitch", "asshole", "bullshit", "crap", "suck", "wtf"],
dictionaries: [
Expand Down
4 changes: 0 additions & 4 deletions desktop/renderer-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@
"lint-staged": "^11.0.0",
"minimist": "^1.2.5",
"prettier": "^2.3.0",
"pretty-bytes": "^5.6.0",
"rc-picker": "^2.5.15",
"react-refresh": "^0.10.0",
"react-resize-detector": "^6.7.5",
"react-transition-group": "^4.4.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.1.2",
"thread-loader": "^3.0.4",
Expand Down
6 changes: 3 additions & 3 deletions desktop/renderer-app/src/components/RoomInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ export interface RoomInfoProps {
}

export class RoomInfo extends React.PureComponent<RoomInfoProps> {
public roomStatusLocale = {
roomStatusLocale = {
[RoomStatus.Idle]: "待开始",
[RoomStatus.Started]: "进行中",
[RoomStatus.Paused]: "已暂停",
[RoomStatus.Stopped]: "已结束",
};

public roomInfoLocale = {
roomInfoLocale = {
[RoomType.BigClass]: "大班课",
[RoomType.SmallClass]: "小班课",
[RoomType.OneToOne]: "一对一",
};

public render(): React.ReactNode {
render(): React.ReactNode {
const { roomStatus, roomType } = this.props;

return (
Expand Down
3 changes: 1 addition & 2 deletions desktop/renderer-app/src/stores/GlobalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export class GlobalStore {
for (const key of keys) {
const value = config[key];
if (value !== null && value !== undefined) {
// @ts-ignore
this[key] = value;
this[key] = value as any;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/src/tasks/Init-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "flat-components/theme/index.less";
import "flat-components/build/style.css";
import "../theme.less";

import { ConfigProvider } from "antd";
Expand Down
3 changes: 1 addition & 2 deletions desktop/renderer-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"baseUrl": ".",
"paths": {
"flat-types": ["../../packages/flat-types/src"],
"flat-i18n": ["../../packages/flat-i18n/locales"],
"flat-components": ["../../packages/flat-components/src"]
"flat-i18n": ["../../packages/flat-i18n/locales"]
}
},
"exclude": ["node_modules"],
Expand Down
1 change: 0 additions & 1 deletion desktop/renderer-app/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ module.exports = {
alias: {
"flat-types": paths.resolvePath("..", "..", "packages", "flat-types", "src"),
"flat-i18n": paths.resolvePath("..", "..", "packages", "flat-i18n", "locales"),
"flat-components": paths.resolvePath("..", "..", "packages", "flat-components", "src"),
},
},
};
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"scripts": {
"preinstall": "node ./scripts/preinstall",
"postinstall": "husky install",
"bootstrap": "yarn install --frozen-lockfile",
"bootstrap": "yarn install --frozen-lockfile && node ./scripts/bootstrap/build-packages.js",
"lint": "yarn workspaces run lint",
"check-spelling": "cspell --no-progress \"**/*.{md,ts,tsx,js,css,less,json,yml,yaml,html,sh}\"",
"storybook": "yarn workspace flat-components start",
"storybook": "yarn workspace flat-components storybook",
"start": "node scripts/launch/index.js",
"preship": "rimraf desktop/renderer-app/dist desktop/main-app/dist desktop/main-app/release desktop/main-app/static",
"ship": "yarn workspace renderer-app build && yarn workspace flat ship",
Expand All @@ -20,9 +20,6 @@
"packages/*",
"desktop/*",
"web/*"
],
"nohoist": [
"flat-components/@pmmmwh/react-refresh-webpack-plugin/**"
]
},
"license": "MIT",
Expand Down
3 changes: 1 addition & 2 deletions packages/flat-components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = {
],
plugins: ["jsx-a11y", "react", "@netless", "prettier", "@typescript-eslint"],
parserOptions: {
ecmaVersion: 2018,
project: "tsconfig.json",
tsconfigRootDir: __dirname,
ecmaVersion: 7,
ecmaFeatures: {
jsx: true,
},
Expand Down Expand Up @@ -260,7 +260,6 @@ module.exports = {
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/restrict-plus-operands": "off",
},

overrides: [
Expand Down
2 changes: 1 addition & 1 deletion packages/flat-components/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/storybook-static
storybook-static
52 changes: 52 additions & 0 deletions packages/flat-components/.storybook/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import i18next from "i18next";
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
import en from "flat-i18n/locales/en.json";
import zhCN from "flat-i18n/locales/zh-CN.json";

const messages = {
en: { translation: en },
"zh-CN": { translation: zhCN },
};

i18next
.use(I18nextBrowserLanguageDetector)
.use(initReactI18next)
.init({
resources: messages,
fallbackLng: "en",
interpolation: {
escapeValue: false, // react already safes from xss
},
});

/**
* i18next 实例
* ```tsx
* // class component
* import { withTranslation, WithTranslation } from 'react-i18next';
* class App extends React.Component<WithTranslation> {
* render() { return <div>{this.props.t('hello')}</div> }
* }
* export default withTranslation()(App);
* // function component
* import { useTranslation } from "react-i18next";
* function App() {
* const { t, i18n } = useTranslation();
* return <div>{t('hello')}</div>
* }
* ```
*/
export const i18n = i18next;

export const languages = ["en", "zh-CN"];

export const languagesWithName = [
{ lang: "en", name: "English" },
{ lang: "zh-CN", name: "简体中文" },
];

/**
* NOTE: to use this library, also install https://github.com/antfu/i18n-ally
* to edit translations. open a new vscode window at <path to renderer-app>.
*/
30 changes: 0 additions & 30 deletions packages/flat-components/.storybook/i18next.js

This file was deleted.

133 changes: 94 additions & 39 deletions packages/flat-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,101 @@
const fs = require("fs");
const path = require("path");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");

module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
{
name: "@storybook/preset-create-react-app",
options: {
craOverrides: {
fileLoaderExcludes: ["less"],
}
}
stories: [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(ts|tsx)",
"../theme/**/*.stories.@(ts|tsx)",
],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
babel: async options => {
return {
...options,
plugins: [
[require.resolve("@babel/plugin-proposal-class-properties"), { loose: true }],
...(options.plugins || []),
],
};
},
webpackFinal: async config => {
setupUrlLoader(config);

config.plugins.push(
new ESLintPlugin({
fix: true,
extensions: ["ts", "tsx"],
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: path.resolve(__dirname, "..", "tsconfig.json"),
diagnosticOptions: {
semantic: true,
syntactic: true,
declaration: true,
},
},
}),
);

config.module.rules.unshift({
test: /\.(sass|scss)(\?.*)?$/i,
sideEffects: true,
use: [
{ loader: require.resolve("style-loader") },
{ loader: require.resolve("css-loader") },
{ loader: require.resolve("sass-loader") },
],
});

config.module.rules.unshift({
test: /\.(less)(\?.*)?$/i,
sideEffects: true,
use: [
{ loader: require.resolve("style-loader") },
{ loader: require.resolve("css-loader") },
{
loader: require.resolve("less-loader"),
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
});

return config;
},
"storybook-react-i18next",
"@storybook/addon-viewport",
],
"webpackFinal": (config) => {
config.module.rules.unshift({
test: /\.less$/,
sideEffects: true,
use: [
};

/** Inline image src */
function setupUrlLoader(config) {
config.module.rules = config.module.rules.filter(rule => {
return !(rule.loader && rule.loader.includes("file-loader"));
});

config.module.rules.unshift(
{
loader: "style-loader",
test: /\.(png|jpg|jpeg|gif|svg|ico|apng)(\?.*)?$/i,
use: [
{
loader: require.resolve("url-loader"),
options: {
limit: 14336,
name: "static/media/[name].[hash:8].[ext]",
esModule: false,
},
},
],
},
{
loader: "css-loader",
test: /\.(eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/i,
loader: require.resolve("file-loader"),
options: {
name: "static/media/[name].[hash:8].[ext]",
esModule: false,
},
},
{
loader: "less-loader",
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
});

return config;
}
}
);
}
3 changes: 3 additions & 0 deletions packages/flat-components/.storybook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Loading

0 comments on commit 8fc00d8

Please sign in to comment.