diff --git a/README.md b/README.md index 4409e100..38afec48 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ This file is maintained by velocitas CLI, do not modify manually. Change setting - OS Recommendation is e.g. Ubuntu >= 22.04 - python3 (If not default in your environment create a symlink or use `python-is-python3`) -- `wget`, `dapr`, `build-essential`, `glibc` need to be installed +- `wget`, `dapr`, `build-essential`, `glibc`, `git` need to be installed ## Project configuration diff --git a/src/modules/git-module.ts b/src/modules/git-facade.ts similarity index 99% rename from src/modules/git-module.ts rename to src/modules/git-facade.ts index 722090a6..63d3d234 100644 --- a/src/modules/git-module.ts +++ b/src/modules/git-facade.ts @@ -17,7 +17,7 @@ import { posix as pathPosix } from 'path'; import { CheckRepoActions, SimpleGit, simpleGit } from 'simple-git'; import { PackageConfig } from './package'; -export class GitHelper { +export class GitFacade { packageConfig: PackageConfig; constructor(packageConfig: PackageConfig) { diff --git a/src/modules/package.ts b/src/modules/package.ts index 1de912e0..7506c419 100644 --- a/src/modules/package.ts +++ b/src/modules/package.ts @@ -18,7 +18,7 @@ import { join } from 'path'; import { Component, ComponentType, deserializeComponentJSON } from './component'; import { DEFAULT_BUFFER_ENCODING } from './constants'; import { ComponentConfig } from './project-config'; -import { GitHelper } from './git-module'; +import { GitFacade } from './git-facade'; export const MANIFEST_FILE_NAME = 'manifest.json'; @@ -52,7 +52,13 @@ export class PackageConfig { } private _isCustomPackage(repository: string): boolean { - return repository.startsWith('ssh://') || repository.startsWith('http://') || repository.startsWith('https://'); + const alternateSshStartPattern = /^.*\@/i; + return ( + repository.startsWith('ssh://') || + alternateSshStartPattern.test(repository) || + repository.startsWith('http://') || + repository.startsWith('https://') + ); } /** * Return the fully qualified URL to the package repository. @@ -85,8 +91,8 @@ export class PackageConfig { async getPackageVersions(): Promise { try { - const gitHelper = new GitHelper(this); - const git = await gitHelper.cloneOrUpdateRepo(true); + const gitFacade = new GitFacade(this); + const git = await gitFacade.cloneOrUpdateRepo(true); const tagsResult = await git.tags(); return tagsResult.all; } catch (error) { @@ -97,8 +103,8 @@ export class PackageConfig { async downloadPackageVersion(verbose?: boolean): Promise { try { - const gitHelper = new GitHelper(this); - await gitHelper.cloneOrUpdateRepo(false); + const gitFacade = new GitFacade(this); + await gitFacade.cloneOrUpdateRepo(false); } catch (error) { console.error(error); } diff --git a/src/modules/setup.ts b/src/modules/setup.ts index e2d3cde0..089abcc6 100644 --- a/src/modules/setup.ts +++ b/src/modules/setup.ts @@ -22,6 +22,8 @@ import { SetupComponent } from './component'; import { PackageConfig } from './package'; import { VariableCollection } from './variables'; +const SUPPORTED_TEXT_FILES_ARRAY = ['.md', '.yaml', '.yml', '.txt', '.json', '.sh', '.html', '.htm', '.xml', '.tpl']; + class ReplaceVariablesStream extends Transform { private _fileExt: string; private _variables: VariableCollection; @@ -94,11 +96,7 @@ export function installComponent(packageConfig: PackageConfig, setupComponent: S dot: true, overwrite: true, transform: function (src: string, _: string, stats: Stats) { - if ( - !['.md', '.yaml', '.yml', '.txt', '.json', '.sh', '.html', '.htm', '.xml', '.tpl'].includes( - path.extname(src), - ) - ) { + if (!SUPPORTED_TEXT_FILES_ARRAY.includes(path.extname(src))) { return null; } diff --git a/test/unit/package.test.ts b/test/unit/package.test.ts index 3f47bfcd..57b9cb67 100644 --- a/test/unit/package.test.ts +++ b/test/unit/package.test.ts @@ -15,6 +15,7 @@ import 'mocha'; import mockfs from 'mock-fs'; import { PackageConfig } from '../../src/modules/package'; +import { expect } from 'chai'; describe('package - module', () => { let envCache: any; @@ -40,6 +41,26 @@ describe('package - module', () => { packageConfig.readPackageManifest(); }); }); + describe('Package config', () => { + it.only('should get package name', () => { + const packageNamePlain = 'TestPackage'; + const packageConfigPlan = new PackageConfig({ name: packageNamePlain, version: 'v1.2.3' }); + const packageNameHttps = 'https://testserver.com/TestOrg/TestPackage.git'; + const packageConfigHttps = new PackageConfig({ name: packageNameHttps, version: 'v1.2.3' }); + const packageNameHttp = 'http://testserver.com/TestOrg/TestPackage.git'; + const packageConfigHttp = new PackageConfig({ name: packageNameHttp, version: 'v1.2.3' }); + const packageNameSsh = 'ssh://testuser@testserver.com:TestOrg/TestPackage.git'; + const packageConfigSsh = new PackageConfig({ name: packageNameSsh, version: 'v1.2.3' }); + const packageNameSshAlternate = 'testuser@testserver.com:TestOrg/TestPackage.git'; + const packageConfigSshAlternate = new PackageConfig({ name: packageNameSshAlternate, version: 'v1.2.3' }); + + expect(packageConfigPlan.getPackageName()).equals(packageNamePlain); + expect(packageConfigHttps.getPackageName()).equals(packageNamePlain); + expect(packageConfigHttp.getPackageName()).equals(packageNamePlain); + expect(packageConfigSsh.getPackageName()).equals(packageNamePlain); + expect(packageConfigSshAlternate.getPackageName()).equals(packageNamePlain); + }); + }); after(() => { process.env = envCache; mockfs.restore();