-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathvalidate.ts
More file actions
95 lines (85 loc) · 3.47 KB
/
validate.ts
File metadata and controls
95 lines (85 loc) · 3.47 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import * as api from '../rest/api'
import config from '../services/config'
import { Flags } from '@oclif/core'
import { AuthCommand } from './authCommand'
import { parseProject } from '../services/project-parser'
import { loadChecklyConfig } from '../services/checkly-config-loader'
import type { Runtime } from '../rest/runtimes'
import { Diagnostics } from '../constructs'
import { splitConfigFilePath } from '../services/util'
import commonMessages from '../messages/common-messages'
export default class Validate extends AuthCommand {
static coreCommand = true
static hidden = true // Expose when validation is more thorough.
static description = 'Validate your project.'
static flags = {
config: Flags.string({
char: 'c',
description: commonMessages.configFile,
}),
'verify-runtime-dependencies': Flags.boolean({
description: '[default: true] Return an error if checks import dependencies that are not supported by the selected runtime.',
default: true,
allowNo: true,
env: 'CHECKLY_VERIFY_RUNTIME_DEPENDENCIES',
}),
}
async run (): Promise<void> {
this.style.actionStart('Parsing your project')
const { flags } = await this.parse(Validate)
const {
config: configFilename,
'verify-runtime-dependencies': verifyRuntimeDependencies,
} = flags
const { configDirectory, configFilenames } = splitConfigFilePath(configFilename)
const {
config: checklyConfig,
constructs: checklyConfigConstructs,
} = await loadChecklyConfig(configDirectory, configFilenames)
const { data: account } = await api.accounts.get(config.getAccountId())
const { data: avilableRuntimes } = await api.runtimes.getAll()
const project = await parseProject({
directory: configDirectory,
projectLogicalId: checklyConfig.logicalId,
projectName: checklyConfig.projectName,
repoUrl: checklyConfig.repoUrl,
checkMatch: checklyConfig.checks?.checkMatch,
browserCheckMatch: checklyConfig.checks?.browserChecks?.testMatch,
multiStepCheckMatch: checklyConfig.checks?.multiStepChecks?.testMatch,
ignoreDirectoriesMatch: checklyConfig.checks?.ignoreDirectoriesMatch,
checkDefaults: checklyConfig.checks,
browserCheckDefaults: checklyConfig.checks?.browserChecks,
monitorDefaults: checklyConfig.checks?.monitors,
availableRuntimes: avilableRuntimes.reduce((acc, runtime) => {
acc[runtime.name] = runtime
return acc
}, <Record<string, Runtime>> {}),
defaultRuntimeId: account.runtimeId,
verifyRuntimeDependencies,
checklyConfigConstructs,
playwrightConfigPath: checklyConfig.checks?.playwrightConfigPath,
include: checklyConfig.checks?.include,
playwrightChecks: checklyConfig.checks?.playwrightChecks,
})
this.style.actionSuccess()
this.style.actionStart('Validating project resources')
const diagnostics = new Diagnostics()
await project.validate(diagnostics)
for (const diag of diagnostics.observations) {
if (diag.isFatal()) {
this.style.longError(diag.title, diag.message)
} else if (!diag.isBenign()) {
this.style.longWarning(diag.title, diag.message)
} else {
this.style.longInfo(diag.title, diag.message)
}
}
if (diagnostics.isFatal()) {
this.style.actionFailure()
this.style.shortError(`Your project is not valid.`)
this.exit(1)
}
this.style.actionSuccess()
this.style.shortSuccess(`Your project is valid.`)
}
}