From 580f98204a4eb80e4c00d3046f1aa873569d3a2c Mon Sep 17 00:00:00 2001 From: atanasovg Date: Thu, 2 Apr 2015 19:59:16 +0300 Subject: [PATCH] Update application bootstrap logic. Resolves #53. --- src/src/com/tns/NativeScriptApplication.java | 2 +- src/src/com/tns/Platform.java | 8 +++---- src/src/com/tns/Require.java | 25 +++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/src/com/tns/NativeScriptApplication.java b/src/src/com/tns/NativeScriptApplication.java index afc6629d7..dd2647d54 100644 --- a/src/src/com/tns/NativeScriptApplication.java +++ b/src/src/com/tns/NativeScriptApplication.java @@ -733,7 +733,7 @@ public void onCreate() { } Platform.init(this); - Platform.run(Platform.DefaultApplicationModuleName); + Platform.run(); onCreateInternal(); } diff --git a/src/src/com/tns/Platform.java b/src/src/com/tns/Platform.java index fb5251fa5..84740e024 100644 --- a/src/src/com/tns/Platform.java +++ b/src/src/com/tns/Platform.java @@ -78,8 +78,6 @@ public class Platform private static ArrayList> ctorCache = new ArrayList>(); - public final static String DefaultApplicationModuleName = "./bootstrap"; - private static JsDebugger jsDebugger; public static boolean IsLogEnabled = BuildConfig.DEBUG; @@ -187,10 +185,10 @@ static void setExtractPolicy(ExtractPolicy policy) extractPolicy = policy; } - public static void run(String appFileName) + public static void run() { - String appContent = Require.getAppContent(appFileName); - runNativeScript(appFileName, appContent); + String[] bootstrapInfo = Require.bootstrapApp(); + runNativeScript(bootstrapInfo[0], bootstrapInfo[1]); } private static int cacheConstructor(String name, String className, Object[] args, String[] methodOverrides) throws ClassNotFoundException, IOException diff --git a/src/src/com/tns/Require.java b/src/src/com/tns/Require.java index fce42f61f..fa20e03a6 100644 --- a/src/src/com/tns/Require.java +++ b/src/src/com/tns/Require.java @@ -55,10 +55,29 @@ public static String getApplicationFilesPath() return ApplicationFilesPath; } - public static String getAppContent(String appFileName) + public static String[] bootstrapApp() { - File bootstrapFile = findModuleFile(appFileName, ""); - return getModuleContent(bootstrapFile.getPath()); + // Bootstrap logic flows like: + // 1. Check for package.json -> `main` field + // 2. Check for index.js + // 3. Check for bootstrap.js + + File bootstrapFile = findModuleFile("./", ""); + if(!bootstrapFile.exists()) + { + bootstrapFile = findModuleFile("./bootstrap", ""); + } + + if(!bootstrapFile.exists()) + { + Platform.APP_FAIL("Application entry point file not found. Please specify either package.json with main field, index.js or bootstrap.js!"); + } + + String[] bootstrapInfo = new String[2]; + bootstrapInfo[0] = bootstrapFile.getName(); + bootstrapInfo[1] = getModuleContent(bootstrapFile.getPath()); + + return bootstrapInfo; } public static String getModuleContent(String modulePath)