Skip to content

Commit

Permalink
Merge pull request #15 from dinoboff/master
Browse files Browse the repository at this point in the history
Add cmd to init a db.
  • Loading branch information
dinoboff committed Mar 25, 2016
2 parents 80da324 + c1a6916 commit c2a55fb
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 606 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extra-rules.json

# Built with npm run make-rules
rules.json
rules.*.json

# Secrets for testing
*.stamp
Expand All @@ -14,4 +15,4 @@ rules.json

*.sublime-project
*.sublime-workspace
singpath.env
singpath.env
8 changes: 8 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"preset": "google",
"excludeFiles": ["node_modules", "coverage"],
"maximumLineLength": 120,
"disallowMultipleVarDecl": {
allExcept: ['undefined']
}
}
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
language: node_js
env:
global:
- SINGPATH_RULES_FB_ID=singpath-travis
- secure: pFgUzjTjBpxnK09BIbXBNCqwderheoG8MT3JZpaipdFn2yuu90ZhSM+KgNSjaJtFRKsq5LAK/tioTPrjOTitXAwAVo+Dd93YgvPh01X9LmPrnYPYx8XmE7P4fV3/ODvMuCMPyQAqPSkJhFrWD0AKZ4f0kc8JQVl90C1ekpp0o7Xi2mtzMyQmt8YiRZTZl4dJel+sw3dsGBFWi/jJE613sngd3pGKX33hz1jfc7xipTOzUQrIGc8V+fML+/kMkf+nYVm/hIqDWxQnstuoF65TO0alGAZflFgFNI2LBjyIe4FF414mrKQcYsKIDkbYDx1+7I8zvHybDGLzz8SOi4ynlHeXrh+YlvcLLctfhrg+dvm0MEzTX2lmsCiIcwjbgOzb3DoHRz0rtc+ZT2+YCucvHpR5COQBt6e387MRY98F/F8jFM30O/d7coaRwtu3qqkqzQ3EFeY4eXXWnUVEuAnccbOQOcppVEfTPpGUaw8+/6a4kmonVjFQ3J+wWpzxCpb5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FXDWPJF9v8FHrLMHLhTw80YkAmqG4s9iPswmJKnsmM+jKRsFB9fWI5n8LWuZGpwqiZPwF5/oc4JJMgVXQXXG40vWWF+lV9zEVw5mHtxJrbaRKkv7IQ=
node_js:
- '4.1'
- '4.2'
install:
- npm install
script:
- npm test
- npm run coveralls
- test -z "$SINGPATH_DEPLOY_TOKEN" || npm run upload-rules-ci
- test -z "$SINGPATH_RULES_FB_SECRET" || npm run test-e2e
- 'npm run lint'
- 'npm run test'
- 'npm run coveralls'
- 'test -z "$SINGPATH_RULES_E2E_FIREBASE_SECRET" || test -z "$SINGPATH_RULES_TOKEN" || ./bin/singpath-rules upload-rules -f $SINGPATH_RULES_E2E_FIREBASE_ID --token $SINGPATH_RULES_TOKEN'
- 'test -z "$SINGPATH_RULES_E2E_FIREBASE_SECRET" || test -z "$SINGPATH_RULES_TOKEN" || npm run test-e2e'
12 changes: 5 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ npm install

Setup a new Firebase DB for testing and set some environment variables:
```
SINGPATH_RULES_FB_ID=some-firebase-id
SINGPATH_RULES_FB_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export SINGPATH_RULES_E2E_FIREBASE_ID=some-firebase-id
export SINGPATH_RULES_E2E_FIREBASE_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```


## Running the e2e tests

```shell
npm run all-rules
npm run upload-rules
npm run test-e2e
make e2e
```


