Skip to content

Commit

Permalink
feat: konnector script commands simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleface committed May 8, 2017
1 parent 43f23ed commit 4fe031f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
71 changes: 31 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ What's Cozy?

![Cozy Logo](https://cdn.rawgit.com/cozy/cozy-guidelines/master/templates/cozy_logo_small.svg)

[Cozy] is a platform that brings all your web services in the same private space. With it, your webapps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one's tracking you.

[Cozy] is a platform that brings all your web services in the same private space. With it, your webapps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one's tracking you.

What's this new konnector?
--------------------------
Expand All @@ -18,48 +17,30 @@ What's this new konnector?

If you want to work on this konnector and submit code modifications, feel free to open pull-requests! See the [contributing guide][contribute] for more information about how to properly open pull-requests.

### Run
### Test the connector without an accessible cozy-stack

If you have a running accessible cozy-stack you can test your modifications to the konnector without installing
and/or updating the konnector in the cozy-stack :
If you just want to test this connector without any cozy available.

You first need an installed [nodejs] (LTS version is fine).

Then just run (but you need to have proper COZY_CREDENTIALS, COZY_URL and COZY_FIELDS environment variables):
We also suggest you tu use [yarn] instead of npm for node packages.

```sh
npm install --global yarn
```

Then run (but you have to have proper COZY_CREDENTIALS, COZY_URL and COZY_FIELDS environment variables):
Then just run :

```sh
yarn
yarn start
```

Where:
- COZY_CREDENTIALS needs to be the result of ```cozy-stack instances token-cli <instance name> <scope>```
- COZY_URL is the full http url to your cozy
- COZY_FIELDS is something like :
```javascript
{
"data":{
"attributes":{
"arguments":{
"account":"cf31eaef5d899404a7e8c3737c1c2d1f",
"folder_to_save":"folderPath",
"slug":"mykonnector"
}
}
}
}
yarn standalone
```

The "account" field is the id of the record with doctype "io.cozy.accounts" which will be used as
parameters for your konnector.
The requests to the cozy-stack will be stubbed using the [./data/fixture.json] file as source of data
and when cozy-client is asked to create or update data, the data will be output to the console.
The bills (or any file) will be saved in the ./data directory.

### Test
### Run the connector linked to a cozy-stack

If you do not want to have to install the konnector on a cozy v3 to test it, you can register the
konnector as an OAuth application with the following commands :
Expand All @@ -77,23 +58,33 @@ After that, your konnector is running but should not work since you did not spec
the target service. You can do this in a [./data/env_fields.json] (you have
[./data/env_fields.json.template] available as a template)

Now run ```yarn init:dev:account``` to create an account in the targeted cozy which will be used by
the connector (the id of the account is saved in ./data/account.txt)

Now run `yarn dev` one more time, it should be ok.

### Hack
### How does the cozy-stack run the connector ?

If you do not want to need to have an accessible cozy-stack, just run :
The cozy-stack runs the connector in a rkt container to be sure it does not affect the environment.

```sh
yarn
yarn standalone
The connector is run by calling npm start with the following envrionment variables :

- COZY_CREDENTIALS needs to be the result of ```cozy-stack instances token-cli <instance name> <scope>```
- COZY_URL is the full http or https url to your cozy
- COZY_FIELDS is something like :
```javascript
{
"data":{
"attributes":{
"arguments":{
"account":"cf31eaef5d899404a7e8c3737c1c2d1f",
"folder_to_save":"folderPath",
"slug":"mykonnector"
}
}
}
}
```

The requests to the cozy-stack will be stubbed using the [./data/fixture.json] file as source of data
and when cozy-client is asked to create or update data, the data will be outputed to the console.
The bills (or any file) will be saved in the ./data directory.
The "account" field is the id of the record with doctype "io.cozy.accounts" which will be used as
parameters for your konnector.

### Maintainer

Expand Down
9 changes: 9 additions & 0 deletions data/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs')
const path = require('path')
const tokenPath = path.join(__dirname, 'token.json')

module.exports = {
NODE_ENV: 'development',
COZY_CREDENTIALS: fs.existsSync(tokenPath) ? fs.readFileSync(tokenPath, 'utf-8') : 'NO TOKEN',
COZY_URL: 'http://cozy.tools:8080'
}
10 changes: 4 additions & 6 deletions data/env_development.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs')
const path = require('path')
const tokenPath = path.join(__dirname, 'token.json')
const fs = require('fs')

// get the account id
const accountIdPath = path.join(__dirname, 'account.txt')
Expand All @@ -9,12 +8,11 @@ if (fs.existsSync(accountIdPath)) {
accountId = fs.readFileSync(accountIdPath, 'utf-8').trim()
} else {
console.log(`No account id file found. Please first run yarn init:dev:account`)
process.exit(0)
}

module.exports = {
COZY_CREDENTIALS: fs.existsSync(tokenPath) ? fs.readFileSync(tokenPath) : 'NO TOKEN',
COZY_URL: 'http://cozy.tools:8080',
module.exports = Object.assign(require('./env.js'), {
NODE_ENV: 'development',
COZY_FIELDS: `{"connector": "mykonnector", "account": "${accountId}", "folder_to_save": "folderPath"}`,
DEBUG: '*'
}
})
5 changes: 3 additions & 2 deletions data/env_standalone.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = Object.assign(require('./env_development.js'), {
NODE_ENV: 'standalone'
module.exports = Object.assign(require('./env.js'), {
NODE_ENV: 'standalone',
COZY_FIELDS: `{"connector": "mykonnector", "account": "noid", "folder_to_save": "folderPath"}`
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"scripts": {
"start": "node index.js",
"init:dev:account": "npm run predev && env-cmd ./data/env_development.js cozy-init-dev-account ./data/account.txt ./data/env_fields.json",
"predev": "env-cmd ./data/env_development.js cozy-authenticate manifest.konnector",
"oauth": "env-cmd ./data/env.js cozy-authenticate manifest.konnector",
"predev": "npm run oauth && env-cmd ./data/env.js cozy-init-dev-account ./data/account.txt ./data/env_fields.json",
"dev": "env-cmd ./data/env_development.js npm start",
"standalone": "env-cmd ./data/env_standalone.js npm start",
"build": "webpack"
Expand All @@ -30,7 +30,7 @@
"cz-conventional-changelog": "^2.0.0",
"env-cmd": "^5.1.0",
"request-debug": "^0.2.0",
"webpack": "^2.4.1"
"webpack": "^2.5.0"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit 4fe031f

Please sign in to comment.