Skip to content

LFX'25:Update the pipeline to achieve clean build without any errors #16574

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 1 addition & 8 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ netlify_install:
[email protected] \
[email protected] \
[email protected] \
@babel/[email protected] \
@babel/[email protected] \
@babel/[email protected] \
@babel/[email protected]
@npm install --omit=dev --save-dev \
[email protected]
@npm install --save \
[email protected]
[email protected]

netlify: netlify_install
@scripts/gen_site.sh
Expand Down
73 changes: 44 additions & 29 deletions scripts/gen_site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,51 @@ set -ex

mkdir -p generated/js generated/img tmp/js


tsc

babel --source-maps --minified --no-comments --presets minify \
tmp/js/constants.js \
tmp/js/utils.js \
tmp/js/feedback.js \
tmp/js/kbdnav.js \
tmp/js/themes.js \
tmp/js/menu.js \
tmp/js/header.js \
tmp/js/sidebar.js \
tmp/js/tabset.js \
tmp/js/prism.js \
tmp/js/codeBlocks.js \
tmp/js/links.js \
tmp/js/resizeObserver.js \
tmp/js/scroll.js \
tmp/js/overlays.js \
tmp/js/lang.js \
tmp/js/callToAction.js \
tmp/js/events.js \
tmp/js/faq.js \
--out-file generated/js/all.min.js

babel --source-maps --minified --no-comments --presets minify \
tmp/js/headerAnimation.js \
--out-file generated/js/headerAnimation.min.js

babel --source-maps --minified --no-comments \
tmp/js/themes_init.js \
--out-file generated/js/themes_init.min.js
#Entrypoint for esbuild to bundle and minify through an entrypoint.js file
cat <<EOF > tmp/js/entrypoint.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Why generate this every time and not check it in?

