Home Reference Source

cables_dev/cables_electron/src/export/export_patch_standalone.js

  1. import sanitizeFileName from "sanitize-filename";
  2. import fs from "fs";
  3. import path from "path";
  4. import cables from "../cables.js";
  5. import libsUtil from "../utils/libs_util.js";
  6. import StandaloneZipExport from "./export_zip_standalone.js";
  7.  
  8. export default class StandaloneExport extends StandaloneZipExport
  9. {
  10. constructor(provider)
  11. {
  12. super(provider, {});
  13.  
  14. this.options.combineJS = false;
  15. this.options.addOpCode = true;
  16. this.options.removeIndexHtml = true;
  17. this.options.rewriteAssetPorts = true;
  18. this.options.flattenAssetNames = false;
  19. this.options.handleAssets = "auto";
  20. this.options.assetsInSubdirs = true;
  21.  
  22. this.finalAssetPath = "assets/";
  23. this.finalJsPath = "/";
  24. }
  25.  
  26. static getName()
  27. {
  28. return "patch";
  29. }
  30.  
  31. _replaceInString(replacements, theString)
  32. {
  33. return theString;
  34. }
  35.  
  36. _addProjectJsCode(proj, opsCode, libs, coreLibs, replacedOpIds, jsCode, options)
  37. {
  38. const libScripts = [];
  39. for (let l = 0; l < libs.length; l++)
  40. {
  41. const lib = libs[l];
  42.  
  43. if (libsUtil.isAssetLib(lib))
  44. {
  45. let libPath = path.join(cables.getLibsPath(), "/", lib);
  46. let libSrc = path.join(this.finalJsPath, lib);
  47. libPath = path.join(cables.getPublicPath(), lib);
  48. libScripts.push({ "name": lib, "file": libPath, "src": libSrc });
  49. }
  50. }
  51.  
  52. for (let f = 0; f < libScripts.length; f++)
  53. {
  54. this.append(fs.readFileSync(libScripts[f].file, "utf8"), { "name": libScripts[f].src });
  55. }
  56. }
  57.  
  58. _addProjectHtmlCode(proj, options, libs, coreLibs, template = "/patchview/patchview_export.html")
  59. {
  60. const projectName = sanitizeFileName(proj.name).replace(/ /g, "_");
  61. const projectNameVer = projectName + proj.exports;
  62. this.append(JSON.stringify(proj), { "name": projectNameVer + ".cables" });
  63. }
  64.  
  65. _getOpExportSubdir(opName)
  66. {
  67. return path.join("ops", this._opsUtil.getOpTargetDir(opName, true));
  68. }
  69.  
  70. static getExportOptions(user, teams, project, exportQuota)
  71. {
  72. return {
  73. "type": this.getName(),
  74. "allowed": true,
  75. "possible": true,
  76. "fields": {}
  77. };
  78. }
  79. }