All files / my/buildContents buildJs.js

100% Statements 25/25
87.5% Branches 14/16
100% Functions 4/4
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68            2x   2x 6x   12x     6x                     6x       8x         6x 6x 6x 6x     6x   1x   6x   1x   6x   1x   6x   1x     6x 6x   20x     6x   6x    
/*
 * Copyright (c) 2021, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
 */
import { pascalCase } from 'change-case';
 
export const buildJs = (contents) => {
  const { properties, targets, componentName } = contents;
 
  const propNames = properties.map((p) => p.name);
 
  // https://developer.salesforce.com/docs/component-library/documentation/en/lwc/use_config_for_app_builder_email_app_pane
  const inboxProps = [
    'dates',
    'emails',
    'location',
    'messageBody',
    'mode',
    'people',
    'source',
    'subject'
  ];
  // merge @api properties for Inbox target.
  const apis = targets.lightning__Inbox.enabled
    ? [
        ...propNames,
        ...inboxProps.filter((ip) => {
          return !propNames.includes(ip);
        })
      ]
    : propNames;
 
  const hasProperties = apis && apis.length > 0;
  const pascal = pascalCase(componentName);
  let js = '';
  js += `import { LightningElement ${
    hasProperties ? ', api' : ''
  } } from "lwc";\n`;
  if (targets.lightningSnapin__ChatMessage.enabled) {
    // https://developer.salesforce.com/docs/component-library/bundle/lightningsnapin-base-chat-message/documentation
    js += `import BaseChatMessage from 'lightningsnapin/baseChatMessage';\n`;
  }
  if (targets.lightningSnapin__Minimized.enabled) {
    // https://developer.salesforce.com/docs/component-library/bundle/lightningsnapin-minimized/documentation
    js += `import { assignHandler, maximize } from 'lightningsnapin/minimized';\n`;
  }
  if (targets.lightningSnapin__PreChat.enabled) {
    // https://developer.salesforce.com/docs/component-library/bundle/lightningsnapin-base-prechat/documentation
    js += `import BasePrechat from 'lightningsnapin/basePrechat';\n`;
  }
  if (targets.lightningSnapin__ChatHeader.enabled) {
    // https://developer.salesforce.com/docs/component-library/bundle/lightningsnapin-base-chat-header/documentation
    js += `import BaseChatHeader from 'lightningsnapin/baseChatHeader';\n`;
  }
 
  js += `export default class ${pascal} extends LightningElement {\n`;
  js += apis
    .map((p) => {
      return p ? `\t@api\n\t${p};\n` : null;
    })
    .join('');
  js += `}`;
 
  return js;
};