|
| 1 | +/* |
| 2 | + * Copyright 2023 Comcast Cable Communications Management, LLC |
| 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 | + * SPDX-License-Identifier: Apache-2.0 |
| 16 | + */ |
| 17 | + |
| 18 | +const fs = require('fs') |
| 19 | +const path = require('path') |
| 20 | + |
| 21 | +// Create lib files directory |
| 22 | +const libDir = path.join(__dirname, '..', 'out', 'lib-files') |
| 23 | +if (!fs.existsSync(libDir)) { |
| 24 | + fs.mkdirSync(libDir, { recursive: true }) |
| 25 | +} |
| 26 | + |
| 27 | +// Get the TypeScript lib directory |
| 28 | +const tsLibPath = path.dirname(require.resolve('typescript/lib/typescript.js')) |
| 29 | + |
| 30 | +// List of essential lib files to copy |
| 31 | +const libFiles = [ |
| 32 | + 'lib.es5.d.ts', |
| 33 | + 'lib.dom.d.ts', |
| 34 | + 'lib.dom.iterable.d.ts', |
| 35 | + 'lib.es2015.d.ts', |
| 36 | + 'lib.es2015.collection.d.ts', |
| 37 | + 'lib.es2015.core.d.ts', |
| 38 | + 'lib.es2015.generator.d.ts', |
| 39 | + 'lib.es2015.iterable.d.ts', |
| 40 | + 'lib.es2015.promise.d.ts', |
| 41 | + 'lib.es2015.proxy.d.ts', |
| 42 | + 'lib.es2015.reflect.d.ts', |
| 43 | + 'lib.es2015.symbol.d.ts', |
| 44 | + 'lib.es2015.symbol.wellknown.d.ts', |
| 45 | + 'lib.es2016.d.ts', |
| 46 | + 'lib.es2016.array.include.d.ts', |
| 47 | + 'lib.es2017.d.ts', |
| 48 | + 'lib.es2017.object.d.ts', |
| 49 | + 'lib.es2017.sharedmemory.d.ts', |
| 50 | + 'lib.es2017.string.d.ts', |
| 51 | + 'lib.es2017.intl.d.ts', |
| 52 | + 'lib.es2017.typedarrays.d.ts', |
| 53 | + 'lib.es2018.d.ts', |
| 54 | + 'lib.es2018.asyncgenerator.d.ts', |
| 55 | + 'lib.es2018.asynciterable.d.ts', |
| 56 | + 'lib.es2018.intl.d.ts', |
| 57 | + 'lib.es2018.promise.d.ts', |
| 58 | + 'lib.es2018.regexp.d.ts', |
| 59 | + 'lib.es2019.d.ts', |
| 60 | + 'lib.es2019.array.d.ts', |
| 61 | + 'lib.es2019.object.d.ts', |
| 62 | + 'lib.es2019.string.d.ts', |
| 63 | + 'lib.es2019.symbol.d.ts', |
| 64 | + 'lib.es2020.d.ts', |
| 65 | + 'lib.es2020.bigint.d.ts', |
| 66 | + 'lib.es2020.promise.d.ts', |
| 67 | + 'lib.es2020.sharedmemory.d.ts', |
| 68 | + 'lib.es2020.string.d.ts', |
| 69 | + 'lib.es2020.symbol.wellknown.d.ts', |
| 70 | + 'lib.es2020.intl.d.ts', |
| 71 | + 'lib.scripthost.d.ts', |
| 72 | + 'lib.webworker.importscripts.d.ts', |
| 73 | +] |
| 74 | + |
| 75 | +// Copy each lib file |
| 76 | +let copiedFiles = 0 |
| 77 | +let errors = 0 |
| 78 | + |
| 79 | +libFiles.forEach((file) => { |
| 80 | + const sourcePath = path.join(tsLibPath, file) |
| 81 | + const destPath = path.join(libDir, file) |
| 82 | + |
| 83 | + try { |
| 84 | + if (fs.existsSync(sourcePath)) { |
| 85 | + fs.copyFileSync(sourcePath, destPath) |
| 86 | + copiedFiles++ |
| 87 | + } else { |
| 88 | + console.warn(`File not found: ${sourcePath}`) |
| 89 | + } |
| 90 | + } catch (error) { |
| 91 | + console.error(`Error copying ${file}: ${error.message}`) |
| 92 | + errors++ |
| 93 | + } |
| 94 | +}) |
| 95 | + |
| 96 | +console.log(`Build complete! Copied ${copiedFiles} lib files with ${errors} errors.`) |
0 commit comments