2020-10-16 16:11:11 +02:00
|
|
|
import pkg from "./package.json";
|
2019-03-21 09:55:04 +01:00
|
|
|
import git from "git-rev-sync";
|
2020-10-16 16:11:11 +02:00
|
|
|
import typescript from 'rollup-plugin-typescript2';
|
|
|
|
|
import { terser } from "rollup-plugin-terser";
|
2019-03-14 09:36:48 +01:00
|
|
|
|
2020-10-22 13:58:10 +02:00
|
|
|
const name = "owl";
|
|
|
|
|
const extend = true;
|
2020-10-16 16:11:11 +02:00
|
|
|
|
|
|
|
|
/**
|
2020-10-22 13:58:10 +02:00
|
|
|
* Meta data to be added on the __info__ object.
|
2020-10-16 16:11:11 +02:00
|
|
|
* Used to let external tools know the current owl version.
|
|
|
|
|
*/
|
2020-10-22 13:58:10 +02:00
|
|
|
const outro = `
|
2020-10-16 16:11:11 +02:00
|
|
|
__info__.version = '${pkg.version}';
|
|
|
|
|
__info__.date = '${new Date().toISOString()}';
|
|
|
|
|
__info__.hash = '${git.short()}';
|
|
|
|
|
__info__.url = 'https://github.com/odoo/owl';
|
2020-10-22 13:58:10 +02:00
|
|
|
`;
|
2020-10-16 16:11:11 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate from a string depicting a path a new path for the minified version.
|
2020-10-22 13:58:10 +02:00
|
|
|
* @param {string} pkgFileName file name
|
2020-10-16 16:11:11 +02:00
|
|
|
*/
|
|
|
|
|
function generateMinifiedNameFromPkgName(pkgFileName) {
|
2020-10-22 13:58:10 +02:00
|
|
|
const parts = pkgFileName.split('.');
|
2020-10-16 16:11:11 +02:00
|
|
|
parts.splice(parts.length - 1, 0, "min");
|
|
|
|
|
return parts.join('.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the rollup config based on the arguments
|
|
|
|
|
* @param {string} format format of the bundle
|
|
|
|
|
* @param {string} generatedFileName generated file name
|
|
|
|
|
* @param {boolean} minified should it be minified
|
|
|
|
|
*/
|
|
|
|
|
function getConfigForFormat(format, generatedFileName, minified = false) {
|
|
|
|
|
return {
|
|
|
|
|
file: minified ? generateMinifiedNameFromPkgName(generatedFileName) : generatedFileName,
|
|
|
|
|
format: format,
|
|
|
|
|
name: name,
|
|
|
|
|
extend: extend,
|
|
|
|
|
outro: outro,
|
2020-10-22 13:58:10 +02:00
|
|
|
plugins: minified ? [terser()] : [],
|
|
|
|
|
indent: ' ', // indent with 4 spaces
|
|
|
|
|
};
|
2020-10-16 16:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
input: "src/index.ts",
|
|
|
|
|
output: [
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read about module formats:
|
|
|
|
|
* https://auth0.com/blog/javascript-module-systems-showdown/
|
|
|
|
|
* https://medium.com/@kelin2025/so-you-wanna-use-es6-modules-714f48b3a953
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
getConfigForFormat('esm', pkg.module),
|
|
|
|
|
getConfigForFormat('esm', pkg.module, true),
|
|
|
|
|
getConfigForFormat('cjs', pkg.main),
|
|
|
|
|
getConfigForFormat('cjs', pkg.main, true),
|
|
|
|
|
getConfigForFormat('iife', pkg.browser),
|
|
|
|
|
getConfigForFormat('iife', pkg.browser, true),
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
typescript({
|
|
|
|
|
useTsconfigDeclarationDir: true
|
|
|
|
|
}),
|
|
|
|
|
]
|
2019-03-14 09:36:48 +01:00
|
|
|
};
|