unity-builder/src/model/image-tag.ts

123 lines
3.3 KiB
TypeScript
Raw Normal View History

import Platform from './platform';
2019-12-22 14:05:15 +00:00
class ImageTag {
public repository: string;
public name: string;
public version: string;
public platform: any;
public builderPlatform: string;
public customImage: any;
2019-12-22 14:05:15 +00:00
constructor(imageProperties) {
const { repository = 'unityci', name = 'editor', version = '2019.2.11f1', platform, customImage } = imageProperties;
2019-12-22 14:05:15 +00:00
2019-12-22 17:07:55 +00:00
if (!ImageTag.versionPattern.test(version)) {
2019-12-22 14:05:15 +00:00
throw new Error(`Invalid version "${version}".`);
}
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(platform, version);
2019-12-22 14:05:15 +00:00
this.repository = repository;
this.name = name;
this.version = version;
this.platform = platform;
this.builderPlatform = builderPlatform;
this.customImage = customImage;
2019-12-22 14:05:15 +00:00
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
2019-12-22 14:05:15 +00:00
}
static get imageSuffixes() {
2019-12-22 14:05:15 +00:00
return {
generic: '',
webgl: 'webgl',
2020-10-24 06:43:29 +00:00
mac: 'mac-mono',
windows: 'windows-mono',
2020-10-24 07:39:01 +00:00
linux: 'base',
linuxIl2cpp: 'linux-il2cpp',
2019-12-22 14:05:15 +00:00
android: 'android',
ios: 'ios',
facebook: 'facebook',
2019-12-22 14:05:15 +00:00
};
}
static getTargetPlatformToImageSuffixMap(platform, version) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } = ImageTag.imageSuffixes;
2019-12-22 14:05:15 +00:00
const [major, minor] = version.split('.').map((digit) => Number(digit));
2020-10-24 06:43:29 +00:00
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
switch (platform) {
case Platform.types.StandaloneOSX:
return mac;
case Platform.types.StandaloneWindows:
return windows;
case Platform.types.StandaloneWindows64:
return windows;
case Platform.types.StandaloneLinux64: {
// Unity versions before 2019.3 do not support il2cpp
if (major >= 2020 || (major === 2019 && minor >= 3)) {
return linuxIl2cpp;
}
return linux;
}
case Platform.types.iOS:
return ios;
case Platform.types.Android:
return android;
case Platform.types.WebGL:
return webgl;
case Platform.types.WSAPlayer:
return windows;
case Platform.types.PS4:
return windows;
case Platform.types.XboxOne:
return windows;
case Platform.types.tvOS:
return windows;
case Platform.types.Switch:
return windows;
// Unsupported
case Platform.types.Lumin:
return windows;
case Platform.types.BJM:
return windows;
case Platform.types.Stadia:
return windows;
case Platform.types.Facebook:
return facebook;
case Platform.types.NoTarget:
return generic;
// Test specific
case Platform.types.Test:
return generic;
default:
throw new Error(`
Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`);
}
2019-12-22 14:05:15 +00:00
}
get tag() {
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
2019-12-22 14:05:15 +00:00
}
2019-12-22 17:07:55 +00:00
get image() {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
2019-12-22 17:07:55 +00:00
}
2019-12-22 14:05:15 +00:00
toString() {
const { image, tag, customImage } = this;
2019-12-22 14:05:15 +00:00
if (customImage && customImage !== '') {
return customImage;
}
2020-10-24 06:43:29 +00:00
return `${image}:${tag}-0`; // '0' here represents the docker repo version
2019-12-22 14:05:15 +00:00
}
}
export default ImageTag;