import { generateConanRecipe } from '../utils'; import { PackageType } from '../../shared/constants'; import { getPackageTypeLabel } from '../../shared/utils'; import { NpmManager } from '../constants'; export const packagePipeline = ({ packageEntity }) => { return packageEntity?.pipeline || null; }; export const packageTypeDisplay = ({ packageEntity }) => { return getPackageTypeLabel(packageEntity.package_type); }; export const packageIcon = ({ packageEntity }) => { if (packageEntity.package_type === PackageType.NUGET) { return packageEntity.nuget_metadatum?.icon_url || null; } return null; }; export const conanInstallationCommand = ({ packageEntity }) => { const recipe = generateConanRecipe(packageEntity); // eslint-disable-next-line @gitlab/require-i18n-strings return `conan install ${recipe} --remote=gitlab`; }; export const conanSetupCommand = ({ conanPath }) => // eslint-disable-next-line @gitlab/require-i18n-strings `conan remote add gitlab ${conanPath}`; export const mavenInstallationXml = ({ packageEntity = {} }) => { const { app_group: appGroup = '', app_name: appName = '', app_version: appVersion = '', } = packageEntity.maven_metadatum; return ` ${appGroup} ${appName} ${appVersion} `; }; export const mavenInstallationCommand = ({ packageEntity = {} }) => { const { app_group: group = '', app_name: name = '', app_version: version = '', } = packageEntity.maven_metadatum; return `mvn dependency:get -Dartifact=${group}:${name}:${version}`; }; export const mavenSetupXml = ({ mavenPath }) => ` gitlab-maven ${mavenPath} gitlab-maven ${mavenPath} gitlab-maven ${mavenPath} `; export const npmInstallationCommand = ({ packageEntity }) => (type = NpmManager.NPM) => { // eslint-disable-next-line @gitlab/require-i18n-strings const instruction = type === NpmManager.NPM ? 'npm i' : 'yarn add'; return `${instruction} ${packageEntity.name}`; }; export const npmSetupCommand = ({ packageEntity, npmPath }) => (type = NpmManager.NPM) => { const scope = packageEntity.name.substring(0, packageEntity.name.indexOf('/')); if (type === NpmManager.NPM) { return `echo ${scope}:registry=${npmPath}/ >> .npmrc`; } return `echo \\"${scope}:registry\\" \\"${npmPath}/\\" >> .yarnrc`; }; export const nugetInstallationCommand = ({ packageEntity }) => `nuget install ${packageEntity.name} -Source "GitLab"`; export const nugetSetupCommand = ({ nugetPath }) => `nuget source Add -Name "GitLab" -Source "${nugetPath}" -UserName -Password `; export const pypiPipCommand = ({ pypiPath, packageEntity }) => // eslint-disable-next-line @gitlab/require-i18n-strings `pip install ${packageEntity.name} --index-url ${pypiPath}`; export const pypiSetupCommand = ({ pypiSetupPath }) => `[gitlab] repository = ${pypiSetupPath} username = __token__ password = `; export const composerRegistryInclude = ({ composerPath }) => { const base = { type: 'composer', url: composerPath }; return JSON.stringify(base); }; export const composerPackageInclude = ({ packageEntity }) => { const base = { [packageEntity.name]: packageEntity.version }; return JSON.stringify(base); };