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

Feature: Redesign CLI console messages and user interactions. #734

Merged
merged 54 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
63a7f6f
Add new cli options.
amovar18 Jun 28, 2024
badd1e7
Fix spinners.
amovar18 Jun 28, 2024
d81e941
Fix technology spinners.
amovar18 Jun 28, 2024
2549fc8
Update validators for cli.
amovar18 Jun 28, 2024
64eece4
Remove use of validators.
amovar18 Jun 28, 2024
5ef9fc9
Small changes.
amovar18 Jul 1, 2024
d7638a3
Add tests for validators.
amovar18 Jul 1, 2024
1323b99
Change limit to number-of-urls.
amovar18 Jul 1, 2024
6a59ed3
Delete validateArgs file.
amovar18 Jul 2, 2024
61ab429
Fix sitemap error messages.
amovar18 Jul 2, 2024
bc62652
Remove extra logging.
amovar18 Jul 2, 2024
440b6dd
Correct validator.
amovar18 Jul 2, 2024
8d428a2
Add cli e2e test.
amovar18 Jul 2, 2024
b19525a
Temporarily skip tests.
amovar18 Jul 2, 2024
d090b6f
Fix spinnies.
amovar18 Jul 2, 2024
64971fb
skip test.
amovar18 Jul 2, 2024
14e64d6
Comment out code.
amovar18 Jul 2, 2024
23acdf4
Update test.
amovar18 Jul 3, 2024
b01b0e3
Add shared config for testing cli.
amovar18 Jul 3, 2024
09b7ade
Fix spinners.
amovar18 Jul 3, 2024
8fdedfc
Fix error messages.
amovar18 Jul 3, 2024
3fef03c
Correct verbose logs.
amovar18 Jul 3, 2024
79e3a97
Add chalk package and paint red the error messages.
amovar18 Jul 4, 2024
3be6260
Add reusbale function to use update spinner text.
amovar18 Jul 4, 2024
cb77a59
Change wording to locale.
amovar18 Jul 4, 2024
c55381d
Use spinnies instead of chalk.
amovar18 Jul 4, 2024
d56737e
Fix messages in spinnies.
amovar18 Jul 4, 2024
ad8491f
Fix tech analysis.
amovar18 Jul 4, 2024
a4d0ad0
Fix spinnies.
amovar18 Jul 4, 2024
f84aff5
Remove fullstop.
amovar18 Jul 4, 2024
e2231f0
Fix failing tests.
amovar18 Jul 4, 2024
ff81328
Change messaging.
amovar18 Jul 4, 2024
a1abb3e
Fix indentation.
amovar18 Jul 4, 2024
559e946
Add spinnies type.
amovar18 Jul 4, 2024
668d453
Add spinnies type.
amovar18 Jul 4, 2024
04a9b38
Add spinnies to main package.json file.
amovar18 Jul 4, 2024
38e0d0f
Conditionally update usage text.
amovar18 Jul 4, 2024
f359066
Remove validation for access.
amovar18 Jul 4, 2024
a1790f6
Add help text at the end of help command.
amovar18 Jul 4, 2024
e345574
Configure help message.
amovar18 Jul 4, 2024
1f72fd0
Capatialise error message.
amovar18 Jul 4, 2024
6373ec4
Fix utl validator to accomodate the URL argument.
amovar18 Jul 5, 2024
9d02d89
Remove default options.
amovar18 Jul 5, 2024
7c110aa
Fix option name to use make CLI readable.
amovar18 Jul 5, 2024
fff6329
Fix package.json.
amovar18 Jul 5, 2024
a86bad0
Fix eslint.
amovar18 Jul 8, 2024
88c8584
Fix condition.
amovar18 Jul 8, 2024
ec07fd0
Fix indent.
amovar18 Jul 8, 2024
8b361a2
Make a redLogger for cli errors
amovar18 Jul 8, 2024
bba5687
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Jul 10, 2024
3187ae1
Fix non provision of argument.
amovar18 Jul 10, 2024
c752911
If argument consists of flags then display error.
amovar18 Jul 11, 2024
aebaaae
Merge develop and resolve conflicts
mohdsayed Jul 15, 2024
ffe74c2
Add back ensureDir
mohdsayed Jul 15, 2024
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
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"ignorePatterns": [
"**/node_modules/**",
"dist/**",
"dist-types/**",
"**/dist/**",
"**/dist-types/**",
"out/**",
"data/**",
"coverage/**"
Expand Down
136 changes: 136 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build-storybook": "storybook build",
"build:all": "npm-run-all **:build ",
"build-cli": "npm run cli-dashboard:build && npm run cli:build",
"build-cli": "npm run i18n:build && npm run common:build && npm run design-system:build && npm run library-detection:build && npm run analysis-utils:build && npm run cli-dashboard:build && npm run cli:build",
"publish:all:local": "npm run build:all && npm run publish:local --workspaces",
"unpublish:all:local": "npm run unpublish:local --workspaces",
"publish:all:remote": "npm run build:all && npm run publish:remote --workspaces",
Expand Down Expand Up @@ -44,7 +44,8 @@
"prepare": "husky install",
"rws-json:update": "node scripts/update-rws-json.cjs",
"storybook": "storybook dev -p 6006",
"test": "jest --config=tests/jest.config.cjs",
"test": "jest --config=tests/unitTest.jest.config.cjs",
"test:e2e": "jest --config=tests/cli.jest.config.cjs",
"test:coverage": "npm run test -- --collectCoverage && open coverage/lcov-report/index.html",
"serve": "webpack serve"
},
Expand Down Expand Up @@ -79,6 +80,7 @@
"@types/react": "^18.2.9",
"@types/react-dom": "^18.2.4",
"@types/sinon-chrome": "^2.2.11",
"@types/spinnies": "^0.5.3",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"autoprefixer": "^10.4.14",
Expand Down
1 change: 1 addition & 0 deletions packages/analysis-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"homepage": "https://github.com/GoogleChromeLabs/ps-analysis-tool",
"dependencies": {
"@google-psat/common": "*",
"chalk": "^5.3.0",
"puppeteer": "^22.10.0",
"simple-cookie": "^1.0.15",
"tldts": "^6.0.14",
Expand Down
37 changes: 25 additions & 12 deletions packages/analysis-utils/src/browserManagement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ export class BrowserManagement {
pageRequests: Record<string, Record<string, RequestData>>;
pageResourcesMaps: Record<string, Record<string, ScriptTagUnderCheck>>;
shouldLogDebug: boolean;

spinnies: Spinnies | undefined;
indent = 0;
constructor(
viewportConfig: ViewportConfig,
isHeadless: boolean,
pageWaitTime: number,
shouldLogDebug: boolean
shouldLogDebug: boolean,
indent: number,
spinnies?: Spinnies
) {
this.viewportConfig = viewportConfig;
this.browser = null;
Expand All @@ -71,11 +74,19 @@ export class BrowserManagement {
this.pageRequests = {};
this.shouldLogDebug = shouldLogDebug;
this.pageResourcesMaps = {};
this.spinnies = spinnies;
this.indent = indent;
}

debugLog(msg: any) {
if (this.shouldLogDebug) {
console.log(msg);
if (this.shouldLogDebug && this.spinnies) {
this.spinnies.add(msg, {
text: msg,
//@ts-ignore
succeedColor: 'white',
status: 'non-spinnable',
indent: this.indent,
});
}
}

Expand All @@ -94,14 +105,14 @@ export class BrowserManagement {
headless: this.isHeadless,
args,
});
this.debugLog('browser intialized');
this.debugLog('Browser intialized');
}

async clickOnAcceptBanner(url: string) {
const page = this.pages[url];

if (!page) {
throw new Error('no page with the provided id was found');
throw new Error('No page with the provided id was found');
}

await page.evaluate(() => {
Expand Down Expand Up @@ -167,14 +178,14 @@ export class BrowserManagement {
throw new Error('no page with the provided id was found');
}

this.debugLog(`starting navigation to url ${url}`);
this.debugLog(`Starting navigation to URL: ${url}`);

try {
await page.goto(url, { timeout: 10000 });
this.debugLog(`done with navigation to url:${url}`);
this.debugLog(`Navigation completed to URL: ${url}`);
} catch (error) {
this.debugLog(
`navigation did not finish in 10 seconds moving on to scrolling`
`Navigation did not finish in 10 seconds moving on to scrolling`
);
//ignore
}
Expand All @@ -192,11 +203,11 @@ export class BrowserManagement {
window.scrollBy(0, 10000);
});
} catch (error) {
this.debugLog(`scrolling the page to the end.`);
this.debugLog('Scrolled to end of page');
//ignore
}

this.debugLog(`scrolling on url:${url}`);
this.debugLog(`Scrolling on URL: ${url}`);
}

responseEventListener(pageId: string, response: HTTPResponse) {
Expand Down Expand Up @@ -461,6 +472,8 @@ export class BrowserManagement {
throw new Error(`no page with the provided id was found:${pageId}`);
}

this.debugLog('Attaching network event listeners to page');

const cdpSession = await page.createCDPSession();

await cdpSession.send('Target.setAutoAttach', {
Expand Down Expand Up @@ -501,7 +514,7 @@ export class BrowserManagement {
this.pageFrameAttachedListener(pageId, ev)
);

this.debugLog('done attaching network event listeners');
this.debugLog('Finished attaching network event listeners');
}

async getJSCookies(page: Page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const analyzeCookiesUrlsAndFetchResources = async (
isHeadless: boolean,
delayTime: number,
cookieDictionary: CookieDatabase,
shouldSkipAcceptBanner: boolean
shouldSkipAcceptBanner: boolean,
verbose: boolean,
spinnies?: Spinnies
) => {
const browser = new BrowserManagement(
{
Expand All @@ -46,7 +48,9 @@ export const analyzeCookiesUrlsAndFetchResources = async (
},
isHeadless,
delayTime,
false
verbose,
urls.length > 2 ? 4 : 3,
amovar18 marked this conversation as resolved.
Show resolved Hide resolved
spinnies
);

await browser.initializeBrowser(true);
Expand Down
Loading
Loading