express-cmd 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a73377e3082ce9abb9e910c7d74789a5184f6b11
4
- data.tar.gz: 7b364ad9da3eb258800bd6985edc929274504c7a
3
+ metadata.gz: 5301e51b2e87d44a253b3bd17eaccad435aa138a
4
+ data.tar.gz: 13edd49f757ba680c93d0cbe7773caa26dbfd583
5
5
  SHA512:
6
- metadata.gz: bd714075d15db5718792f258f3434b25c99160172262aa7cc96136e1dcdbfccc8d2ad82dd8dd737ba976d99b1511dfed50e6bef88760f65028a6bed15822c729
7
- data.tar.gz: 7289bf3608b1559ffad6484121e9f3d63d3274dba3ab86b23d2b6f7c8dd17000900f93a75133062916856fd31dc90f04b3c25faa22ae2a95026c693b0cfd56d0
6
+ metadata.gz: ca912f7f467cc187f97bb62fcf841879ef1c008d0dec8f9a2639b24d306fe1073cccd0bfbaa9a110f42dbb0d922f2cf3584b23f534cf1d141754bbd5740d7672
7
+ data.tar.gz: f58d075f22e5c92257a86e416a4cef59a8ab5759f8fcb779d690c797c82a87cac696c2ffaacb5f1ddfd75737e283d0fa34a2bbfd9e790cdcf0ebd6668c0dfd4a
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /test-project
11
+
12
+ /*.gem
data/README.md CHANGED
@@ -20,16 +20,20 @@ Or install it yourself as:
20
20
 
21
21
  I choose `mongodb` as my datastore, and I perfer to use `mongoose`.
22
22
 
23
- 1. make sure you have installed node-inspector (debug tool) and nodemon (node auto reload after saved).
23
+ 1. make sure you have installed node-inspector (debug tool) and nodemon (node auto reload after saved).
24
24
 
25
25
  ```bash
26
26
  npm install -g node-inspector
27
27
  npm install -g nodemon
28
28
  ```
29
29
 
30
- 2. `express app_name`, and you can specify an option, for example `express my-project --skip_npm_install`.
30
+ 2. `express app_name`, and you can specify an option, for example `express my-project --skip_npm_install`.
31
31
 
32
- **supported options**: `--skip_npm_install`.
32
+ > supported options:
33
+
34
+ `--skip_npm_install`.
35
+
36
+ 3. I use `i18next` as translations framework.
33
37
 
34
38
  ## Test
35
39
 
@@ -12,35 +12,47 @@ module ExpressCmd
12
12
  end
13
13
 
14
14
  def setup_lib
15
- keep_file "#{app_name}/lib"
15
+ empty_directory "#{app_name}/lib"
16
16
  copy_file "lib/errors.js", "#{app_name}/lib/errors.js"
17
17
  copy_file "lib/logger.js", "#{app_name}/lib/logger.js"
18
18
  end
19
19
 
20
20
  def setup_config
21
- keep_file "#{app_name}/config"
21
+ empty_directory "#{app_name}/config"
22
22
  copy_file "config/mongo.js", "#{app_name}/config/mongo.js"
23
23
  copy_file "config/mongo.yml", "#{app_name}/config/mongo.yml"
24
+
25
+ empty_directory "#{app_name}/config/locales"
26
+ empty_directory "#{app_name}/config/locales/en-us"
27
+ empty_directory "#{app_name}/config/locales/zh-cn"
28
+ copy_file "config/locales/en-us/ns.special.json", "#{app_name}/config/locales/en-us/ns.special.json"
29
+ copy_file "config/locales/zh-cn/ns.special.json", "#{app_name}/config/locales/zh-cn/ns.special.json"
30
+ copy_file "config/i18n.js", "#{app_name}/config/i18n.js"
24
31
  end
25
32
 
26
33
  def setup_middleware
27
- keep_file "#{app_name}/middlewares"
34
+ empty_directory "#{app_name}/middlewares"
28
35
  copy_file "middlewares/before-filter.js", "#{app_name}/middlewares/before-filter.js"
29
36
  copy_file "middlewares/error-handler.js", "#{app_name}/middlewares/error-handler.js"
30
37
  copy_file "middlewares/morgan-log.js", "#{app_name}/middlewares/morgan-log.js"
38
+ copy_file "middlewares/i18n.js", "#{app_name}/middlewares/i18n.js"
39
+ end
40
+
41
+ def setup_model
42
+ keep_file "#{app_name}/models"
31
43
  end
32
44
 
33
45
  def setup_route
34
- keep_file "#{app_name}/routes"
46
+ empty_directory "#{app_name}/routes"
35
47
  copy_file "routes/instance.js", "#{app_name}/routes/instance.js"
36
48
  copy_file "routes/configuration.js", "#{app_name}/routes/configuration.js"
37
49
  copy_file "routes/translation.js", "#{app_name}/routes/translation.js"
38
50
  end
39
51
 
40
52
  def setup_test
41
- keep_file "#{app_name}/test"
53
+ empty_directory "#{app_name}/test"
42
54
  keep_file "#{app_name}/test/reporter"
43
- keep_file "#{app_name}/test/units"
55
+ empty_directory "#{app_name}/test/units"
44
56
 
45
57
  copy_file "test/test-helper.js", "#{app_name}/test/test-helper.js"
46
58
  copy_file "test/units/demo_test.js", "#{app_name}/test/units/demo_test.js"
@@ -1,3 +1,3 @@
1
1
  module ExpressCmd
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -2,7 +2,5 @@
2
2
  /.idea
3
3
  /node_modules
4
4
  /log
5
- /test/reporter/*.xml
5
+ /test/reporter
6
6
  .npm-debug.log
7
-
8
- /*.gem
@@ -0,0 +1,20 @@
1
+ var i18n = require('i18next');
2
+ var path = require('path');
3
+
4
+ configDir = path.join(__dirname, '../config')
5
+
6
+ // I18n Config
7
+ // http://i18next.com/node/pages/doc_init.html
8
+ i18n.init({
9
+ detectLngQS: 'locale',
10
+ lngWhitelist: ['en-us', 'zh-cn'],
11
+ resGetPath: configDir + "/locales/__lng__/__ns__.json",
12
+ ns: {namespaces: ['ns.special'], defaultNs: 'ns.special'},
13
+ debug: true,
14
+ lowerCaseLng: true,
15
+ fallbackLng: ['en-us'],
16
+ useCookie: false,
17
+ detectLngFromLocalStorage: false
18
+ });
19
+
20
+ module.exports = i18n;
@@ -0,0 +1,12 @@
1
+ {
2
+ "errorHandling": {
3
+ "badRequest": "Invalid request data",
4
+ "authRequired": "Authorization required",
5
+ "forbidden": "Forbidden",
6
+ "notFound": "Not found",
7
+ "internalServerError": "Internal server error",
8
+ "multiJson": {
9
+ "decode": "Problems parsing JSON"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "errorHandling": {
3
+ "badRequest": "错误的请求",
4
+ "authRequired": "验证失败",
5
+ "forbidden": "未授权",
6
+ "notFound": "未找到",
7
+ "internalServerError": "内部错误",
8
+ "multiJson": {
9
+ "decode": "解析JSON出错"
10
+ }
11
+ }
12
+ }
@@ -1,3 +1,5 @@
1
+ var i18n = require('../config/i18n');
2
+
1
3
  var hasProp = {}.hasOwnProperty;
2
4
  var extend = function (child, parent) {
3
5
  for (var key in parent) {
@@ -18,7 +20,7 @@ var AuthError = (function (superClass) {
18
20
 
19
21
  function AuthError(message) {
20
22
  this.status = 401;
21
- this.message = 'Unauthorized';
23
+ this.message = message || i18n.t('errorHandling.authRequired');
22
24
  AuthError.__super__.constructor.call(this, this.message);
23
25
  }
24
26
 
@@ -30,7 +32,7 @@ var ReqError = (function (superClass) {
30
32
 
31
33
  function ReqError(message) {
32
34
  this.status = 400;
33
- this.message = 'Invalid request data';
35
+ this.message = message || i18n.t('errorHandling.badRequest');
34
36
  ReqError.__super__.constructor.call(this, this.message);
35
37
  }
36
38
 
@@ -13,7 +13,8 @@ module.exports = function(app) {
13
13
  if ('OPTIONS' === req.method || req.path === '/favicon.ico') {
14
14
  return res.status(204).end();
15
15
  }
16
- // TODO: write your auth logic.
16
+
17
+ // TODO: You can write your auth logic.
17
18
  if (!req.get('X-Access-Token')) {
18
19
  return next(new AuthError());
19
20
  } else {
@@ -0,0 +1,5 @@
1
+ var i18n = require('../config/i18n');
2
+
3
+ module.exports = function (app) {
4
+ app.use(i18n.handle);
5
+ }
@@ -20,6 +20,7 @@
20
20
  "ejs": "^2.3.2",
21
21
  "express": "^4.12.4",
22
22
  "file-stream-rotator": "0.0.6",
23
+ "i18next": "^1.7.10",
23
24
  "js-yaml": "^3.3.1",
24
25
  "mocha": "^2.2.5",
25
26
  "mocha-jenkins-reporter": "^0.1.8",
@@ -17,6 +17,8 @@ app.use(cookieParser());
17
17
  app.set('port', process.env.PORT || 9292);
18
18
  app.set('env', process.env.NODE_ENV || 'development');
19
19
 
20
+ // I18n
21
+ require('./middlewares/i18n')(app);
20
22
  // Before Filter
21
23
  require('./middlewares/before-filter')(app);
22
24
  // Access Log
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - wluo
@@ -133,12 +133,16 @@ files:
133
133
  - templates/.gitignore
134
134
  - templates/Makefile
135
135
  - templates/README.md.erb
136
+ - templates/config/i18n.js
137
+ - templates/config/locales/en-us/ns.special.json
138
+ - templates/config/locales/zh-cn/ns.special.json
136
139
  - templates/config/mongo.js
137
140
  - templates/config/mongo.yml
138
141
  - templates/lib/errors.js
139
142
  - templates/lib/logger.js
140
143
  - templates/middlewares/before-filter.js
141
144
  - templates/middlewares/error-handler.js
145
+ - templates/middlewares/i18n.js
142
146
  - templates/middlewares/morgan-log.js
143
147
  - templates/package.json.erb
144
148
  - templates/routes/configuration.js