'Package a Google Doc Add-on for publishing

I have an editor add-on in App script that I have developed. Everything is in a library. It uses a sidebar and help dialog using HTML Service. And it can edit the Doc from events on the sidebar. But two things I can't figure out. I've looked at various pages on Add-on but can't quite figure it out.

First how to add the Add-on menus from the librar. And second, how to handle server calls from the menu or sidebar. I have been testing as a library resource and right now the Doc Code.gs contains 2 function.

The similar questions do not answer this directly.

function onOpen() {
  try {
    var cpMenu = DocumentApp.getUi().createAddonMenu();
    cpMenu.addItem("Side Bar","CalcPad.showSideBar");
    cpMenu.addItem("Calculate","CalcPad.calculate");
    cpMenu.addItem("Help","CalcPad.showHelp");
    cpMenu.addToUi();
  }
  catch(err) {
    Logger.log(err);
  }
};

function runCalcPadRequest(request) {
  try {
    return CalcPad.runCalcPadRequest(request);
  }
  catch(err) {
    DocumentApp.getUi().alert(err);
  }
};

How do I move these to the library and configure the manifest so that they are envoked. On the sidebar there is a help button that when clicked displays the help dialog. But this requires a server call (Doc Code.gs) as shown above. google.script.run.CalcPad.runCalcPadRequest doesn't work.

function helpOnClick() {
  try {
    google.script.run.runCalcPadRequest({ name: "showHelp" });
  }
  catch(err) {
    showMessage("Error in JS_Sidebar.helpOnClick: "+err);
  }
};

Any advise appreciated. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source