diff --git a/.eslintrc.js b/.eslintrc.js index 65707f5768b85b3da8e58c303c299d74fadee166..493c903fb32823ee16abdb4f53353bc64e4792cb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,7 +10,7 @@ module.exports = { jasmine: true, }, globals: { - APP_TYPE: true, + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 page: true, }, rules: { @@ -27,6 +27,7 @@ module.exports = { devDependencies: ['**/tests/**.js', '/mock/**/**.js', '**/**.test.js'], }, ], + 'import/no-cycle': 0, 'jsx-a11y/no-noninteractive-element-interactions': 0, 'jsx-a11y/click-events-have-key-events': 0, 'jsx-a11y/no-static-element-interactions': 0, diff --git a/.prettierignore b/.prettierignore index 6ce5e0186c7069221cdc1a321f1683d9c38d7c97..d33a869654cab5d4fcbc620cfb97d38bb0dcca36 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,3 @@ -**/*.md **/*.svg package.json .umi diff --git a/.prettierrc b/.prettierrc index d3698d4da5d190ff9dea6edf62f82369e6b16c62..064fef49ec669ecd6a362132ad6733fd7f2527c2 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,6 +2,7 @@ "singleQuote": true, "trailingComma": "all", "printWidth": 100, + "proseWrap": "never", "overrides": [ { "files": ".prettierrc", diff --git a/config/config.ts b/config/config.ts index 5a13406462c259d7a0788272f8b93cb3a488a04d..c7b5c76b5c14402af430d2097bb4d97421b20ae3 100644 --- a/config/config.ts +++ b/config/config.ts @@ -6,7 +6,8 @@ import defaultSettings from './defaultSettings'; import webpackPlugin from './plugin.config'; const { pwa, primaryColor } = defaultSettings; -const { APP_TYPE, TEST } = process.env; +// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST } = process.env; const plugins: IPlugin[] = [ [ @@ -57,8 +58,8 @@ const plugins: IPlugin[] = [ ]; // 针对 preview.pro.ant.design 的 GA 统计代码 -// 业务上不需要这个 -if (APP_TYPE === 'site') { +// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { plugins.push([ 'umi-plugin-ga', { @@ -71,12 +72,14 @@ export default { // add for transfer to umi plugins, define: { - APP_TYPE: APP_TYPE || '', + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 }, treeShaking: true, targets: { ie: 11, }, + devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false, // 路由配置 routes: [ { diff --git a/config/plugin.config.ts b/config/plugin.config.ts index 2273586e6753a24ea561f7ff8764926e3985688a..59ce550f422072f454a634ec5725b0cd1f39de35 100644 --- a/config/plugin.config.ts +++ b/config/plugin.config.ts @@ -24,8 +24,11 @@ function getModulePackageName(module) { } export default config => { - // pro 和 开发环境再添加这个插件 - if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') { + // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + if ( + process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' || + process.env.NODE_ENV !== 'production' + ) { // 将所有 less 合并为一个供 themePlugin使用 const outFile = path.join(__dirname, '../.temp/ant-design-pro.less'); const stylesDir = path.join(__dirname, '../src/'); diff --git a/jest.config.js b/jest.config.js index a1d8c22c46eb9e2af27371cbda86fc9d70fd7ea2..147a0252e938fa18917cac5bdc4446e1f86765a8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,8 @@ module.exports = { testURL: 'http://localhost:8000', preset: 'jest-puppeteer', + extraSetupFiles: ['./tests/setupTests.js'], globals: { - APP_TYPE: false, + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 }, }; diff --git a/lambda/mock/matchMock.js b/lambda/mock/matchMock.js index 94027802a6174e0bc0322a402c51d1ec51a53bd7..d74236126428dd543e48b76cbd9a1b3be1eec21a 100644 --- a/lambda/mock/matchMock.js +++ b/lambda/mock/matchMock.js @@ -14,7 +14,7 @@ function parseKey(key) { method = spliced[0].toLowerCase(); path = spliced[1]; // eslint-disable-line } - const routerBasePath = process.env.NODE_ENV === 'dev' ? `${path}` : `/.netlify/functions${path}`; + const routerBasePath = `${path}`; return { method, path: routerBasePath, diff --git a/netlify.toml b/netlify.toml index 5ecaa9640ddcfa44e69b09a66fda260740f87a3b..9d3438c4aff06f5a644d10167b5c7133f5175e45 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,7 +3,7 @@ [[redirects]] from = "/api/*" - to = "https://us-central1-antd-pro.cloudfunctions.net/api/api/:splat" + to = "/.netlify/functions/api/:splat" status = 200 force = true [redirects.headers] diff --git a/package.json b/package.json index 42626d912893f186223f00d24905fa70b006d6b6..a33e49fd35906650b5c04d862ff6332d2f8e27d7 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "lint:style": "stylelint 'src/**/*.less' --syntax less", "lint:ts": "tslint -p . -c tslint.yml", "prettier": "node ./scripts/prettier.js", - "start": "cross-env APP_TYPE=site umi dev", + "site": "umi build && npm run functions:build", + "start": "cross-env ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION=site umi dev", "start:no-mock": "cross-env MOCK=none umi dev", "test": "umi test", "test:all": "node ./tests/run-tests.js", @@ -111,29 +112,27 @@ "gh-pages": "^2.0.1", "husky": "^1.3.1", "jest-puppeteer": "^4.1.0", + "jsdom-global": "^3.0.2", "less": "^3.9.0", "lint-staged": "^8.1.1", "merge-umi-mock-data": "^1.0.4", "mockjs": "^1.0.1-beta3", "netlify-lambda": "^1.4.3", - "prettier": "^1.16.4", - "serverless-http": "^1.9.1", + "prettier": "^1.17.0", + "serverless-http": "^2.0.1", "slash2": "^2.0.0", "stylelint": "^9.10.1", "stylelint-config-css-modules": "^1.3.0", "stylelint-config-prettier": "^5.0.0", - "stylelint-config-rational-order": "^0.0.4", + "stylelint-config-rational-order": "^0.1.0", "stylelint-config-standard": "^18.2.0", - "stylelint-declaration-block-no-ignored-properties": "^1.1.0", + "stylelint-declaration-block-no-ignored-properties": "^2.1.0", "stylelint-order": "^2.0.0", "tslint": "^5.12.1", "tslint-config-prettier": "^1.17.0", "tslint-eslint-rules": "^5.4.0", "tslint-react": "^3.6.0", - "umi-plugin-ga": "^1.1.3", - "umi-plugin-pro-block": "^1.3.0", - "umi-plugin-react": "^1.7.2", - "umi-types": "^0.2.0" + "umi-plugin-ga": "^1.1.3" }, "optionalDependencies": { "puppeteer": "^1.12.1" diff --git a/scripts/getPrettierFiles.js b/scripts/getPrettierFiles.js index 2b01a8ef4828ec14503fabdd0ddf1779209d3cea..500ab0926cc3f5da078c23bed6219c4a6244e79c 100644 --- a/scripts/getPrettierFiles.js +++ b/scripts/getPrettierFiles.js @@ -7,11 +7,13 @@ const getPrettierFiles = () => { const configFiles = glob.sync('config/**/*.js*', { ignore: ['**/node_modules/**', 'build/**'] }); const scriptFiles = glob.sync('scripts/**/*.js'); const lessFiles = glob.sync('src/**/*.less*', { ignore: ['**/node_modules/**', 'build/**'] }); + const mdFiles = glob.sync('src/**/*.md*', { ignore: ['**/node_modules/**', 'build/**'] }); files = files.concat(jsFiles); files = files.concat(tsFiles); files = files.concat(configFiles); files = files.concat(scriptFiles); files = files.concat(lessFiles); + files = files.concat(mdFiles); if (!files.length) { return; } diff --git a/src/global.tsx b/src/global.tsx index d2e1a05cca82bc372e3e04857f27b2a0c40574e5..3a97886280b2db3d7938bf32bb382ea2de61a31e 100644 --- a/src/global.tsx +++ b/src/global.tsx @@ -3,8 +3,6 @@ import { notification, Button, message } from 'antd'; import { formatMessage } from 'umi-plugin-react/locale'; import defaultSettings from '../config/defaultSettings'; -(window as any).React = React; - const { pwa } = defaultSettings; // if pwa is true if (pwa) { @@ -59,4 +57,9 @@ if (pwa) { onClose: async () => {}, }); }); +} else if ('serviceWorker' in navigator) { + // eslint-disable-next-line compat/compat + navigator.serviceWorker.ready.then(registration => { + registration.unregister(); + }); } diff --git a/src/layouts/UserLayout.tsx b/src/layouts/UserLayout.tsx index 9f3fd1dc56a97abc0344044551c2888a22b171f6..9b757c80f569c8d121a610ba03cac6f53bb7b5e7 100644 --- a/src/layouts/UserLayout.tsx +++ b/src/layouts/UserLayout.tsx @@ -32,7 +32,7 @@ const links = [ const copyright = ( - Copyright 2018 蚂蚁金服体验技术部出品 + Copyright 2019 蚂蚁金服体验技术部出品 ); diff --git a/src/models/setting.ts b/src/models/setting.ts index bafdb3d4b5a246059c7095a5147e4d12db293201..6b8e0e673ef635a6bfd5cbed5e52f531e8f2dba3 100644 --- a/src/models/setting.ts +++ b/src/models/setting.ts @@ -14,7 +14,8 @@ let lessNodesAppended: boolean; const updateTheme: (primaryColor?: string) => void = primaryColor => { // Don't compile less in production! - if (APP_TYPE !== 'site') { + // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site') { return; } // Determine if the component is remounted diff --git a/src/utils/authority.ts b/src/utils/authority.ts index a87ac378e8a168a2d976cfaa1aabfb229b14fd04..bf0fa80609629b29d4710982a49f358ad3a8a266 100644 --- a/src/utils/authority.ts +++ b/src/utils/authority.ts @@ -13,7 +13,8 @@ export function getAuthority(str?: string): any { if (typeof authority === 'string') { return [authority]; } - if (!authority && APP_TYPE === 'site') { + // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { return ['admin']; } return authority; diff --git a/tests/setupTests.js b/tests/setupTests.js new file mode 100644 index 0000000000000000000000000000000000000000..1b15573e707eeef6e5faeafa240d27ac7ae33c1f --- /dev/null +++ b/tests/setupTests.js @@ -0,0 +1 @@ +import 'jsdom-global/register';