CommandLineBuild.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using XGame.Editor.Compiler;
  2. using System.IO;
  3. using XGame.Framework.Json;
  4. namespace XGame.Editor.Build
  5. {
  6. /// <summary>
  7. /// 命令行打包
  8. /// </summary>
  9. public class CommandLineBuild
  10. {
  11. public static void BuildApp()
  12. {
  13. var configPath = BuildUtils.GetCommandLineArgs();
  14. //var configPath = PathDefine.ExtAssetsPath + "/Editor/BuildConfig.json";
  15. if (string.IsNullOrEmpty(configPath) || !File.Exists(configPath))
  16. {
  17. BuildLog.Error($"Can't Find BuildConfig.json. Path:{configPath}");
  18. UnityEditor.EditorApplication.Exit((int)BuildErrorCode.ConfigFileMissing);
  19. return;
  20. }
  21. var configStr = File.ReadAllText(configPath);
  22. var config = XJson.ToObject<BuildConfig>(configStr);
  23. BuildApp(config);
  24. }
  25. public static void BuildApp(BuildConfig config)
  26. {
  27. BuildLog.Log($"CommandLineBuild BuildApp Start. Target:{config.target} publish:{config.publishType} isSetScriptDefine:{config.isSetScriptDefine}" +
  28. $" ignoreGenIlrt:{config.project.isIgnoreGenIlrt}");
  29. var builder = new ContextBuilder(config, true);
  30. if (builder.Build())
  31. {
  32. var context = builder.GetProduct();
  33. CompileScriptsHandle.Clear();
  34. var cmd = CmdFactory.Create(context);
  35. cmd.Start();
  36. }
  37. }
  38. }
  39. }