Expand Down Expand Up @@ -77,8 +75,8 @@ describe('something', function() {
beforeEach(() => {
// reset suite before each test (includes patching console.warn)
suite = new fb.testSuite({
firebaseId: process.env.SINGPATH_RULES_FB_ID,
firebaseSecret: process.env.SINGPATH_RULES_FB_SECRET
firebaseId: process.env.SINGPATH_RULES_E2E_FIREBASE_ID,
firebaseSecret: process.env.SINGPATH_RULES_E2E_FIREBASE_SECRET
});
});

Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
default: rules.json
.PHONY: default

.upload-rules.${SINGPATH_RULES_FB_ID}.stamp: rules.json
# SINGPATH_RULES_FB_ID should be set.
.upload-rules.${SINGPATH_RULES_E2E_FIREBASE_ID}.stamp: rules.json
# SINGPATH_RULES_E2E_FIREBASE_ID should be set.
#
# example:
#
# export SINGPATH_RULES_FB_ID=singpath-dev"
# export SINGPATH_RULES_E2E_FIREBASE_ID=singpath-dev"
#
npm run upload-rules
touch $@

rules.json: rules/*.bolt
npm run rules

e2e: .upload-rules.${SINGPATH_RULES_FB_ID}.stamp
# SINGPATH_RULES_FB_SECRET and SINGPATH_RULES_FB_ID should be set.
e2e: .upload-rules.${SINGPATH_RULES_E2E_FIREBASE_ID}.stamp
# SINGPATH_RULES_E2E_FIREBASE_ID and SINGPATH_RULES_E2E_FIREBASE_SECRET should be set.
#
# example:
#
# export SINGPATH_RULES_FB_ID=singpath-dev"
# export SINGPATH_RULES_FB_SECRET=xxxxxxx
# export SINGPATH_RULES_E2E_FIREBASE_ID=singpath-dev"
# export SINGPATH_RULES_E2E_FIREBASE_SECRET=xxxxxxx
#
npm run test-e2e
.PHONY: e2e
Expand All @@ -43,5 +43,5 @@ test:
npm run test
.PHONY: tests

upload-rules: .upload-rules.${SINGPATH_RULES_FB_ID}.stamp
upload-rules: .upload-rules.${SINGPATH_RULES_E2E_FIREBASE_ID}.stamp
.PHONY: upload-rules
61 changes: 14 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ Rules and migration scripts for Singpath Firbase db.
## Setup

We will rely [firebase-tools](https://github.com/firebase/firebase-tools) to
upload rules and data.
upload data.

1. setup a new npm project and install dependencies:

```shell
npm init
npm install --save firebase-tools
npm install --save singpath/singpath-rules
npm install -g firebase-tools
npm install -g @singpath/singpath-rules
```

2. setup a Firebase project in the current directory (it should like
to your staging DB):

```shell
./node_modules/.bin/firebase init
./node_modules/.bin/firebase login
npm init
firebase init
firebase login
```

3. edit firebase.json to add the "rules" entry:
Expand All @@ -49,42 +49,21 @@ upload rules and data.
}
```

Because `firebase-tools` and `singpath-rules` are installed locally you need to
use `./node_modules/.bin/[script-name]`. For recurrent tasks using it,
you should add a "scripts" entry in `package.json` which will have
`./node_modules/.bin` in its path when executed with `npm run`.
4. upload rules and seed data to your Firebase DB.

E.g, `package.json`:
```json
{
"name": "rules",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"rules": "singpath-rules compile",
"deploy-rules": "firebase deploy:rules",
"deploy-rules-production": "firebase deploy:rules -f my-firebase-production-id"
},
"author": "",
"license": "ISC",
"dependencies": {
"firebase-tools": "^2.1.1",
"singpath-rules": "github:singpath/singpath-rules"
}
}
```
```
singpath-rules init-db
```


## Building json rules

`firebase-tools` (see below) will support bolt rules directly sometime in the
future, but for now we need them in the current json encoded form.

To compile the rules (from `node_modules/singpath-rules/rules`):
To compile the rules:
```shell
./node_modules/.bin/singpath-rules compile
singpath-rules compile
```

You will find the rules in `rules.json`.
Expand All @@ -93,22 +72,10 @@ You will find the rules in `rules.json`.
## Uploading rules

```json
./node_modules/.bin/firebase deploy:rules
./node_modules/.bin/singpath-rules upload-rules
```

Use the `-f` to switch the Firebase DB to upload to.

## Uploading data

To upload the school and badge data:
```json
./node_modules/.bin/firebase data:set \
/classMentors/badges \
node_modules/singpath-rules/data/classMentors/badges.json
./node_modules/.bin/firebase data:set \
/classMentors/schools \
node_modules/singpath-rules/data/classMentors/schools.json
```
Use the `-f` to switch the Firebase DB to upload to and `-a` to set the secret.


## Development
Expand Down

0 comments on commit c2a55fb

Please sign in to comment.