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

84 lines
1.9 KiB
JavaScript
Raw Normal View History

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