Asad Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 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 | |
Asad Memon | c70a3db | 2022-06-30 18:34:22 +0000 | [diff] [blame] | 15 | import commonjs from '@rollup/plugin-commonjs'; |
Asad Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 16 | import resolve from '@rollup/plugin-node-resolve'; |
| 17 | import pluginTypescript from '@rollup/plugin-typescript'; |
Asad Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 18 | import path from 'path'; |
| 19 | import dts from 'rollup-plugin-dts'; |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 20 | import nodePolyfills from 'rollup-plugin-node-polyfills'; |
Asad Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 21 | import sourceMaps from 'rollup-plugin-sourcemaps'; |
| 22 | |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 23 | import tsConfig from './tsconfig.json'; |
Asad Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 24 | |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 25 | export 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 Memon | 098e07d | 2022-07-19 22:53:53 +0000 | [diff] [blame] | 31 | 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 Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 50 | format: 'esm', |
Asad Memon | 098e07d | 2022-07-19 22:53:53 +0000 | [diff] [blame] | 51 | banner: '/* eslint-disable */' |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 52 | }], |
| 53 | plugins: [ |
| 54 | pluginTypescript( |
| 55 | {tsconfig: './tsconfig.json', exclude: ['**/*_test.ts']}), |
| 56 | resolve(), |
| 57 | commonjs(), |
Asad Memon | c70a3db | 2022-06-30 18:34:22 +0000 | [diff] [blame] | 58 | |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 59 | // 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 Memon | c70a3db | 2022-06-30 18:34:22 +0000 | [diff] [blame] | 76 | |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 77 | // 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 Memon | b030b95 | 2022-06-15 11:41:02 -0700 | [diff] [blame] | 111 | |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 112 | // Resolve source maps to the original source |
| 113 | sourceMaps() |
| 114 | ] |
Asad Memon | 84632a3 | 2022-08-31 17:43:07 +0000 | [diff] [blame] | 115 | } |
Asad Memon | 9d12e55 | 2022-07-19 22:09:43 +0000 | [diff] [blame] | 116 | ]; |