Skip to content

Commit

Permalink
Work on PR review findings
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Meister <dennis.meister@bosch.com>
  • Loading branch information
dennismeister93 committed Jul 19, 2023
1 parent fca8785 commit 3357f0a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/modules/git-module.ts → src/modules/git-facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 12 additions & 6 deletions src/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -85,8 +91,8 @@ export class PackageConfig {

async getPackageVersions(): Promise<string[]> {
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) {
Expand All @@ -97,8 +103,8 @@ export class PackageConfig {

async downloadPackageVersion(verbose?: boolean): Promise<void> {
try {
const gitHelper = new GitHelper(this);
await gitHelper.cloneOrUpdateRepo(false);
const gitFacade = new GitFacade(this);
await gitFacade.cloneOrUpdateRepo(false);
} catch (error) {
console.error(error);
}
Expand Down
8 changes: 3 additions & 5 deletions src/modules/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions test/unit/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 3357f0a

Please sign in to comment.