@multiplayer-app/cli 1.3.35
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/LICENSE +21 -0
- package/README.md +54 -0
- package/bin/multiplayer-app-cli +114 -0
- package/package.json +47 -0
- package/src/api.js +97 -0
- package/src/commands/deployments/create.js +70 -0
- package/src/commands/releases/create.js +55 -0
- package/src/commands/sourcemaps/upload.js +76 -0
- package/src/helper.js +5 -0
- package/src/index.js +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Multiplayer Software, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
This module is for creating release and deployment. It can be used from the command line or programatically from a node script.
|
|
4
|
+
|
|
5
|
+
## Command Line
|
|
6
|
+
|
|
7
|
+
### Install
|
|
8
|
+
|
|
9
|
+
In order to create release or deployment from the command line, install the library globally.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install -g @multiplayer-app/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
16
|
+
|
|
17
|
+
Options can be provided on the command line or as environment variables.
|
|
18
|
+
|
|
19
|
+
##### Create release:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
multiplayer-app-cli releases create --apiKey=[apiKey] --service=[name] --release=[release] --releaseNotes=[releaseNotes]
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--apiKey Multiplayer personal user API key (MULTIPLAYER_API_KEY)
|
|
26
|
+
--service Service name (SERVICE_NAME)
|
|
27
|
+
--release Service release (RELEASE)
|
|
28
|
+
--commitHash [Optional] Repository URL (REPOSITORY_URL)
|
|
29
|
+
--releaseNotes [Optional] Release notes (RELEASE_NOTES)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
##### To create deployment:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
multiplayer-app-cli deployments create --apiKey=[apiKey] --service=[name] --release=[release] --environment=[environment]
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
--apiKey Multiplayer personal user API key (MULTIPLAYER_API_KEY)
|
|
39
|
+
--service Service name (SERVICE_NAME)
|
|
40
|
+
--release Service release (RELEASE)
|
|
41
|
+
--environment [Optional] Environment name (ENVIRONMENT)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Upload sourcemap
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
multiplayer-app-cli sourcemap upload /path/to/directory --apiKey=[apiKey] --service=[name] --release=[release] --environment=[environment]
|
|
48
|
+
|
|
49
|
+
Options:
|
|
50
|
+
--apiKey Multiplayer personal user API key (MULTIPLAYER_API_KEY)
|
|
51
|
+
--service Service name (SERVICE_NAME)
|
|
52
|
+
--release Service release (RELEASE)
|
|
53
|
+
--environment [Optional] Environment name (ENVIRONMENT)
|
|
54
|
+
```
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import yargs from 'yargs'
|
|
4
|
+
import { hideBin } from 'yargs/helpers'
|
|
5
|
+
import { create as createRelease } from '../src/commands/releases/create.js'
|
|
6
|
+
import { create as createDeployment } from '../src/commands/deployments/create.js'
|
|
7
|
+
import { upload as uploadSourcemap } from '../src/commands/sourcemaps/upload.js'
|
|
8
|
+
|
|
9
|
+
function handleResult(err, response) {
|
|
10
|
+
if (err) {
|
|
11
|
+
if (err.status) console.error('Status Code:', err.status)
|
|
12
|
+
if (err.response) console.error(err.response.text)
|
|
13
|
+
else console.error(err.message)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
} else {
|
|
16
|
+
console.log(JSON.stringify(response, null, 2))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
yargs(hideBin(process.argv))
|
|
21
|
+
.command('releases', 'Manage releases', (yargs) => {
|
|
22
|
+
yargs.command(
|
|
23
|
+
'create',
|
|
24
|
+
'Create a release',
|
|
25
|
+
(yargs) => yargs
|
|
26
|
+
.option('apiKey', { describe: 'Multiplayer personal user API key (MULTIPLAYER_API_KEY)', type: 'string' })
|
|
27
|
+
.option('service', { describe: 'Service name (SERVICE_NAME)', type: 'string' })
|
|
28
|
+
.option('releaseVersion', { describe: 'Release version (RELEASE)', type: 'string' })
|
|
29
|
+
.option('commitHash', { describe: 'Commit hash (COMMIT_HASH)', type: 'string' })
|
|
30
|
+
.option('releaseNotes', { describe: '[Optional] Release notes (RELEASE_NOTES)', type: 'string' })
|
|
31
|
+
.option('baseUrl', { describe: '[Optional] Base URL (BASE_URL)', type: 'string' }),
|
|
32
|
+
(argv) => {
|
|
33
|
+
|
|
34
|
+
const options = {
|
|
35
|
+
apiKey: argv.apiKey || process.env.MULTIPLAYER_API_KEY,
|
|
36
|
+
service: argv.service || process.env.SERVICE_NAME,
|
|
37
|
+
release: argv.release || process.env.RELEASE,
|
|
38
|
+
commitHash: argv.commitHash || process.env.COMMIT_HASH,
|
|
39
|
+
releaseNotes: argv.releaseNotes || process.env.RELEASE_NOTES,
|
|
40
|
+
baseUrl: argv.baseUrl || process.env.BASE_URL,
|
|
41
|
+
}
|
|
42
|
+
if (!options.apiKey) return exitWithError('A Multiplayer personal user API key is required.', yargs)
|
|
43
|
+
if (!options.service) return exitWithError('A service name is required.', yargs)
|
|
44
|
+
if (!options.release) return exitWithError('A release is required.', yargs)
|
|
45
|
+
createRelease(options, handleResult)
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
.demandCommand()
|
|
49
|
+
.help()
|
|
50
|
+
})
|
|
51
|
+
.command('deployments', 'Manage deployments', (yargs) => {
|
|
52
|
+
yargs.command(
|
|
53
|
+
'create',
|
|
54
|
+
'Create a deployment',
|
|
55
|
+
(yargs) => yargs
|
|
56
|
+
.option('apiKey', { describe: 'Multiplayer personal user API key (MULTIPLAYER_API_KEY)', type: 'string' })
|
|
57
|
+
.option('service', { describe: 'Service name (SERVICE_NAME)', type: 'string' })
|
|
58
|
+
.option('release', { describe: 'Service release (RELEASE)', type: 'string' })
|
|
59
|
+
.option('environment', { describe: 'Environment name (ENVIRONMENT)', type: 'string' })
|
|
60
|
+
.option('baseUrl', { describe: '[Optional] Base URL (BASE_URL)', type: 'string' }),
|
|
61
|
+
(argv) => {
|
|
62
|
+
const options = {
|
|
63
|
+
apiKey: argv.apiKey || process.env.MULTIPLAYER_API_KEY,
|
|
64
|
+
service: argv.service || process.env.SERVICE_NAME,
|
|
65
|
+
release: argv.release || process.env.VERSION,
|
|
66
|
+
environment: argv.environment || process.env.ENVIRONMENT,
|
|
67
|
+
baseUrl: argv.baseUrl || process.env.BASE_URL,
|
|
68
|
+
}
|
|
69
|
+
if (!options.apiKey) return exitWithError('A Multiplayer personal user API key is required.', yargs)
|
|
70
|
+
if (!options.service) return exitWithError('A service name is required.', yargs)
|
|
71
|
+
if (!options.release) return exitWithError('A version is required.', yargs)
|
|
72
|
+
if (!options.environment) return exitWithError('A environment is required.', yargs)
|
|
73
|
+
createDeployment(options, handleResult)
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
.demandCommand()
|
|
77
|
+
.help()
|
|
78
|
+
})
|
|
79
|
+
.command('sourcemaps', 'Manage sourcemaps', (yargs) => {
|
|
80
|
+
yargs.command(
|
|
81
|
+
'upload <directories...>',
|
|
82
|
+
'Upload sourcemaps from a directory',
|
|
83
|
+
(yargs) => yargs
|
|
84
|
+
.positional('directories', { describe: 'Path to directory containing sourcemap files' })
|
|
85
|
+
.option('apiKey', { describe: 'Multiplayer personal user API key (MULTIPLAYER_API_KEY)', type: 'string' })
|
|
86
|
+
.option('service', { describe: 'Service name (SERVICE_NAME)', type: 'string' })
|
|
87
|
+
.option('release', { describe: 'Service release (RELEASE)', type: 'string' })
|
|
88
|
+
.option('baseUrl', { describe: '[Optional] Base URL (BASE_URL)', type: 'string' }),
|
|
89
|
+
(argv) => {
|
|
90
|
+
const options = {
|
|
91
|
+
apiKey: argv.apiKey || process.env.MULTIPLAYER_API_KEY,
|
|
92
|
+
service: argv.service || process.env.SERVICE_NAME,
|
|
93
|
+
release: argv.release || process.env.RELEASE,
|
|
94
|
+
baseUrl: argv.baseUrl || process.env.BASE_URL,
|
|
95
|
+
}
|
|
96
|
+
if (!options.apiKey) return exitWithError('A Multiplayer personal user API key is required.', yargs)
|
|
97
|
+
if (!options.service) return exitWithError('A service name is required.', yargs)
|
|
98
|
+
if (!options.release) return exitWithError('A release is required.', yargs)
|
|
99
|
+
|
|
100
|
+
uploadSourcemap(argv.directories, options, handleResult)
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
.demandCommand()
|
|
104
|
+
.help()
|
|
105
|
+
})
|
|
106
|
+
.demandCommand()
|
|
107
|
+
.help()
|
|
108
|
+
.parse()
|
|
109
|
+
|
|
110
|
+
function exitWithError(message, yargsInstance) {
|
|
111
|
+
yargsInstance.showHelp()
|
|
112
|
+
console.error(message)
|
|
113
|
+
process.exit(1)
|
|
114
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@multiplayer-app/cli",
|
|
3
|
+
"version": "1.3.35",
|
|
4
|
+
"description": "Multiplayer CLI",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Multiplayer Software, Inc.",
|
|
7
|
+
"url": "https://www.multiplayer.app"
|
|
8
|
+
},
|
|
9
|
+
"private": false,
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/multiplayer-app/multiplayer-session-recorder-javascript/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/multiplayer-app/multiplayer-session-recorder-javascript.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18",
|
|
21
|
+
"npm": ">=8"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"multiplayer",
|
|
25
|
+
"api",
|
|
26
|
+
"release",
|
|
27
|
+
"sourcemap",
|
|
28
|
+
"deployment"
|
|
29
|
+
],
|
|
30
|
+
"main": "src/index.js",
|
|
31
|
+
"bin": {
|
|
32
|
+
"multiplayer-app-cli": "./bin/multiplayer-app-cli"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint src/**/*.js",
|
|
36
|
+
"preversion": "npm run lint",
|
|
37
|
+
"prepublishOnly": "npm run lint"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"jsonwebtoken": "9.0.3",
|
|
41
|
+
"superagent": "10.1.0",
|
|
42
|
+
"yargs": "16.0.3"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"eslint": "9.30.1"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import superagent from 'superagent'
|
|
2
|
+
|
|
3
|
+
const MULTIPLAYER_BASE_API_URL = 'https://api.multiplayer.app/v0'
|
|
4
|
+
|
|
5
|
+
export const getDefaultBranchId = async (
|
|
6
|
+
apiKey,
|
|
7
|
+
workspaceId,
|
|
8
|
+
projectId,
|
|
9
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
10
|
+
) => {
|
|
11
|
+
const response = await superagent.get(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/branches/default`)
|
|
12
|
+
.set('x-api-key', apiKey)
|
|
13
|
+
|
|
14
|
+
return response.body?._id
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getEntityId = async (
|
|
18
|
+
apiKey,
|
|
19
|
+
workspaceId,
|
|
20
|
+
projectId,
|
|
21
|
+
branchId,
|
|
22
|
+
entityName,
|
|
23
|
+
entityType,
|
|
24
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
25
|
+
) => {
|
|
26
|
+
const response = await superagent.get(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/branches/${branchId}/entities?key=${entityName}&type=${entityType}&limit=1&skip=0`)
|
|
27
|
+
.set('x-api-key', apiKey)
|
|
28
|
+
|
|
29
|
+
const entityId = response.body?.data?.[0]?.entityId
|
|
30
|
+
if (!entityId) {
|
|
31
|
+
throw new Error(`Entity ${entityName} not found`)
|
|
32
|
+
}
|
|
33
|
+
return entityId
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const createRelease = async (
|
|
37
|
+
apiKey,
|
|
38
|
+
workspaceId,
|
|
39
|
+
projectId,
|
|
40
|
+
payload,
|
|
41
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
42
|
+
) => {
|
|
43
|
+
const response = await superagent.post(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/releases`)
|
|
44
|
+
.set('x-api-key', apiKey)
|
|
45
|
+
.send(payload)
|
|
46
|
+
|
|
47
|
+
return response.body
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const getReleaseId = async (
|
|
51
|
+
apiKey,
|
|
52
|
+
workspaceId,
|
|
53
|
+
projectId,
|
|
54
|
+
entityId,
|
|
55
|
+
version,
|
|
56
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
57
|
+
) => {
|
|
58
|
+
const response = await superagent.get(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/releases?version=${version}&entity=${entityId}`)
|
|
59
|
+
.set('x-api-key', apiKey)
|
|
60
|
+
|
|
61
|
+
const versionId = response.body?.data?.[0]?._id
|
|
62
|
+
if (!versionId) {
|
|
63
|
+
throw new Error(`Version ${version} not found`)
|
|
64
|
+
}
|
|
65
|
+
return versionId
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const createDeployment = async (
|
|
69
|
+
apiKey,
|
|
70
|
+
workspaceId,
|
|
71
|
+
projectId,
|
|
72
|
+
payload,
|
|
73
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
74
|
+
) => {
|
|
75
|
+
const response = await superagent.post(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/deployments`)
|
|
76
|
+
.set('x-api-key', apiKey)
|
|
77
|
+
.send(payload)
|
|
78
|
+
|
|
79
|
+
return response.body
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const uploadSourcemap = async (
|
|
83
|
+
apiKey,
|
|
84
|
+
workspaceId,
|
|
85
|
+
projectId,
|
|
86
|
+
releaseId,
|
|
87
|
+
filePath,
|
|
88
|
+
stream,
|
|
89
|
+
baseUrl = MULTIPLAYER_BASE_API_URL,
|
|
90
|
+
) => {
|
|
91
|
+
const response = await superagent.post(`${baseUrl}/version/workspaces/${workspaceId}/projects/${projectId}/releases/${releaseId}/sourcemaps`)
|
|
92
|
+
.set('x-api-key', apiKey)
|
|
93
|
+
.set('Content-disposition', `attachment; filename=${filePath}`)
|
|
94
|
+
.attach('file', stream, filePath)
|
|
95
|
+
|
|
96
|
+
return response.body
|
|
97
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as API from '../../api.js'
|
|
2
|
+
import { decodeJwtToken } from '../../helper.js'
|
|
3
|
+
|
|
4
|
+
export const create = async (options, callback) => {
|
|
5
|
+
try {
|
|
6
|
+
const {
|
|
7
|
+
apiKey,
|
|
8
|
+
service,
|
|
9
|
+
release,
|
|
10
|
+
environment,
|
|
11
|
+
baseUrl,
|
|
12
|
+
} = options
|
|
13
|
+
|
|
14
|
+
const jwtToken = decodeJwtToken(apiKey) || {}
|
|
15
|
+
|
|
16
|
+
const branchId = await API.getDefaultBranchId(
|
|
17
|
+
apiKey,
|
|
18
|
+
jwtToken.workspace,
|
|
19
|
+
jwtToken.project,
|
|
20
|
+
baseUrl,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const serviceId = await API.getEntityId(
|
|
24
|
+
apiKey,
|
|
25
|
+
jwtToken.workspace,
|
|
26
|
+
jwtToken.project,
|
|
27
|
+
branchId,
|
|
28
|
+
service,
|
|
29
|
+
'platform_component',
|
|
30
|
+
baseUrl,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const releaseId = await API.getReleaseId(
|
|
34
|
+
apiKey,
|
|
35
|
+
jwtToken.workspace,
|
|
36
|
+
jwtToken.project,
|
|
37
|
+
serviceId,
|
|
38
|
+
release,
|
|
39
|
+
baseUrl,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const environmentId = await API.getEntityId(
|
|
43
|
+
apiKey,
|
|
44
|
+
jwtToken.workspace,
|
|
45
|
+
jwtToken.project,
|
|
46
|
+
branchId,
|
|
47
|
+
environment,
|
|
48
|
+
'environment',
|
|
49
|
+
baseUrl,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
await API.createDeployment(
|
|
53
|
+
apiKey,
|
|
54
|
+
jwtToken.workspace,
|
|
55
|
+
jwtToken.project,
|
|
56
|
+
{
|
|
57
|
+
entity: serviceId,
|
|
58
|
+
release: releaseId,
|
|
59
|
+
environment: environmentId,
|
|
60
|
+
},
|
|
61
|
+
baseUrl,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
callback(null, {
|
|
65
|
+
message: 'Deployment created successfully',
|
|
66
|
+
})
|
|
67
|
+
} catch (err) {
|
|
68
|
+
callback(err, null)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as API from '../../api.js'
|
|
2
|
+
import { decodeJwtToken } from '../../helper.js'
|
|
3
|
+
|
|
4
|
+
export const create = async (options, callback) => {
|
|
5
|
+
try {
|
|
6
|
+
const {
|
|
7
|
+
apiKey,
|
|
8
|
+
service,
|
|
9
|
+
release,
|
|
10
|
+
commitHash,
|
|
11
|
+
repositoryUrl,
|
|
12
|
+
releaseNotes,
|
|
13
|
+
baseUrl,
|
|
14
|
+
} = options
|
|
15
|
+
|
|
16
|
+
const jwtToken = decodeJwtToken(apiKey) || {}
|
|
17
|
+
|
|
18
|
+
const branchId = await API.getDefaultBranchId(
|
|
19
|
+
apiKey,
|
|
20
|
+
jwtToken.workspace,
|
|
21
|
+
jwtToken.project,
|
|
22
|
+
baseUrl,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const serviceId = await API.getEntityId(
|
|
26
|
+
apiKey,
|
|
27
|
+
jwtToken.workspace,
|
|
28
|
+
jwtToken.project,
|
|
29
|
+
branchId,
|
|
30
|
+
service,
|
|
31
|
+
'platform_component',
|
|
32
|
+
baseUrl,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
await API.createRelease(
|
|
36
|
+
apiKey,
|
|
37
|
+
jwtToken.workspace,
|
|
38
|
+
jwtToken.project,
|
|
39
|
+
{
|
|
40
|
+
entity: serviceId,
|
|
41
|
+
version: release,
|
|
42
|
+
releaseNotes: releaseNotes || '',
|
|
43
|
+
commitHash,
|
|
44
|
+
repositoryUrl,
|
|
45
|
+
},
|
|
46
|
+
baseUrl,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
callback(null, {
|
|
50
|
+
message: 'Release created successfully',
|
|
51
|
+
})
|
|
52
|
+
} catch (err) {
|
|
53
|
+
callback(err, null)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import * as API from '../../api.js'
|
|
4
|
+
import { decodeJwtToken } from '../../helper.js'
|
|
5
|
+
|
|
6
|
+
const collectSourcemaps = (dir) => {
|
|
7
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
8
|
+
const files = []
|
|
9
|
+
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const fullPath = path.join(dir, entry.name)
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
files.push(...collectSourcemaps(fullPath))
|
|
14
|
+
} else if (entry.isFile() && entry.name.endsWith('.map')) {
|
|
15
|
+
files.push(fullPath)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return files
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const upload = async (directories, options, callback) => {
|
|
22
|
+
try {
|
|
23
|
+
const { apiKey, service, release, baseUrl } = options
|
|
24
|
+
|
|
25
|
+
const jwtToken = decodeJwtToken(apiKey) || {}
|
|
26
|
+
|
|
27
|
+
const branchId = await API.getDefaultBranchId(
|
|
28
|
+
apiKey,
|
|
29
|
+
jwtToken.workspace,
|
|
30
|
+
jwtToken.project,
|
|
31
|
+
baseUrl,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const serviceId = await API.getEntityId(
|
|
35
|
+
apiKey,
|
|
36
|
+
jwtToken.workspace,
|
|
37
|
+
jwtToken.project,
|
|
38
|
+
branchId,
|
|
39
|
+
service,
|
|
40
|
+
'platform_component',
|
|
41
|
+
baseUrl,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
const releaseId = await API.getReleaseId(
|
|
45
|
+
apiKey,
|
|
46
|
+
jwtToken.workspace,
|
|
47
|
+
jwtToken.project,
|
|
48
|
+
serviceId,
|
|
49
|
+
release,
|
|
50
|
+
baseUrl,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const files = directories.flatMap(collectSourcemaps)
|
|
54
|
+
|
|
55
|
+
if (files.length === 0) {
|
|
56
|
+
return callback(new Error(`No sourcemap files found in directories: ${directories.join(', ')}`), null)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const filePath of files) {
|
|
60
|
+
const stream = fs.createReadStream(filePath)
|
|
61
|
+
await API.uploadSourcemap(
|
|
62
|
+
apiKey,
|
|
63
|
+
jwtToken.workspace,
|
|
64
|
+
jwtToken.project,
|
|
65
|
+
releaseId,
|
|
66
|
+
filePath,
|
|
67
|
+
stream,
|
|
68
|
+
baseUrl,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
callback(null, { message: `Uploaded ${files.length} sourcemap(s) successfully` })
|
|
73
|
+
} catch (err) {
|
|
74
|
+
callback(err, null)
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/helper.js
ADDED
package/src/index.js
ADDED