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

Add and use shared package for website setup #17568

Merged
merged 9 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -75,6 +75,7 @@ packages/foundation-legacy/ @khmakoto
# packages/jest-serializer-merge-styles/ # packages/jest-serializer-merge-styles/
packages/merge-styles/ @dzearing packages/merge-styles/ @dzearing
packages/monaco-editor/ @ecraig12345 packages/monaco-editor/ @ecraig12345
packages/public-docsite-setup/ @ecraig12345
packages/react-hooks/ @ecraig12345 packages/react-hooks/ @ecraig12345
packages/style-utilities/ @dzearing packages/style-utilities/ @dzearing
packages/style-utilities/src/interfaces/ @phkuo @dzearing packages/style-utilities/src/interfaces/ @phkuo @dzearing
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -137,6 +137,7 @@ package-lock.json


# Website # Website
/apps/public-docsite/flights/ /apps/public-docsite/flights/
/site-manifests/


# Rush files - since we are moving away from it # Rush files - since we are moving away from it
/common /common
Expand Down
5 changes: 3 additions & 2 deletions apps/pr-deploy-site/pr-deploy-site.js
Expand Up @@ -20,7 +20,7 @@ var siteInfo = [
}, },
{ {
package: '@fluentui/public-docsite', package: '@fluentui/public-docsite',
link: './public-docsite/index.html?devhost', link: './public-docsite/index.html',
icon: 'Website', icon: 'Website',
title: 'Website', title: 'Website',
}, },
Expand Down Expand Up @@ -62,7 +62,8 @@ var siteInfo = [
}, },
]; ];


var hrefMatch = window.location.href.match(/refs\/(pull|heads)\/([^/]+)/); // location.pathname will be like /pull/17568/ or /heads/master/
var hrefMatch = window.location.pathname.match(/^\/(pull|heads)\/([^/]+)/);
var repoUrl = 'https://github.com/microsoft/fluentui'; var repoUrl = 'https://github.com/microsoft/fluentui';
if (hrefMatch) { if (hrefMatch) {
var link = /** @type {HTMLAnchorElement} */ (document.getElementById('prLink')); var link = /** @type {HTMLAnchorElement} */ (document.getElementById('prLink'));
Expand Down
1 change: 0 additions & 1 deletion apps/public-docsite/config/pre-copy.json
@@ -1,6 +1,5 @@
{ {
"copyTo": { "copyTo": {
"dist": ["./index.html"],
"lib": ["./src/**/*.json"] "lib": ["./src/**/*.json"]
} }
} }
189 changes: 12 additions & 177 deletions apps/public-docsite/homepage.htm
@@ -1,3 +1,10 @@
<!--
This file is a mirror of the actual developer.microsoft.com/fluentui bootstrap code which is
located an internal repo. See team onenote for more information.

Please REMOVE COMMENTS when copying to the internal repo.
-->

<div <div
id="metadata" id="metadata"
title="Home - Fluent UI" title="Home - Fluent UI"
Expand All @@ -20,84 +27,10 @@
} }
</style> </style>


<!-- prettier-ignore -->
<script type="text/javascript"> <script type="text/javascript">
var appInsights = // Application Insights setup
window.appInsights || var appInsights=window.appInsights||(function(e){function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n);});};}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement('script');(n.src=e.url||'https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js'),i.getElementsByTagName('script')[0].parentNode.appendChild(n);});try{t.cookie=i.cookie;}catch(e){}(t.queue=[]),(t.version=2);for(var r=['Event','PageView','Exception','Trace','DependencyData','Metric','PageViewPerformance'];r.length;) n('track'+r.pop());n('startTrackPage'),n('stopTrackPage');var s='Track'+r[0];if((n('start'+s),n('stop'+s),n('addTelemetryInitializer'),n('setAuthenticatedUserContext'),n('clearAuthenticatedUserContext'),n('flush'),(t.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4,}),!(!0===e.disableExceptionTracking||(e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&& !0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)))){n('_'+(r='onerror'));var o=a[r];(a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return (!0 !==c&&t['_'+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s,}),c);}),(e.autoExceptionInstrumented=!0);}return t;})({instrumentationKey:'',});(window.appInsights=appInsights),appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView({});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the spacing here since this code isn't important and it's smaller that way

