/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
/* eslint no-console: "off" */
const path = require('path');
const rollup = require('rollup');
const buble = require('rollup-plugin-buble');
const replace = require('rollup-plugin-replace');
const commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve');
const vue = require('rollup-plugin-vue').default;
const getComponents = require('./get-components.js');

let cache;

function build(cb) {
  const env = process.env.NODE_ENV || 'development';
  const target = process.env.TARGET || 'universal';
  const f7VuePath = env === 'development'
    ? '../src/framework7-vue'
    : '../dist/framework7-vue.esm.js';
  const components = getComponents();

  const IMPORT_PLUGIN = 'import VuePlugin from \'./vue-plugin.js\';';
  const IMPORT_COMPONENTS = components.map(c => `import ${c.name} from './components/${c.file}';`).join('\n');
  const EXPORT = `
export {
  ${components.map(c => `${c.name},`).join('\n  ')}
};
export default VuePlugin;

  `.trim();

  rollup.rollup({
    input: './kitchen-sink/src/app.js',
    cache,
    plugins: [
      replace({
        'process.env.NODE_ENV': JSON.stringify(env), // or 'production'
        'process.env.TARGET': JSON.stringify(target),
        'framework7-vue': () => path.resolve(__dirname, f7VuePath).replace(/\\/g, '/'),
        IMPORT_PLUGIN,
        IMPORT_COMPONENTS,
        EXPORT,
        IMPORT_COMPONENTS_BUNDLE: '',
        REGISTER_COMPONENTS_BUNDLE: '',
      }),
      resolve({ jsnext: true }),
      commonjs(),
      vue(),
      buble(),
    ],
  }).then((bundle) => {
    cache = bundle;
    return bundle.write({
      format: 'umd',
      name: 'app',
      strict: true,
      sourcemap: false,
      cache,
      file: './kitchen-sink/js/app.js',
    });
  }).then(() => {
    if (cb) cb();
  }).catch((err) => {
    if (cb) cb();
    console.log(err.toString());
  });
}

module.exports = build;

@@ -1169,24 +1169,54 @@
   replace(%7B%0A
+        delimiters: %5B'', ''%5D,%0A
         'pro
@@ -1337,16 +1337,17 @@
         
+%22
 'framewo
@@ -1358,16 +1358,17 @@
 vue'
+%22
 : () =%3E 
 path
@@ -1363,16 +1363,20 @@
 : () =%3E 
+%60'$%7B
 path.res
@@ -1421,16 +1421,19 @@
 /g, '/')
+%7D'%60
 ,%0A      

Fix import