text: /**
   * Copyright IBM Corp. 2018, 2018
   *
   * This source code is licensed under the Apache-2.0 license found in the
   * LICENSE file in the root directory of this source tree.
   */
  
  'use strict';
  
  const meta = require('@carbon/icons/build-info.json');
  const { reporter } = require('@carbon/cli-reporter');
  const { rollup } = require('rollup');
  const babel = require('rollup-plugin-babel');
  const virtual = require('./plugins/virtual');
  const { createIconComponent } = require('./createIconComponent');
  const isWin = process.platform === 'win32';
  
  const BUNDLE_FORMATS = [
    {
      format: 'esm',
      dir: 'es',
    },
    {
      format: 'cjs',
      dir: 'lib',
    },
  ];
  
  const external = ['@carbon/icon-helpers'];
  const babelConfig = {
    babelrc: false,
    exclude: /node_modules/,
    presets: [
      [
        '@babel/preset-env',
        {
          targets: {
            browsers: ['extends browserslist-config-carbon'],
          },
        },
      ],
    ],
  };
  
  /**
   * Take the processed `meta.json` file from `@carbon/icons` and generate an
   * entrypoint for `@carbon/icons-vue`. This entrypoint is generated by
   * building icon components built on top of the `<Icon>` primitive in `src`.
   */
  async function build() {
    reporter.info('Creating components');
    const modules = meta.map(icon => {
      const { source } = createIconComponent(icon.moduleName, icon.descriptor);
      return {
        moduleName: icon.moduleName,
        filepath: icon.outputOptions.file
          .replace(isWin ? /^es\\/g : /^es\//g, '')
          .slice(0, -3),
        source,
      };
    });
  
    const entrypoint = `export const CarbonIconsVue = {
    install(Vue, options) {
      const { components } = options;
      Object.keys(components).forEach(key => {
        Vue.component(key, components[key]);
      });
    },
  }`;
  
    reporter.info('Bundling may take a while...');
    const bundle = await rollup({
      input: {
        index: '__entrypoint__.js',
        ...modules.reduce(
          (acc, { filepath, moduleName }) => ({
            ...acc,
            [filepath]: `${moduleName}.js`,
          }),
          {}
        ),
      },
      external,
      plugins: [
        virtual({
          '__entrypoint__.js': entrypoint,
          ...modules.reduce(
            (acc, { moduleName, source }) => ({
              ...acc,
              [`${moduleName}.js`]: source,
            }),
            {}
          ),
        }),
        babel(babelConfig),
      ],
    });
  
    reporter.info('Writing out to files');
    await Promise.all(
      BUNDLE_FORMATS.map(({ format, dir }) => {
        return bundle.write({
          format,
          dir,
        });
      })
    );
  }
  
  build()
    .then(() => {
      reporter.success('Done!');
    })
    .catch(error => {
      // eslint-disable-next-line no-console
      console.error(error);
    });
  