Skip to content

Commit 064590b

Browse files
Rewrite example js/assets paths to the gh-pages CDN (#5840)
* Rewrite example js/assets paths to the gh-pages CDN Point the ../../js/ and ../../assets/ references in the gh-pages examples at the jsDelivr-hosted aframevr/aframe@gh-pages copies so the examples load their helper scripts and assets from the CDN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * remove replace-in-file dependency * rewrite script to do the read and write file only once, use a simple replaceInFileSync function, no need for 10 dependencies * use the opening double quote in the regex to avoid generating an invalid URL for future examples with another directory depth --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 59c0c11 commit 064590b

3 files changed

Lines changed: 23 additions & 159 deletions

File tree

package-lock.json

Lines changed: 0 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"karma-webpack": "^5.0.0",
8484
"markserv": "github:sukima/markserv#feature/fix-broken-websoketio-link",
8585
"mocha": "^10.0.0",
86-
"replace-in-file": "^8.3.0",
8786
"shelljs": "^0.8.5",
8887
"sinon": "<12.0.0",
8988
"sinon-chai": "^3.7.0",

scripts/preghpages.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env node
2-
3-
const path = require('path');
4-
2+
const fs = require('node:fs');
3+
const path = require('node:path');
54
const shell = require('shelljs');
6-
const replaceInFileSync = require('replace-in-file').replaceInFileSync;
75

86
const pkg = require('../package.json');
97
const aframeVersion = pkg.version;
@@ -29,14 +27,27 @@ shell.cp('-r', [
2927
'*.md'
3028
], 'gh-pages');
3129

30+
function replaceInFileSync ({ files, processor }) {
31+
for (const file of fs.globSync(files)) {
32+
const input = fs.readFileSync(file, 'utf8');
33+
const output = processor.reduce((content, process) => process(content), input);
34+
if (output !== input) {
35+
fs.writeFileSync(file, output);
36+
}
37+
}
38+
}
39+
3240
function htmlReplace (before, after) {
33-
replaceInFileSync({
34-
from: before,
35-
to: after,
36-
files: 'gh-pages/**/*.html'
37-
});
41+
return (input) => input.replace(before, after);
3842
}
3943

40-
htmlReplace('../../../dist/aframe-master.module.min.js', `https://aframe.io/releases/${aframeVersion}/aframe.module.min.js`);
41-
htmlReplace('../../../dist/aframe-master.js', `https://aframe.io/releases/${aframeVersion}/aframe.min.js`);
42-
htmlReplace(/\.\.\/\.\.\/\.\.\/super-three-package/g, `https://cdn.jsdelivr.net/npm/super-three@${threeVersion}`);
44+
replaceInFileSync({
45+
files: 'gh-pages/**/*.html',
46+
processor: [
47+
htmlReplace('"../../../dist/aframe-master.module.min.js', `"https://aframe.io/releases/${aframeVersion}/aframe.module.min.js`),
48+
htmlReplace('"../../../dist/aframe-master.js', `"https://aframe.io/releases/${aframeVersion}/aframe.min.js`),
49+
htmlReplace(/"\.\.\/\.\.\/\.\.\/super-three-package/g, `"https://cdn.jsdelivr.net/npm/super-three@${threeVersion}`),
50+
htmlReplace(/"\.\.\/\.\.\/js\//g, '"https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/js/'),
51+
htmlReplace(/"\.\.\/\.\.\/assets\//g, '"https://cdn.jsdelivr.net/gh/aframevr/aframe@gh-pages/examples/assets/')
52+
]
53+
});

0 commit comments

Comments
 (0)