Sfoglia il codice sorgente

add version query string when load locales.

narro 5 anni fa
parent
commit
f8f462fe2d
12 ha cambiato i file con 52 aggiunte e 11 eliminazioni
  1. 3
    1
      .gitignore
  2. 3
    0
      CHANGELOG.md
  3. 1
    1
      README.md
  4. 18
    1
      config-overrides.js
  5. 3
    2
      lib/App.js
  6. 1
    1
      lib/App.js.map
  7. 1
    1
      lib/constant.js
  8. 1
    1
      lib/constant.js.map
  9. 8
    0
      lib/version.json
  10. 3
    2
      package.json
  11. 2
    1
      src/App.js
  12. 8
    0
      version.ejs

+ 3
- 1
.gitignore Vedi File

@@ -44,4 +44,6 @@ yarn.lock
44 44
 .env.production.local
45 45
 npm-debug.log*
46 46
 yarn-debug.log*
47
-yarn-error.log*
47
+yarn-error.log*
48
+
49
+src/version.json

+ 3
- 0
CHANGELOG.md Vedi File

@@ -1,5 +1,8 @@
1 1
 # CHANGELOG
2 2
 
3
+## 1.0.4
4
+- [x] 请求locales文件时加上hash值
5
+
3 6
 ## 1.0.3
4 7
 - [x] 修复语言文件覆盖的问题(将语言文件放到了linksFrontend库)
5 8
 

+ 1
- 1
README.md Vedi File

@@ -2,7 +2,7 @@
2 2
 
3 3
 通用评论系统及编辑器
4 4
 
5
-**`version 1.0.3`**
5
+**`version 1.0.4`**
6 6
 
