All files / scripts heroku.js

0% Statements 0/24
0% Branches 0/12
0% Functions 0/8
0% Lines 0/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 69 70 71 72 73 74 75 76 77 78 79 80                                                                                                                                                               
// Heroku build/serve orchestration for the static sites this monorepo deploys.
//
// One Heroku app == one "target" (a Storybook instance, the icons catalog, ...).
// The app selects its target with the DEPLOY_TARGET config var; this script owns
// the build command and the served directory for each target, so there is no
// deployment logic scattered across package.json shell interpolation.
//
//   heroku-postbuild -> node ./scripts/heroku.js build   (runs on the dyno)
//   start            -> node ./scripts/heroku.js serve    (serves the output)
//
// DEPLOY_TARGET defaults to "storybook", so existing Storybook apps that set no
// such var keep their current behavior. (Avoid the HEROKU_* prefix here: Heroku
// reserves that namespace for platform-injected vars.)
 
import { execFileSync } from 'node:child_process';
 
/**
 * Each target defines how to build its artifacts and which directory to serve.
 * `staticRoot` is read after the build so it can honor per-app config vars.
 */
const TARGETS = {
  storybook: {
    build() {
      // Existing Storybook contract: COMPONENT_PACKAGE picks the workspace,
      // STORYBOOK_CONFIG_DIR/STORYBOOK_OUTPUT_DIR are read by build-storybook.
      const pkg = process.env.COMPONENT_PACKAGE || '@salesforce-ux/sds-components';
      run('yarn', ['turbo', 'run', 'build-storybook', `--filter=${pkg}`]);
    },
    staticRoot: () => process.env.STORYBOOK_OUTPUT_DIR || './storybook-static',
  },
  site: {
    build() {
      run('yarn', [
        'turbo',
        'run',
        'build',
        '--filter=@salesforce-ux/design-tokens',
        '--filter=@salesforce-ux/design-system-2-site',
      ]);
    },
    staticRoot: () => 'packages/design-system-2-site/out',
  },
  icons: {
    build() {
      // build produces dist/ (sprites + download zip); build:public inlines
      // those into a self-contained public/index.html, so build must run first.
      run('yarn', ['workspace', '@salesforce-ux/icons', 'build']);
      run('yarn', ['workspace', '@salesforce-ux/icons', 'build:public']);
    },
    staticRoot: () => 'packages/icons/public',
  },
};
 
function run(cmd, args) {
  execFileSync(cmd, args, { stdio: 'inherit' });
}
 
function main() {
  const mode = process.argv[2];
  const targetName = process.env.DEPLOY_TARGET || 'storybook';
  const target = TARGETS[targetName];
 
  if (!target) {
    const known = Object.keys(TARGETS).join(', ');
    console.error(`Unknown DEPLOY_TARGET "${targetName}". Known targets: ${known}.`);
    process.exit(1);
  }
 
  if (mode === 'build') {
    target.build();
  } else if (mode === 'serve') {
    run('yarn', ['http-server', target.staticRoot()]);
  } else {
    console.error('Usage: node scripts/heroku.js <build|serve>');
    process.exit(1);
  }
}
 
main();