From c458a8c74637a09521c6122891732b941295ae1e Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Wed, 13 Aug 2025 17:38:11 +0530 Subject: [PATCH 01/20] chore: fuselageSnap local init --- .../loki/fuselageSnap/src/git/git_local.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/actions/loki/fuselageSnap/src/git/git_local.js diff --git a/.github/actions/loki/fuselageSnap/src/git/git_local.js b/.github/actions/loki/fuselageSnap/src/git/git_local.js new file mode 100644 index 0000000000..5c17349399 --- /dev/null +++ b/.github/actions/loki/fuselageSnap/src/git/git_local.js @@ -0,0 +1,18 @@ +import { execa } from 'execa'; + +export async function getChangedFile(headCommit) { + // `git --no-pager diff --name-only --no-relative ${baseCommit} ${headCommit}` + const { stdout } = await execa('git', [ + '--no-pager', + 'diff', + '--name-only', + '--no-relative', + headCommit, + ]); + const changedFile = stdout.split('\n'); + // console.log(headCommit); + // see the changed files using the sha + return changedFile; +} +const temp = await getChangedFile('fa873a105b7c304fad6c580d0d65d340e99f1a37'); +console.log(temp); From b48be509e3b32f990d196bccdd3397468bbadca3 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Wed, 13 Aug 2025 19:06:39 +0530 Subject: [PATCH 02/20] chore: add local changed file --- tools/fuselageSnap-local/.gitignore | 2 ++ tools/fuselageSnap-local/.prettierignore | 2 ++ .../bin/fuselagesnap-local.js | 11 +++++++++++ tools/fuselageSnap-local/package.json | 12 ++++++++++++ .../fuselageSnap-local/src}/git_local.js | 4 +--- tools/fuselageSnap-local/tsconfig.json | 19 +++++++++++++++++++ yarn.lock | 8 ++++++++ 7 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 tools/fuselageSnap-local/.gitignore create mode 100644 tools/fuselageSnap-local/.prettierignore create mode 100755 tools/fuselageSnap-local/bin/fuselagesnap-local.js create mode 100644 tools/fuselageSnap-local/package.json rename {.github/actions/loki/fuselageSnap/src/git => tools/fuselageSnap-local/src}/git_local.js (72%) create mode 100644 tools/fuselageSnap-local/tsconfig.json diff --git a/tools/fuselageSnap-local/.gitignore b/tools/fuselageSnap-local/.gitignore new file mode 100644 index 0000000000..76add878f8 --- /dev/null +++ b/tools/fuselageSnap-local/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/tools/fuselageSnap-local/.prettierignore b/tools/fuselageSnap-local/.prettierignore new file mode 100644 index 0000000000..c37e8bdbd5 --- /dev/null +++ b/tools/fuselageSnap-local/.prettierignore @@ -0,0 +1,2 @@ +/node_modules +!.* \ No newline at end of file diff --git a/tools/fuselageSnap-local/bin/fuselagesnap-local.js b/tools/fuselageSnap-local/bin/fuselagesnap-local.js new file mode 100755 index 0000000000..c78f5acd31 --- /dev/null +++ b/tools/fuselageSnap-local/bin/fuselagesnap-local.js @@ -0,0 +1,11 @@ +import { getChangedFileLocal } from '../src/git_local.js' +import { execa } from 'execa'; + +// const log = await getChangedFileLocal('c458a8c74637a09521c6122891732b941295ae1e') +// git rev-parse HEAD +async function run() { + const headCommit = await execa`git rev-parse HEAD`; + const changedFiles = await getChangedFileLocal(headCommit.stdout); + console.log(changedFiles); +} +run(); \ No newline at end of file diff --git a/tools/fuselageSnap-local/package.json b/tools/fuselageSnap-local/package.json new file mode 100644 index 0000000000..8905cf985f --- /dev/null +++ b/tools/fuselageSnap-local/package.json @@ -0,0 +1,12 @@ +{ + "private": true, + "name": "fuselagesnap-local", + "scripts": { + "build": "tsc -p tsconfig.json", + "lint": "lint .", + "lint-and-fix": "lint-and-fix" + }, + "type": "module", + "bin": "bin/fuselagesnap-local.js", + "version": "0.0.1" +} diff --git a/.github/actions/loki/fuselageSnap/src/git/git_local.js b/tools/fuselageSnap-local/src/git_local.js similarity index 72% rename from .github/actions/loki/fuselageSnap/src/git/git_local.js rename to tools/fuselageSnap-local/src/git_local.js index 5c17349399..5d99f3e0f1 100644 --- a/.github/actions/loki/fuselageSnap/src/git/git_local.js +++ b/tools/fuselageSnap-local/src/git_local.js @@ -1,6 +1,6 @@ import { execa } from 'execa'; -export async function getChangedFile(headCommit) { +export async function getChangedFileLocal(headCommit) { // `git --no-pager diff --name-only --no-relative ${baseCommit} ${headCommit}` const { stdout } = await execa('git', [ '--no-pager', @@ -14,5 +14,3 @@ export async function getChangedFile(headCommit) { // see the changed files using the sha return changedFile; } -const temp = await getChangedFile('fa873a105b7c304fad6c580d0d65d340e99f1a37'); -console.log(temp); diff --git a/tools/fuselageSnap-local/tsconfig.json b/tools/fuselageSnap-local/tsconfig.json new file mode 100644 index 0000000000..db5bf9523e --- /dev/null +++ b/tools/fuselageSnap-local/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "allowJs": true, + "target": "ES2015", + "module": "CommonJS", + "lib": ["ES2020"], + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "resolveJsonModule": true, + "outDir": "./dist/" + }, + "exclude": ["./bin", "./dist"] +} diff --git a/yarn.lock b/yarn.lock index b6ca45cd37..0efd681c45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12661,6 +12661,14 @@ __metadata: languageName: node linkType: hard +"fuselagesnap-local@workspace:tools/fuselageSnap-local": + version: 0.0.0-use.local + resolution: "fuselagesnap-local@workspace:tools/fuselageSnap-local" + bin: + fuselagesnap-local: bin/fuselagesnap-local.js + languageName: unknown + linkType: soft + "fuselagesnap@workspace:.github/actions/loki/fuselageSnap": version: 0.0.0-use.local resolution: "fuselagesnap@workspace:.github/actions/loki/fuselageSnap" From 001e419030ceb0ed8ad98c3f7815f502880e599c Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Wed, 13 Aug 2025 19:22:45 +0530 Subject: [PATCH 03/20] chore: local logs affected components --- .../bin/fuselagesnap-local.js | 11 -- tools/fuselageSnap-local/bin/index.js | 109 ++++++++++++++++++ tools/fuselageSnap-local/package.json | 7 +- yarn.lock | 6 +- 4 files changed, 120 insertions(+), 13 deletions(-) delete mode 100755 tools/fuselageSnap-local/bin/fuselagesnap-local.js create mode 100755 tools/fuselageSnap-local/bin/index.js diff --git a/tools/fuselageSnap-local/bin/fuselagesnap-local.js b/tools/fuselageSnap-local/bin/fuselagesnap-local.js deleted file mode 100755 index c78f5acd31..0000000000 --- a/tools/fuselageSnap-local/bin/fuselagesnap-local.js +++ /dev/null @@ -1,11 +0,0 @@ -import { getChangedFileLocal } from '../src/git_local.js' -import { execa } from 'execa'; - -// const log = await getChangedFileLocal('c458a8c74637a09521c6122891732b941295ae1e') -// git rev-parse HEAD -async function run() { - const headCommit = await execa`git rev-parse HEAD`; - const changedFiles = await getChangedFileLocal(headCommit.stdout); - console.log(changedFiles); -} -run(); \ No newline at end of file diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js new file mode 100755 index 0000000000..2defacf319 --- /dev/null +++ b/tools/fuselageSnap-local/bin/index.js @@ -0,0 +1,109 @@ +import { writeFileSync } from 'fs'; +import { execa } from 'execa'; + +import { getChangedFileLocal } from '../src/git_local.js'; +import { getAffectedComponents } from '../../../.github/actions/loki/fuselageSnap/src/getAffectedComponents.js'; +import { readStatsFile } from '../../../.github/actions/loki/fuselageSnap/src/stats/readStatsFile.js'; +import { trimStatsFile } from '../../../.github/actions/loki/fuselageSnap/src/stats/trimStatsFile.js'; +import { copyFiles } from '../../../.github/actions/loki/fuselageSnap/src/utils/copyFiles.js'; +import { generateRegex } from '../../../.github/actions/loki/fuselageSnap/src/utils/generateRegex.js'; + +// yarn build-storybook --stats-json gives project-stats.json which has component titles +// where as index.json gives the webpack base dependency graph +// index.js run from the root of the project +const filesToCopy = [ + { + src: './packages/fuselage/storybook-static/index.json', + dest: '.github/actions/loki/fuselageSnap/dist/fuselage-sb.json', + }, + { + src: './packages/fuselage-toastbar/storybook-static/index.json', + dest: '.github/actions/loki/fuselageSnap/dist/fuselage-toastbar-sb.json', + }, + { + src: './packages/onboarding-ui/storybook-static/index.json', + dest: '.github/actions/loki/fuselageSnap/dist/onboarding-ui-sb.json', + }, + { + src: './packages/layout/storybook-static/index.json', + dest: '.github/actions/loki/fuselageSnap/dist/layout-sb.json', + }, + { + src: './packages/fuselage/storybook-static/preview-stats.json', + dest: '.github/actions/loki/fuselageSnap/dist/fuselage-stats.json', + }, + { + src: './packages/fuselage-toastbar/storybook-static/preview-stats.json', + dest: '.github/actions/loki/fuselageSnap/dist/fuselage-toastbar-stats.json', + }, + { + src: './packages/onboarding-ui/storybook-static/preview-stats.json', + dest: '.github/actions/loki/fuselageSnap/dist/onboarding-ui-stats.json', + }, + { + src: './packages/layout/storybook-static/preview-stats.json', + dest: '.github/actions/loki/fuselageSnap/dist/layout-stats.json', + }, +]; + +writeFileSync( + '.github/actions/loki/fuselageSnap/dist/save.json', + '{"file_names":[]}', + function (err) { + if (err) { + return console.log(err); + } + console.log('The file was saved!'); + }, +); +writeFileSync( + '.github/actions/loki/fuselageSnap/dist/non-storybook-files.json', + '{"file_names":[]}', + function (err) { + if (err) { + return console.log(err); + } + console.log('The file was saved!'); + }, +); + +async function run() { + // getTrimmedstats + const promises = []; + for (const { src, dest } of filesToCopy) { + copyFiles(src, dest); + if (dest.includes('stats')) { + const trimmedPath = `.github/actions/loki/fuselageSnap/dist/trimmed-${dest.split('/').slice(-1)}`; + promises.push(trimStatsFile(dest, trimmedPath)); + } + } + + await Promise.all(promises); + const headCommit = await execa`git rev-parse HEAD`; + const changedFiles = await getChangedFileLocal(headCommit.stdout); + const data = await getAffectedComponents(changedFiles); + const regex = generateRegex(data); + const nonStatsFileName = await readStatsFile( + '.github/actions/loki/fuselageSnap/dist/save.json', + ); + const nonStryBkFiles = await readStatsFile( + '.github/actions/loki/fuselageSnap/dist/non-storybook-files.json', + ); + if (regex.fuselage.length === 0) { + regex.fuselage = 'skip'; + } + if (regex['fuselage-toastbar'].length === 0) { + regex['fuselage-toastbar'] = 'skip'; + } + if (regex.layout.length === 0) { + regex.layout = 'skip'; + } + if (regex['onboarding-ui'].length === 0) { + regex['onboarding-ui'] = 'skip'; + } + console.log(regex['fuselage']); + console.log(regex['fuselage-toastbar']); + console.log(regex['layout']); + console.log(regex['onboarding-ui']); +} +run(); diff --git a/tools/fuselageSnap-local/package.json b/tools/fuselageSnap-local/package.json index 8905cf985f..356b5bde96 100644 --- a/tools/fuselageSnap-local/package.json +++ b/tools/fuselageSnap-local/package.json @@ -7,6 +7,11 @@ "lint-and-fix": "lint-and-fix" }, "type": "module", - "bin": "bin/fuselagesnap-local.js", + "bin": "bin/index.js", + "devDependencies": { + "eslint": "^9.29.0", + "lint-all": "workspace:~", + "prettier": "~3.5.3" + }, "version": "0.0.1" } diff --git a/yarn.lock b/yarn.lock index 0efd681c45..0053f0848e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12664,8 +12664,12 @@ __metadata: "fuselagesnap-local@workspace:tools/fuselageSnap-local": version: 0.0.0-use.local resolution: "fuselagesnap-local@workspace:tools/fuselageSnap-local" + dependencies: + eslint: "npm:^9.29.0" + lint-all: "workspace:~" + prettier: "npm:~3.5.3" bin: - fuselagesnap-local: bin/fuselagesnap-local.js + fuselagesnap-local: bin/index.js languageName: unknown linkType: soft From b54e30121e8222e5d88cd764a16892c731bf3623 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Wed, 13 Aug 2025 19:33:52 +0530 Subject: [PATCH 04/20] fix: lint --- package.json | 4 ++- tools/fuselageSnap-local/bin/index.js | 50 ++++++++++++--------------- yarn.lock | 3 +- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index d00939f5ef..7bde5ca310 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "update-storybook": "yarn turbo run update-storybook", "loki:test": "yarn turbo run loki:test --cache-dir=\".turbo\"", "loki:test-ci": "yarn turbo run loki:test-ci --cache-dir=\".turbo\"", - "update-readme": "update-readme" + "update-readme": "update-readme", + "fuselageSnap": "fuselagesnap-local" }, "devDependencies": { "@changesets/changelog-github": "~0.5.1", @@ -44,6 +45,7 @@ "eslint-plugin-react-hooks": "~5.2.0", "eslint-plugin-storybook": "~9.0.11", "execa": "~9.6.0", + "fuselagesnap-local": "workspace:~", "globals": "~16.2.0", "husky": "~9.1.7", "hygen": "~6.2.11", diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 2defacf319..e3af12c757 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -1,12 +1,12 @@ import { writeFileSync } from 'fs'; + import { execa } from 'execa'; -import { getChangedFileLocal } from '../src/git_local.js'; import { getAffectedComponents } from '../../../.github/actions/loki/fuselageSnap/src/getAffectedComponents.js'; -import { readStatsFile } from '../../../.github/actions/loki/fuselageSnap/src/stats/readStatsFile.js'; import { trimStatsFile } from '../../../.github/actions/loki/fuselageSnap/src/stats/trimStatsFile.js'; import { copyFiles } from '../../../.github/actions/loki/fuselageSnap/src/utils/copyFiles.js'; import { generateRegex } from '../../../.github/actions/loki/fuselageSnap/src/utils/generateRegex.js'; +import { getChangedFileLocal } from '../src/git_local.js'; // yarn build-storybook --stats-json gives project-stats.json which has component titles // where as index.json gives the webpack base dependency graph @@ -79,31 +79,25 @@ async function run() { } await Promise.all(promises); - const headCommit = await execa`git rev-parse HEAD`; - const changedFiles = await getChangedFileLocal(headCommit.stdout); - const data = await getAffectedComponents(changedFiles); - const regex = generateRegex(data); - const nonStatsFileName = await readStatsFile( - '.github/actions/loki/fuselageSnap/dist/save.json', - ); - const nonStryBkFiles = await readStatsFile( - '.github/actions/loki/fuselageSnap/dist/non-storybook-files.json', - ); - if (regex.fuselage.length === 0) { - regex.fuselage = 'skip'; - } - if (regex['fuselage-toastbar'].length === 0) { - regex['fuselage-toastbar'] = 'skip'; - } - if (regex.layout.length === 0) { - regex.layout = 'skip'; - } - if (regex['onboarding-ui'].length === 0) { - regex['onboarding-ui'] = 'skip'; - } - console.log(regex['fuselage']); - console.log(regex['fuselage-toastbar']); - console.log(regex['layout']); - console.log(regex['onboarding-ui']); + const headCommit = await execa`git rev-parse HEAD`; + const changedFiles = await getChangedFileLocal(headCommit.stdout); + const data = await getAffectedComponents(changedFiles); + const regex = generateRegex(data); + if (regex.fuselage.length === 0) { + regex.fuselage = 'skip'; + } + if (regex['fuselage-toastbar'].length === 0) { + regex['fuselage-toastbar'] = 'skip'; + } + if (regex.layout.length === 0) { + regex.layout = 'skip'; + } + if (regex['onboarding-ui'].length === 0) { + regex['onboarding-ui'] = 'skip'; + } + console.log(regex.fuselage); + console.log(regex['fuselage-toastbar']); + console.log(regex.layout); + console.log(regex['onboarding-ui']); } run(); diff --git a/yarn.lock b/yarn.lock index 0053f0848e..502bcc6fd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5548,6 +5548,7 @@ __metadata: eslint-plugin-react-hooks: "npm:~5.2.0" eslint-plugin-storybook: "npm:~9.0.11" execa: "npm:~9.6.0" + fuselagesnap-local: "workspace:~" globals: "npm:~16.2.0" husky: "npm:~9.1.7" hygen: "npm:~6.2.11" @@ -12661,7 +12662,7 @@ __metadata: languageName: node linkType: hard -"fuselagesnap-local@workspace:tools/fuselageSnap-local": +"fuselagesnap-local@workspace:tools/fuselageSnap-local, fuselagesnap-local@workspace:~": version: 0.0.0-use.local resolution: "fuselagesnap-local@workspace:tools/fuselageSnap-local" dependencies: From 35cd741fc58ed084240943a814ec0b62e3ba7203 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Thu, 14 Aug 2025 00:49:45 +0530 Subject: [PATCH 05/20] chore: local suppport complete --- tools/fuselageSnap-local/bin/index.js | 97 ++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 8 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index e3af12c757..60dae1cef3 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -1,3 +1,4 @@ +import { spawn } from 'child_process'; import { writeFileSync } from 'fs'; import { execa } from 'execa'; @@ -11,6 +12,24 @@ import { getChangedFileLocal } from '../src/git_local.js'; // yarn build-storybook --stats-json gives project-stats.json which has component titles // where as index.json gives the webpack base dependency graph // index.js run from the root of the project +export const execCommand = (command) => { + return new Promise((resolve, reject) => { + const childProcess = spawn(command, { + stdio: 'inherit', + shell: true, + }); + childProcess.on('error', (error) => { + reject(error); + }); + childProcess.on('exit', (code) => { + if (code === 0) { + resolve(); + } else { + reject(new Error(`Command exited with code ${code}.`)); + } + }); + }); +}; const filesToCopy = [ { src: './packages/fuselage/storybook-static/index.json', @@ -83,21 +102,83 @@ async function run() { const changedFiles = await getChangedFileLocal(headCommit.stdout); const data = await getAffectedComponents(changedFiles); const regex = generateRegex(data); + + const colorize = (...args) => ({ + black: `\x1b[30m${args.join(' ')}`, + red: `\x1b[31m${args.join(' ')}`, + green: `\x1b[32m${args.join(' ')}`, + yellow: `\x1b[33m${args.join(' ')}`, + blue: `\x1b[34m${args.join(' ')}`, + magenta: `\x1b[35m${args.join(' ')}`, + cyan: `\x1b[36m${args.join(' ')}`, + white: `\x1b[37m${args.join(' ')}`, + bgBlack: `\x1b[40m${args.join(' ')}\x1b[0m`, + bgRed: `\x1b[41m${args.join(' ')}\x1b[0m`, + bgGreen: `\x1b[42m${args.join(' ')}\x1b[0m`, + bgYellow: `\x1b[43m${args.join(' ')}\x1b[0m`, + bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`, + bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`, + bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`, + bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`, + }); + console.log( + colorize('Remember to git add . your changes before running fuselageSnap') + .magenta, + ); if (regex.fuselage.length === 0) { - regex.fuselage = 'skip'; + console.log( + colorize('skipping fuselage no affected components found').green, + ); + } else if (regex.fuselage === 'full test') { + console.log(colorize('Running full visual tests for fuselage').green); + await execCommand('cd packages/fuselage && yarn loki:test'); + } else { + console.log(colorize('Running fuselageSnap for fuselage ').bgBlue); + await execCommand( + `cd packages/fuselage && yarn loki:test --storiesFilter="${regex.fuselage}"`, + ); } + if (regex['fuselage-toastbar'].length === 0) { - regex['fuselage-toastbar'] = 'skip'; + console.log( + colorize('skipping fuselage-toastbar no affected components found').green, + ); + } else if (regex['fuselage-toastbar'] === 'full test') { + console.log( + colorize('Running full visual tests for fuselage-toastbar').green, + ); + await execCommand('cd packages/fuselage-toastbar && yarn loki:test'); + } else { + console.log(colorize('Running fuselageSnap for fuselage-toastbar ').bgBlue); + await execCommand( + `cd packages/fuselage-toastbar && yarn loki:test --storiesFilter="${regex['fuselage-toastbar']}`, + ); } + if (regex.layout.length === 0) { - regex.layout = 'skip'; + console.log(colorize('skipping layout no affected components found').green); + } else if (regex.layout === 'full test') { + console.log(colorize('Running full visual tests for layout').green); + await execCommand('cd packages/layout && yarn loki:test'); + } else { + console.log(colorize('Running fuselageSnap for layout ').bgBlue); + await execCommand( + `cd packages/layout && yarn loki:test --storiesFilter="${regex.layout}`, + ); } + if (regex['onboarding-ui'].length === 0) { - regex['onboarding-ui'] = 'skip'; + console.log( + colorize('skipping onboarding-ui no affected components found').green, + ); + } else if (regex['onboarding-ui'] === 'full test') { + console.log(colorize('Running full visual tests for onboarding-ui').green); + await execCommand('cd packages/onboarding-ui && yarn loki:test'); + } else { + console.log(colorize('Running fuselageSnap for onboarding-ui ').bgBlue); + await execCommand( + `cd packages/onboarding-ui && yarn loki:test --storiesFilter="${regex['onboarding-ui']}`, + ); } - console.log(regex.fuselage); - console.log(regex['fuselage-toastbar']); - console.log(regex.layout); - console.log(regex['onboarding-ui']); } run(); From 1505c40930b9548b529cba66d50035a4c7bafbc7 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 00:28:53 +0530 Subject: [PATCH 06/20] chore: remove full test trigger on tools change --- .github/actions/loki/fuselageSnap/src/getAffectedComponents.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js index 69c51ee6be..f49b244b1d 100644 --- a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js +++ b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js @@ -96,7 +96,7 @@ async function mergeCmpDeps(saveDirectDps, saveIndirectDps, pkgToFileMap) { function potentialFullTest(changedFiles) { for (const file of changedFiles) { - if (file.includes('tools') || file.includes('yarn.lock')) { + if (file.includes('yarn.lock')) { return true; } const pkg = file.split('/')[0]; From 47e2f451714300cfefa42f9b80dd142bd613d4fb Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 00:50:46 +0530 Subject: [PATCH 07/20] chore: add promise resolve on exit and fix unterminated quoted string --- tools/fuselageSnap-local/bin/index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 60dae1cef3..280369a1b0 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -22,11 +22,7 @@ export const execCommand = (command) => { reject(error); }); childProcess.on('exit', (code) => { - if (code === 0) { - resolve(); - } else { - reject(new Error(`Command exited with code ${code}.`)); - } + resolve(); }); }); }; @@ -133,12 +129,13 @@ async function run() { console.log(colorize('Running full visual tests for fuselage').green); await execCommand('cd packages/fuselage && yarn loki:test'); } else { - console.log(colorize('Running fuselageSnap for fuselage ').bgBlue); + console.log(colorize('Running fuselageSnap for fuselage ').green); await execCommand( `cd packages/fuselage && yarn loki:test --storiesFilter="${regex.fuselage}"`, ); } + if (regex['fuselage-toastbar'].length === 0) { console.log( colorize('skipping fuselage-toastbar no affected components found').green, @@ -151,7 +148,7 @@ async function run() { } else { console.log(colorize('Running fuselageSnap for fuselage-toastbar ').bgBlue); await execCommand( - `cd packages/fuselage-toastbar && yarn loki:test --storiesFilter="${regex['fuselage-toastbar']}`, + `cd packages/fuselage-toastbar && yarn loki:test --storiesFilter="${regex['fuselage-toastbar']}"`, ); } @@ -163,7 +160,7 @@ async function run() { } else { console.log(colorize('Running fuselageSnap for layout ').bgBlue); await execCommand( - `cd packages/layout && yarn loki:test --storiesFilter="${regex.layout}`, + `cd packages/layout && yarn loki:test --storiesFilter="${regex.layout}"`, ); } @@ -177,7 +174,7 @@ async function run() { } else { console.log(colorize('Running fuselageSnap for onboarding-ui ').bgBlue); await execCommand( - `cd packages/onboarding-ui && yarn loki:test --storiesFilter="${regex['onboarding-ui']}`, + `cd packages/onboarding-ui && yarn loki:test --storiesFilter="${regex['onboarding-ui']}"`, ); } } From 049c9214b4c0c481ae8ef19c62548b31ce950b61 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 01:37:47 +0530 Subject: [PATCH 08/20] refactor: used loops instead of if statements --- tools/fuselageSnap-local/bin/index.js | 78 +++++++-------------------- 1 file changed, 18 insertions(+), 60 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 280369a1b0..0f9cbfc553 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -21,7 +21,7 @@ export const execCommand = (command) => { childProcess.on('error', (error) => { reject(error); }); - childProcess.on('exit', (code) => { + childProcess.on('exit', () => { resolve(); }); }); @@ -117,65 +117,23 @@ async function run() { bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`, bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`, }); - console.log( - colorize('Remember to git add . your changes before running fuselageSnap') - .magenta, - ); - if (regex.fuselage.length === 0) { - console.log( - colorize('skipping fuselage no affected components found').green, - ); - } else if (regex.fuselage === 'full test') { - console.log(colorize('Running full visual tests for fuselage').green); - await execCommand('cd packages/fuselage && yarn loki:test'); - } else { - console.log(colorize('Running fuselageSnap for fuselage ').green); - await execCommand( - `cd packages/fuselage && yarn loki:test --storiesFilter="${regex.fuselage}"`, - ); - } - - - if (regex['fuselage-toastbar'].length === 0) { - console.log( - colorize('skipping fuselage-toastbar no affected components found').green, - ); - } else if (regex['fuselage-toastbar'] === 'full test') { - console.log( - colorize('Running full visual tests for fuselage-toastbar').green, - ); - await execCommand('cd packages/fuselage-toastbar && yarn loki:test'); - } else { - console.log(colorize('Running fuselageSnap for fuselage-toastbar ').bgBlue); - await execCommand( - `cd packages/fuselage-toastbar && yarn loki:test --storiesFilter="${regex['fuselage-toastbar']}"`, - ); - } - - if (regex.layout.length === 0) { - console.log(colorize('skipping layout no affected components found').green); - } else if (regex.layout === 'full test') { - console.log(colorize('Running full visual tests for layout').green); - await execCommand('cd packages/layout && yarn loki:test'); - } else { - console.log(colorize('Running fuselageSnap for layout ').bgBlue); - await execCommand( - `cd packages/layout && yarn loki:test --storiesFilter="${regex.layout}"`, - ); - } - - if (regex['onboarding-ui'].length === 0) { - console.log( - colorize('skipping onboarding-ui no affected components found').green, - ); - } else if (regex['onboarding-ui'] === 'full test') { - console.log(colorize('Running full visual tests for onboarding-ui').green); - await execCommand('cd packages/onboarding-ui && yarn loki:test'); - } else { - console.log(colorize('Running fuselageSnap for onboarding-ui ').bgBlue); - await execCommand( - `cd packages/onboarding-ui && yarn loki:test --storiesFilter="${regex['onboarding-ui']}"`, - ); + // await execCommand('yarn build-storybook'); + const pkgs = ['fuselage', 'fuselage-toastbar', 'layout', 'onboarding-ui']; + /* eslint-disable no-await-in-loop */ + for (const pkg of pkgs) { + if (regex[`${pkg}`].length === 0) { + console.log( + colorize(`skipping ${pkg} no affected components found`).bgBlue, + ); + } else if (regex[`${pkg}`] === 'full test') { + console.log(colorize(`Running full visual tests for ${pkg}`).bgBlue); + await execCommand(`cd packages/${pkg} && yarn loki:test`); + } else { + console.log(colorize(`Running fuselageSnap for ${pkg}`).bgBlue); + await execCommand( + `cd packages/${pkg} && yarn loki:test --storiesFilter="${regex[pkg]}"`, + ); + } } } run(); From 1fb7f1a53544d235f3ed02a67735a30bfc9af061 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 01:58:48 +0530 Subject: [PATCH 09/20] chore: add build-storybook before fuselageSnap run --- tools/fuselageSnap-local/bin/index.js | 43 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 0f9cbfc553..b63b03895e 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -12,20 +12,6 @@ import { getChangedFileLocal } from '../src/git_local.js'; // yarn build-storybook --stats-json gives project-stats.json which has component titles // where as index.json gives the webpack base dependency graph // index.js run from the root of the project -export const execCommand = (command) => { - return new Promise((resolve, reject) => { - const childProcess = spawn(command, { - stdio: 'inherit', - shell: true, - }); - childProcess.on('error', (error) => { - reject(error); - }); - childProcess.on('exit', () => { - resolve(); - }); - }); -}; const filesToCopy = [ { src: './packages/fuselage/storybook-static/index.json', @@ -61,6 +47,21 @@ const filesToCopy = [ }, ]; +export const execCommand = (command) => { + return new Promise((resolve, reject) => { + const childProcess = spawn(command, { + stdio: 'inherit', + shell: true, + }); + childProcess.on('error', (error) => { + reject(error); + }); + childProcess.on('exit', () => { + resolve(); + }); + }); +}; + writeFileSync( '.github/actions/loki/fuselageSnap/dist/save.json', '{"file_names":[]}', @@ -98,6 +99,7 @@ async function run() { const changedFiles = await getChangedFileLocal(headCommit.stdout); const data = await getAffectedComponents(changedFiles); const regex = generateRegex(data); + const pkgs = ['fuselage', 'fuselage-toastbar', 'layout', 'onboarding-ui']; const colorize = (...args) => ({ black: `\x1b[30m${args.join(' ')}`, @@ -118,8 +120,19 @@ async function run() { bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`, }); // await execCommand('yarn build-storybook'); - const pkgs = ['fuselage', 'fuselage-toastbar', 'layout', 'onboarding-ui']; /* eslint-disable no-await-in-loop */ + if (regex.fuselage.length > 0) { + await execCommand('yarn build-storybook'); + } else if (regex['fuselage-toastbar'].length > 0) { + await execCommand('cd packages/fuselage-toastbar && yarn build-storybook'); + } else if (regex.layout.length > 0) { + await execCommand('cd packages/fuselage-toastbar && yarn build-storybook'); + await execCommand('cd packages/onboarding-ui && yarn build-storybook'); + await execCommand('cd packages/layout && yarn build-storybook'); + } else if (regex['onboarding-ui'].length > 0) { + await execCommand('cd packages/onboarding-ui && yarn build-storybook'); + } + for (const pkg of pkgs) { if (regex[`${pkg}`].length === 0) { console.log( From eeb78c792cdddd430482a67bbf36fef31332912d Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 02:12:25 +0530 Subject: [PATCH 10/20] update --- tools/fuselageSnap-local/package.json | 1 - tools/fuselageSnap-local/tsconfig.json | 19 ------------------- 2 files changed, 20 deletions(-) delete mode 100644 tools/fuselageSnap-local/tsconfig.json diff --git a/tools/fuselageSnap-local/package.json b/tools/fuselageSnap-local/package.json index 356b5bde96..7b72f9e15a 100644 --- a/tools/fuselageSnap-local/package.json +++ b/tools/fuselageSnap-local/package.json @@ -2,7 +2,6 @@ "private": true, "name": "fuselagesnap-local", "scripts": { - "build": "tsc -p tsconfig.json", "lint": "lint .", "lint-and-fix": "lint-and-fix" }, diff --git a/tools/fuselageSnap-local/tsconfig.json b/tools/fuselageSnap-local/tsconfig.json deleted file mode 100644 index db5bf9523e..0000000000 --- a/tools/fuselageSnap-local/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "target": "ES2015", - "module": "CommonJS", - "lib": ["ES2020"], - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", - "resolveJsonModule": true, - "outDir": "./dist/" - }, - "exclude": ["./bin", "./dist"] -} From 278001a8595bd8dc449c4680494017becdb92240 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 17:17:13 +0530 Subject: [PATCH 11/20] chore: add scss file support --- .../fuselageSnap/src/getAffectedComponents.js | 81 +++++++++++-------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js index f49b244b1d..8fe480eb9f 100644 --- a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js +++ b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js @@ -123,41 +123,56 @@ export const getAffectedComponents = async (changedFiles) => { layout, }; } - const filterChangedFiles = []; - const unfilteredChangedFiles = []; - for (const file of changedFiles) { - if (file.includes('packages')) { - filterChangedFiles.push(file); - } else { - unfilteredChangedFiles.push(file); + else { + const filterChangedFiles = []; + const unfilteredChangedFiles = []; + for (const file of changedFiles) { + if (file.includes('packages')) { + // SCSS files are not included in the webpack dependency graph. + // If a changed file is a `*.styles.scss` inside `components/`, + // map it to its parent component’s `.tsx` file. + // Example: `Button.styles.scss` → `Button.tsx` + if(file.includes('styles.scss') && file.includes('components')) { + const part = file.split('/'); + const replace = part[part.length-2]; + part[part.length-1] = `${replace}.tsx`; + filterChangedFiles.push(part.join('/')); + } + else { + filterChangedFiles.push(file); + } + } else { + unfilteredChangedFiles.push(file); + } } - } - const promises = []; - for (const file of unfilteredChangedFiles) { - promises.push( - getNonStatsFile( - file, - '.github/actions/loki/fuselageSnap/dist/non-storybook-files', - ), - ); - } - await Promise.all(promises); - const map = mapPackagesToFilePath(filterChangedFiles); - const directDepsPromises = []; - const indirectDepsPromises = []; - const pkgNames = []; + const promises = []; + for (const file of unfilteredChangedFiles) { + promises.push( + getNonStatsFile( + file, + '.github/actions/loki/fuselageSnap/dist/non-storybook-files', + ), + ); + } + await Promise.all(promises); + const map = mapPackagesToFilePath(filterChangedFiles); + const directDepsPromises = []; + const indirectDepsPromises = []; + const pkgNames = []; - for (const pkgName in map) { - if (Object.prototype.hasOwnProperty.call(map, pkgName)) { - pkgNames.push(pkgName); - directDepsPromises.push(getDirectDependencies(map[pkgName], pkgName)); - indirectDepsPromises.push(getIndirectDps(pkgName)); + for (const pkgName in map) { + if (Object.prototype.hasOwnProperty.call(map, pkgName)) { + pkgNames.push(pkgName); + directDepsPromises.push(getDirectDependencies(map[pkgName], pkgName)); + indirectDepsPromises.push(getIndirectDps(pkgName)); + } } - } - const saveDirectDps = await Promise.all(directDepsPromises); - const saveIndirectDps = await Promise.all(indirectDepsPromises); + const saveDirectDps = await Promise.all(directDepsPromises); + const saveIndirectDps = await Promise.all(indirectDepsPromises); - const result = await mergeCmpDeps(saveDirectDps, saveIndirectDps, map); - return result; -}; + const result = await mergeCmpDeps(saveDirectDps, saveIndirectDps, map); + return result; + + } + }; From 63f09505d99db282c0c08c8b70b1935f4846a0ca Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 17:26:24 +0530 Subject: [PATCH 12/20] fix: lint --- .../fuselageSnap/src/getAffectedComponents.js | 89 +++++++++---------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js index 8fe480eb9f..9de548b705 100644 --- a/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js +++ b/.github/actions/loki/fuselageSnap/src/getAffectedComponents.js @@ -123,56 +123,53 @@ export const getAffectedComponents = async (changedFiles) => { layout, }; } - else { - const filterChangedFiles = []; - const unfilteredChangedFiles = []; - for (const file of changedFiles) { - if (file.includes('packages')) { - // SCSS files are not included in the webpack dependency graph. - // If a changed file is a `*.styles.scss` inside `components/`, - // map it to its parent component’s `.tsx` file. - // Example: `Button.styles.scss` → `Button.tsx` - if(file.includes('styles.scss') && file.includes('components')) { - const part = file.split('/'); - const replace = part[part.length-2]; - part[part.length-1] = `${replace}.tsx`; - filterChangedFiles.push(part.join('/')); - } - else { - filterChangedFiles.push(file); - } + + const filterChangedFiles = []; + const unfilteredChangedFiles = []; + for (const file of changedFiles) { + if (file.includes('packages')) { + // SCSS files are not included in the webpack dependency graph. + // If a changed file is a `*.styles.scss` inside `components/`, + // map it to its parent component’s `.tsx` file. + // Example: `Button.styles.scss` → `Button.tsx` + if (file.includes('styles.scss') && file.includes('components')) { + const part = file.split('/'); + const replace = part[part.length - 2]; + part[part.length - 1] = `${replace}.tsx`; + filterChangedFiles.push(part.join('/')); } else { - unfilteredChangedFiles.push(file); + filterChangedFiles.push(file); } + } else { + unfilteredChangedFiles.push(file); } - const promises = []; - for (const file of unfilteredChangedFiles) { - promises.push( - getNonStatsFile( - file, - '.github/actions/loki/fuselageSnap/dist/non-storybook-files', - ), - ); - } - await Promise.all(promises); - const map = mapPackagesToFilePath(filterChangedFiles); - const directDepsPromises = []; - const indirectDepsPromises = []; - const pkgNames = []; + } + const promises = []; + for (const file of unfilteredChangedFiles) { + promises.push( + getNonStatsFile( + file, + '.github/actions/loki/fuselageSnap/dist/non-storybook-files', + ), + ); + } + await Promise.all(promises); + const map = mapPackagesToFilePath(filterChangedFiles); + const directDepsPromises = []; + const indirectDepsPromises = []; + const pkgNames = []; - for (const pkgName in map) { - if (Object.prototype.hasOwnProperty.call(map, pkgName)) { - pkgNames.push(pkgName); - directDepsPromises.push(getDirectDependencies(map[pkgName], pkgName)); - indirectDepsPromises.push(getIndirectDps(pkgName)); - } + for (const pkgName in map) { + if (Object.prototype.hasOwnProperty.call(map, pkgName)) { + pkgNames.push(pkgName); + directDepsPromises.push(getDirectDependencies(map[pkgName], pkgName)); + indirectDepsPromises.push(getIndirectDps(pkgName)); } + } - const saveDirectDps = await Promise.all(directDepsPromises); - const saveIndirectDps = await Promise.all(indirectDepsPromises); - - const result = await mergeCmpDeps(saveDirectDps, saveIndirectDps, map); - return result; + const saveDirectDps = await Promise.all(directDepsPromises); + const saveIndirectDps = await Promise.all(indirectDepsPromises); - } - }; + const result = await mergeCmpDeps(saveDirectDps, saveIndirectDps, map); + return result; +}; From 659a6d3ca30362d2296a4c83471ae2aad4a99a31 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 19:11:28 +0530 Subject: [PATCH 13/20] refactor: used seperate function to get relevant graph --- .../fuselageSnap/src/getIndirectDependency.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js index 4901939d8e..17ab00dc6c 100644 --- a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js +++ b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js @@ -74,18 +74,30 @@ const graph = [ { 'tools-utils': 'lint-all' }, { 'update-readme': 'lint-all' }, ]; - /** * * @param {string} pkgName - Name of the package that a changed file belongs to. * @returns {Promise>>>} - A list of objects where each key is the dependent package name * and the value is a Set of affected component titles. */ -export const getIndirectDps = async (pkgName) => { +export const getRelevantGraph = (pkgName) => { const relevantGraph = graph.filter((obj) => { const key = Object.keys(obj)[0]; - return isStoryBookPkg(key) && Object.values(obj)[0] === pkgName; + if (isStoryBookPkg(key) && Object.values(obj)[0] === pkgName) { + return key; + } + return ''; }); + return relevantGraph; +}; +export const getIndirectDps = async (pkgName) => { + const relevantGraph = getRelevantGraph(pkgName); + // for(const temp of relevantGraph) { + // console.log(temp.length); + // console.log(Object.keys(temp)[0]); + // console.log(Object.values(temp)[0]); + // } + console.log(relevantGraph); const promises = relevantGraph.map(async (obj) => { const key = Object.keys(obj)[0]; @@ -100,3 +112,5 @@ export const getIndirectDps = async (pkgName) => { const overall = await Promise.all(promises); return overall; }; + +await getIndirectDps('layout'); From 0e66395392beaee40759168f063a625ee91882dd Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 21:53:50 +0530 Subject: [PATCH 14/20] chore: add transitive dependency --- .../fuselageSnap/src/getIndirectDependency.js | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js index 17ab00dc6c..f5ee3a9502 100644 --- a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js +++ b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js @@ -83,22 +83,31 @@ const graph = [ export const getRelevantGraph = (pkgName) => { const relevantGraph = graph.filter((obj) => { const key = Object.keys(obj)[0]; - if (isStoryBookPkg(key) && Object.values(obj)[0] === pkgName) { - return key; - } - return ''; + return isStoryBookPkg(key) && Object.values(obj)[0] === pkgName; }); return relevantGraph; }; export const getIndirectDps = async (pkgName) => { const relevantGraph = getRelevantGraph(pkgName); - // for(const temp of relevantGraph) { - // console.log(temp.length); - // console.log(Object.keys(temp)[0]); - // console.log(Object.values(temp)[0]); - // } - console.log(relevantGraph); - + const transitive = []; + for (const obj of relevantGraph) { + transitive.push(getRelevantGraph(Object.keys(obj)[0])); + } + for (const arr of transitive) { + for (const obj_tr of arr) { + const transitive_keys = Object.keys(obj_tr)[0]; + let isPresent = 0; + for (const obj_rel of relevantGraph) { + const rel_keys = Object.keys(obj_rel)[0]; + if (transitive_keys === rel_keys) { + isPresent = 1; + } + } + if (isPresent === 0) { + relevantGraph.push(obj_tr); + } + } + } const promises = relevantGraph.map(async (obj) => { const key = Object.keys(obj)[0]; const result = await getReasons( @@ -112,5 +121,3 @@ export const getIndirectDps = async (pkgName) => { const overall = await Promise.all(promises); return overall; }; - -await getIndirectDps('layout'); From bef1d4e07ebebd6b3f496a5fee4550ab762a2121 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sat, 16 Aug 2025 23:19:20 +0530 Subject: [PATCH 15/20] refactor: used own function to merge dependencies --- .../fuselageSnap/src/getIndirectDependency.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js index f5ee3a9502..86e7d38f62 100644 --- a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js +++ b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js @@ -80,18 +80,18 @@ const graph = [ * @returns {Promise>>>} - A list of objects where each key is the dependent package name * and the value is a Set of affected component titles. */ -export const getRelevantGraph = (pkgName) => { - const relevantGraph = graph.filter((obj) => { +export const traverseGraph = (pkgName) => { + const traversedData = graph.filter((obj) => { const key = Object.keys(obj)[0]; return isStoryBookPkg(key) && Object.values(obj)[0] === pkgName; }); - return relevantGraph; + return traversedData; }; -export const getIndirectDps = async (pkgName) => { - const relevantGraph = getRelevantGraph(pkgName); +export const mergePkgsObj = (pkgName) => { + const relevantGraph = traverseGraph(pkgName); const transitive = []; for (const obj of relevantGraph) { - transitive.push(getRelevantGraph(Object.keys(obj)[0])); + transitive.push(traverseGraph(Object.keys(obj)[0])); } for (const arr of transitive) { for (const obj_tr of arr) { @@ -108,6 +108,11 @@ export const getIndirectDps = async (pkgName) => { } } } + return relevantGraph; +}; +export const getIndirectDps = async (pkgName) => { + const relevantGraph = mergePkgsObj(pkgName); + console.log(relevantGraph); const promises = relevantGraph.map(async (obj) => { const key = Object.keys(obj)[0]; const result = await getReasons( From dc6d6260afdd37bbf14e67e5581e540db327f5ba Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sun, 17 Aug 2025 00:30:21 +0530 Subject: [PATCH 16/20] chore: build storybook of the affected packages --- tools/fuselageSnap-local/bin/index.js | 66 +++++++++++++++++++-------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index b63b03895e..1fcd0464d2 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -4,11 +4,11 @@ import { writeFileSync } from 'fs'; import { execa } from 'execa'; import { getAffectedComponents } from '../../../.github/actions/loki/fuselageSnap/src/getAffectedComponents.js'; +import { mergePkgsObj } from '../../../.github/actions/loki/fuselageSnap/src/getIndirectDependency.js'; import { trimStatsFile } from '../../../.github/actions/loki/fuselageSnap/src/stats/trimStatsFile.js'; import { copyFiles } from '../../../.github/actions/loki/fuselageSnap/src/utils/copyFiles.js'; import { generateRegex } from '../../../.github/actions/loki/fuselageSnap/src/utils/generateRegex.js'; import { getChangedFileLocal } from '../src/git_local.js'; - // yarn build-storybook --stats-json gives project-stats.json which has component titles // where as index.json gives the webpack base dependency graph // index.js run from the root of the project @@ -82,9 +82,53 @@ writeFileSync( console.log('The file was saved!'); }, ); - async function run() { - // getTrimmedstats + const buildStoryBookPromises = []; + const headCommit = await execa`git rev-parse HEAD`; + const changedFiles = await getChangedFileLocal(headCommit.stdout); + const storyBookPkgs = new Set(); + for (const file of changedFiles) { + if (file.includes('packages')) { + if (file.split('/')[1] === 'fuselage') { + storyBookPkgs.add('fuselage'); + break; + } + const pkgMap = mergePkgsObj(file.split('/')[1]); + for (const pkgName of pkgMap) { + storyBookPkgs.add(Object.keys(pkgName)[0]); + } + } + if (file.includes('yarn.lock') || file.includes('package.json')) { + storyBookPkgs.add('fuselage'); + } + } + + for (const pkg of storyBookPkgs) { + if (pkg === 'fuselage') { + buildStoryBookPromises.push(execCommand('yarn build-storybook')); + break; + } else if (pkg === 'fuselage-toastbar') { + buildStoryBookPromises.push( + execCommand('cd packages/fuselage-toastbar && yarn build-storybook'), + ); + } else if (pkg === 'layout') { + buildStoryBookPromises.push( + execCommand('cd packages/fuselage-toastbar && yarn build-storybook'), + ); + buildStoryBookPromises.push( + execCommand('cd packages/onboarding-ui && yarn build-storybook'), + ); + buildStoryBookPromises.push( + execCommand('cd packages/layout && yarn build-storybook'), + ); + } else if (pkg === 'onboarding-ui') { + buildStoryBookPromises.push( + execCommand('cd onboarding-ui && yarn build-storybook'), + ); + } + } + await Promise.all(buildStoryBookPromises); + const promises = []; for (const { src, dest } of filesToCopy) { copyFiles(src, dest); @@ -95,8 +139,7 @@ async function run() { } await Promise.all(promises); - const headCommit = await execa`git rev-parse HEAD`; - const changedFiles = await getChangedFileLocal(headCommit.stdout); + const data = await getAffectedComponents(changedFiles); const regex = generateRegex(data); const pkgs = ['fuselage', 'fuselage-toastbar', 'layout', 'onboarding-ui']; @@ -119,20 +162,7 @@ async function run() { bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`, bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`, }); - // await execCommand('yarn build-storybook'); /* eslint-disable no-await-in-loop */ - if (regex.fuselage.length > 0) { - await execCommand('yarn build-storybook'); - } else if (regex['fuselage-toastbar'].length > 0) { - await execCommand('cd packages/fuselage-toastbar && yarn build-storybook'); - } else if (regex.layout.length > 0) { - await execCommand('cd packages/fuselage-toastbar && yarn build-storybook'); - await execCommand('cd packages/onboarding-ui && yarn build-storybook'); - await execCommand('cd packages/layout && yarn build-storybook'); - } else if (regex['onboarding-ui'].length > 0) { - await execCommand('cd packages/onboarding-ui && yarn build-storybook'); - } - for (const pkg of pkgs) { if (regex[`${pkg}`].length === 0) { console.log( From bca33510caf851aaaf650e24f36f0cf9393a4500 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sun, 17 Aug 2025 01:24:06 +0530 Subject: [PATCH 17/20] chore: add current pkg storybook build --- tools/fuselageSnap-local/bin/index.js | 43 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 1fcd0464d2..a37bfaac3d 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -82,6 +82,22 @@ writeFileSync( console.log('The file was saved!'); }, ); +async function copyFilesToDest(filesToCopy, location) { + const promises = []; + for(const pkg of location ) { + for (const { src, dest } of filesToCopy) { + if(src.split('/')[2] === pkg) { + copyFiles(src, dest); + if (dest.includes('stats')) { + const trimmedPath = `.github/actions/loki/fuselageSnap/dist/trimmed-${dest.split('/').slice(-1)}`; + promises.push(trimStatsFile(dest, trimmedPath)); + } + } + } + } + + await Promise.all(promises); +} async function run() { const buildStoryBookPromises = []; const headCommit = await execa`git rev-parse HEAD`; @@ -93,6 +109,7 @@ async function run() { storyBookPkgs.add('fuselage'); break; } + storyBookPkgs.add(file.split('/')[1]); const pkgMap = mergePkgsObj(file.split('/')[1]); for (const pkgName of pkgMap) { storyBookPkgs.add(Object.keys(pkgName)[0]); @@ -102,15 +119,20 @@ async function run() { storyBookPkgs.add('fuselage'); } } - + const storyBookFilesToCopy = []; for (const pkg of storyBookPkgs) { if (pkg === 'fuselage') { buildStoryBookPromises.push(execCommand('yarn build-storybook')); + storyBookFilesToCopy.push('fuselage'); + storyBookFilesToCopy.push('fuselage-toastbar'); + storyBookFilesToCopy.push('layout'); + storyBookFilesToCopy.push('onboarding-ui'); break; } else if (pkg === 'fuselage-toastbar') { buildStoryBookPromises.push( execCommand('cd packages/fuselage-toastbar && yarn build-storybook'), ); + storyBookFilesToCopy.push('fuselage-toastbar'); } else if (pkg === 'layout') { buildStoryBookPromises.push( execCommand('cd packages/fuselage-toastbar && yarn build-storybook'), @@ -121,25 +143,20 @@ async function run() { buildStoryBookPromises.push( execCommand('cd packages/layout && yarn build-storybook'), ); + storyBookFilesToCopy.push('fuselage-toastbar'); + storyBookFilesToCopy.push('onboarding-ui'); + storyBookFilesToCopy.push('layout'); } else if (pkg === 'onboarding-ui') { buildStoryBookPromises.push( - execCommand('cd onboarding-ui && yarn build-storybook'), + execCommand('cd packages/onboarding-ui && yarn build-storybook'), ); + storyBookFilesToCopy.push('onboarding-ui'); } } await Promise.all(buildStoryBookPromises); - - const promises = []; - for (const { src, dest } of filesToCopy) { - copyFiles(src, dest); - if (dest.includes('stats')) { - const trimmedPath = `.github/actions/loki/fuselageSnap/dist/trimmed-${dest.split('/').slice(-1)}`; - promises.push(trimStatsFile(dest, trimmedPath)); - } + if(storyBookFilesToCopy.length > 0) { + await copyFilesToDest(filesToCopy, storyBookFilesToCopy); } - - await Promise.all(promises); - const data = await getAffectedComponents(changedFiles); const regex = generateRegex(data); const pkgs = ['fuselage', 'fuselage-toastbar', 'layout', 'onboarding-ui']; From 50980849e4659869fe04d13d6a6c6dde7f2ed763 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sun, 17 Aug 2025 01:52:22 +0530 Subject: [PATCH 18/20] fix: multiple builds at the same packages at same time --- tools/fuselageSnap-local/bin/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index a37bfaac3d..1d381d7741 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -119,6 +119,17 @@ async function run() { storyBookPkgs.add('fuselage'); } } + for(const pkg of storyBookPkgs) { + if (pkg === 'fuselage') { + storyBookPkgs.delete('fuselage-toastbar'); + storyBookPkgs.delete('layout'); + storyBookPkgs.delete('onboarding-ui'); + } + else if (pkg === 'layout') { + storyBookPkgs.delete('fuselage-toastbar'); + storyBookPkgs.delete('onboarding-ui'); + } + } const storyBookFilesToCopy = []; for (const pkg of storyBookPkgs) { if (pkg === 'fuselage') { From 8b0f514ed70b2fe58324af48a609a2036b4a229a Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sun, 17 Aug 2025 01:53:05 +0530 Subject: [PATCH 19/20] fix: lint --- tools/fuselageSnap-local/bin/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/fuselageSnap-local/bin/index.js b/tools/fuselageSnap-local/bin/index.js index 1d381d7741..3b3af4ef52 100755 --- a/tools/fuselageSnap-local/bin/index.js +++ b/tools/fuselageSnap-local/bin/index.js @@ -84,9 +84,9 @@ writeFileSync( ); async function copyFilesToDest(filesToCopy, location) { const promises = []; - for(const pkg of location ) { + for (const pkg of location) { for (const { src, dest } of filesToCopy) { - if(src.split('/')[2] === pkg) { + if (src.split('/')[2] === pkg) { copyFiles(src, dest); if (dest.includes('stats')) { const trimmedPath = `.github/actions/loki/fuselageSnap/dist/trimmed-${dest.split('/').slice(-1)}`; @@ -95,7 +95,7 @@ async function copyFilesToDest(filesToCopy, location) { } } } - + await Promise.all(promises); } async function run() { @@ -119,13 +119,12 @@ async function run() { storyBookPkgs.add('fuselage'); } } - for(const pkg of storyBookPkgs) { + for (const pkg of storyBookPkgs) { if (pkg === 'fuselage') { storyBookPkgs.delete('fuselage-toastbar'); storyBookPkgs.delete('layout'); storyBookPkgs.delete('onboarding-ui'); - } - else if (pkg === 'layout') { + } else if (pkg === 'layout') { storyBookPkgs.delete('fuselage-toastbar'); storyBookPkgs.delete('onboarding-ui'); } @@ -165,7 +164,7 @@ async function run() { } } await Promise.all(buildStoryBookPromises); - if(storyBookFilesToCopy.length > 0) { + if (storyBookFilesToCopy.length > 0) { await copyFilesToDest(filesToCopy, storyBookFilesToCopy); } const data = await getAffectedComponents(changedFiles); From 8fa6a3e32f89ad004af348724bf5ac890c93d2b4 Mon Sep 17 00:00:00 2001 From: Anxhul10 Date: Sun, 17 Aug 2025 01:53:41 +0530 Subject: [PATCH 20/20] chore: remove logs --- .github/actions/loki/fuselageSnap/src/getIndirectDependency.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js index 86e7d38f62..0cfccfc346 100644 --- a/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js +++ b/.github/actions/loki/fuselageSnap/src/getIndirectDependency.js @@ -112,7 +112,6 @@ export const mergePkgsObj = (pkgName) => { }; export const getIndirectDps = async (pkgName) => { const relevantGraph = mergePkgsObj(pkgName); - console.log(relevantGraph); const promises = relevantGraph.map(async (obj) => { const key = Object.keys(obj)[0]; const result = await getReasons(