forked from cozy/cozy-data-system
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.coffee
56 lines (48 loc) · 1.64 KB
/
commands.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Client = require("request-json").JsonClient
path = require 'path'
fs = require 'fs'
switch process.argv[2]
when 'test-install'
slug = process.argv[3]
permFile = process.argv[4] or '../package.json'
packagePath = path.join process.cwd(), permFile
try
packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
catch e
console.log "Could not read package.json"
console.log e.stack
process.exit 2
data =
docType: "Application"
state: 'installed'
slug: slug
name: slug
password: 'apptoken'
permissions: {}
port: 42
for doctype, perm of packageData['cozy-permissions']
data.permissions[doctype.toLowerCase()] = perm
client = new Client "http://localhost:9101/"
client.setBasicAuth 'home', 'token'
client.post "access/", data, (err, res, body) ->
if err
console.log "Cannot create app"
console.log err.stack or err
process.exit 3
console.log "App created"
process.exit 0
when 'cleanup-db'
helpers = require './test/helpers'
db_helper = require './helpers/db_connect_helper'
db = db_helper.db_connect()
cleanUpFn = helpers.clearDB db
cleanUpFn (err) ->
if err
console.log "An error occured"
console.log err.stack or err
process.exit 1
else
process.exit 0
else
console.log "Wrong command"
process.exit 1