소스 검색

Merge branch 'master' into v4

陈帅 6 년 전
부모
커밋
c7bffe52f1
15개의 변경된 파일40개의 추가작업 그리고 25개의 파일을 삭제
  1. 2 1
      .eslintrc.js
  2. 0 1
      .prettierignore
  3. 1 0
      .prettierrc
  4. 7 4
      config/config.ts
  5. 5 2
      config/plugin.config.ts
  6. 2 1
      jest.config.js
  7. 1 1
      lambda/mock/matchMock.js
  8. 1 1
      netlify.toml
  9. 8 9
      package.json
  10. 2 0
      scripts/getPrettierFiles.js
  11. 5 2
      src/global.tsx
  12. 1 1
      src/layouts/UserLayout.tsx
  13. 2 1
      src/models/setting.ts
  14. 2 1
      src/utils/authority.ts
  15. 1 0
      tests/setupTests.js

+ 2 - 1
.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,

+ 0 - 1
.prettierignore

@@ -1,4 +1,3 @@
-**/*.md
 **/*.svg
 package.json
 .umi

+ 1 - 0
.prettierrc

@@ -2,6 +2,7 @@
   "singleQuote": true,
   "trailingComma": "all",
   "printWidth": 100,
+  "proseWrap": "never",
   "overrides": [
     {
       "files": ".prettierrc",

+ 7 - 4
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: [
     {

+ 5 - 2
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/');

+ 2 - 1
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 专用环境变量,请不要在你的项目中使用它。
   },
 };

+ 1 - 1
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,

+ 1 - 1
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]

+ 8 - 9
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"

+ 2 - 0
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;
   }

+ 5 - 2
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();
+  });
 }

+ 1 - 1
src/layouts/UserLayout.tsx

@@ -32,7 +32,7 @@ const links = [
 
 const copyright = (
   <Fragment>
-    Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品
+    Copyright <Icon type="copyright" /> 2019 蚂蚁金服体验技术部出品
   </Fragment>
 );
 

+ 2 - 1
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

+ 2 - 1
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;

+ 1 - 0
tests/setupTests.js

@@ -0,0 +1 @@
+import 'jsdom-global/register';