(function(e) {
function n(e) {
t[e] = function() {
var n = arguments;
t.queue.push(function() {
t[e].apply(t, n);
});
};
}
var t = { config: e };
t.initialize = !0;
var i = document,
a = window;
setTimeout(function() {
var n = i.createElement('script');
(n.src = e.url || 'https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js'),
i.getElementsByTagName('script')[0].parentNode.appendChild(n);
});
try {
t.cookie = i.cookie;
} catch (e) {}
(t.queue = []), (t.version = 2);
for (
var r = ['Event', 'PageView', 'Exception', 'Trace', 'DependencyData', 'Metric', 'PageViewPerformance'];
r.length;

)
n('track' + r.pop());
n('startTrackPage'), n('stopTrackPage');
var s = 'Track' + r[0];
if (
(n('start' + s),
n('stop' + s),
n('addTelemetryInitializer'),
n('setAuthenticatedUserContext'),
n('clearAuthenticatedUserContext'),
n('flush'),
(t.SeverityLevel = {
Verbose: 0,
Information: 1,
Warning: 2,
Error: 3,
Critical: 4,
}),
!(
!0 === e.disableExceptionTracking ||
(e.extensionConfig &&
e.extensionConfig.ApplicationInsightsAnalytics &&
!0 === e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)
))
) {
n('_' + (r = 'onerror'));
var o = a[r];
(a[r] = function(e, n, i, a, s) {
var c = o && o(e, n, i, a, s);
return (
!0 !== c &&
t['_' + r]({
message: e,
url: n,
lineNumber: i,
columnNumber: a,
error: s,
}),
c
);
}),
(e.autoExceptionInstrumented = !0);
}
return t;
})({
instrumentationKey: '8a822908-f374-4206-900d-07ef9d2d4e9f',
});
(window.appInsights = appInsights),
appInsights.queue && 0 === appInsights.queue.length && appInsights.trackPageView({});
</script> </script>


<div id="main"> <div id="main">
Expand All @@ -112,103 +45,5 @@
</div> </div>
</div> </div>


<script type="text/javascript"> <!-- Compiled setup script (copy from dist/loadSite.js) -->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The big setup script block was basically moved to packages/public-docsite-setup/src/loadSite.ts, with some unnecessary parts removed (like script load handler variants that as far as I can tell were for IE 8?) and bugs fixed. The option for loading test builds against the real site has also been removed.

// @ts-check <script type="text/javascript" href="loadSite.js"></script>
var isProduction = location.hostname === 'developer.microsoft.com';
var isDev = getParameterByName('dev') === '1' || !!getParameterByName('strict');
var devhost = getParameterByName('devhost');
var entryPointFilename = 'fabric-sitev5';
var appPath = '';
var Flight = {};

if (devhost !== null) {
if (devhost === '') {
devhost = location.origin + location.pathname.replace('homepage.htm', '');
}
appPath = devhost;
Flight.baseCDNUrl = devhost;
loadAppScripts();
} else {
var fabricVersions = [5, 6, 7, 8];

var fabricVersion = Number(
getParameterByName('fabricVer') ||
window.sessionStorage.getItem('fabricVer') ||
fabricVersions[fabricVersions.length - 1]
);

if (fabricVersions.indexOf(fabricVersion) > -1) {
window.sessionStorage.setItem('fabricVer', fabricVersion);
}

var prefixVer =
fabricVersions.indexOf(fabricVersion) > -1 && fabricVersion !== fabricVersions.slice(-1)[0]
? 'v' + fabricVersion + '-'
: '';

var configPrefix = 'fabric-website-' + prefixVer + (isProduction ? 'prod' : 'df');

var configScript = ['https://fabricweb.azureedge.net/fabric-website/manifests/' + configPrefix + '.js'];

loadScripts(configScript, function() {
if (window.Flight) {
appPath = window.Flight.baseCDNUrl;
loadAppScripts();
}
});
}

function loadScripts(array, callback) {
var loader = function(src, handler, failHandler) {
var script = document.createElement('script');
script.src = src;
script.onload = script.onreadystatechange = function() {
script.onreadystatechange = script.onload = null;
handler();
};

script.onerror = function() {
script.onerror = null;
if (failHandler) {
failHandler();
}
};

var head = document.getElementsByTagName('head')[0];
(head || document.body).appendChild(script);
};
(function run() {
if (array.length != 0) {
const scriptName = array.shift();
loader(scriptName, run, function() {
window.MonacoConfig.useMinified = false;
loader(scriptName.replace('.min.js', '.js'), run);
});
} else {
callback && callback();
}
})();
}

function loadAppScripts() {
loadScripts([appPath + entryPointFilename + (isDev ? '.js' : '.min.js')]);

window.MonacoConfig = {
baseUrl: appPath,
useMinified: !isDev,
crossDomain: true,
};
}

function getParameterByName(name, url) {
if (!url) {
url = location.href;
}
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
</script>