idlize

Форк
0
/
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

16
import nodeResolve from "@rollup/plugin-node-resolve";
17
import os from 'os';
18
import replace from '@rollup/plugin-replace';
19
import terser from "@rollup/plugin-terser";
20
import typescript from "@rollup/plugin-typescript";
21
import * as path from "path";
22

23
const platform = os.platform()
24
const isWindows = (platform === 'win32')
25

26
function crossPathRelative(from, to) {
27
    if (isWindows) {
28
        return path.relative(from, to).replace(/\\/g, '\\\\')
29
    } else {
30
        return path.relative(from, to)
31
    }
32
}
33

34
const mode = process.env.mode
35
const arch = process.env.arch
36

37
console.log(`rollup args: mode = ${mode}, arch = ${arch}`)
38
const generatedDir = `generated`
39
const arkoalaArkuiSrcDir = `${generatedDir}/${mode}/koalaui/arkoala-arkui/src`
40
const tsconfigFile = `tsconfig-${mode == 'subset' ? mode : 'generated'}.json`
41
const outDir = path.resolve('lib')
42

43
const ENABLE_SOURCE_MAPS = true;  // Enable for debugging
44

45
/** @type {import("rollup").RollupOptions} */
46
export default {
47
    input: `${arkoalaArkuiSrcDir}/index.ts`,
48
    output: {
49
        file: "./lib/idlizeComponents.js",
50
        format: "commonjs",
51
        sourcemap: ENABLE_SOURCE_MAPS,
52
        sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
53
            // For some reason Rollup adds extra ../ to relativeSourcePath, remove it
54
            let absolute = path.join(sourcemapPath, relativeSourcePath);
55
            let relative = path.relative(path.dirname(sourcemapPath), absolute);
56
            return relative
57
        },
58
        plugins: [
59
            // terser()
60
        ],
61
        banner: [
62
            "#!/usr/bin/env node",
63
            APACHE_LICENSE_HEADER()
64
        ].join("\n"),
65
    },
66
    external: ["commander", "typescript", "webidl2"],
67
    plugins: [
68
        typescript({
69
            outputToFilesystem: false,
70
            module: "ESNext",
71
            sourceMap: ENABLE_SOURCE_MAPS,
72
            declarationMap: false,
73
            declaration: false,
74
            composite: false,
75
            tsconfig: tsconfigFile
76
        }),
77
        nodeResolve({
78
            extensions: [".js", ".mjs", ".cjs", ".ts", ".cts", ".mts"]
79
        }),
80
        replace({
81
            'LOAD_NATIVE': `globalThis.requireNapi("libNativeBridge_ohos_${arch}.so")`,
82
        })
83
    ]
84
}
85

86
function APACHE_LICENSE_HEADER() {
87
    return `
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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.