express-cmd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/express +5 -0
- data/express-cmd.gemspec +32 -0
- data/lib/express_cmd.rb +3 -0
- data/lib/express_cmd/generator.rb +64 -0
- data/lib/express_cmd/version.rb +3 -0
- data/spec/generate_spec.rb +6 -0
- data/spec/spec_helper.rb +72 -0
- data/templates/.gitignore +6 -0
- data/templates/Makefile +23 -0
- data/templates/README.md.erb +2 -0
- data/templates/lib/errors.js +43 -0
- data/templates/lib/logger.js +32 -0
- data/templates/middlewares/before-filter.js +23 -0
- data/templates/middlewares/error-handler.js +15 -0
- data/templates/middlewares/morgan-log.js +21 -0
- data/templates/package.json.erb +34 -0
- data/templates/routes/configuration.js +5 -0
- data/templates/routes/instance.js +9 -0
- data/templates/routes/translation.js +5 -0
- data/templates/server.js +45 -0
- data/templates/test/test-helper.js +2 -0
- data/templates/test/units/demo_test.js +12 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77faa4bacd536793459ae2304eb0d052bfafae44
|
4
|
+
data.tar.gz: 1adfec2e2ff87a01b2e32a14481524021a29a238
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4deaf6a98c7783c49bf9030473cb4f24008459058029a01ffd440bf6f06c68e5493ad6b7de6635c7819e07ef1b667ef5e0cad9e6b3804489bf7b85e82680c393
|
7
|
+
data.tar.gz: 665c11831b915ca1e63aad8674654681d3a8333cc8dcad919207bea256118307639440113d2c5fce703ca8f08af5c1f4fff55eda7240636360a9b837cbd8664e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 wluo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# ExpressCmd
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/express/cmd`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'express-cmd'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install express-cmd
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/express-cmd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/express
ADDED
data/express-cmd.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'express_cmd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "express-cmd"
|
8
|
+
spec.version = ExpressCmd::VERSION
|
9
|
+
spec.authors = ["wluo"]
|
10
|
+
spec.email = ["luowei---010101@163.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Command for generating sinatra project}
|
13
|
+
spec.description = %q{Generate a sinatra project.}
|
14
|
+
spec.homepage = "https://github.com/hilotus/express-cmd"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.1.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "thor", "~> 0.19"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
30
|
+
spec.add_development_dependency "pry-stack_explorer", "~> 0.4"
|
31
|
+
spec.add_development_dependency "pry-byebug", "~> 3.0"
|
32
|
+
end
|
data/lib/express_cmd.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module ExpressCmd
|
4
|
+
class Generator < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
argument :app_name
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.join(File.dirname(__FILE__), "../../", "templates")
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_lib
|
14
|
+
keep_file "#{app_name}/lib"
|
15
|
+
copy_file "lib/errors.js", "#{app_name}/lib/errors.js"
|
16
|
+
copy_file "lib/logger.js", "#{app_name}/lib/logger.js"
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_config
|
20
|
+
keep_file "#{app_name}/config"
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_middleware
|
24
|
+
keep_file "#{app_name}/middlewares"
|
25
|
+
copy_file "middlewares/before-filter.js", "#{app_name}/middlewares/before-filter.js"
|
26
|
+
copy_file "middlewares/error-handler.js", "#{app_name}/middlewares/error-handler.js"
|
27
|
+
copy_file "middlewares/morgan-log.js", "#{app_name}/middlewares/morgan-log.js"
|
28
|
+
end
|
29
|
+
|
30
|
+
def setup_route
|
31
|
+
keep_file "#{app_name}/routes"
|
32
|
+
copy_file "routes/instance.js", "#{app_name}/routes/instance.js"
|
33
|
+
copy_file "routes/configuration.js", "#{app_name}/routes/configuration.js"
|
34
|
+
copy_file "routes/translation.js", "#{app_name}/routes/translation.js"
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup_test
|
38
|
+
keep_file "#{app_name}/test"
|
39
|
+
keep_file "#{app_name}/test/reporter"
|
40
|
+
keep_file "#{app_name}/test/units"
|
41
|
+
|
42
|
+
copy_file "test/test-helper.js", "#{app_name}/test/test-helper.js"
|
43
|
+
copy_file "test/units/demo_test.js", "#{app_name}/test/units/demo_test.js"
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup_appfile
|
47
|
+
copy_file ".gitignore", "#{app_name}/.gitignore"
|
48
|
+
copy_file "Makefile", "#{app_name}/Makefile"
|
49
|
+
copy_file "server.js", "#{app_name}/server.js"
|
50
|
+
template "package.json.erb", "#{app_name}/package.json"
|
51
|
+
template "README.md.erb", "#{app_name}/README.md"
|
52
|
+
end
|
53
|
+
|
54
|
+
def bundle_install
|
55
|
+
system "cd #{app_name} && npm install && cd ../"
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def keep_file(destination)
|
61
|
+
create_file "#{destination}/.gitkeep"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'express_cmd' # and any other gems you need
|
5
|
+
|
6
|
+
require 'pry' # for debuge
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# config.include Capybara::DSL,:type=>:request
|
10
|
+
# The settings below are suggested to provide a good initial experience
|
11
|
+
# with RSpec, but feel free to customize to your heart's content.
|
12
|
+
#=begin
|
13
|
+
# These two settings work together to allow you to limit a spec run
|
14
|
+
# to individual examples or groups you care about by tagging them with
|
15
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
16
|
+
# get run.
|
17
|
+
# config.filter_run :focus
|
18
|
+
# config.run_all_when_everything_filtered = true
|
19
|
+
|
20
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
21
|
+
# file, and it's useful to allow more verbose output when running an
|
22
|
+
# individual spec file.
|
23
|
+
# if config.files_to_run.one?
|
24
|
+
# Use the documentation formatter for detailed output,
|
25
|
+
# unless a formatter has already been configured
|
26
|
+
# (e.g. via a command-line flag).
|
27
|
+
# config.default_formatter = 'doc'
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Print the 10 slowest examples and example groups at the
|
31
|
+
# end of the spec run, to help surface which specs are running
|
32
|
+
# particularly slow.
|
33
|
+
config.profile_examples = 10
|
34
|
+
|
35
|
+
# Run specs in random order to surface order dependencies. If you find an
|
36
|
+
# order dependency and want to debug it, you can fix the order by providing
|
37
|
+
# the seed, which is printed after each run.
|
38
|
+
# --seed 1234
|
39
|
+
config.order = :random
|
40
|
+
|
41
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
42
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
43
|
+
# test failures related to randomization by passing the same `--seed` value
|
44
|
+
# as the one that triggered the failure.
|
45
|
+
Kernel.srand config.seed
|
46
|
+
|
47
|
+
# rspec-expectations config goes here. You can use an alternate
|
48
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
49
|
+
# assertions if you prefer.
|
50
|
+
config.expect_with :rspec do |expectations|
|
51
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
expectations.syntax = :expect
|
55
|
+
|
56
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
57
|
+
end
|
58
|
+
|
59
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
60
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
61
|
+
config.mock_with :rspec do |mocks|
|
62
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
63
|
+
# For more details, see:
|
64
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
65
|
+
mocks.syntax = :expect
|
66
|
+
|
67
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
68
|
+
# a real object. This is generally recommended.
|
69
|
+
mocks.verify_partial_doubles = true
|
70
|
+
end
|
71
|
+
#=end
|
72
|
+
end
|
data/templates/Makefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
TESTS = test/units/**/*.js
|
2
|
+
REPORTER = spec
|
3
|
+
|
4
|
+
test:
|
5
|
+
@./node_modules/.bin/mocha \
|
6
|
+
--require test/test-helper.js \
|
7
|
+
--timeout 15000 \
|
8
|
+
--colors \
|
9
|
+
--reporter $(REPORTER) \
|
10
|
+
$(TESTS)
|
11
|
+
|
12
|
+
.PHONY: test
|
13
|
+
|
14
|
+
jenkins:
|
15
|
+
@JUNIT_REPORT_PATH=test/reporter/report.xml JUNIT_REPORT_STACK=1 \
|
16
|
+
./node_modules/.bin/mocha \
|
17
|
+
--require test/test-helper.js \
|
18
|
+
--timeout 15000 \
|
19
|
+
--colors \
|
20
|
+
--reporter mocha-jenkins-reporter \
|
21
|
+
$(TESTS)
|
22
|
+
|
23
|
+
.PHONY: jenkins
|
@@ -0,0 +1,43 @@
|
|
1
|
+
var hasProp = {}.hasOwnProperty;
|
2
|
+
var extend = function(child, parent) {
|
3
|
+
for (var key in parent) {
|
4
|
+
if (hasProp.call(parent, key))
|
5
|
+
child[key] = parent[key];
|
6
|
+
}
|
7
|
+
function ctor() {
|
8
|
+
this.constructor = child;
|
9
|
+
}
|
10
|
+
ctor.prototype = parent.prototype;
|
11
|
+
child.prototype = new ctor();
|
12
|
+
child.__super__ = parent.prototype;
|
13
|
+
return child;
|
14
|
+
};
|
15
|
+
|
16
|
+
var AuthError = (function(superClass) {
|
17
|
+
extend(AuthError, superClass);
|
18
|
+
|
19
|
+
function AuthError(message) {
|
20
|
+
this.status = 401;
|
21
|
+
this.message = 'Unauthorized';
|
22
|
+
AuthError.__super__.constructor.call(this, this.message);
|
23
|
+
}
|
24
|
+
|
25
|
+
return AuthError;
|
26
|
+
})(Error);
|
27
|
+
|
28
|
+
var ReqError = (function(superClass) {
|
29
|
+
extend(ReqError, superClass);
|
30
|
+
|
31
|
+
function ReqError(message) {
|
32
|
+
this.status = 400;
|
33
|
+
this.message = 'Invalid request data';
|
34
|
+
ReqError.__super__.constructor.call(this, this.message);
|
35
|
+
}
|
36
|
+
|
37
|
+
return ReqError;
|
38
|
+
})(Error);
|
39
|
+
|
40
|
+
module.exports = {
|
41
|
+
AuthError: AuthError,
|
42
|
+
ReqError: ReqError
|
43
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var winston = require('winston');
|
2
|
+
var path = require('path');
|
3
|
+
|
4
|
+
var transports = [];
|
5
|
+
transports.push(new winston.transports.DailyRotateFile({
|
6
|
+
name: 'system',
|
7
|
+
datePattern: 'yyyy-MM-dd.log',
|
8
|
+
filename: path.join(__dirname, '../log', 'system-'),
|
9
|
+
json: false,
|
10
|
+
level: 'info'
|
11
|
+
}));
|
12
|
+
transports.push(new winston.transports.Console({
|
13
|
+
colorize: true
|
14
|
+
}));
|
15
|
+
|
16
|
+
var exceptionHandlers = [];
|
17
|
+
exceptionHandlers.push(new winston.transports.DailyRotateFile({
|
18
|
+
name: 'exception',
|
19
|
+
datePattern: 'yyyy-MM-dd.log',
|
20
|
+
filename: path.join(__dirname, '../log', 'exception-'),
|
21
|
+
json: false,
|
22
|
+
level: 'debug'
|
23
|
+
}));
|
24
|
+
exceptionHandlers.push(new winston.transports.Console({
|
25
|
+
colorize: true,
|
26
|
+
level: 'debug'
|
27
|
+
}));
|
28
|
+
|
29
|
+
module.exports = new winston.Logger({
|
30
|
+
transports: transports,
|
31
|
+
exceptionHandlers: exceptionHandlers
|
32
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
var AuthError = require('../lib/errors').AuthError;
|
2
|
+
|
3
|
+
module.exports = function(app) {
|
4
|
+
return app.use(function(req, res, next) {
|
5
|
+
var origin = req.get('origin');
|
6
|
+
if (origin) {
|
7
|
+
res.header('Access-Control-Allow-Origin', origin);
|
8
|
+
}
|
9
|
+
res.header('Access-Control-Allow-Credentials', 'true');
|
10
|
+
res.header('Content-Type', 'application/json; charset=UTF-8');
|
11
|
+
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
12
|
+
|
13
|
+
if ('OPTIONS' === req.method || req.path === '/favicon.ico') {
|
14
|
+
return res.status(204).end();
|
15
|
+
}
|
16
|
+
// TODO: write your auth logic.
|
17
|
+
if (!req.get('X-Access-Token')) {
|
18
|
+
return next(new AuthError());
|
19
|
+
} else {
|
20
|
+
return next();
|
21
|
+
}
|
22
|
+
});
|
23
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
var logger = require('../lib/logger');
|
2
|
+
|
3
|
+
// definded error handler.
|
4
|
+
module.exports = function(app, apiRouter) {
|
5
|
+
return app.use(function(err, req, res, next) {
|
6
|
+
var statusCode = err.status || 500;
|
7
|
+
logger.error(statusCode + ": " + err.message + ", \n " + (err.stack || ''));
|
8
|
+
|
9
|
+
res.status(statusCode);
|
10
|
+
return res.json({
|
11
|
+
code: statusCode,
|
12
|
+
error: err.message
|
13
|
+
});
|
14
|
+
});
|
15
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
var morgan = require('morgan');
|
2
|
+
var path = require('path');
|
3
|
+
var fs = require('fs');
|
4
|
+
|
5
|
+
module.exports = function(app) {
|
6
|
+
var accessLogStream, env, logDirectory;
|
7
|
+
|
8
|
+
logDirectory = path.join(__dirname, '../log');
|
9
|
+
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory);
|
10
|
+
env = app.get('env');
|
11
|
+
|
12
|
+
accessLogStream = require('file-stream-rotator').getStream({
|
13
|
+
filename: logDirectory + '/access-' + env + '-%DATE%.log',
|
14
|
+
frequency: 'daily',
|
15
|
+
verbose: env === 'development',
|
16
|
+
date_format: "YYYY-MM-DD"
|
17
|
+
});
|
18
|
+
return app.use(morgan('combined', {
|
19
|
+
stream: accessLogStream
|
20
|
+
}));
|
21
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"name": "<%= app_name %>",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "TODO: xxxx",
|
5
|
+
"private": true,
|
6
|
+
"scripts": {
|
7
|
+
"start": "nodemon server.js",
|
8
|
+
"debug": "nodemon --debug server.js",
|
9
|
+
"test": "make test"
|
10
|
+
},
|
11
|
+
"keywords": [
|
12
|
+
],
|
13
|
+
"author": "CB",
|
14
|
+
"license": "ISC",
|
15
|
+
"dependencies": {
|
16
|
+
"async": "^1.2.1",
|
17
|
+
"body-parser": "^1.12.3",
|
18
|
+
"chai": "^3.0.0",
|
19
|
+
"cookie-parser": "^1.3.4",
|
20
|
+
"ejs": "^2.3.2",
|
21
|
+
"express": "^4.12.4",
|
22
|
+
"file-stream-rotator": "0.0.6",
|
23
|
+
"js-yaml": "^3.3.1",
|
24
|
+
"mocha": "^2.2.5",
|
25
|
+
"mocha-jenkins-reporter": "^0.1.8",
|
26
|
+
"moment": "^2.10.3",
|
27
|
+
"morgan": "^1.5.2",
|
28
|
+
"multer": "^0.1.8",
|
29
|
+
"path": "^0.11.14",
|
30
|
+
"query-string": "^2.3.0",
|
31
|
+
"rsvp": "^3.0.18",
|
32
|
+
"winston": "^1.0.0"
|
33
|
+
}
|
34
|
+
}
|
data/templates/server.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var app = express();
|
3
|
+
var bodyParser = require('body-parser');
|
4
|
+
var multer = require('multer');
|
5
|
+
var cookieParser = require('cookie-parser');
|
6
|
+
|
7
|
+
var logger = require('./lib/logger');
|
8
|
+
|
9
|
+
// MiddleWare
|
10
|
+
app.use(bodyParser.json());
|
11
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
12
|
+
app.use(multer());
|
13
|
+
app.use(cookieParser());
|
14
|
+
|
15
|
+
app.set('port', process.env.PORT || 9292);
|
16
|
+
app.set('env', process.env.NODE_ENV || 'development');
|
17
|
+
|
18
|
+
// Before Filter
|
19
|
+
require('./middlewares/before-filter')(app);
|
20
|
+
// Error handler
|
21
|
+
require('./middlewares/error-handler')(app);
|
22
|
+
// Access Log
|
23
|
+
require('./middlewares/morgan-log')(app);
|
24
|
+
|
25
|
+
// Routes Example
|
26
|
+
var apiRouter = express.Router();
|
27
|
+
var instanceRouter = express.Router();
|
28
|
+
var configurationRouter = express.Router({ mergeParams: true });
|
29
|
+
var translationRouter = express.Router({ mergeParams: true });
|
30
|
+
|
31
|
+
instanceRouter.use('/:hostname/configurations', configurationRouter);
|
32
|
+
instanceRouter.use('/:hostname/translations', translationRouter);
|
33
|
+
apiRouter.use('/instances', instanceRouter);
|
34
|
+
|
35
|
+
require('./routes/configuration')(configurationRouter);
|
36
|
+
require('./routes/translation')(translationRouter);
|
37
|
+
require('./routes/instance')(instanceRouter);
|
38
|
+
|
39
|
+
app.use('/api', apiRouter);
|
40
|
+
|
41
|
+
app.listen(app.get('port'), function() {
|
42
|
+
logger.info('Server started, listened on ' + app.get('port') + '.');
|
43
|
+
});
|
44
|
+
|
45
|
+
module.exports = app;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe('Demo Test', function(){
|
2
|
+
it("#Chai should sample example", function(done) {
|
3
|
+
var user = {
|
4
|
+
name: 'tj',
|
5
|
+
pets: ['tobi', 'loki', 'jane', 'bandit']
|
6
|
+
};
|
7
|
+
|
8
|
+
user.should.have.property('name', 'tj');
|
9
|
+
user.should.have.property('pets').with.length(4);
|
10
|
+
done();
|
11
|
+
});
|
12
|
+
});
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: express-cmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wluo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.19'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.19'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-stack_explorer
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: Generate a sinatra project.
|
112
|
+
email:
|
113
|
+
- luowei---010101@163.com
|
114
|
+
executables:
|
115
|
+
- express
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/express
|
127
|
+
- express-cmd.gemspec
|
128
|
+
- lib/express_cmd.rb
|
129
|
+
- lib/express_cmd/generator.rb
|
130
|
+
- lib/express_cmd/version.rb
|
131
|
+
- spec/generate_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- templates/.gitignore
|
134
|
+
- templates/Makefile
|
135
|
+
- templates/README.md.erb
|
136
|
+
- templates/lib/errors.js
|
137
|
+
- templates/lib/logger.js
|
138
|
+
- templates/middlewares/before-filter.js
|
139
|
+
- templates/middlewares/error-handler.js
|
140
|
+
- templates/middlewares/morgan-log.js
|
141
|
+
- templates/package.json.erb
|
142
|
+
- templates/routes/configuration.js
|
143
|
+
- templates/routes/instance.js
|
144
|
+
- templates/routes/translation.js
|
145
|
+
- templates/server.js
|
146
|
+
- templates/test/test-helper.js
|
147
|
+
- templates/test/units/demo_test.js
|
148
|
+
homepage: https://github.com/hilotus/express-cmd
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 2.1.0
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.4.8
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Command for generating sinatra project
|
172
|
+
test_files:
|
173
|
+
- spec/generate_spec.rb
|
174
|
+
- spec/spec_helper.rb
|