Skip to content

Commit 580f982

Browse files
committed
Update application bootstrap logic. Resolves NativeScript#53.
1 parent 6339af2 commit 580f982

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/src/com/tns/NativeScriptApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public void onCreate() {
733733
}
734734

735735
Platform.init(this);
736-
Platform.run(Platform.DefaultApplicationModuleName);
736+
Platform.run();
737737

738738
onCreateInternal();
739739
}

src/src/com/tns/Platform.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public class Platform
7878

7979
private static ArrayList<Constructor<?>> ctorCache = new ArrayList<Constructor<?>>();
8080

81-
public final static String DefaultApplicationModuleName = "./bootstrap";
82-
8381
private static JsDebugger jsDebugger;
8482

8583
public static boolean IsLogEnabled = BuildConfig.DEBUG;
@@ -187,10 +185,10 @@ static void setExtractPolicy(ExtractPolicy policy)
187185
extractPolicy = policy;
188186
}
189187

190-
public static void run(String appFileName)
188+
public static void run()
191189
{
192-
String appContent = Require.getAppContent(appFileName);
193-
runNativeScript(appFileName, appContent);
190+
String[] bootstrapInfo = Require.bootstrapApp();
191+
runNativeScript(bootstrapInfo[0], bootstrapInfo[1]);
194192
}
195193

196194
private static int cacheConstructor(String name, String className, Object[] args, String[] methodOverrides) throws ClassNotFoundException, IOException

src/src/com/tns/Require.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,29 @@ public static String getApplicationFilesPath()
5555
return ApplicationFilesPath;
5656
}
5757

58-
public static String getAppContent(String appFileName)
58+
public static String[] bootstrapApp()
5959
{
60-
File bootstrapFile = findModuleFile(appFileName, "");
61-
return getModuleContent(bootstrapFile.getPath());
60+
// Bootstrap logic flows like:
61+
// 1. Check for package.json -> `main` field
62+
// 2. Check for index.js
63+
// 3. Check for bootstrap.js
64+
65+
File bootstrapFile = findModuleFile("./", "");
66+
if(!bootstrapFile.exists())
67+
{
68+
bootstrapFile = findModuleFile("./bootstrap", "");
69+
}
70+
71+
if(!bootstrapFile.exists())
72+
{
73+
Platform.APP_FAIL("Application entry point file not found. Please specify either package.json with main field, index.js or bootstrap.js!");
74+
}
75+
76+
String[] bootstrapInfo = new String[2];
77+
bootstrapInfo[0] = bootstrapFile.getName();
78+
bootstrapInfo[1] = getModuleContent(bootstrapFile.getPath());
79+
80+
return bootstrapInfo;
6281
}
6382

6483
public static String getModuleContent(String modulePath)

0 commit comments

Comments
 (0)