/* eslint-env node */ // This rollup script is run by the command: // 'npm run build' // For developers, it's advised to run the command in watch mode: // 'npm run build -- -w" import {join, basename} from 'path'; import {lstatSync, readdirSync} from 'fs'; import rimraf from 'rimraf'; import babel from '@rollup/plugin-babel'; import copy from 'rollup-plugin-copy'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import nodePolyfills from 'rollup-plugin-node-polyfills'; import url from '@rollup/plugin-url'; // for XML/SVG files import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'; import {terser} from 'rollup-plugin-terser'; // utilities functions const isDirectory = (source) => { return lstatSync(source).isDirectory(); }; const getDirectories = (source) => { return readdirSync(source).map((nme) => join(source, nme)).filter((i) => isDirectory(i)); }; // capture the list of files to build for extensions and ext-locales const extensionFiles = readdirSync('src/editor/extensions'); const extensionLocaleDirs = getDirectories('src/editor/extensions/ext-locale'); const extensionLocaleFiles = []; extensionLocaleDirs.forEach((dir) => { readdirSync(dir).forEach((file) => { extensionLocaleFiles.push([dir, file]); }); }); // remove existing distribution // eslint-disable-next-line no-console rimraf('./dist', () => console.info('recreating dist')); // config for svgedit core module const config = [{ input: 'src/editor/index.js', output: [ { format: 'es', inlineDynamicImports: true, sourcemap: true, dir: 'dist/editor' }, { format: 'system', dir: 'dist/editor/system', inlineDynamicImports: true } ], plugins: [ copy({ targets: [ { src: 'src/editor/index.html', dest: 'dist/editor' }, { src: 'src/editor/index.html', dest: 'dist/editor/system', rename: 'index.html', transform: (contents) => contents.toString() .replace('