|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import * as fs from 'fs'; |
| 3 | +import * as path from 'path'; |
| 4 | +import * as rimraf from 'rimraf'; |
| 5 | + |
| 6 | +/* |
| 7 | + * This script is used to sync the source files from @sentry/angular to @sentry/angular-ivy. |
| 8 | + * Because @sentry/angular-ivy only differs from @sentry/angular in the way it is built, we |
| 9 | + * want to keep source files in sync to avoid having to maintain the same source files twice. |
| 10 | + * This file is run before we actually build @sentry/angular-ivy, so that the symlinks are |
| 11 | + * always up to date. |
| 12 | + */ |
| 13 | + |
| 14 | +console.log('------------------------------------------------------------'); |
| 15 | +console.log('Syncing @sentry/angular and @sentry/angular-ivy source files'); |
| 16 | + |
| 17 | +const ANGULAR_PATH = path.resolve(__dirname, '..', '..', 'angular'); |
| 18 | +const ANGULAR_IVY_PATH = path.resolve(__dirname, '..'); |
| 19 | + |
| 20 | +const angularSrcPath = path.resolve(ANGULAR_PATH, 'src'); |
| 21 | +const angularIvySrcPath = path.resolve(ANGULAR_IVY_PATH, 'src'); |
| 22 | + |
| 23 | +const angularIvySrcDirContent = fs.readdirSync(angularIvySrcPath); |
| 24 | +angularIvySrcDirContent.forEach(entry => { |
| 25 | + if (entry !== 'sdk.ts') { |
| 26 | + rimraf.sync(path.resolve(angularIvySrcPath.toString(), entry)); |
| 27 | + } |
| 28 | +}); |
| 29 | + |
| 30 | +syncDir(angularSrcPath, angularIvySrcPath); |
| 31 | + |
| 32 | +console.log('------------------------------------------------------------'); |
| 33 | + |
| 34 | +function syncDir(srcDir: fs.PathLike, targetDir: fs.PathLike): void { |
| 35 | + const srcDirContent = fs.readdirSync(srcDir, { withFileTypes: true }).filter(file => file.name !== 'sdk.ts'); |
| 36 | + srcDirContent.forEach(entry => { |
| 37 | + if (entry.isDirectory()) { |
| 38 | + const newTargetDir = path.resolve(targetDir.toString(), entry.name); |
| 39 | + if (!fs.existsSync(newTargetDir)) { |
| 40 | + fs.mkdirSync(newTargetDir); |
| 41 | + } |
| 42 | + return syncDir(path.resolve(srcDir.toString(), entry.name), newTargetDir); |
| 43 | + } |
| 44 | + |
| 45 | + const relativeSourceFilePath = path.relative(process.cwd(), path.resolve(srcDir.toString(), entry.name)); |
| 46 | + const relativeTargetFilePath = path.relative(process.cwd(), path.resolve(targetDir.toString(), entry.name)); |
| 47 | + |
| 48 | + console.log(`Syncing ${relativeSourceFilePath} to ${relativeTargetFilePath}`); |
| 49 | + |
| 50 | + fs.symlinkSync(path.join('..', relativeSourceFilePath), relativeTargetFilePath, 'file'); |
| 51 | + }); |
| 52 | +} |
0 commit comments