Skip to content

ODGodinho/Stanley-Crawler-Event

Repository files navigation

Stanley Imagem
Stanley Crawler With Events By Dragons Gamers

Template Stanley for Crawler Puppeteer/Playwright project πŸ€–!

codecov Stargazers Made by ODGodinho Forks Repository size GitHub last commit License StyleCI

Table of Contents


πŸŽ‡ Benefits

  • πŸš€ Speed start new crawler using typescript
  • 🚨 Over 800 rules for pattern, possible errors and errors in Linter
  • πŸŽ‡ Code quality guaranteed
  • πŸ“’ AutoReview when opening a pull-request/merge AutoReview Comment example
  • πŸ§ͺ Automatic Test when opening pull-request/merge
  • πŸ“ˆ Automatic Code Coverage when opening pull-request/merge Code Coverage example
  • πŸ“¦ Automatic Package and release generate on merge
  • πŸͺ Run Lint/Test command pre-commit execute
  • βš™οΈ IOT/IOC (Inversion of Control) for easy use of libraries
  • 🟒 Make:Files Command to make base files

πŸ“— Libraries

πŸ“ Dependencies

πŸ”˜ Use Template

Click in use this template button and clone your template project

Use Template

πŸ™ˆ Change to Puppeteer

To change you crawler to use puppeteer you change ./engine.ts file for:

import puppeteer, {
    type Browser,
    type PuppeteerLaunchOptions,
    type Page,
    type BrowserContext,
    type PuppeteerNode,
} from "puppeteer";

import {
    type Context as ContextClass,
    type Browser as BrowserClass,
    type Page as PageClass,
} from "./Browser";

export type BrowserTypeEngine = PuppeteerNode;

export type BrowserClassEngine = Browser;

export type ContextClassEngine = BrowserContext;

export type PageClassEngine = Page;

export type BrowserOptionsEngine = PuppeteerLaunchOptions;

export const browserEngine = puppeteer;

⏩ Get Started


🦻 Event / Listeners

Events can be fired with EventBusInterface Example Include the execution of your page in an event so that you can execute any page at any time

export class ExampleEventListener implements EventListenerInterface<EventTypes, EventName.ExampleEvent> {

    @inject(ContainerName.Logger)
    public readonly log!: LoggerInterface;

    public async handler(_receivedData: unknown) {
        await this.log.info('Example Event Listener');
    }

}

Register all Events name in ./src/app/Enums/EventName.ts


Register all Events Types in ./@types/EventsInterface.ts


Register your events in EventServiceProvider to automatic listeners.

↖️ Selector

The selectors are in the selectors folder

export const googleSearchSelector = {
    searchInput: "input[name=\"q\"]",
    buttons: {
        submit: "input[name=\"btnK\"] >> visible=true",
    },
};

export type GoogleSearchSelectorType = typeof googleSearchSelector;

Register all Selectors in ./src/app/Selectors/index.ts

βš™οΈ Container Bind

this.bind(
    ContainerName.Logger,
).to(ConsoleLogger).inSingletonScope();

Register all Container name in src/app/Enums/ContainerName.ts Register all Container Inject in src/app/Container.ts

❕ Extract Text Helper

Use Str, Num, Arr helpers class to manipulate Text, Numbers and Arrays

import { Str } from "@odg/chemical-x";

const value = new Str(
    this.page.locator("#money").innerText(),
).money();

🟒 Make File

To Make a file run command

Use this to make Page, Handler, Selectors...

yarn odg make

Example to make Page File

yarn odg make:page Search

# help with
yarn odg make:page --help

πŸ’“ Cycle Time

πŸ“½οΈ Project Life Cycle

Project Life cycle

LifeCycle

🐠 Service Life Cycle

Example Service Life Cycle

LifeCycle

πŸ’¦ Page Life Cycle

Example Page Life Cycle

LifeCycle

πŸ€„ Handler Life Cycle

Example Handler Life Cycle

LifeCycle

πŸ’» Prepare To Develop

Copy .env.example to .env and add the values according to your needs.

πŸ“ Start Project

First install dependencies with the following command

yarn install
# or
npm install

πŸ“¨ Build and Run

To build the project, you can use the following command

if you change files, you need to run yarn build and yarn start again

yarn build && yarn start
# or
yarn dev

πŸ§ͺ Teste Code

To Test execute this command

yarn test
# or
yarn test:watch

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages