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";
|
2025-01-09 09:43:15 -05:00
|
|
|
import typescript from "rollup-plugin-typescript2";
|
2020-10-16 16:11:11 +02:00
|
|
|
import { terser } from "rollup-plugin-terser";
|
2022-06-09 14:08:11 +02:00
|
|
|
import dts from "rollup-plugin-dts";
|
2020-10-16 16:11:11 +02:00
|
|
|
|
2022-05-26 12:11:10 +02:00
|
|
|
let input, output;
|
|
|
|
|
|
2022-07-12 13:07:03 +02:00
|
|
|
const IIFE_FILENAME = "dist/owl.iife.js";
|
|
|
|
|
const CJS_FILENAME = "dist/owl.cjs.js";
|
|
|
|
|
const ES_FILENAME = "dist/owl.es.js";
|
|
|
|
|
|
|
|
|
|
if (pkg.module !== ES_FILENAME || pkg.main !== CJS_FILENAME) {
|
|
|
|
|
throw new Error("package.json has been modified. Build script should be updated accordingly");
|
2025-01-09 09:43:15 -05:00
|
|
|
}
|
2022-07-12 13:07:03 +02:00
|
|
|
|
2020-10-22 13:58:10 +02:00
|
|
|
const outro = `
|
2020-10-16 16:11:11 +02:00
|
|
|
__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
|
|
|
|
2022-05-26 12:11:10 +02:00
|
|
|
switch (process.argv[4]) {
|
2025-01-09 09:43:15 -05:00
|
|
|
case "compiler":
|
|
|
|
|
(input = "src/compiler/index.ts"),
|
|
|
|
|
(output = [getConfigForFormat("cjs", "dist/compiler.js", "")]);
|
2022-05-26 12:11:10 +02:00
|
|
|
break;
|
|
|
|
|
case "runtime":
|
2022-05-26 23:45:40 +02:00
|
|
|
input = "src/runtime/index.ts";
|
2022-05-26 12:11:10 +02:00
|
|
|
output = [
|
2025-01-09 09:43:15 -05:00
|
|
|
getConfigForFormat("esm", addSuffix(ES_FILENAME, "runtime"), outro),
|
|
|
|
|
getConfigForFormat("cjs", addSuffix(CJS_FILENAME, "runtime"), outro),
|
|
|
|
|
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro),
|
|
|
|
|
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro, true),
|
|
|
|
|
];
|
2022-05-26 12:11:10 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-09 09:43:15 -05:00
|
|
|
(input = "src/index.ts"),
|
|
|
|
|
(output = [
|
|
|
|
|
getConfigForFormat("esm", ES_FILENAME, outro),
|
|
|
|
|
getConfigForFormat("cjs", CJS_FILENAME, outro),
|
|
|
|
|
getConfigForFormat("iife", IIFE_FILENAME, outro),
|
|
|
|
|
getConfigForFormat("iife", IIFE_FILENAME, outro, true),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2022-05-26 12:11: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
|
|
|
*/
|
2022-05-26 12:11:10 +02:00
|
|
|
function addSuffix(pkgFileName, suffix) {
|
2025-01-09 09:43:15 -05:00
|
|
|
const parts = pkgFileName.split(".");
|
2022-05-26 12:11:10 +02:00
|
|
|
parts.splice(parts.length - 1, 0, suffix);
|
2025-01-09 09:43:15 -05:00
|
|
|
return parts.join(".");
|
2020-10-16 16:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2022-05-26 12:11:10 +02:00
|
|
|
function getConfigForFormat(format, generatedFileName, outro, minified = false) {
|
2020-10-16 16:11:11 +02:00
|
|
|
return {
|
2022-05-26 12:11:10 +02:00
|
|
|
file: minified ? addSuffix(generatedFileName, "min") : generatedFileName,
|
2020-10-16 16:11:11 +02:00
|
|
|
format: format,
|
2022-05-26 12:11:10 +02:00
|
|
|
name: "owl",
|
|
|
|
|
extend: true,
|
2020-10-16 16:11:11 +02:00
|
|
|
outro: outro,
|
2020-11-26 16:45:25 +01:00
|
|
|
freeze: false,
|
2020-10-22 13:58:10 +02:00
|
|
|
plugins: minified ? [terser()] : [],
|
2025-01-09 09:43:15 -05:00
|
|
|
indent: " ", // indent with 4 spaces
|
2020-10-22 13:58:10 +02:00
|
|
|
};
|
2020-10-16 16:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-09 14:08:11 +02:00
|
|
|
export default [
|
|
|
|
|
{
|
|
|
|
|
input,
|
|
|
|
|
output,
|
|
|
|
|
plugins: [
|
|
|
|
|
typescript({
|
2025-01-09 09:43:15 -05:00
|
|
|
useTsconfigDeclarationDir: true,
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: "src/compiler/standalone/index.ts",
|
|
|
|
|
output: [{ file: "dist/compile_templates.mjs", format: "es" }],
|
|
|
|
|
external: ["fs", "fs/promises", "path", "jsdom"],
|
|
|
|
|
plugins: [
|
|
|
|
|
typescript({
|
|
|
|
|
useTsconfigDeclarationDir: true,
|
2022-06-09 14:08:11 +02:00
|
|
|
}),
|
2025-01-09 09:43:15 -05:00
|
|
|
],
|
2022-06-09 14:08:11 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: "dist/types/index.d.ts",
|
|
|
|
|
output: [{ file: "dist/types/owl.d.ts", format: "es" }],
|
|
|
|
|
plugins: [dts()],
|
|
|
|
|
},
|
|
|
|
|
];
|