Skip to content

Commit

Permalink
Rename all options to camelCase, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Dec 11, 2016
1 parent 7e8446d commit 5b3dfcc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Install node-gtfs directly from [npm](https://npmjs.org):

## Command-line example

gtfs-import --config-path /path/to/your/custom-config.json
gtfs-import --configPath /path/to/your/custom-config.json

## Code example

Expand All @@ -47,9 +47,9 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
| option | type | description |
| ------ | ---- | ----------- |
| `agencies` | array | An array of GTFS files to be imported. |
| `mongo_url` | string | The URL of the MongoDB database to import to. |
| `mongoUrl` | string | The URL of the MongoDB database to import to. |
| `verbose` | boolean | Whether or not to print output to the console. |
| `skip_delete` | boolean | Whether or not to skip deleting existing data from the database. |
| `skipDelete` | boolean | Whether or not to skip deleting existing data from the database. |

### Agencies

Expand Down Expand Up @@ -129,10 +129,10 @@ API along with your API token.

### MongoDB URI

Add the MongoDB URI to `config.json` with the key `mongo_url`. Running locally, you may want to use `mongodb://localhost:27017/gtfs`.
Add the MongoDB URI to `config.json` with the key `mongoUrl`. Running locally, you may want to use `mongodb://localhost:27017/gtfs`.
```
{
"mongo_url": "mongodb://localhost:27017/gtfs",
"mongoUrl": "mongodb://localhost:27017/gtfs",
"agencies": [
{
"agency_key": "myAgency",
Expand All @@ -148,7 +148,7 @@ If you don't want the import script to print any output to the console, you can

```
{
"mongo_url": "mongodb://localhost:27017/gtfs",
"mongoUrl": "mongodb://localhost:27017/gtfs",
"agencies": [
{
"agency_key": "localAgency",
Expand All @@ -161,18 +161,18 @@ If you don't want the import script to print any output to the console, you can

### Deleting existing data

If you don't want the import script to delete all existing data from the database with the same `agency_key`, you can set `skip_delete` to `false`. Defaults to `true`.
If you don't want the import script to delete all existing data from the database with the same `agency_key`, you can set `skipDelete` to `false`. Defaults to `true`.

```
{
"mongo_url": "mongodb://localhost:27017/gtfs",
"mongoUrl": "mongodb://localhost:27017/gtfs",
"agencies": [
{
"agency_key": "localAgency",
"path": ""/path/to/the/unzipped/gtfs/"
}
],
"skip_delete": true
"skipDelete": true
}
```

Expand All @@ -192,19 +192,19 @@ If you want to run this locally, make sure mongo in installed and running.

By default, it will look for a `config.json` file in the project root. To specify a different path for the configuration file:

gtfs-import --config-path /path/to/your/custom-config.json
gtfs-import --configPath /path/to/your/custom-config.json

### Command Line options

#### Skip Delete
By default, the import script will delete any existing data with the same `agency_key` from your database. If you don't want this to happen, pass the `--skip-delete` flag
By default, the import script will delete any existing data with the same `agency_key` from your database. If you don't want this to happen, pass the `--skipDelete` flag

gtfs-import --skip-delete
gtfs-import --skipDelete

#### Specify path to config JSON file
You can specify the path to a config file to be used by the import script.

gtfs-import --config-path /path/to/your/custom-config.json
gtfs-import --configPath /path/to/your/custom-config.json

#### Show help
Show all command line options
Expand All @@ -229,7 +229,7 @@ Configuration can be a JSON object in your code

const gtfs = require('gtfs');
const config = {
mongo_url: 'mongodb://localhost:27017/gtfs',
mongoUrl: 'mongodb://localhost:27017/gtfs',
agencies: [
{
agency_key: 'county-connection',
Expand Down
12 changes: 6 additions & 6 deletions bin/gtfs-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const argv = require('yargs')
.usage('Usage: $0 --config ./config.json')
.help()
.option('c', {
alias: 'config-path',
alias: 'configPath',
describe: 'Path to config file',
default: './config.json',
type: 'string'
})
.option('s', {
alias: 'skip-delete',
alias: 'skipDelete',
describe: 'Don\'t delete existing data for `agency_key` on import',
type: 'boolean',
default: false
})
.argv;

const configPath = path.join(process.cwd(), argv['config-path']);
const configPath = path.join(process.cwd(), argv['configPath']);


function handleError(err) {
Expand All @@ -32,13 +32,13 @@ function getConfig() {
try {
const config = require(configPath);

if (argv['skip-delete']) {
config.skip_delete = argv['skip-delete'];
if (argv['skipDelete']) {
config.skipDelete = argv['skipDelete'];
}

return config;
} catch (err) {
handleError(new Error(`Cannot find configuration file at \`${configPath}\`. Use config-sample.json as a starting point, pass --config-path option`));
handleError(new Error(`Cannot find configuration file at \`${configPath}\`. Use config-sample.json as a starting point, pass --configPath option`));
}
}

Expand Down
2 changes: 1 addition & 1 deletion config-sample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mongo_url": "mongodb://localhost:27017/gtfs",
"mongoUrl": "mongodb://localhost:27017/gtfs",
"agencies": [
{
"agency_key": "county-connection",
Expand Down
10 changes: 5 additions & 5 deletions lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function readFiles(task, cb) {

function removeDatabase(task, cb) {
// Remove old db records based on agency_key
// Overridde using the --skip-delete command line argument
// or `skip_delete` in config.json
if (task.skip_delete) {
// Overridde using the --skipDelete command line argument
// or `skipDelete` in config.json
if (task.skipDelete) {
log(`\n${task.agency_key}: Skipping deletion of existing data`);
return cb(null, task);
}
Expand Down Expand Up @@ -352,15 +352,15 @@ module.exports = (config, cb) => {
log(`Starting GTFS import for ${fileCount} ${utils.pluralize('file', fileCount)}`);

// Open database and create queue for agency list
MongoClient.connect(config.mongo_url, { w: 1 }).then((db) => {
MongoClient.connect(config.mongoUrl, { w: 1 }).then((db) => {
const q = async.queue(importGTFS, 1);
// Loop through all agencies specified
config.agencies.forEach((item) => {
const task = _.pick(item, ['exclude', 'agency_key']);

task.db = db;

task.skip_delete = config.skip_delete;
task.skipDelete = config.skipDelete;

if (item.url) {
task.agency_url = item.url;
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gtfs",
"description": "Import GTFS transit data into mongodb and query routes, stops, times, fares and more",
"version": "0.8.5",
"version": "0.9.0",
"keywords": [
"transit",
"gtfs",
Expand Down Expand Up @@ -36,14 +36,14 @@
"csv": "1.1.0",
"lodash": "4.17.2",
"mkdirp": "0.5.1",
"moment": "2.17.0",
"mongodb": "2.2.12",
"mongoose": "4.7.0",
"moment": "2.17.1",
"mongodb": "2.2.15",
"mongoose": "4.7.2",
"proj4": "2.3.15",
"request": "2.79.0",
"rimraf": "2.5.4",
"unzip2": "0.2.5",
"yargs": "6.4.0"
"yargs": "6.5.0"
},
"repository": {
"type": "git",
Expand All @@ -58,11 +58,11 @@
"main": "index",
"devDependencies": {
"csv-parse": "1.1.7",
"eslint": "3.11.1",
"eslint": "3.12.0",
"eslint-config-airbnb-base": "10.0.1",
"eslint-plugin-import": "2.2.0",
"mocha": "3.2.0",
"should": "11.1.1",
"should": "11.1.2",
"timekeeper": "1.0.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mongo_url": "mongodb://localhost:27017/gtfs-test",
"mongoUrl": "mongodb://localhost:27017/gtfs-test",
"agencies": [],
"verbose": false
}
4 changes: 2 additions & 2 deletions test/support/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ let db;

exports.connect = (config, cb) => {
// Open the connection to the server
MongoClient.connect(config.mongo_url, (err, client) => {
MongoClient.connect(config.mongoUrl, (err, client) => {
should.not.exists(err);
should.exists(client);
db = client;

// use mongoose to connect
mongoose.connect(config.mongo_url, (err) => {
mongoose.connect(config.mongoUrl, (err) => {
if (err) {
return cb(err);
}
Expand Down

0 comments on commit 5b3dfcc

Please sign in to comment.