idlize
/
rollup.config.components.mjs
105 строк · 3.4 Кб
1/*
2* Copyright (c) 2024 Huawei Device Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16import nodeResolve from "@rollup/plugin-node-resolve";17import os from 'os';18import replace from '@rollup/plugin-replace';19import terser from "@rollup/plugin-terser";20import typescript from "@rollup/plugin-typescript";21import * as path from "path";22
23const platform = os.platform()24const isWindows = (platform === 'win32')25
26function crossPathRelative(from, to) {27if (isWindows) {28return path.relative(from, to).replace(/\\/g, '\\\\')29} else {30return path.relative(from, to)31}32}
33
34const mode = process.env.mode35const arch = process.env.arch36
37console.log(`rollup args: mode = ${mode}, arch = ${arch}`)38const generatedDir = `generated`39const arkoalaArkuiSrcDir = `${generatedDir}/${mode}/koalaui/arkoala-arkui/src`40const tsconfigFile = `tsconfig-${mode == 'subset' ? mode : 'generated'}.json`41const outDir = path.resolve('lib')42
43const ENABLE_SOURCE_MAPS = true; // Enable for debugging44
45/** @type {import("rollup").RollupOptions} */
46export default {47input: `${arkoalaArkuiSrcDir}/index.ts`,48output: {49file: "./lib/idlizeComponents.js",50format: "commonjs",51sourcemap: ENABLE_SOURCE_MAPS,52sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {53// For some reason Rollup adds extra ../ to relativeSourcePath, remove it54let absolute = path.join(sourcemapPath, relativeSourcePath);55let relative = path.relative(path.dirname(sourcemapPath), absolute);56return relative57},58plugins: [59// terser()60],61banner: [62"#!/usr/bin/env node",63APACHE_LICENSE_HEADER()64].join("\n"),65},66external: ["commander", "typescript", "webidl2"],67plugins: [68typescript({69outputToFilesystem: false,70module: "ESNext",71sourceMap: ENABLE_SOURCE_MAPS,72declarationMap: false,73declaration: false,74composite: false,75tsconfig: tsconfigFile76}),77nodeResolve({78extensions: [".js", ".mjs", ".cjs", ".ts", ".cts", ".mts"]79}),80replace({81'LOAD_NATIVE': `globalThis.requireNapi("libNativeBridge_ohos_${arch}.so")`,82})83]84}
85
86function APACHE_LICENSE_HEADER() {87return `88/**
89* @license
90* Copyright (c) ${new Date().getUTCFullYear()} Huawei Device Co., Ltd.91* Licensed under the Apache License, Version 2.0 (the "License");
92* you may not use this file except in compliance with the License.
93* You may obtain a copy of the License at
94*
95* http://www.apache.org/licenses/LICENSE-2.0
96*
97* Unless required by applicable law or agreed to in writing, software
98* distributed under the License is distributed on an "AS IS" BASIS,
99* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
100* See the License for the specific language governing permissions and
101* limitations under the License.
102*/
103
104`
105}
106