Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move chectl project name into a separate constant #1091

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as os from 'os'
import * as path from 'path'

import { CHE_OPERATOR_CR_PATCH_YAML_KEY, CHE_OPERATOR_CR_YAML_KEY, LOG_DIRECTORY_KEY } from '../common-flags'
import { CHECTL_PROJECT_NAME } from '../constants'
import { getProjectName, getProjectVersion, readCRFile } from '../util'

import { KubeHelper } from './kube'
Expand Down Expand Up @@ -45,7 +46,7 @@ export namespace ChectlContext {
ctx[IS_OPENSHIFT] = await kube.isOpenShift()
ctx[IS_OPENSHIFT4] = await kube.isOpenShift4()

ctx.isChectl = getProjectName() === 'chectl'
ctx.isChectl = getProjectName() === CHECTL_PROJECT_NAME
ctx.isNightly = getProjectVersion().includes('next') || getProjectVersion() === CHECTL_DEVELOPMENT_VERSION

if (flags['listr-renderer'] as any) {
Expand Down
5 changes: 3 additions & 2 deletions src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Listr = require('listr')
import * as path from 'path'
import * as semver from 'semver'

import { CHECTL_PROJECT_NAME } from '../constants'
import { CheTasks } from '../tasks/che'
import { getClusterClientCommand, getProjectName, getProjectVersion } from '../util'

Expand Down Expand Up @@ -183,7 +184,7 @@ export namespace VersionHelper {
* Returns latest chectl version for the given channel.
*/
export async function getLatestChectlVersion(channel: string): Promise<string | undefined> {
if (getProjectName() !== 'chectl') {
if (getProjectName() !== CHECTL_PROJECT_NAME) {
return
}

Expand All @@ -205,7 +206,7 @@ export namespace VersionHelper {
export async function isChectlUpdateAvailable(cacheDir: string, forceRecheck = false): Promise<boolean> {
// Do not use ctx inside this function as the function is used from hook where ctx is not yet defined.

if (getProjectName() !== 'chectl') {
if (getProjectName() !== CHECTL_PROJECT_NAME) {
// Do nothing for chectl flavors
return false
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

export const CHECTL_PROJECT_NAME = 'chectl'

// minimal installable versions by current chectl
export const MIN_OLM_INSTALLER_VERSION = '7.17.0'
export const MIN_CHE_OPERATOR_INSTALLER_VERSION = '7.13.1'
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/prerun/new-version-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { Hook } from '@oclif/config'
import { cli } from 'cli-ux'

import { VersionHelper } from '../../api/version'
import { CHECTL_PROJECT_NAME } from '../../constants'
import { getProjectName } from '../../util'

const isChectl = getProjectName() === 'chectl'
const isChectl = getProjectName() === CHECTL_PROJECT_NAME
const hook: Hook<'prerun'> = async function (options) {
if (!isChectl) {
return
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function downloadYaml(url: string): Promise<any> {
}

export function getEmbeddedTemplatesDirectory(): string {
// Embedded templates are located in the templates directory taht is in the project/installation root:
// Embedded templates are located in the templates directory that is in the project/installation root:
// chectl
// |- templates
// |- src
Expand Down