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 +4 -4
- data/.gitignore +2 -0
- data/README.md +7 -3
- data/lib/express_cmd/generator.rb +18 -6
- data/lib/express_cmd/version.rb +1 -1
- data/templates/.gitignore +1 -3
- data/templates/config/i18n.js +20 -0
- data/templates/config/locales/en-us/ns.special.json +12 -0
- data/templates/config/locales/zh-cn/ns.special.json +12 -0
- data/templates/lib/errors.js +4 -2
- data/templates/middlewares/before-filter.js +2 -1
- data/templates/middlewares/i18n.js +5 -0
- data/templates/package.json.erb +1 -0
- data/templates/server.js +2 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5301e51b2e87d44a253b3bd17eaccad435aa138a
|
4
|
+
data.tar.gz: 13edd49f757ba680c93d0cbe7773caa26dbfd583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca912f7f467cc187f97bb62fcf841879ef1c008d0dec8f9a2639b24d306fe1073cccd0bfbaa9a110f42dbb0d922f2cf3584b23f534cf1d141754bbd5740d7672
|
7
|
+
data.tar.gz: f58d075f22e5c92257a86e416a4cef59a8ab5759f8fcb779d690c797c82a87cac696c2ffaacb5f1ddfd75737e283d0fa34a2bbfd9e790cdcf0ebd6668c0dfd4a
|
data/.gitignore
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
53
|
+
empty_directory "#{app_name}/test"
|
42
54
|
keep_file "#{app_name}/test/reporter"
|
43
|
-
|
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"
|
data/lib/express_cmd/version.rb
CHANGED
data/templates/.gitignore
CHANGED
@@ -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
|
+
}
|
data/templates/lib/errors.js
CHANGED
@@ -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 = '
|
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 =
|
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
|
-
|
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 {
|
data/templates/package.json.erb
CHANGED
data/templates/server.js
CHANGED
@@ -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.
|
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
|