blob: fbe041be214794fd4a7c73cd9b2f02f4b90e1acb [file] [log] [blame]
Asad Memonb030b952022-06-15 11:41:02 -07001// Copyright 2022 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
Asad Memonc70a3db2022-06-30 18:34:22 +000015import commonjs from '@rollup/plugin-commonjs';
Asad Memonb030b952022-06-15 11:41:02 -070016import resolve from '@rollup/plugin-node-resolve';
17import pluginTypescript from '@rollup/plugin-typescript';
Asad Memonb030b952022-06-15 11:41:02 -070018import path from 'path';
19import dts from 'rollup-plugin-dts';
Asad Memon9d12e552022-07-19 22:09:43 +000020import nodePolyfills from 'rollup-plugin-node-polyfills';
Asad Memonb030b952022-06-15 11:41:02 -070021import sourceMaps from 'rollup-plugin-sourcemaps';
22
Asad Memon9d12e552022-07-19 22:09:43 +000023import tsConfig from './tsconfig.json';
Asad Memonb030b952022-06-15 11:41:02 -070024
Asad Memon9d12e552022-07-19 22:09:43 +000025export default [
26 // Bundle proto collection script
27 {
28 input: path.join('pw_protobuf_compiler', 'ts', 'build.ts'),
29 output: [{
30 file: path.join('dist', 'bin', 'pw_protobuf_compiler.js'),
Asad Memon098e07d2022-07-19 22:53:53 +000031 format: 'cjs',
32 banner: '#!/usr/bin/env node\n\nconst window = null;'
33 }],
34 plugins: [
35 pluginTypescript(
36 {tsconfig: './tsconfig.json', exclude: ['**/*_test.ts']}),
37 resolve(),
38 commonjs(),
39
40 // Resolve source maps to the original source
41 sourceMaps()
42 ]
43 },
44 // bundle proto collection template used by the above script
45 {
46 input: path.join(
47 'pw_protobuf_compiler', 'ts', 'ts_proto_collection.template.ts'),
48 output: [{
49 file: path.join('dist', 'bin', 'ts_proto_collection.template.js'),
Asad Memon9d12e552022-07-19 22:09:43 +000050 format: 'esm',
Asad Memon098e07d2022-07-19 22:53:53 +000051 banner: '/* eslint-disable */'
Asad Memon9d12e552022-07-19 22:09:43 +000052 }],
53 plugins: [
54 pluginTypescript(
55 {tsconfig: './tsconfig.json', exclude: ['**/*_test.ts']}),
56 resolve(),
57 commonjs(),
Asad Memonc70a3db2022-06-30 18:34:22 +000058
Asad Memon9d12e552022-07-19 22:09:43 +000059 // Resolve source maps to the original source
60 sourceMaps()
61 ]
62 },
63 // Bundle proto collection into one UMD file for consumption from browser
64 {
65 input: path.join('dist', 'protos', 'collection.ts'),
66 output: [{
67 file: path.join('dist', 'protos', 'collection.umd.js'),
68 format: 'umd',
69 sourcemap: true,
70 name: 'PigweedProtoCollection',
71 }],
72 plugins: [
73 pluginTypescript({tsconfig: './tsconfig.json'}),
74 commonjs(),
75 resolve(),
Asad Memonc70a3db2022-06-30 18:34:22 +000076
Asad Memon9d12e552022-07-19 22:09:43 +000077 // Resolve source maps to the original source
78 sourceMaps()
79 ]
80 },
81 // Types for proto collection
82 {
83 input: path.join(
84 'dist', 'protos', 'types', 'dist', 'protos', 'collection.d.ts'),
85 output:
86 [{file: path.join('dist', 'protos', 'collection.d.ts'), format: 'es'}],
87 plugins: [dts({compilerOptions: tsConfig.compilerOptions})]
88 },
89 // Bundle Pigweed modules
90 {
91 input: path.join('ts', 'index.ts'),
92 output: [
93 {
94 file: path.join('dist', 'index.umd.js'),
95 format: 'umd',
96 sourcemap: true,
97 name: 'Pigweed',
98 },
99 {
100 file: path.join('dist', 'index.mjs'),
101 format: 'esm',
102 sourcemap: true,
103 }
104 ],
105 plugins: [
106 pluginTypescript(
107 {tsconfig: './tsconfig.json', exclude: ['**/*_test.ts']}),
108 nodePolyfills(),
109 resolve(),
110 commonjs(),
Asad Memonb030b952022-06-15 11:41:02 -0700111
Asad Memon9d12e552022-07-19 22:09:43 +0000112 // Resolve source maps to the original source
113 sourceMaps()
114 ]
Asad Memon84632a32022-08-31 17:43:07 +0000115 }
Asad Memon9d12e552022-07-19 22:09:43 +0000116];