1/* 2 * Copyright (c) 2024-2025 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 16import * as fs from 'fs'; 17import * as path from 'path'; 18 19const targetDir = './builtIn/typescript'; 20 21function emptyDir(dir: string): void { 22 if (fs.existsSync(dir)) { 23 fs.readdirSync(dir).forEach(file => { 24 const filePath = path.join(dir, file); 25 if (fs.statSync(filePath).isFile()) { 26 fs.unlinkSync(filePath); 27 } else if (fs.statSync(filePath).isDirectory()) { 28 emptyDir(filePath); 29 fs.rmdirSync(filePath); 30 } 31 }); 32 } 33} 34 35if (!fs.existsSync(targetDir)) { 36 fs.mkdirSync(targetDir, { recursive: true }); 37} else { 38 emptyDir(targetDir); 39} 40 41fs.mkdirSync(path.join(targetDir, 'api')); 42fs.mkdirSync(path.join(targetDir, 'api/@internal')); 43 44const sourceFile1 = './node_modules/typescript/lib/lib.es2015.collection.d.ts'; 45const sourceFile2 = './node_modules/typescript/lib/lib.es5.d.ts'; 46 47function copyFile(source: string, destination: string): void { 48 if (fs.existsSync(source)) { 49 fs.copyFileSync(source, destination); 50 } else { 51 console.log('Error copy typescript collection definition file'); 52 } 53} 54 55copyFile(sourceFile1, path.join(targetDir, 'api/@internal', 'lib.es2015.collection.d.ts')); 56copyFile(sourceFile2, path.join(targetDir, 'api/@internal', 'lib.es5.d.ts'));