Skip to content

Commit 00f7dfe

Browse files
fix: use lastIndexOf to make getSamplePath cross-platform
On GitHub-hosted runners the workspace path contains the repo name multiple times (e.g. .../igniteui-angular-examples/igniteui-angular-examples/...), causing split(repoName)[1] to return "/" instead of the samples sub-path. Downstream helpers (getSampleGroup, getSampleControl, getSampleFolder) would then return undefined and crash utils.replace with "Cannot read properties of undefined (reading 'split')". Replace split(repoName)[1] with lastIndexOf + substring so the function always anchors to the last occurrence of the repo name, making it work correctly on Windows, macOS, and Linux regardless of how many parent directories share the repo name.
1 parent 2bfbfaa commit 00f7dfe

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

browser/scripts/browser.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const sampleOutput = './src/samples/'; // /browser/src/samples/
3232
// C:\REPOS\GitInternalDocs\igniteui-angular-examples\samples\charts\data-chart\axis-sharing
3333
// returns ../samples/charts/data-chart/axis-sharing
3434
function getSamplePath(dirPath) {
35-
var ret = dirPath.split(repoName)[1];
35+
var idx = dirPath.lastIndexOf(repoName);
36+
var ret = dirPath.substring(idx + repoName.length);
3637
ret = ".." + ret.split("\\").join("/");
3738
return ret;
3839
}
@@ -99,14 +100,14 @@ var sampleSourcePaths = [
99100
// sampleRoot + 'charts/data-chart/column-chart-styling/package.json',
100101
// sampleRoot + 'charts/data-chart/format-specifiers/package.json',
101102
// sampleRoot + 'charts/data-chart/financial-price-series/package.json',
102-
// sampleRoot + 'charts/data-chart/final-value-layer-styling/package.json',
103+
// sampleRoot + 'charts/data-chart/final-value-layer-styling/package.json',
103104
// sampleRoot + 'charts/data-chart/legends/package.json',
104105
// sampleRoot + 'charts/data-chart/selection-matcher/package.json',
105106
// sampleRoot + 'charts/data-chart/tooltip-template/package.json',
106107
// sampleRoot + 'charts/data-chart/transition-event/package.json',
107108
// sampleRoot + 'charts/data-chart/trendline-layer/package.json',
108109
// sampleRoot + 'charts/data-chart/waterfall-chart/package.json',
109-
// sampleRoot + 'charts/data-chart/user-annotation-layer/package.json',
110+
// sampleRoot + 'charts/data-chart/user-annotation-layer/package.json',
110111
// sampleRoot + 'charts/data-chart/axis*/package.json',
111112
// sampleRoot + 'charts/data-chart/bar*/package.json',
112113
// sampleRoot + 'charts/data-chart/chart*/package.json',
@@ -861,7 +862,7 @@ function updateCodeViewer(cb) {
861862
dataContent += data.content + "\r\n";
862863
}
863864

864-
var codeViewData = {};
865+
var codeViewData = {};
865866
codeViewData.isMain = true,
866867
codeViewData.hasRelativeAssetsUrls = false,
867868
codeViewData.fileExtension = 'ts';
@@ -1159,7 +1160,7 @@ function gitAcceptCurrent(cb) {
11591160

11601161
var gitCurrentTag = "<<<<<<< HEAD\r\n";
11611162
var gitIncomingTag = ">>>>>>> master\r\n";
1162-
1163+
11631164
var gitCurrentStart = fileContent.indexOf(gitCurrentTag);
11641165
var gitCurrentEnd = fileContent.indexOf("=======");
11651166
var gitIncomingStart = fileContent.indexOf("=======");
@@ -1172,16 +1173,16 @@ function gitAcceptCurrent(cb) {
11721173
// console.log(current);
11731174
// console.log("incoming");
11741175
// console.log(incoming);
1175-
fileContent = fileContent.replace(incoming, "");
1176+
fileContent = fileContent.replace(incoming, "");
11761177
fileContent = fileContent.replace(gitCurrentTag, "");
11771178
fileContent = fileContent.replace(gitIncomingTag, "");
11781179

11791180
// console.log("fileContent");
1180-
// console.log(fileContent);
1181+
// console.log(fileContent);
11811182
fs.writeFileSync(filePath, fileContent);
1182-
1183+
11831184
console.log("changed " + filePath);
1184-
}
1185+
}
11851186
else {
11861187

11871188
}
@@ -1443,19 +1444,19 @@ function logVersionIgniteUI(cb) {
14431444
} exports.logVersionIgniteUI = logVersionIgniteUI;
14441445

14451446

1446-
// move samples files up one level, e.g. /scr/app/*.* to /scr/*.*
1447+
// move samples files up one level, e.g. /scr/app/*.* to /scr/*.*
14471448
exports.moveAppFiles = function moveAppFiles(cb) {
14481449
var appFolders = [];
14491450

14501451
gulp.src(
1451-
"../samples/**/src/app/*.*",
1452-
"../samples/**/type-scatter-symbol-series/src/app/*.*",
1452+
"../samples/**/src/app/*.*",
1453+
"../samples/**/type-scatter-symbol-series/src/app/*.*",
14531454
{allowEmpty: true})
14541455
.pipe(es.map(function(file, fileCallback) {
1455-
1456+
14561457
var fileContent = file.contents.toString();
1457-
let fileOutput = file.dirname.replace("\\app", "") + "\\" + file.basename;
1458-
1458+
let fileOutput = file.dirname.replace("\\app", "") + "\\" + file.basename;
1459+
14591460
if (appFolders.indexOf(file.dirname) < 0) {
14601461
appFolders.push(file.dirname);
14611462
}
@@ -1465,13 +1466,13 @@ exports.moveAppFiles = function moveAppFiles(cb) {
14651466
fileCallback(null, file);
14661467
}))
14671468
.on("end", function() {
1468-
1469+
14691470
console.log(appFolders);
14701471
console.log("moved " + appFolders.length + " samples from /scr/app/*.* to /scr/*.* ");
14711472
del(appFolders, {force: true});
14721473

14731474
for (let i = 0; i < appFolders.length; i++) {
1474-
1475+
14751476
var mainPath = appFolders[i].replace("\\app", "") + "\\main.ts";
14761477
let mainFile = fs.readFileSync(mainPath).toString();
14771478
mainFile = mainFile.replace("/app/", "/");
@@ -1480,8 +1481,8 @@ exports.moveAppFiles = function moveAppFiles(cb) {
14801481
cb();
14811482
});
14821483

1483-
}
1484-
1484+
}
1485+
14851486
exports.updateCodeSandbox = function updateCodeSandbox(cb) {
14861487
var appFolders = [];
14871488
var copyFiles = [
@@ -1496,18 +1497,18 @@ exports.updateCodeSandbox = function updateCodeSandbox(cb) {
14961497
"sandbox.config.json",
14971498
"src\\config",
14981499
];
1499-
1500+
15001501
gulp.src( [
1501-
"../samples/**/package.json",
1502+
"../samples/**/package.json",
15021503
// "../samples/**/display-osm-imagery/package.json",
1503-
// "../samples/**/doughnut-chart/overview/package.json",
1504-
// "../samples/**/display-heat-imagery/package.json",
1504+
// "../samples/**/doughnut-chart/overview/package.json",
1505+
// "../samples/**/display-heat-imagery/package.json",
15051506
], {allowEmpty: true})
15061507
.pipe(es.map(function(file, fileCallback) {
1507-
1508+
15081509
var fileContent = file.contents.toString();
1509-
let fileOutput = file.dirname + "\\" + file.basename;
1510-
1510+
let fileOutput = file.dirname + "\\" + file.basename;
1511+
15111512
console.log("updating " + fileOutput);
15121513
fileContent = fileContent.replace('"@angular/animations": "17.0.0"','"@angular/animations": "^17.2.1"');
15131514
fileContent = fileContent.replace('"@angular/common": "17.0.0"','"@angular/common": "^17.2.1"');
@@ -1530,10 +1531,10 @@ exports.updateCodeSandbox = function updateCodeSandbox(cb) {
15301531
fileContent = fileContent.replace('"hammerjs": "2.0.8"','"hammerjs": "^2.0.8"');
15311532

15321533
fs.writeFileSync(fileOutput, fileContent);
1533-
1534+
15341535
for (let i = 0; i < deleteFiles.length; i++) {
15351536
var deletePath = file.dirname + "\\" + deleteFiles[i];
1536-
console.log("delete " + deletePath);
1537+
console.log("delete " + deletePath);
15371538
del([deletePath], {force: true});
15381539
}
15391540

@@ -1552,4 +1553,4 @@ exports.updateCodeSandbox = function updateCodeSandbox(cb) {
15521553
cb();
15531554
});
15541555

1555-
}
1556+
}

0 commit comments

Comments
 (0)