• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
15import commonjs from '@rollup/plugin-commonjs';
16import resolve from '@rollup/plugin-node-resolve';
17import pluginTypescript from '@rollup/plugin-typescript';
18import path from 'path';
19import nodePolyfills from 'rollup-plugin-node-polyfills';
20import postcss from 'rollup-plugin-postcss';
21import sourceMaps from 'rollup-plugin-sourcemaps';
22
23export default [
24  // Bundle proto collection script
25  {
26    input: path.join('pw_protobuf_compiler', 'ts', 'build.ts'),
27    output: [
28      {
29        file: path.join('dist', 'bin', 'pw_protobuf_compiler.js'),
30        format: 'cjs',
31        banner: '#!/usr/bin/env node\n\nconst window = null;',
32      },
33    ],
34    plugins: [
35      pluginTypescript({
36        tsconfig: './tsconfig.json',
37        exclude: ['**/*_test.ts'],
38      }),
39      resolve(),
40      commonjs(),
41
42      // Resolve source maps to the original source
43      sourceMaps(),
44    ],
45  },
46  // bundle proto collection template used by the above script
47  {
48    input: path.join(
49      'pw_protobuf_compiler',
50      'ts',
51      'ts_proto_collection.template.ts',
52    ),
53    output: [
54      {
55        file: path.join('dist', 'bin', 'ts_proto_collection.template.js'),
56        format: 'esm',
57        banner: '/* eslint-disable */',
58      },
59    ],
60    plugins: [
61      pluginTypescript({
62        tsconfig: './tsconfig.json',
63        exclude: ['**/*_test.ts'],
64      }),
65      resolve(),
66      commonjs(),
67
68      // Resolve source maps to the original source
69      sourceMaps(),
70    ],
71  },
72  // Bundle proto collection into one UMD file for consumption from browser
73  {
74    input: path.join('dist', 'protos', 'collection.ts'),
75    output: [
76      {
77        file: path.join('dist', 'protos', 'collection.umd.js'),
78        format: 'umd',
79        sourcemap: true,
80        name: 'PigweedProtoCollection',
81      },
82    ],
83    plugins: [
84      pluginTypescript({ tsconfig: './tsconfig.json' }),
85      commonjs(),
86      resolve(),
87
88      // Resolve source maps to the original source
89      sourceMaps(),
90    ],
91  },
92  // Bundle Pigweed log component and modules
93  {
94    input: path.join('ts', 'logging.ts'),
95    output: [
96      {
97        file: path.join('dist', 'logging.umd.js'),
98        format: 'umd',
99        sourcemap: true,
100        name: 'PigweedLogging',
101        inlineDynamicImports: true,
102      },
103      {
104        file: path.join('dist', 'logging.mjs'),
105        format: 'esm',
106        sourcemap: true,
107        inlineDynamicImports: true,
108      },
109    ],
110    plugins: [
111      postcss({ plugins: [] }),
112      pluginTypescript({
113        tsconfig: './tsconfig.json',
114        exclude: ['**/*_test.ts'],
115      }),
116      nodePolyfills(),
117      resolve(),
118      commonjs(),
119
120      // Resolve source maps to the original source
121      sourceMaps(),
122    ],
123  },
124  // Bundle Pigweed modules
125  {
126    input: path.join('ts', 'index.ts'),
127    output: [
128      {
129        file: path.join('dist', 'index.umd.js'),
130        format: 'umd',
131        sourcemap: true,
132        name: 'Pigweed',
133      },
134      {
135        file: path.join('dist', 'index.mjs'),
136        format: 'esm',
137        sourcemap: true,
138      },
139    ],
140    plugins: [
141      pluginTypescript({
142        tsconfig: './tsconfig.json',
143        exclude: ['**/*_test.ts'],
144      }),
145      nodePolyfills(),
146      resolve(),
147      commonjs(),
148
149      // Resolve source maps to the original source
150      sourceMaps(),
151    ],
152  },
153];
154