Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] instrument the typedoc github pages with ApplicationInsights #2237

Merged
merged 7 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"npm-pack": "node common/scripts/install-run-rush.js npm-pack --verbose",
"npm-publish": "node ./tools/release-tools/npm_publish.js",
"npm-set-latest": "node ./tools/release-tools/npm_set_latest.js",
"gh-status": "node ./tools/status-tools/github-status.js"
"gh-status": "node ./tools/status-tools/github-status.js",
"script-inject": "node tools/github-page-script-injection/injectScript.js"
siyuniu-ms marked this conversation as resolved.
Show resolved Hide resolved
},
"repository": {
"type": "git",
Expand Down
59 changes: 59 additions & 0 deletions tools/github-page-script-injection/injectScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const fs = require('fs');
const path = require('path');

// Recursively process a folder and its subfolders to search for HTML files
const processFolder = (folderPath) => {
const files = fs.readdirSync(folderPath);

files.forEach((file) => {
const filePath = path.join(folderPath, file);
console.log(` ${filePath}`);

if (fs.statSync(filePath).isDirectory()) {
// If the current path is a directory, recursively process it
processFolder(filePath);
} else if (path.extname(file) === '.html') {
// If it's an HTML file, inject the script
console.log(`process ${filePath}`);

injectScript(filePath);
}
});
};


// Start processing from the 'docs' folder
const docsFolder = path.join(__dirname, '../../docs');
processFolder(docsFolder);

function injectScript(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

// Read the script content from a file
const scriptFilePath = path.join(__dirname, 'script.js');
const scriptContent = fs.readFileSync(scriptFilePath, 'utf8');

// Check if the script content is already present in the file
const fileContent = fs.readFileSync(filePath, 'utf8');

// Check if the script content is already present in the file
if (fileContent.includes(scriptContent)) {
console.log(`Script already present in ${filePath}`);
return;
}
// Create the modified content by inserting the script tag right before the closing head tag
const modifiedContent = data.replace(/(<\/head[^>]*)/i, `\n${scriptContent}\n$1`);
// Save the modified content back to the file
fs.writeFile(filePath, modifiedContent, (err) => {
if (err) {
console.error('Error writing to file:', err);
return;
}
console.log(`Script injected successfully into ${filePath}`);
});
});
}
18 changes: 18 additions & 0 deletions tools/github-page-script-injection/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading