Skip to content

Commit

Permalink
v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
FejZa committed Sep 26, 2024
1 parent ff33962 commit 739837e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.9]

### Added

- Added UnityPackageManagerTools for adding and removing packages from a project

## [1.0.8]

### Removed
Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export * from './lib/unity-log-streamer';
export * from './lib/unity-tool-runner';
export * from './lib/unity-path-tools';
export * from './lib/unity-version-tools';
export * from './lib/unity-package-manager-tools';
export * from './lib/utilities';
export * from './lib/models';
60 changes: 60 additions & 0 deletions lib/unity-package-manager-tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Dinomite. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

import path = require('path');
import fs from 'fs';

export class UnityPackageManagerTools {

private static readonly packagesFolder = 'Packages';
private static readonly packageManifestFile = 'manifest.json';

/**
* Adds a package to a project's package manifest.
*
* @param projectPath The path to the project on disc.
* @param packageName The package identifer.
* @param versionOrGitUrl The package version to install (can also be a git URL in case the package is installed via git).
*/
public static addPackageToProject(projectPath: string, packageName: string, versionOrGitUrl: string): Error | null | undefined {
try {
const packageManifestFilePath = path.join(projectPath, UnityPackageManagerTools.packagesFolder, UnityPackageManagerTools.packageManifestFile);
const packageManifestFileContent = fs.readFileSync(packageManifestFilePath, { encoding: 'utf8' });
let jsonData = JSON.parse(packageManifestFileContent);

if (!jsonData.dependencies.hasOwnProperty(packageName)) {
jsonData.dependencies[packageName] = versionOrGitUrl;
const updatedData = JSON.stringify(jsonData);
fs.writeFileSync(packageManifestFilePath, updatedData, 'utf-8');
}
} catch (e) {
if (e instanceof Error) {
return e;
}
}
}

/**
* Removes a package from a project's package manifest.
*
* @param projectPath The path to the project on disc.
* @param packageName The package identifer.
*/
public static removePackageFromProject(projectPath: string, packageName: string): Error | null | undefined {
try {
const packageManifestFilePath = path.join(projectPath, UnityPackageManagerTools.packagesFolder, UnityPackageManagerTools.packageManifestFile);
const packageManifestFileContent = fs.readFileSync(packageManifestFilePath, { encoding: 'utf8' });
let jsonData = JSON.parse(packageManifestFileContent);

if (jsonData.dependencies.hasOwnProperty(packageName)) {
delete jsonData.dependencies[packageName];
const updatedData = JSON.stringify(jsonData);
fs.writeFileSync(packageManifestFilePath, updatedData, 'utf-8');
}
} catch (e) {
if (e instanceof Error) {
return e;
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dinomite-studios/unity-azure-pipelines-tasks-lib",
"version": "1.0.8",
"version": "1.0.9",
"description": "A library containing common implementations for pipeline tasks available in the Unity Tools for Azure DevOps extension.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
47 changes: 47 additions & 0 deletions test/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"dependencies": {
"com.unity.ai.navigation": "2.0.4",
"com.unity.collab-proxy": "2.5.1",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.inputsystem": "1.11.0",
"com.unity.multiplayer.center": "1.0.0",
"com.unity.render-pipelines.universal": "17.0.3",
"com.unity.test-framework": "1.4.5",
"com.unity.timeline": "1.8.7",
"com.unity.ugui": "2.0.0",
"com.unity.visualscripting": "1.9.4",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}
24 changes: 24 additions & 0 deletions test/unity-package-manager-tools.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Dinomite. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

import 'mocha';
import { expect } from 'chai';
import { UnityPackageManagerTools } from '../dist';

describe('UnityPackageManagerTools',
() => {
it('Invalid file path should return error', () => {
const error = UnityPackageManagerTools.addPackageToProject('XYZ:\\This\\Path\\Does\\Not\\Exist', 'games.dinomite.azurepipelines', 'https://github.com/Dinomite-Studios/unity-azure-pipelines-tasks-build-scripts.git');
expect(error);
});

it('games.dinomite.azurepipelines package was added to manifest', () => {
const error = UnityPackageManagerTools.addPackageToProject(__dirname, 'games.dinomite.azurepipelines', 'https://github.com/Dinomite-Studios/unity-azure-pipelines-tasks-build-scripts.git');
expect(!error);
});

it('games.dinomite.azurepipelines package was removed from manifest', () => {
const error = UnityPackageManagerTools.removePackageFromProject(__dirname, 'games.dinomite.azurepipelines');
expect(!error);
});
});
2 changes: 1 addition & 1 deletion test/unity-version-tools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('UnityVersionTools',
expect(error);
});

it('Test ProjectVersion.txt should return 2020.2.0f1 (3721df5a8b28) stable', () => {
it('ProjectVersion.txt should return 2020.2.0f1 (3721df5a8b28) stable', () => {
const { info, error } = UnityVersionTools.determineProjectVersionFromFile(__dirname);
const expectedResult: UnityVersionInfo = {
version: '2020.2.0f1',
Expand Down

0 comments on commit 739837e

Please sign in to comment.