Skip to content

Commit 0f8b396

Browse files
committed
add syncSourceFiles.ts script
1 parent dc25def commit 0f8b396

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

packages/angular-ivy/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
browser: true,
44
},
55
extends: ['../../.eslintrc.js'],
6+
ignorePatterns: ['scripts/**/*'],
67
};

packages/angular-ivy/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"engines": {
1010
"node": ">=12"
1111
},
12-
"private": true,
1312
"main": "build/bundles/sentry-angular.umd.js",
1413
"module": "build/fesm2015/sentry-angular.js",
1514
"publishConfig": {
@@ -42,15 +41,16 @@
4241
"zone.js": "~0.11.4"
4342
},
4443
"scripts": {
45-
"build": "yarn build:transpile",
44+
"build": "yarn build:syncSymlinks && yarn build:transpile",
4645
"build:transpile": "ng build",
4746
"build:dev": "yarn build",
48-
"build:watch": "yarn build:transpile:watch",
47+
"build:watch": "yarn build:syncSymlinks && yarn build:transpile:watch",
4948
"build:dev:watch": "yarn build:watch",
5049
"build:transpile:watch": "ng build --watch",
5150
"build:tarball": "npm pack ./build",
51+
"build:syncSymlinks": "ts-node ./scripts/syncSourceFiles.ts",
5252
"circularDepCheck": "madge --circular src/index.ts",
53-
"clean": "rimraf build coverage sentry-angular-*.tgz",
53+
"clean": "rimraf build coverage sentry-angular-ivy-*.tgz",
5454
"fix": "run-s fix:eslint fix:prettier",
5555
"fix:eslint": "eslint . --format stylish --fix",
5656
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)