@ossy/deployment-tools 0.0.30 → 0.0.31
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/dist/619.index.js +3 -3
- package/dist/index.js +7348 -20121
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/aws-credentials-client.ts +18 -12
- package/src/caddy-client.ts +5 -8
- package/src/ci-rest-api.ts +2 -2
- package/src/cli-commands/deploy-handler.ts +2 -2
- package/src/cli-commands/index.ts +3 -3
- package/src/cli-commands/start-handler.ts +3 -3
- package/src/cli-commands/status-handler.ts +2 -2
- package/src/cli-commands/stop-handler.ts +2 -2
- package/src/deployment-platform-client.ts +7 -10
- package/src/deployment-queue-client.ts +9 -14
- package/src/docker-client.ts +10 -10
- package/src/log/index.ts +34 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/deployment-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "Collection of scripts and tools to aid deployment of containers and static files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@actions/core": "^1.10.0",
|
|
17
17
|
"@aws-sdk/client-sqs": "^3.186.0",
|
|
18
18
|
"@aws-sdk/client-sts": "^3.188.0",
|
|
19
|
+
"@aws-sdk/types": "^3.193.0",
|
|
19
20
|
"arg": "^5.0.2",
|
|
20
21
|
"express": "^4.18.1",
|
|
21
22
|
"nanoid": "^4.0.0",
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import * as core from '@actions/core'
|
|
2
|
-
import { STSClient, AssumeRoleWithWebIdentityCommand
|
|
2
|
+
import { STSClient, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts'
|
|
3
3
|
import { DeploymentPlatform } from 'types'
|
|
4
|
-
import {
|
|
4
|
+
import { logDebug, logInfo, logError } from 'log'
|
|
5
|
+
import { Credentials } from '@aws-sdk/types'
|
|
5
6
|
|
|
6
7
|
export class AwsCredentialsClient {
|
|
7
8
|
|
|
8
|
-
static resolveAwsCredentials({ awsAccountId, awsRegion, awsRoleToAssume }: DeploymentPlatform) {
|
|
9
|
+
static resolveAwsCredentials({ awsAccountId, awsRegion, awsRoleToAssume }: DeploymentPlatform): Promise<Credentials | undefined> {
|
|
9
10
|
// If awsRoleToAssume is present, then we assume we run in a github workflow
|
|
10
11
|
// If awsRoleToAssume is not present, then we assume they are resolved localy by aws-sdk
|
|
11
12
|
if (!awsRoleToAssume) {
|
|
12
|
-
|
|
13
|
+
logInfo({ message: `[AwsCredentialsClient] No aws role to assume was found, leaving auth logic to @aws-sdk package` })
|
|
13
14
|
return Promise.resolve(undefined)
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const stsClient = new STSClient({ region: awsRegion })
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
logInfo({ message: '[AwsCredentialsClient] Fetching GitHub ID token' })
|
|
19
20
|
return core.getIDToken('sts.amazonaws.com')
|
|
20
21
|
.then(webIdentityToken => {
|
|
21
|
-
|
|
22
|
+
logInfo({ message: `[AwsCredentialsClient] Attempting to resolve aws credentials by assuming the role: ${awsRoleToAssume}` })
|
|
22
23
|
return stsClient.send(new AssumeRoleWithWebIdentityCommand({
|
|
23
24
|
RoleArn: `arn:aws:iam::${awsAccountId}:role/${awsRoleToAssume}`,
|
|
24
25
|
RoleSessionName: 'GitHubActions',
|
|
@@ -26,13 +27,18 @@ export class AwsCredentialsClient {
|
|
|
26
27
|
WebIdentityToken: webIdentityToken
|
|
27
28
|
}))
|
|
28
29
|
})
|
|
29
|
-
.then(responseData => ({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}))
|
|
30
|
+
// .then(responseData => ({
|
|
31
|
+
// AccessKeyId: responseData.Credentials.AccessKeyId,
|
|
32
|
+
// SessionToken: responseData.Credentials.SessionToken,
|
|
33
|
+
// SecretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
34
|
+
// }))
|
|
35
|
+
.then(responseData => responseData.Credentials)
|
|
36
|
+
.then(data => {
|
|
37
|
+
logDebug({ message: '[AwsCredentialsClient] AssumeRoleWithWebIdentityCommand responseData.Credentials', data })
|
|
38
|
+
return data
|
|
39
|
+
})
|
|
34
40
|
.catch(error => {
|
|
35
|
-
|
|
41
|
+
logError({ message: '[AwsCredentialsClient] Could not resolve temporary credentials', error })
|
|
36
42
|
return undefined
|
|
37
43
|
})
|
|
38
44
|
}
|
package/src/caddy-client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch'
|
|
2
|
-
import {
|
|
2
|
+
import { logInfo, logError } from './log'
|
|
3
3
|
import { DeploymentPlatform, ContainerDeploymentRequest } from 'types'
|
|
4
4
|
|
|
5
5
|
export const Matchers = {
|
|
@@ -24,10 +24,7 @@ export class CaddyClient {
|
|
|
24
24
|
|
|
25
25
|
const url = `${deploymentRequest.subdomain}.${deploymentPlatform.activeEnvironment}.${deploymentPlatform.domain}`
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
type: 'info',
|
|
29
|
-
message: `[CaddyClient] Updating caddy config to route ${url} to localhost:${deploymentRequest.hostPort}`
|
|
30
|
-
})
|
|
27
|
+
logInfo({ message: `[CaddyClient] Updating caddy config to route ${url} to localhost:${deploymentRequest.hostPort}` })
|
|
31
28
|
|
|
32
29
|
return fetch(`http://localhost:2019/config/apps/http/servers/${deploymentPlatform.ciServerName}/routes/0/handle`, {
|
|
33
30
|
method: 'POST',
|
|
@@ -39,11 +36,11 @@ export class CaddyClient {
|
|
|
39
36
|
}
|
|
40
37
|
]))
|
|
41
38
|
})
|
|
42
|
-
.catch(error =>
|
|
39
|
+
.catch(error => logError({ message: `[CaddyClient] Could not update caddy config to include ${url}`, error }))
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
static applyDefaultServerConfig(deploymentPlatform: DeploymentPlatform) {
|
|
46
|
-
|
|
43
|
+
logInfo({ message: '[CaddyClient] Applying default caddy config' })
|
|
47
44
|
return fetch('http://localhost:2019/load', {
|
|
48
45
|
method: 'POST',
|
|
49
46
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -105,7 +102,7 @@ export class CaddyClient {
|
|
|
105
102
|
}
|
|
106
103
|
})
|
|
107
104
|
})
|
|
108
|
-
.catch(error =>
|
|
105
|
+
.catch(error => logError({ message: '[CaddyClient] Could not apply default caddy config', error }))
|
|
109
106
|
}
|
|
110
107
|
|
|
111
108
|
}
|
package/src/ci-rest-api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express'
|
|
2
2
|
import { DeploymentPlatform } from 'types'
|
|
3
|
-
import {
|
|
3
|
+
import { logInfo } from './log'
|
|
4
4
|
|
|
5
5
|
export class CiRestApi {
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ export class CiRestApi {
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
server.listen(deploymentPlatform.ciInternalServerPort, () => {
|
|
21
|
-
|
|
21
|
+
logInfo({ message: `[ContainerManagerServer] API is live on port ${deploymentPlatform.ciInternalServerPort}`})
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import arg from 'arg'
|
|
2
|
-
import {
|
|
2
|
+
import { logInfo } from '../log'
|
|
3
3
|
import { DeploymentPlatformClient } from 'deployment-platform-client'
|
|
4
4
|
|
|
5
5
|
export const deployHandler = cliArgs => {
|
|
6
|
-
|
|
6
|
+
logInfo({ message: 'Running deploy command' })
|
|
7
7
|
|
|
8
8
|
const parsedArgs = arg({
|
|
9
9
|
'--username': String,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logError } from '../log'
|
|
2
2
|
import { startHandler } from './start-handler'
|
|
3
3
|
import { stopHandler } from './stop-handler'
|
|
4
4
|
import { statusHandler } from './status-handler'
|
|
@@ -6,7 +6,7 @@ import { deployHandler } from './deploy-handler'
|
|
|
6
6
|
|
|
7
7
|
export const runCliCommand = ({ name, args }) => {
|
|
8
8
|
|
|
9
|
-
if (!name) return
|
|
9
|
+
if (!name) return logError({ message: 'No command provided' })
|
|
10
10
|
|
|
11
11
|
const commandHandler = {
|
|
12
12
|
start: startHandler,
|
|
@@ -16,7 +16,7 @@ export const runCliCommand = ({ name, args }) => {
|
|
|
16
16
|
}[name]
|
|
17
17
|
|
|
18
18
|
if (!commandHandler) {
|
|
19
|
-
return
|
|
19
|
+
return logError({ message: 'Command not implemented, did you spell it correctly?' })
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
commandHandler(args)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import arg from 'arg'
|
|
2
2
|
import { platform } from 'os'
|
|
3
|
-
import {
|
|
3
|
+
import { logInfo, logError } from '../log'
|
|
4
4
|
import { DeploymentPlatformClient } from 'deployment-platform-client'
|
|
5
5
|
|
|
6
6
|
export const startHandler = cliArgs => {
|
|
7
|
-
|
|
7
|
+
logInfo({ message: 'Running start command' })
|
|
8
8
|
|
|
9
9
|
const Platforms = {
|
|
10
10
|
windows: 'win32',
|
|
@@ -12,7 +12,7 @@ export const startHandler = cliArgs => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if ([Platforms.windows].includes(platform())) {
|
|
15
|
-
return
|
|
15
|
+
return logError({ message: 'Deployment tools do not support this os' })
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const parsedArgs = arg({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exec } from 'child_process'
|
|
2
|
-
import {
|
|
2
|
+
import { logInfo } from '../log'
|
|
3
3
|
|
|
4
4
|
export const statusHandler = () => {
|
|
5
|
-
|
|
5
|
+
logInfo({ message: 'Running status command' })
|
|
6
6
|
exec('systemctl status deployment-tools.service')
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exec } from 'child_process'
|
|
2
|
-
import {
|
|
2
|
+
import { logInfo } from '../log'
|
|
3
3
|
|
|
4
4
|
export const stopHandler = () => {
|
|
5
|
-
|
|
5
|
+
logInfo({ message: 'Running stop command' })
|
|
6
6
|
exec('systemctl stop deployment-tools.service')
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ import { CaddyClient } from './caddy-client'
|
|
|
13
13
|
import { DockerClient } from './docker-client'
|
|
14
14
|
import { DeploymentQueueClient } from './deployment-queue-client'
|
|
15
15
|
import { CiRestApi } from './ci-rest-api'
|
|
16
|
-
import {
|
|
16
|
+
import { logInfo, logError } from 'log'
|
|
17
17
|
|
|
18
18
|
export class DeploymentPlatformClient {
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ export class DeploymentPlatformClient {
|
|
|
21
21
|
DeploymentPlatformClient.getDeploymentPlatforms(pathToDeploymentPlatforms).then(([firstPlatformFound]) => {
|
|
22
22
|
|
|
23
23
|
if (!firstPlatformFound) {
|
|
24
|
-
|
|
24
|
+
logError({ message: '[DeploymentPlatformClient] Could not find a deployment platform' })
|
|
25
25
|
return Promise.reject()
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -38,7 +38,7 @@ export class DeploymentPlatformClient {
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
})
|
|
41
|
-
.catch(error =>
|
|
41
|
+
.catch(error => logError({ message: '[DeploymentPlatformClient] Could not start the deployment platform', error }))
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
//eslint-disable-next-line max-params
|
|
@@ -56,22 +56,19 @@ export class DeploymentPlatformClient {
|
|
|
56
56
|
.then(([platforms, deploymentTemplates]) => {
|
|
57
57
|
deploymentTemplates.map(deploymentTemplate => {
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
type: 'info',
|
|
61
|
-
message: `[DeploymentPlatformClient]: Found deployment platforms [${platforms.map(x => x.platformName).join(', ')}]`
|
|
62
|
-
})
|
|
59
|
+
logInfo({ message: `[DeploymentPlatformClient]: Found deployment platforms [${platforms.map(x => x.platformName).join(', ')}]` })
|
|
63
60
|
|
|
64
61
|
const deploymentPlatform = platforms.find(platform => platform.platformName === deploymentTemplate.targetDeploymentPlatform)
|
|
65
62
|
|
|
66
63
|
if (!deploymentPlatform) {
|
|
67
|
-
|
|
64
|
+
logError({ message: `[DeploymentPlatformClient] Could not find a deployment platform with the name ${deploymentTemplate.targetDeploymentPlatform}` })
|
|
68
65
|
return Promise.reject()
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
|
72
69
|
|
|
73
70
|
if (deploymentTemplate.type !== SupportedDeploymentTypes.Container) {
|
|
74
|
-
|
|
71
|
+
logError({ message: `[DeploymentPlatformClient] Unsupported deployment type of ${deploymentTemplate.type}` })
|
|
75
72
|
return Promise.reject()
|
|
76
73
|
}
|
|
77
74
|
|
|
@@ -86,7 +83,7 @@ export class DeploymentPlatformClient {
|
|
|
86
83
|
|
|
87
84
|
})
|
|
88
85
|
})
|
|
89
|
-
.catch(error =>
|
|
86
|
+
.catch(error => logError({ message: '[DeploymentPlatformClient] Could not send deployment request', error }))
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
static getDeploymentTemplates(pathToOssyFile: string): Promise<DeploymentTemplate[]> {
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
} from '@aws-sdk/client-sqs'
|
|
7
7
|
import { DeploymentPlatform, ContainerDeploymentRequest } from 'types'
|
|
8
8
|
import { AwsCredentialsClient } from 'aws-credentials-client'
|
|
9
|
-
import {
|
|
9
|
+
import { logInfo, logError } from 'log'
|
|
10
10
|
|
|
11
11
|
export class DeploymentQueueClient {
|
|
12
12
|
|
|
13
13
|
static sendDeploymentRequest(deploymentPlatform: DeploymentPlatform, deploymentRequest: ContainerDeploymentRequest) {
|
|
14
|
-
|
|
14
|
+
logInfo({ message: '[DeploymentQueueClient] Starting deployment sequence' })
|
|
15
15
|
return DeploymentQueueClient.createAwsSqsClient(deploymentPlatform)
|
|
16
16
|
.then(sqsClient => {
|
|
17
17
|
|
|
@@ -21,19 +21,14 @@ export class DeploymentQueueClient {
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
return sqsClient.send(command)
|
|
24
|
-
.then(() =>
|
|
25
|
-
.catch(error =>
|
|
26
|
-
type: 'error',
|
|
27
|
-
message: '[DeploymentQueueClient] Could not send deployment request',
|
|
28
|
-
error
|
|
29
|
-
}))
|
|
30
|
-
|
|
24
|
+
.then(() => logInfo({ message: '[DeploymentQueueClient] Deployment request sent' }))
|
|
25
|
+
.catch(error => logError({ message: '[DeploymentQueueClient] Could not send deployment request', error }))
|
|
31
26
|
})
|
|
32
27
|
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
static pollForDeploymentRequests(deploymentPlatform: DeploymentPlatform, handleDeploymentRequest: (deploymentRequest: ContainerDeploymentRequest) => Promise<void>) {
|
|
36
|
-
|
|
31
|
+
logInfo({ message: '[DeploymentQueueClient] Starting polling for deployment requests' })
|
|
37
32
|
DeploymentQueueClient.createAwsSqsClient(deploymentPlatform).then(sqsClient => {
|
|
38
33
|
const FIVE_MINUTES = 3000
|
|
39
34
|
|
|
@@ -44,7 +39,7 @@ export class DeploymentQueueClient {
|
|
|
44
39
|
sqsClient.send(receiveMessageCommand)
|
|
45
40
|
.then(data => data.Messages.map(message => {
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
logInfo({ message: '[DeploymentQueueClient] Received deployment request' })
|
|
48
43
|
|
|
49
44
|
handleDeploymentRequest(JSON.parse(message.Body))
|
|
50
45
|
.then(() => {
|
|
@@ -55,12 +50,12 @@ export class DeploymentQueueClient {
|
|
|
55
50
|
})
|
|
56
51
|
|
|
57
52
|
sqsClient.send(deleteMessageCommand)
|
|
58
|
-
.then(() =>
|
|
59
|
-
.catch(error =>
|
|
53
|
+
.then(() => logInfo({ message: '[DeploymentQueueClient] Removing deployment request from queue' }))
|
|
54
|
+
.catch(error => logError({ message: '[DeploymentQueueClient] Could not delete message from queue', error }))
|
|
60
55
|
})
|
|
61
56
|
|
|
62
57
|
}))
|
|
63
|
-
.catch(error =>
|
|
58
|
+
.catch(error => logError({ message: '[ContainerManagerServer] Could not handle incoming deployment request', error }))
|
|
64
59
|
}, FIVE_MINUTES)
|
|
65
60
|
|
|
66
61
|
})
|
package/src/docker-client.ts
CHANGED
|
@@ -3,7 +3,7 @@ import fs from 'fs'
|
|
|
3
3
|
import { nanoid } from 'nanoid'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
|
-
import {
|
|
6
|
+
import { logInfo, logError } from './log'
|
|
7
7
|
import { DeploymentPlatform, ContainerDeploymentRequest } from 'types'
|
|
8
8
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url)
|
|
@@ -12,13 +12,13 @@ const __dirname = path.dirname(__filename)
|
|
|
12
12
|
export class DockerClient {
|
|
13
13
|
|
|
14
14
|
static createDockerNetworkForContainerManagerServer(deploymentPlatform: DeploymentPlatform) {
|
|
15
|
-
|
|
15
|
+
logInfo({ message: '[DockerClient] Creating docker network for comunication between containers' })
|
|
16
16
|
exec(`sudo docker network create ${deploymentPlatform.ciDockerNetworkName}`)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
static stopContainer(deploymentRequest: ContainerDeploymentRequest) {
|
|
20
20
|
const name = deploymentRequest.image.replaceAll('/', '_')
|
|
21
|
-
|
|
21
|
+
logInfo({ message: `Running docker stop for image with the name of ${name}` })
|
|
22
22
|
return `sudo docker stop ${name} ||`
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -26,7 +26,7 @@ export class DockerClient {
|
|
|
26
26
|
const name = image.replaceAll('/', '_')
|
|
27
27
|
const imageUrl = !!registry ? `${registry}/${image}` : image
|
|
28
28
|
const envsAsString = Object.entries(env || {}).reduce((envs, [name, value]) => `${envs} --env ${name}=${value}`, '')
|
|
29
|
-
|
|
29
|
+
logInfo({ message: `Running docker start for image with the name of ${name} with port mapping ${hostPort}:${containerPort} and source ${imageUrl}` })
|
|
30
30
|
return `sudo docker run -d -p ${hostPort}:${containerPort} --name=${name} --network=${deploymentPlatform.ciDockerNetworkName} --network-alias=${name} --rm ${envsAsString} ${imageUrl}`
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,17 +34,17 @@ export class DockerClient {
|
|
|
34
34
|
const shouldAuthenticate = username || authentication
|
|
35
35
|
|
|
36
36
|
if (!shouldAuthenticate) {
|
|
37
|
-
|
|
37
|
+
logInfo({ message: 'No docker credentials provided, assuming image is publicly hosted' })
|
|
38
38
|
return ''
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
logInfo({ message: `Resolving docker credentials for ${registry}` })
|
|
42
42
|
return `sudo docker login ${registry} -u ${username} -p ${authentication}`
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
static deploy(deploymentPlatform: DeploymentPlatform, deploymentRequest: ContainerDeploymentRequest): Promise<void> {
|
|
46
46
|
return new Promise(resolve => {
|
|
47
|
-
|
|
47
|
+
logInfo({ message: 'Starting docker deployment sequence' })
|
|
48
48
|
|
|
49
49
|
const dockerCommandScript = `'#!/bin/bash'
|
|
50
50
|
${DockerClient.stopContainer(deploymentRequest)}
|
|
@@ -61,15 +61,15 @@ ${DockerClient.startContainer(deploymentPlatform, deploymentRequest)}`
|
|
|
61
61
|
const command = exec(`bash ${FilePaths.DeploymentScript}`)
|
|
62
62
|
|
|
63
63
|
command.stdout.on('data', data => {
|
|
64
|
-
|
|
64
|
+
logInfo({ message: `[DockerClient]: ${data}` })
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
command.stderr.on('data', (data) => {
|
|
68
|
-
|
|
68
|
+
logError({ message: `[DockerClient]: ${data}` })
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
command.on('close', code => {
|
|
72
|
-
|
|
72
|
+
logInfo({ message: `[DockerClient] command exited with code ${code}` })
|
|
73
73
|
fs.unlinkSync(FilePaths.DeploymentScript)
|
|
74
74
|
resolve()
|
|
75
75
|
})
|
package/src/log/index.ts
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
interface LogInput {
|
|
2
|
-
type:
|
|
2
|
+
type: TypeOfMessage;
|
|
3
3
|
message: string;
|
|
4
|
-
|
|
4
|
+
data?: any;
|
|
5
|
+
dataPrefix: string;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
enum TypeOfMessage {
|
|
9
|
+
Info = 'INFO',
|
|
10
|
+
Error = 'ERROR',
|
|
11
|
+
Debug = 'DEBUG'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const log = (...params) => {
|
|
15
|
+
console.log(...params)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function prefixTo(prefix: string, message: string) {
|
|
19
|
+
`[${prefix}]${message.startsWith('[') ? '' : ': '}`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const logInfo = logInput => {
|
|
23
|
+
const messagePrefix = prefixTo(TypeOfMessage.Info, logInput.message)
|
|
24
|
+
log(`${messagePrefix}${logInput.message}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const logError = logInput => {
|
|
28
|
+
const messagePrefix = prefixTo(TypeOfMessage.Error, logInput.message)
|
|
29
|
+
log(`${messagePrefix}${logInput.message}`)
|
|
30
|
+
logInput.error && log('\n[Reason]:', logInput.error, '\n')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const logDebug = logInput => {
|
|
34
|
+
const isDebugOn = process.env.DEBUG || false
|
|
35
|
+
if (!isDebugOn) return
|
|
36
|
+
const messagePrefix = prefixTo(TypeOfMessage.Debug, logInput.message)
|
|
37
|
+
log(`${messagePrefix}${logInput.message}`)
|
|
38
|
+
logInput.data && log('\n[Debug data]:', logInput.data, '\n')
|
|
11
39
|
}
|