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

95 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-12-22 17:07:55 +00:00
import { has, get, trimEnd, trimStart } from 'lodash-es';
import Platform from './platform';
2019-12-22 14:05:15 +00:00
class ImageTag {
2019-12-22 14:05:15 +00:00
constructor(imageProperties) {
const {
repository = 'unityci',
name = 'editor',
2019-12-22 14:05:15 +00:00
version = '2019.2.11f1',
2019-12-22 17:07:55 +00:00
platform,
customImage,
2019-12-22 14:05:15 +00:00
} = imageProperties;
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}".`);
}
if (!has(ImageTag.targetPlatformToImageSuffixMap, platform)) {
2019-12-22 17:07:55 +00:00
throw new Error(`Platform "${platform}" is currently not supported.`);
2019-12-22 14:05:15 +00:00
}
const builderPlatform = get(
ImageTag.targetPlatformToImageSuffixMap,
2019-12-22 17:07:55 +00:00
platform,
ImageTag.imageSuffixes.generic,
2019-12-22 14:05:15 +00:00
);
Object.assign(this, { repository, name, version, platform, builderPlatform, 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',
2019-12-22 14:05:15 +00:00
android: 'android',
ios: 'ios',
facebook: 'facebook',
2019-12-22 14:05:15 +00:00
};
}
static get targetPlatformToImageSuffixMap() {
const { generic, webgl, mac, windows, android, ios, facebook } = ImageTag.imageSuffixes;
2019-12-22 14:05:15 +00:00
2020-10-24 06:43:29 +00:00
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
2019-12-22 14:05:15 +00:00
return {
[Platform.types.StandaloneOSX]: mac,
[Platform.types.StandaloneWindows]: windows,
[Platform.types.StandaloneWindows64]: windows,
[Platform.types.StandaloneLinux64]: windows,
[Platform.types.iOS]: ios,
[Platform.types.Android]: android,
[Platform.types.WebGL]: webgl,
[Platform.types.WSAPlayer]: windows,
[Platform.types.PS4]: windows,
[Platform.types.XboxOne]: windows,
[Platform.types.tvOS]: windows,
[Platform.types.Switch]: windows,
// Unsupported
[Platform.types.Lumin]: windows,
[Platform.types.BJM]: windows,
[Platform.types.Stadia]: windows,
[Platform.types.Facebook]: facebook,
[Platform.types.NoTarget]: generic,
// Test specific
[Platform.types.Test]: generic,
2019-12-22 14:05:15 +00:00
};
}
get tag() {
return trimEnd(`${this.version}-${this.builderPlatform}`, '-');
}
2019-12-22 17:07:55 +00:00
get image() {
return trimStart(`${this.repository}/${this.name}`, '/');
}
2019-12-22 14:05:15 +00:00
toString() {
2019-12-22 17:07:55 +00:00
const { image, tag } = this;
2019-12-22 14:05:15 +00:00
if (this.customImage && this.customImage !== '') {
return this.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;