7 7
 ```js
8 8
 import Comment, { Editor, RenderText } from 'comment';

+ 18
- 1
config-overrides.js Vedi File

@@ -1,7 +1,12 @@
1 1
 const { injectBabelPlugin, compose } = require('react-app-rewired');
2 2
 const rewireCssModules = require('react-app-rewire-css-modules');
3 3
 const rewireLess = require('react-app-rewire-less');
4
-
4
+const WebpackVersionFilePlugin = require('webpack-version-file-plugin');
5
+const execa = require('execa');
6
+const path = require('path');
7
+const gitHash = execa.sync('git', ['rev-parse', '--short', 'HEAD']).stdout;
8
+const gitNumCommits = Number(execa.sync('git', ['rev-list', 'HEAD', '--count']).stdout);
9
+const gitDirty = execa.sync('git', ['status', '-s', '-uall']).stdout.length > 0;
5 10
 
6 11
 module.exports = compose(
7 12
   rewireCssModules,
@@ -14,6 +19,18 @@ module.exports = function override(config, env) {
14 19
     rewireLess
15 20
   );
16 21
 
22
+  config.plugins.push(new WebpackVersionFilePlugin({
23
+    packageFile: path.join(__dirname, 'package.json'),
24
+    template: path.join(__dirname, 'version.ejs'),
25
+    outputFile: path.join(__dirname, '/src/version.json'),
26
+    extras: {
27
+      'githash': gitHash,
28
+      'gitNumCommits': gitNumCommits,
29
+      'timestamp': Date.now(),
30
+      'dirty': gitDirty
31
+    }
32
+  }));
33
+
17 34
   config = injectBabelPlugin(['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }], config);
18 35
   return rewires(config, env);
19 36
 };

+ 3
- 2
lib/App.js Vedi File

@@ -140,11 +140,12 @@ var App = function (_Component) {
140 140
       currentLocale = _lang.SUPPORT_LOCALES.find(function (item) {
141 141
         return item.value === currentLocale;
142 142
       }) ? currentLocale : "zh-CN";
143
+      var version = require('./version.json').hash;
143 144
       // 使用绝对路径
144
-      var languageURL = _constant.LANGUAGE_LINK + "/" + currentLocale + ".json";
145
+      var languageURL = _constant.LANGUAGE_LINK + "/" + currentLocale + ".json?v=" + version;
145 146
       return fetch(languageURL).then(function (response) {
146 147
         if (response.status >= 400) {
147
-          throw new Error('Bad response from server');
148
+          throw new Error("Bad response from server");
148 149
         }
149 150
         return response.json();
150 151
       }).then(function (data) {

+ 1
- 1
lib/App.js.map
File diff suppressed because it is too large
Vedi File


+ 1
- 1
lib/constant.js Vedi File

@@ -33,5 +33,5 @@ var COMMENT_TYPE = exports.COMMENT_TYPE = {
33 33
 };
34 34
 
35 35
 // 线上静态库地址
36
-var LANGUAGE_LINK = exports.LANGUAGE_LINK = process.env.NODE_ENV === 'production' ? "//a.links123.cn/lang" : "//a.links123.net/lang";
36
+var LANGUAGE_LINK = exports.LANGUAGE_LINK = process.env.NODE_ENV === "production" ? "//a.links123.cn/lang" : "//a.links123.net/lang";
37 37
 //# sourceMappingURL=constant.js.map

+ 1
- 1
lib/constant.js.map Vedi File

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","OSS_ENDPOINT","OSS_BUCKET","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","URL_REGEXP","REGEXP","AVATAR","IMAGE_SPLIT","IMAGE_PROCESS","IMAGE_PROCESS_SMALL","IMAGE_PROCESS_LARGE","COMMENT_TYPE","COMMENT","REPLY","LANGUAGE_LINK","process","env","NODE_ENV"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,sCAAe,6BAArB;AACA,IAAMC,kCAAa,eAAnB;AACA,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,6CAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,kCAAa,oGAAnB;;AAEA,IAAMC,0BAAS,eAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB;;AAEA,IAAMC,wCAAgB,mCAAtB;AACA,IAAMC,oDAAsB,mCAA5B;AACA,IAAMC,oDAAsB,mCAA5B;;AAEA,IAAMC,sCAAe;AAC1BC,WAAS,SADiB;AAE1BC,SAAO;AAFmB,CAArB;;AAKP;AACO,IAAMC,wCAAgBC,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GAC3B,sBAD2B,GACF,uBADpB","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\r\n\r\nexport const LIMIT = 10; // 默认 limit\r\n\r\nexport const OSS_ENDPOINT = \"oss-cn-beijing.aliyuncs.com\";\r\nexport const OSS_BUCKET = \"links-comment\";\r\nexport const DRIVER_LICENSE_PATH = \"/comment\";\r\n\r\nexport const OSS_LINK = \"//links-comment.oss-cn-beijing.aliyuncs.com\";\r\n\r\nexport const MAX_UPLOAD_NUMBER = 4;\r\n\r\nexport const URL_REGEXP = /((http(s)?:)?\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\r\n\r\nexport const REGEXP = /\\[[^[\\]]+?\\]/g;\r\n\r\nexport const AVATAR = \"\";\r\n\r\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\r\n\r\nexport const IMAGE_PROCESS = \"?x-oss-process=image/resize,h_350\";\r\nexport const IMAGE_PROCESS_SMALL = \"?x-oss-process=image/resize,h_100\";\r\nexport const IMAGE_PROCESS_LARGE = \"?x-oss-process=image/resize,h_500\";\r\n\r\nexport const COMMENT_TYPE = {\r\n  COMMENT: \"comment\",\r\n  REPLY: \"reply\"\r\n};\r\n\r\n// 线上静态库地址\r\nexport const LANGUAGE_LINK = process.env.NODE_ENV === 'production' ?\r\n  \"//a.links123.cn/lang\" : \"//a.links123.net/lang\";\r\n"]}
1
+{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","OSS_ENDPOINT","OSS_BUCKET","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","URL_REGEXP","REGEXP","AVATAR","IMAGE_SPLIT","IMAGE_PROCESS","IMAGE_PROCESS_SMALL","IMAGE_PROCESS_LARGE","COMMENT_TYPE","COMMENT","REPLY","LANGUAGE_LINK","process","env","NODE_ENV"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,sCAAe,6BAArB;AACA,IAAMC,kCAAa,eAAnB;AACA,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,6CAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,kCAAa,oGAAnB;;AAEA,IAAMC,0BAAS,eAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB;;AAEA,IAAMC,wCAAgB,mCAAtB;AACA,IAAMC,oDAAsB,mCAA5B;AACA,IAAMC,oDAAsB,mCAA5B;;AAEA,IAAMC,sCAAe;AAC1BC,WAAS,SADiB;AAE1BC,SAAO;AAFmB,CAArB;;AAKP;AACO,IAAMC,wCACXC,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,sBADJ,GAEI,uBAHC","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\r\n\r\nexport const LIMIT = 10; // 默认 limit\r\n\r\nexport const OSS_ENDPOINT = \"oss-cn-beijing.aliyuncs.com\";\r\nexport const OSS_BUCKET = \"links-comment\";\r\nexport const DRIVER_LICENSE_PATH = \"/comment\";\r\n\r\nexport const OSS_LINK = \"//links-comment.oss-cn-beijing.aliyuncs.com\";\r\n\r\nexport const MAX_UPLOAD_NUMBER = 4;\r\n\r\nexport const URL_REGEXP = /((http(s)?:)?\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\r\n\r\nexport const REGEXP = /\\[[^[\\]]+?\\]/g;\r\n\r\nexport const AVATAR = \"\";\r\n\r\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\r\n\r\nexport const IMAGE_PROCESS = \"?x-oss-process=image/resize,h_350\";\r\nexport const IMAGE_PROCESS_SMALL = \"?x-oss-process=image/resize,h_100\";\r\nexport const IMAGE_PROCESS_LARGE = \"?x-oss-process=image/resize,h_500\";\r\n\r\nexport const COMMENT_TYPE = {\r\n  COMMENT: \"comment\",\r\n  REPLY: \"reply\"\r\n};\r\n\r\n// 线上静态库地址\r\nexport const LANGUAGE_LINK =\r\n  process.env.NODE_ENV === \"production\"\r\n    ? \"//a.links123.cn/lang\"\r\n    : \"//a.links123.net/lang\";\r\n"]}

+ 8
- 0
lib/version.json Vedi File

@@ -0,0 +1,8 @@
1
+{
2
+    "name":       "comment",
3
+    "buildDate":  1550239468846,
4
+    "version":    "1.0.3",
5
+    "numCommits": 129,
6
+    "hash":       "486ece3",
7
+    "dirty":      true
8
+}

+ 3
- 2
package.json Vedi File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "comment",
3
-  "version": "1.0.3",
3
+  "version": "1.0.4",
4 4
   "main": "lib/App.js",
5 5
   "description": "通用评论",
6 6
   "keywords": [
@@ -22,7 +22,8 @@
22 22
     "react-dom": "^16.4.1",
23 23
     "react-intl-universal": "^1.15.2",
24 24
     "react-scripts": "1.1.4",
25
-    "shortid": "^2.2.11"
25
+    "shortid": "^2.2.11",
26
+    "webpack-version-file-plugin": "^0.3.3"
26 27
   },
27 28
   "lint-staged": {
28 29
     "src/**/*.{js,jsx,json,css,less}": [

+ 2
- 1
src/App.js Vedi File

@@ -73,8 +73,9 @@ class App extends Component {
73 73
     currentLocale = SUPPORT_LOCALES.find(item => item.value === currentLocale)
74 74
       ? currentLocale
75 75
       : "zh-CN";
76
+    const version = require("./version.json").hash;
76 77
     // 使用绝对路径
77
-    const languageURL = `${LANGUAGE_LINK}/${currentLocale}.json`;
78
+    const languageURL = `${LANGUAGE_LINK}/${currentLocale}.json?v=${version}`;
78 79
     return fetch(languageURL)
79 80
       .then(response => {
80 81
         if (response.status >= 400) {

+ 8
- 0
version.ejs Vedi File

@@ -0,0 +1,8 @@
1
+{
2
+    "name":       "<%= package.name %>",
3
+    "buildDate":  <%= extras.timestamp %>,
4
+    "version":    "<%= package.version %>",
5
+    "numCommits": <%= extras.gitNumCommits %>,
6
+    "hash":       "<%= extras.githash %>",
7
+    "dirty":      <%= extras.dirty %>
8
+}