old_contents: import { app, Menu } from 'electron';
  
  export default win => {
    const viewMenu = () => ({
      label: 'View',
      submenu: [
        { role: 'togglefullscreen' },
        ...(process.env.NODE_ENV === 'development' ? [
          { role: 'reload' },
          { role: 'toggledevtools' },
        ] : []),
      ],
    });
  
    const goMenu = () => ({
      label: 'Go',
      submenu: [
        {
          label: 'Back',
          accelerator: 'Alt+Left',
          click: () => win.webContents.goBack(),
        },
        {
          label: 'Forward',
          accelerator: 'Alt+Right',
          click: () => win.webContents.goForward(),
        },
      ],
    });
  
    const template = [
      { role: 'editMenu' },
      viewMenu(),
      ...(process.env.NODE_ENV === 'development' ? [goMenu()] : []),
      { role: 'windowMenu' },
    ];
  
    if (process.platform === 'darwin') {
      template.unshift({
        label: app.getName(),
        submenu: [
          { role: 'about' },
          { type: 'separator' },
          { role: 'hide' },
          { role: 'hideothers' },
          { role: 'unhide' },
          { type: 'separator' },
          { role: 'quit' },
        ],
      });
    }
  
    const menu = Menu.buildFromTemplate(template);
  
    return menu;
  };
  
new_contents: import { app, Menu, MenuItem } from 'electron';
  
  function getDefaultSubmenu(role) {
    return new MenuItem({ role }).submenu.items
      .map(menuItem => ({ role: menuItem.role, type: menuItem.type }));
  }
  
  export default win => {
    const template = [];
  
    if (process.platform === 'darwin') {
      const appMenu = {
        label: app.getName(),
        submenu: getDefaultSubmenu('appMenu'),
      };
      template.push(appMenu);
    }
  
    const editMenu = { role: 'editMenu' };
    template.push(editMenu);
  
    const viewMenu = {
      label: 'View',
      submenu: [
        { role: 'togglefullscreen' },
        ...(process.env.NODE_ENV === 'development' ? [
          { role: 'reload' },
          { role: 'toggledevtools' },
        ] : []),
      ],
    };
    template.push(viewMenu);
  
    if (process.env.NODE_ENV === 'development') {
      const goMenu = {
        label: 'Go',
        submenu: [
          {
            label: 'Back',
            accelerator: 'Alt+Left',
            click: () => win.webContents.goBack(),
          },
          {
            label: 'Forward',
            accelerator: 'Alt+Right',
            click: () => win.webContents.goForward(),
          },
        ],
      };
      template.push(goMenu);
    }
  
    const windowMenu = { role: 'windowMenu' };
    template.push(windowMenu);
  
    const menu = Menu.buildFromTemplate(template);
  
    return menu;
  };
  
subject: Refactor menu template