(This question doesn't presuppose I know the answer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

esbuild needs an entrypoint for bundling the files and it does when the files are ESModules and the typescript files which is used in this repo is not ESModules but are legacy old standard type global scripts.esbuild follows the import and build a dependency graph so this temporary file is needed for esbuild for bundling the files together and minify them.

You can check the tsconfig.json the target is set to es6.

When you compile a .ts file for ex:- tsc src/ts/faq.ts --target es6 It will throw an error because the files are not following the ES6 standard.

This file is just an entrypoint and nothing else for bundling and minification.

Copy link
Member

Choose a reason for hiding this comment

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

Why not have that file exist in say src/ts/entrypoint.js rather than creating it arbitrarily?

For future maintainers, it would not be intuitive to look in gen_site.sh for a magic file.

import "./constants.js";
import "./utils.js";
import "./feedback.js";
import "./kbdnav.js";
import "./themes.js";
import "./menu.js";
import "./header.js";
import "./sidebar.js";
import "./tabset.js";
import "./prism.js";
import "./codeBlocks.js";
import "./links.js";
import "./resizeObserver.js";
import "./scroll.js";
import "./overlays.js";
import "./lang.js";
import "./callToAction.js";
import "./events.js";
import "./faq.js";
EOF

# Bundle + minify with sourcemap
esbuild tmp/js/entrypoint.js \
--bundle \
--minify \
--sourcemap \
--target=es6 \
--outfile=generated/js/all.min.js

esbuild tmp/js/headerAnimation.js \
--minify \
--sourcemap \
--target=es6 \
--outfile=generated/js/headerAnimation.min.js
Comment on lines +55 to +59
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still relevant that this be a separate file?
(Some digging may be required to find out what it does and why it was done this way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it needs to be a seperate file otherwise it can break the site.I have to do a bunch more test.


esbuild tmp/js/themes_init.js \
--bundle \
--minify \
--sourcemap \
--target=es6 \
--outfile=generated/js/themes_init.min.js

svgstore -o generated/img/icons.svg src/icons/**/*.svg
1 change: 0 additions & 1 deletion src/ts/callToAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Copy link
Contributor

Choose a reason for hiding this comment

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

were changes such as this required to lint, or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes make lint-typescript was throwing errors.

const callToActionDelayMs = 250;

function handleCallToAction(): void {
Expand Down
6 changes: 4 additions & 2 deletions src/ts/codeBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { listen , copyToClipboard , getById} from "./utils";
import { button , ariaLabel , mouseenter , mouseleave , click , active} from "./constants";
import { readLocalStorage } from "./themes_init";
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

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

review top tip: I don't know anything about Typescript but it would be worth providing a little context as to why these need to be added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to be added to make them ESModules and follow ES6 standards otherwise the .ts files will be complied as global scripts and global scripts are now legacy code which doesn't follow ES6 standard.

declare const buttonCopy: string;
declare const buttonDownload: string;
declare const buttonPrint: string;
declare const docTitle: string;
declare const branchName: string;
declare const Prism: any;

declare var iconFile: string;
let syntaxColoring = true;

// All the voodoo needed to support our fancy code blocks
Expand Down
24 changes: 12 additions & 12 deletions src/ts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const click = "click";
const mouseenter = "mouseenter";
const mouseleave = "mouseleave";
const active = "active";
const keyup = "keyup";
const keydown = "keydown";
const button = "button";
const ariaLabel = "aria-label";
const ariaExpanded = "aria-expanded";
const ariaSelected = "aria-selected";
const ariaControls = "aria-controls";
const tabIndex = "tabindex";
export const click = "click";
export const mouseenter = "mouseenter";
export const mouseleave = "mouseleave";
export const active = "active";
export const keyup = "keyup";
export const keydown = "keydown";
export const button = "button";
export const ariaLabel = "aria-label";
export const ariaExpanded = "aria-expanded";
export const ariaSelected = "aria-selected";
export const ariaControls = "aria-controls";
export const tabIndex = "tabindex";
3 changes: 3 additions & 0 deletions src/ts/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

// Handles banners and stickers
import { listen , getByClass } from "./utils"
import { readLocalStorage } from "./themes_init";
import { click } from "./constants";
function handleEvents(): void {
const now = new Date().valueOf();
let remainingEventImpressions: any = {};
Expand Down
2 changes: 1 addition & 1 deletion src/ts/faq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { listen } from "./utils"
const faqBlockCollapsed = "faq-block--collapsed";

function handleFaqBlocks(): void {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { getById } from "./utils";
declare function gtag(type: string, action: string, payload: any): void;

function sendFeedback(language: string, value: number): void {
export function sendFeedback(language: string, value: number): void {
gtag("event", "click-" + language, {
event_category: "Helpful",
event_label: window.location.pathname,
Expand Down
3 changes: 3 additions & 0 deletions src/ts/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

// Attach the event handlers to support the search box and hamburger
import { getById ,getByTag , listen ,getByClass } from "./utils";
import { click, keyup } from "./constants";
import { closeActiveOverlay } from "./overlays";
function handleHeader(): void {
const searchForm = "search-form";
const headerLinks = "header-links";
Expand Down
2 changes: 2 additions & 0 deletions src/ts/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

// The set of languages supported by the site, add new ones at the end
import { createCookie , navigateToUrlOrRoot , listen ,getById } from "./utils";
import { click } from "./constants";
const languages = ["en", "zh", "uk"];

function handleLanguageSwitch(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { getById } from "./utils";
declare var iconFile: string;

function handleLinks(): void {
Expand Down
3 changes: 3 additions & 0 deletions src/ts/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.

// Attach the event handlers to support menus
import { listen , toggleAttribute , keyCodes , isPrintableCharacter } from "./utils"
import { click, ariaExpanded, keydown } from "./constants";
import { toggleOverlay , showOverlay , closeActiveOverlay } from "./overlays";
function handleMenu(): void {
document.querySelectorAll<HTMLElement>(".menu").forEach(menu => {
const trigger = menu.querySelector<HTMLElement>(".menu-trigger");
Expand Down
13 changes: 8 additions & 5 deletions src/ts/overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { listen } from "./utils";
import { click } from "./constants";
declare class Popper {
constructor(a: HTMLElement, b: HTMLElement, c: any);
public destroy(): void;
}
declare var iconFile: string;
// Path to the SVG icon sprite file
Copy link
Contributor

Choose a reason for hiding this comment

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

comments should be above the line?

Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
declare var iconFile: string;
// Path to the SVG icon sprite file
// Path to the SVG icon sprite file
declare var iconFile: string;


// tracks any overlay displayed on the page (e.g. menu or popover)
let overlay: HTMLElement | null = null;
let popper: Popper | null = null;

// show/hide the specific overlay
function toggleOverlay(element: HTMLElement): void {
export function toggleOverlay(element: HTMLElement): void {
if (overlay === element) {
closeActiveOverlay();
} else {
Expand All @@ -35,7 +38,7 @@ function toggleOverlay(element: HTMLElement): void {
}

// explicitly show the specific overlay
function showOverlay(element: HTMLElement): void {
export function showOverlay(element: HTMLElement): void {
if (overlay === element) {
return;
}
Expand All @@ -45,7 +48,7 @@ function showOverlay(element: HTMLElement): void {
}

// explicitly close the active overlay
function closeActiveOverlay(): void {
export function closeActiveOverlay(): void {
if (overlay) {
overlay.classList.remove("show");
overlay = null;
Expand All @@ -57,7 +60,7 @@ function closeActiveOverlay(): void {
}
}

function handleOverlays(): void {
export function handleOverlays(): void {
// Attach a popper to the given anchor
function attachPopper(anchor: HTMLElement, element: HTMLElement): void {
if (popper) {
Expand Down
4 changes: 3 additions & 1 deletion src/ts/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.

// initialized after the DOM has been loaded
import { getById , listen } from "./utils";
import { click } from "./constants";
let scrollToTopButton: HTMLElement | null;
let tocLinks: HTMLCollectionOf<HTMLAnchorElement>;
let tocHeadings: HTMLElement[] = [];
const tocHeadings: HTMLElement[] = [];
let pageHeader: HTMLElement | null;

function handleScroll(): void {
Expand Down
9 changes: 7 additions & 2 deletions src/ts/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { getById , toggleAttribute , isPrintableCharacter ,keyCodes, getByClass ,listen } from "./utils";
import { button , click , ariaExpanded , keydown , active} from "./constants";
declare type Callback = (element: HTMLElement) => void;

/* tslint:disable */
interface Window {
export {}; // Make this a module

declare global {
interface Window {
observeResize(el: HTMLElement, callback: Callback): void;
}
}
/* tslint:enable */

Expand Down
4 changes: 3 additions & 1 deletion src/ts/tabset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { getById , listen , keyCodes , isPrintableCharacter} from "./utils";
import { ariaControls, ariaSelected, button, keydown, tabIndex } from "./constants";
import { readLocalStorage } from "./themes_init";
function selectTabsets(categoryName: string, categoryValue: string): void {
document.querySelectorAll(".tabset").forEach(tabset => {
tabset.querySelectorAll(".tab-strip").forEach(o => {
Expand Down
4 changes: 3 additions & 1 deletion src/ts/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { listen , getById} from "./utils";
import { click } from "./constants";
import { applyStyleSheet , lightThemeItem , currentTheme , lightTheme , themeStorageItem , darkThemeItem , darkTheme} from "./themes_init";
function handleThemes(): void {
// reapply this in case the first call didn't 'stick' due to timing
applyStyleSheet(currentTheme);
Expand Down
31 changes: 17 additions & 14 deletions src/ts/themes_init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const darkThemeClass = "dark-theme";
const darkTheme = "Dark Theme";
const darkThemeItem = "dark-theme-item";
const lightTheme = "Light Theme";
const lightThemeItem = "light-theme-item";
const themeStorageItem = "style";

function applyStyleSheet(theme: string | null): void {
export const darkThemeClass = "dark-theme";
export const darkTheme = "Dark Theme";
export const darkThemeItem = "dark-theme-item";
export const lightTheme = "Light Theme";
export const lightThemeItem = "light-theme-item";
export const themeStorageItem = "style";

// Export should be defined at the top of the module

export let currentTheme = readLocalStorage(themeStorageItem);

export function applyStyleSheet(theme: string | null): void {
// convert legacy cookie values
if (theme === "dark") {
theme = darkTheme;
Expand All @@ -38,23 +42,23 @@ function applyStyleSheet(theme: string | null): void {
let item = document.getElementById(lightThemeItem);
if (item) {
if (theme === darkTheme) {
item.classList.remove(active);
item.classList.remove("active");
} else {
item.classList.add(active);
item.classList.add("active");
}
}

item = document.getElementById(darkThemeItem);
if (item) {
if (theme === darkTheme) {
item.classList.add(active);
item.classList.add("active");
} else {
item.classList.remove(active);
item.classList.remove("active");
}
}
}

function readLocalStorage(name: string): string | null {
export function readLocalStorage(name: string): string | null {
let value = localStorage.getItem(name);
if (value) {
return value;
Expand Down Expand Up @@ -93,7 +97,6 @@ function readSystemDefault(): string | null {
return null;
}

let currentTheme = readLocalStorage(themeStorageItem);
if (currentTheme === null) {
currentTheme = readSystemDefault();
}
Expand Down
Loading