@ossy/cli 0.0.3-alpha → 0.0.4-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cms/cli.js +14 -15
package/package.json
CHANGED
package/src/cms/cli.js
CHANGED
|
@@ -3,16 +3,11 @@ import { resolve } from 'path'
|
|
|
3
3
|
import { readFileSync } from 'fs'
|
|
4
4
|
import arg from 'arg'
|
|
5
5
|
import fetch from 'node-fetch'
|
|
6
|
-
import { logInfo, logErrorAndReject, logDebug } from '../log.js'
|
|
7
|
-
|
|
8
|
-
const config = {
|
|
9
|
-
apiUrl: 'https://api.ossy.se/api/v0',
|
|
10
|
-
// apiUrl: 'http://localhost:3001/api/v0'
|
|
11
|
-
}
|
|
6
|
+
import { logInfo, logError, logErrorAndReject, logDebug } from '../log.js'
|
|
12
7
|
|
|
13
8
|
const Api = {
|
|
14
|
-
uploadResourceTemplates: (token, workspaceId, resourceTemplates) => {
|
|
15
|
-
const endpoint = `${
|
|
9
|
+
uploadResourceTemplates: (apiUrl, token, workspaceId, resourceTemplates) => {
|
|
10
|
+
const endpoint = `${apiUrl}/workspaces/${workspaceId}/resource-templates`
|
|
16
11
|
|
|
17
12
|
const fetchOptions = {
|
|
18
13
|
method: 'POST',
|
|
@@ -34,19 +29,20 @@ const importResourceTemplates = options => {
|
|
|
34
29
|
'--authentication': String,
|
|
35
30
|
'--a': '--authentication',
|
|
36
31
|
|
|
37
|
-
'--
|
|
38
|
-
'-
|
|
32
|
+
'--config': String,
|
|
33
|
+
'-c': '--config',
|
|
39
34
|
}, { argv: options })
|
|
40
35
|
|
|
41
36
|
logInfo({ message: '[CMS] reading files' })
|
|
42
|
-
const token = parsedArgs['--authentication']
|
|
43
|
-
const filePath = resolve(parsedArgs['--
|
|
37
|
+
const token = parsedArgs['--authentication'];
|
|
38
|
+
const filePath = resolve(parsedArgs['--config'])
|
|
44
39
|
|
|
45
40
|
if (!token) return logErrorAndReject({ message: '[CMS] No token provided with --authentication'})
|
|
46
41
|
|
|
47
42
|
return resolveConfigImport(filePath)
|
|
48
43
|
.then(module => {
|
|
49
44
|
const config = module?.default
|
|
45
|
+
const apiUrl = config?.apiUrl || 'https://api.ossy.se/api/v0'
|
|
50
46
|
const workspaceId = config?.workspaceId
|
|
51
47
|
const resourceTemplates = config?.resourceTemplates
|
|
52
48
|
|
|
@@ -54,9 +50,12 @@ const importResourceTemplates = options => {
|
|
|
54
50
|
if (!resourceTemplates) return logErrorAndReject({ message: '[CMS] No resource templates provided in ossy.json'})
|
|
55
51
|
|
|
56
52
|
logInfo({ message: '[CMS] uploading resource templates' })
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
.
|
|
53
|
+
|
|
54
|
+
Api.uploadResourceTemplates(apiUrl, token, workspaceId, resourceTemplates)
|
|
55
|
+
.then(response => {
|
|
56
|
+
logInfo({ message: '[CMS] Done' })
|
|
57
|
+
})
|
|
58
|
+
.catch(error => logError({ message: '[CMS] Error', error }))
|
|
60
59
|
})
|
|
61
60
|
|
|
62
61
|
}
|