Skip to content

Commit 88ba64a

Browse files
committed
Upgraded to Grind 0.7.0
1 parent d152d5b commit 88ba64a

22 files changed

+175
-119
lines changed

.babelrc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"presets": [ "grind" ],
33
"plugins": [
44
[
5-
"babel-plugin-module-alias", [
6-
{ "src": "./app", "expose": "App" },
7-
{ "src": "./boot", "expose": "Boot" }
8-
]
5+
"module-resolver", {
6+
"alias": {
7+
"App": "./app",
8+
"Boot": "./boot"
9+
}
10+
}
911
]
1012
]
1113
}

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ language: node_js
22
node_js:
33
- "6"
44
- "7"
5+
- "8"
56
sudo: false
67
script: "bin/lint"

app/Bootstrap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import 'App/Providers/RoutesProvider'
88

99
const app = new Grind()
1010

11-
app.providers.push(DatabaseProvider)
12-
app.providers.push(OrmProvider)
13-
app.providers.push(SwaggerProvider)
14-
app.providers.push(RoutesProvider)
11+
app.providers.add(DatabaseProvider)
12+
app.providers.add(OrmProvider)
13+
app.providers.add(SwaggerProvider)
14+
app.providers.add(RoutesProvider)
1515

1616
module.exports = app

app/Commands/StatesListCommand.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from 'grind-cli'
1+
import { Command, InputArgument, InputOption } from 'grind-cli'
22

33
import 'App/Models/StateModel'
44

@@ -10,12 +10,14 @@ export class StatesListCommand extends Command {
1010
description = 'List all states in the database'
1111

1212
// Arguments available for this command
13-
arguments = [ 'term?' ]
13+
arguments = [
14+
new InputArgument('term', InputArgument.VALUE_OPTIONAL, 'Search term'),
15+
]
1416

1517
// Options for this command
16-
options = {
17-
limit: 'Limit the number of states'
18-
}
18+
options = [
19+
new InputOption('limit', InputOption.VALUE_OPTIONAL, 'Limit the number of states', '100')
20+
]
1921

2022
run() {
2123
const limit = Number.parseInt(this.option('limit', 100))

app/Controllers/BaseController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ export class BaseController extends Controller {
1616
return { limit, offset }
1717
}
1818

19+
paginationRange(req, limit = 100) {
20+
const pagination = this.pagination(req, limit)
21+
return { start: pagination.offset, end: (pagination.limit + pagination.offset) - 1 }
22+
}
23+
1924
}

app/Controllers/CompaniesController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export class CompaniesController extends BaseController {
66
model = CompanyModel
77

88
index(req, res) {
9-
return this.model.query().subset(this.pagination(req)).then(rows => {
9+
const { start, end } = this.paginationRange(req)
10+
11+
return this.model.query().range(start, end).then(rows => {
1012
if(rows.isNil) {
1113
throw new NotFoundError('No companies found')
1214
}

app/Controllers/CountriesController.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export class CountriesController extends BaseController {
66
model = CountryModel
77

88
index(req, res) {
9-
return this.model.query().subset(this.pagination(req)).then(rows => {
9+
const { start, end } = this.paginationRange(req)
10+
11+
return this.model.query().range(start, end).then(rows => {
1012
if(rows.isNil) {
1113
throw new NotFoundError('No countries found')
1214
}
@@ -26,7 +28,9 @@ export class CountriesController extends BaseController {
2628
throw new ValidationError({ term: 'term is required' })
2729
}
2830

29-
return this.model.find(req.query.term).subset(this.pagination(req)).then(rows => {
31+
const { start, end } = this.paginationRange(req)
32+
33+
return this.model.find(req.query.term).range(start, end).then(rows => {
3034
if(rows.isNil) {
3135
throw new NotFoundError('No countries found, try a different term')
3236
}

app/Controllers/StatesController.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export class StatesController extends BaseController {
66
model = StateModel
77

88
index(req, res) {
9-
return this.model.query().subset(this.pagination(req)).then(rows => {
9+
const { start, end } = this.paginationRange(req)
10+
11+
return this.model.query().range(start, end).then(rows => {
1012
if(rows.isNil) {
1113
throw new NotFoundError('No states found')
1214
}
@@ -26,7 +28,9 @@ export class StatesController extends BaseController {
2628
throw new BadRequestError('`term` is required')
2729
}
2830

29-
return this.model.find(req.query.term).subset(this.pagination(req)).then(rows => {
31+
const { start, end } = this.paginationRange(req)
32+
33+
return this.model.find(req.query.term).range(start, end).then(rows => {
3034
if(rows.isNil) {
3135
throw new NotFoundError('No states found, try a different term')
3236
}

bin/.init

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pushd $NODE_ROOT > /dev/null
1919
NODE_ROOT="`pwd`"
2020
popd > /dev/null
2121

22+
pushd $NODE_ROOT/.. > /dev/null
23+
export BASE_PATH="`pwd`"
24+
popd > /dev/null
25+
2226
if [ -f "$NODE_ROOT/../.env" ];
2327
then
2428
source "$NODE_ROOT/../.env"

bin/build

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ source ${0%/*}/.init
44

55
strip_babel() {
66
cp "$1" "$1-tmp"
7-
8-
if [ $(node -e 'console.log(Number.parseFloat(process.version.substring(1)) >= 7)') == "true" ]; then
9-
cat "$1-tmp" | sed 's/babel-node/node/g' | sed 's/FLAGS=.*$/FLAGS="--harmony-async-await"/g' > "$1"
10-
else
11-
cat "$1-tmp" | sed 's/babel-node/node/g' | sed 's/FLAGS=.*$/FLAGS=""/g' > "$1"
12-
fi
13-
7+
cat "$1-tmp" | sed "s/require('babel-register')//g" > "$1"
148
rm "$1-tmp"
159
}
1610

@@ -27,7 +21,8 @@ echo "Setting up bins"
2721
cp -R bin build/bin
2822
rm build/bin/build build/bin/lint
2923

30-
strip_babel build/bin/cli
24+
strip_babel build/boot/Cli.js
25+
strip_babel build/boot/Http.js
3126
chmod +x build/bin/* build/bin/.init
3227

3328
echo "Done"

0 commit comments

Comments
 (0)