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

@ -15,9 +15,9 @@ import {
getEntryPath,
getEntryDirPath,
getPackageJson,
getPlatform,
getProjectRootPath,
} from './project';
import { getPlatform, getPlatformName, addPlatform } from '../platforms';
// intentionally populated manually
// as this generates nicer typings
@ -50,7 +50,11 @@ export default {
getEntryPath,
getEntryDirPath,
getDistPath,
getPlatform,
getPackageJson,
},
platform: {
getPlatform,
getPlatformName,
addPlatform,
},
};

View File

@ -1,20 +1,20 @@
import { resolve, basename, dirname } from 'path';
import { resolve, dirname } from 'path';
import { env, Platform } from '../index';
import { error } from './log';
import { getPlatform } from '../platforms';
export function getProjectRootPath(): string {
// todo: find actual path?
return process.cwd();
//__dirname
}
export function getAbsoluteDistPath() {
return resolve(getProjectRootPath(), getDistPath());
}
export function getEntryPath() {
const platform = getPlatform();
// use platform specific entry path
if (platform.getEntryPath) {
return platform.getEntryPath();
}
// fallback to main field in package.json
const packageJson = getPackageJson();
return resolve(getProjectRootPath(), packageJson.main);
@ -25,30 +25,19 @@ export function getEntryDirPath() {
}
export function getDistPath() {
if (env.ios) {
const appName = basename(getProjectRootPath());
return `platforms/ios/${appName}/app`;
const platform = getPlatform();
// use platform specific entry path
if (platform.getDistPath) {
return platform.getDistPath();
}
if (env.android) {
return `platforms/android/app/src/main/assets/app`;
}
// todo: additional platforms
// perhaps we could combine platform specifics into "plugins"
// 3rd party platforms would be treated the same
// fallback to a generic dist folder
return 'dist';
}
export function getPlatform(): Platform {
if (env?.android) {
return 'android';
}
if (env?.ios) {
return 'ios';
}
error('You need to provide a target platform!');
export function getAbsoluteDistPath() {
return resolve(getProjectRootPath(), getDistPath());
}
interface IPackageJson {