2019-09-18 14:05:16 +00:00
|
|
|
import { join, sep } from 'path';
|
2019-09-17 12:45:15 +00:00
|
|
|
import commonjs from 'rollup-plugin-commonjs';
|
2019-11-09 22:50:30 +00:00
|
|
|
import { eslint } from 'rollup-plugin-eslint';
|
2019-09-17 12:45:15 +00:00
|
|
|
import json from 'rollup-plugin-json';
|
|
|
|
import multiEntry from 'rollup-plugin-multi-entry';
|
|
|
|
import resolve from 'rollup-plugin-node-resolve';
|
2019-11-09 22:50:30 +00:00
|
|
|
import replace from 'rollup-plugin-replace';
|
2019-09-17 12:45:15 +00:00
|
|
|
import typescript from 'rollup-plugin-typescript2';
|
2019-09-28 09:25:07 +00:00
|
|
|
import yaml from 'rollup-plugin-yaml';
|
2019-09-17 12:45:15 +00:00
|
|
|
|
2020-06-29 23:23:16 +00:00
|
|
|
const flag_debug = process.env['DEBUG'] === 'TRUE';
|
|
|
|
|
2019-09-17 12:45:15 +00:00
|
|
|
const metadata = require('../package.json');
|
2019-09-29 21:06:03 +00:00
|
|
|
|
|
|
|
const external = require('./rollup-external.json').names;
|
2019-09-18 12:32:45 +00:00
|
|
|
const namedExports = require('./rollup-named.json');
|
2019-09-17 12:45:15 +00:00
|
|
|
|
2019-09-18 13:35:45 +00:00
|
|
|
const rootPath = process.env['ROOT_PATH'];
|
|
|
|
const targetPath = process.env['TARGET_PATH'];
|
|
|
|
|
2019-09-17 12:45:15 +00:00
|
|
|
const bundle = {
|
2019-09-29 21:06:03 +00:00
|
|
|
external,
|
|
|
|
input: {
|
|
|
|
include: [
|
|
|
|
join(rootPath, 'src', 'index.ts'),
|
|
|
|
join(rootPath, 'test', 'harness.ts'),
|
|
|
|
join(rootPath, 'test', '**', 'Test*.ts'),
|
|
|
|
],
|
|
|
|
},
|
2019-09-17 12:45:15 +00:00
|
|
|
manualChunks(id) {
|
2019-09-18 14:05:16 +00:00
|
|
|
if (id.includes(`${sep}test${sep}`)) {
|
2019-09-29 21:06:03 +00:00
|
|
|
return 'test';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id.match(/commonjs-external/i) || id.match(/commonjsHelpers/)) {
|
|
|
|
return 'vendor';
|
2019-09-17 12:45:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 23:23:16 +00:00
|
|
|
if (id.match(/node-resolve:/)) {
|
|
|
|
return 'vendor';
|
|
|
|
}
|
|
|
|
|
2020-06-30 13:16:22 +00:00
|
|
|
if (id.includes(`chai`) || id.includes(`sinon`) || id.includes('source-map')) {
|
2020-06-29 23:23:16 +00:00
|
|
|
return 'test';
|
2020-06-30 13:16:22 +00:00
|
|
|
}
|
2020-06-29 23:23:16 +00:00
|
|
|
|
2019-09-18 14:05:16 +00:00
|
|
|
if (id.includes(`${sep}node_modules${sep}`)) {
|
2019-09-17 12:45:15 +00:00
|
|
|
return 'vendor';
|
|
|
|
}
|
|
|
|
|
2019-09-18 14:05:16 +00:00
|
|
|
if (id.includes(`${sep}src${sep}index`)) {
|
2019-09-17 12:45:15 +00:00
|
|
|
return 'index';
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:23:16 +00:00
|
|
|
if (id.includes(`${sep}src${sep}`) || id.includes(`${sep}rules${sep}`)) {
|
2019-09-17 12:45:15 +00:00
|
|
|
return 'main';
|
|
|
|
}
|
2019-11-11 00:20:42 +00:00
|
|
|
|
2020-06-30 13:16:22 +00:00
|
|
|
if (id.includes(process.env['HOME'])) {
|
|
|
|
return 'linked';
|
2020-06-29 23:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id.length === 30 && id.match(/^[a-f0-9]+$/)) {
|
|
|
|
return 'vendor';
|
2019-11-11 00:20:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-30 13:16:22 +00:00
|
|
|
if (flag_debug) {
|
|
|
|
console.log('file does not belong to any chunk:', id);
|
|
|
|
}
|
|
|
|
|
2019-11-11 00:20:42 +00:00
|
|
|
return 'nochunk';
|
2019-09-17 12:45:15 +00:00
|
|
|
},
|
|
|
|
output: {
|
2019-09-18 12:32:45 +00:00
|
|
|
dir: targetPath,
|
2019-09-17 12:45:15 +00:00
|
|
|
chunkFileNames: '[name].js',
|
|
|
|
entryFileNames: 'entry-[name].js',
|
2020-06-29 23:45:29 +00:00
|
|
|
exports: 'named',
|
2020-06-29 23:23:16 +00:00
|
|
|
format: 'module',
|
2020-06-29 23:45:29 +00:00
|
|
|
minifyInternalExports: false,
|
2019-09-17 12:45:15 +00:00
|
|
|
sourcemap: true,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
multiEntry(),
|
|
|
|
json(),
|
2019-09-28 09:25:07 +00:00
|
|
|
yaml(),
|
2019-09-17 12:45:15 +00:00
|
|
|
replace({
|
|
|
|
delimiters: ['{{ ', ' }}'],
|
|
|
|
values: {
|
|
|
|
BUILD_JOB: process.env['CI_JOB_ID'],
|
|
|
|
BUILD_RUNNER: process.env['CI_RUNNER_DESCRIPTION'],
|
|
|
|
GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'],
|
|
|
|
GIT_COMMIT: process.env['CI_COMMIT_SHA'],
|
|
|
|
NODE_VERSION: process.env['NODE_VERSION'],
|
2019-09-17 13:57:45 +00:00
|
|
|
PACKAGE_NAME: metadata.name,
|
|
|
|
PACKAGE_VERSION: metadata.version,
|
2019-09-17 12:45:15 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
resolve({
|
|
|
|
preferBuiltins: true,
|
|
|
|
}),
|
|
|
|
commonjs({
|
|
|
|
namedExports,
|
|
|
|
}),
|
2019-11-09 22:50:30 +00:00
|
|
|
eslint({
|
2019-09-28 09:25:07 +00:00
|
|
|
exclude: [
|
2019-09-29 21:06:03 +00:00
|
|
|
join('node_modules', '**'),
|
|
|
|
join('src', 'resource'),
|
|
|
|
join('src', '**', '*.json'),
|
|
|
|
join('src', '**', '*.yml'),
|
|
|
|
],
|
|
|
|
include: [
|
2020-06-29 23:23:16 +00:00
|
|
|
join('src', '**', '*.ts'),
|
|
|
|
join('test', '**', '*.ts'),
|
2019-09-28 09:25:07 +00:00
|
|
|
],
|
2019-09-17 12:45:15 +00:00
|
|
|
throwOnError: true,
|
2021-07-10 22:32:47 +00:00
|
|
|
useEslintrc: true,
|
2019-09-17 12:45:15 +00:00
|
|
|
}),
|
|
|
|
typescript({
|
2019-09-29 21:06:03 +00:00
|
|
|
cacheRoot: join(targetPath, 'cache', 'rts2'),
|
2019-09-17 12:45:15 +00:00
|
|
|
rollupCommonJSResolveHack: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default [
|
|
|
|
bundle,
|
|
|
|
];
|