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

feat: improve latest version handling #292

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TagResult } from 'simple-git';
import { CliFileSystem } from '../utils/fs-bridge';
import { ComponentManifest } from './component';
import { packageDownloader } from './package-downloader';
import { getLatestVersion } from './semver';

export const MANIFEST_FILE_NAME = 'manifest.json';

Expand Down Expand Up @@ -80,7 +81,16 @@ export class PackageConfig {
return join(getPackageFolderPath(), this.getPackageName());
}

getPackageDirectoryWithLatestVersion(): string {
const filesAndFolders = CliFileSystem.readdirSync(this.getPackageDirectory());
const latestVersion = getLatestVersion(filesAndFolders);
return join(this.getPackageDirectory(), latestVersion);
}

getPackageDirectoryWithVersion(): string {
if (this.version === 'latest') {
return this.getPackageDirectoryWithLatestVersion();
}
return join(this.getPackageDirectory(), this.version);
}

Expand Down
2 changes: 0 additions & 2 deletions src/modules/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export function getLatestVersion(versions: string[]): string {
latestVersion = currentVersion;
}
}
} else {
console.log('Not valid');
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/utils/fs-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ interface IFileSystem {
* @returns The absolute path.
*/
realpathSync(path: fs.PathLike): string;

/**
* Reads a directory synchronously.
* @param path A path to a file or directory.
*/
readdirSync(path: fs.PathLike): string[];
}

/**
Expand Down Expand Up @@ -122,6 +128,10 @@ class RealFileSystem implements IFileSystem {
realpathSync(path: fs.PathLike): string {
return fs.realpathSync(path);
}

readdirSync(path: fs.PathLike): string[] {
return fs.readdirSync(path);
}
}

export type MockFileSystemObj = Record<string, string>;
Expand Down Expand Up @@ -170,6 +180,10 @@ export class MockFileSystem implements IFileSystem, IFileSystemTests {
return path.toString();
}

readdirSync(path: fs.PathLike): string[] {
return [this._fileSystemObj[path.toString()]];
}

async promisesMkdir(path: string): Promise<void> {
this._fileSystemObj[path] = '';
}
Expand Down Expand Up @@ -254,6 +268,14 @@ export class CliFileSystem {
return this._impl.realpathSync(path);
}

/**
* Reads a directory synchronously.
* @param path A path to a file or directory.
*/
static readdirSync(path: fs.PathLike): string[] {
return this._impl.readdirSync(path);
}

/**
* Asynchronously creates a directory.
* @param path A path to the directory to create.
Expand Down
2 changes: 1 addition & 1 deletion testbench/test-exec/.velocitas.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": {
"devenv-runtimes": "v4.0.3",
"devenv-runtimes": "latest",
"test-package": "test-version"
},
"variables": {
Expand Down
5 changes: 2 additions & 3 deletions testbench/test-init/.velocitasInvalidComponent.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"packages": {
"https://github.com/eclipse-velocitas/devenv-devcontainer-setup.git": "v1.5.0"
"https://github.com/eclipse-velocitas/devenv-devcontainer-setup.git": "latest"
},
"components": [
"invalid-component"
],
"variables": {
"appManifestPath": "./app/AppManifest.json",
"githubRepoId": "<myrepo>"
},
"cliVersion": "v0.10.0"
}
}
8 changes: 4 additions & 4 deletions testbench/test-init/.velocitasLegacy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"packages": [
{
"repo": "devenv-runtimes",
"version": "v4.0.0"
"version": "latest"
},
{
"repo": "devenv-github-workflows",
"version": "v6.0.1"
"version": "latest"
},
{
"repo": "devenv-github-templates",
"version": "v1.0.5"
"version": "latest"
},
{
"repo": "devenv-devcontainer-setup",
"version": "v2.2.1"
"version": "latest"
}
],
"variables": {
Expand Down
13 changes: 6 additions & 7 deletions testbench/test-init/.velocitasNew.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"packages": {
"https://github.com/eclipse-velocitas/pkg-velocitas-main.git": "v0.0.2",
"https://github.com/eclipse-velocitas/devenv-devcontainer-setup.git": "v2.4.4",
"https://github.com/eclipse-velocitas/devenv-runtimes.git": "v4.0.3",
"https://github.com/eclipse-velocitas/devenv-github-templates.git": "v1.0.5",
"https://github.com/eclipse-velocitas/devenv-github-workflows.git": "v6.0.4"
"https://github.com/eclipse-velocitas/pkg-velocitas-main.git": "latest",
"https://github.com/eclipse-velocitas/devenv-devcontainer-setup.git": "latest",
"https://github.com/eclipse-velocitas/devenv-runtimes.git": "latest",
"https://github.com/eclipse-velocitas/devenv-github-templates.git": "latest",
"https://github.com/eclipse-velocitas/devenv-github-workflows.git": "latest"
},
"components": [
"vapp-core-python",
Expand All @@ -21,6 +21,5 @@
"variables": {
"appManifestPath": "./app/AppManifest.json",
"githubRepoId": "<myrepo>"
},
"cliVersion": "v0.10.0"
}
}