import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import copy from "rollup-plugin-copy";
import sass from "rollup-plugin-sass";

// `npm run build` -> `production` is true
// `npm run dev` -> `production` is false
const production = !process.env.ROLLUP_WATCH;

export default [
    // Basic test
    {
        input: 'test/basic/index.jsx',
        output: {
            file: 'public/basic/index.js',
            format: 'iife', // immediately-invoked function expression — suitable for <script> tags
            sourcemap: true
        },
        plugins: [
            sass(),
            babel(), // babel
            resolve({
                extensions: [ '.mjs', '.js', '.jsx', '.json' ],
            }), // node_modules
            commonjs(), // CJS-modules
            production && terser(), // minify, but only in production
            copy({
                targets: [
                    { src: 'test/basic/index.html', dest: 'public/basic' }
                ],
                copyOnce: true
            })
        ]
    },
    // SVG test
    {
        input: 'test/svg/index.jsx',
        output: {
            file: 'public/svg/index.js',
            format: 'iife', // immediately-invoked function expression — suitable for <script> tags
            sourcemap: true
        },
        plugins: [
            sass(),
            babel(), // babel
            resolve({
                extensions: [ '.mjs', '.js', '.jsx', '.json' ],
            }), // node_modules
            commonjs(), // CJS-modules
            production && terser(), // minify, but only in production
            copy({
                targets: [
                    { src: 'test/svg/index.html', dest: 'public/svg' }
                ],
                copyOnce: true
            })
        ]
    },
    // Todos MVC
    {
        input: 'test/todos-mvc/index.jsx',
        output: {
            file: 'public/todos-mvc/index.js',
            format: 'iife', // immediately-invoked function expression — suitable for <script> tags
            sourcemap: true
        },
        plugins: [
            sass(),
            babel(), // babel
            resolve({
                extensions: [ '.mjs', '.js', '.jsx', '.json' ],
            }), // node_modules
            commonjs(), // CJS-modules
            production && terser(), // minify, but only in production
            copy({
                targets: [
                    { src: 'test/todos-mvc/index.html', dest: 'public/todos-mvc' }
                ],
                copyOnce: true
            })
        ]
    },
    // Tests index-page
    {
        input: 'test/index.jsx',
        output: {
            file: 'public/index.js',
            format: 'iife', // immediately-invoked function expression — suitable for <script> tags
            sourcemap: true
        },
        plugins: [
            sass(),
            babel(), // babel
            resolve(), // node_modules
            commonjs(), // CJS-modules
            production && terser(), // minify, but only in production
            copy({
                targets: [
                    { src: 'test/index.html', dest: 'public' }
                ],
                copyOnce: true
            })
        ]
    }
];