main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ---- 扩展注入热更新脚本开始 ----
  2. jsb.fileUtils.addSearchPath(jsb.fileUtils.getWritablePath() + "oops_framework_remote", true);
  3. var fileList = [];
  4. var storagePath = "oops_framework_remote";
  5. var tempPath = storagePath + "_temp/";
  6. var baseOffset = tempPath.length;
  7. if (jsb.fileUtils.isDirectoryExist(tempPath) && !jsb.fileUtils.isFileExist(tempPath + 'project.manifest.temp')) {
  8. jsb.fileUtils.listFilesRecursively(tempPath, fileList);
  9. fileList.forEach(srcPath => {
  10. var relativePath = srcPath.substr(baseOffset);
  11. var dstPath = storagePath + relativePath;
  12. if (srcPath[srcPath.length - 1] === "/") {
  13. jsb.fileUtils.createDirectory(dstPath)
  14. }
  15. else {
  16. if (jsb.fileUtils.isFileExist(dstPath)) {
  17. jsb.fileUtils.removeFile(dstPath)
  18. }
  19. jsb.fileUtils.renameFile(srcPath, dstPath);
  20. }
  21. })
  22. jsb.fileUtils.removeDirectory(tempPath);
  23. }
  24. // ---- 扩展注入热更新脚本结束 ----
  25. // SystemJS support.
  26. window.self = window;
  27. require("src/system.bundle.js");
  28. const importMapJson = jsb.fileUtils.getStringFromFile("src/import-map.json");
  29. const importMap = JSON.parse(importMapJson);
  30. System.warmup({
  31. importMap,
  32. importMapUrl: 'src/import-map.json',
  33. defaultHandler: (urlNoSchema) => {
  34. require(urlNoSchema.startsWith('/') ? urlNoSchema.substr(1) : urlNoSchema);
  35. },
  36. });
  37. System.import('./application.js')
  38. .then(({ Application }) => {
  39. return new Application();
  40. }).then((application) => {
  41. return System.import('cc').then((cc) => {
  42. require('jsb-adapter/engine-adapter.js');
  43. return application.init(cc);
  44. }).then(() => {
  45. return application.start();
  46. });
  47. }).catch((err) => {
  48. console.error(err.toString() + ', stack: ' + err.stack);
  49. });