feat: extract platforms

This commit is contained in:
Igor Randjelovic
2020-12-07 13:41:22 +01:00
parent 7df2f09cfc
commit 2f39cf5ed6
15 changed files with 377 additions and 44 deletions

View File

@@ -0,0 +1,11 @@
import { INativeScriptPlatform } from '.';
function getDistPath() {
return `platforms/android/app/src/main/assets/app`;
}
const AndroidPlatform: INativeScriptPlatform = {
getDistPath,
}
export default AndroidPlatform;

View File

@@ -0,0 +1,47 @@
import { error } from "../helpers/log";
import { env, Platform } from "../";
import AndroidPlatform from "./android";
import iOSPlatform from "./ios";
export interface INativeScriptPlatform {
getEntryPath?(): string;
getDistPath?(): string
}
const platforms = {
android: AndroidPlatform,
ios: iOSPlatform,
}
export function addPlatform(name: string, platform: INativeScriptPlatform) {
console.log('adding platform', name, platform)
platforms[name] = platform;
}
export function getPlatform(): INativeScriptPlatform {
return platforms[getPlatformName()]
}
export function getPlatformName(): Platform {
if (env?.android) {
return 'android';
}
if (env?.ios) {
return 'ios';
}
// support custom platforms
if(env?.platform) {
return env.platform;
}
throw error(`
You need to provide a target platform!
Available platforms: ${Object.keys(platforms).join(', ')}
Use --env=platform=<platform> or --env=android, --env=ios to specify the target platform.
`);
}

View File

@@ -0,0 +1,15 @@
import { basename } from "path";
import { getProjectRootPath } from "../helpers/project";
import { INativeScriptPlatform } from '.';
function getDistPath() {
const appName = basename(getProjectRootPath());
return `platforms/ios/${appName}/app`;
}
const iOSPlatform: INativeScriptPlatform = {
getDistPath,
}
export default iOSPlatform;