DEV Community

Cover image for Introducting Lightship 0.1.0
Anwar
Anwar

Posted on

Introducting Lightship 0.1.0

Hello and welcome to my new article where I would like to showcase my newest open-source project: Lightship PHP.

How it started

It all started from a Tweet, where I was asking the Laravel community if folks would be interesting in a command line tool to facilitate running Google Lighthouse reports for their routes.

This tweet stimulated the comments section and it gave me the will to go and start creating a package for the community.

Doubts

I like to challenge myself, as if I was a user of the package. So I asked myself if the package was easy to use, and turns out I had spent a few hours struggling to install Google Chrome headless, and setting it up so that I could call it from my package (I use Docker).

This was the first thing that made me re-think the success of this project.

After a little chat with my brother Amin, because we have great discusses and these chats always gives me good feedbacks to keep challeging myself, we started to imagine:

What if we did not had to use a web browser to get a web page audit?

So I started fiddling with some prototypes using pure HTTP calls, and it started to get some good results. I was about to wrap up a first working version and when I presented it to my bro on Discord, this was the revelation.

The audits were pretty fast, and we started to create an organization (links at the end of the article), as well as an RFC and some implementations for Node and PHP.

Usage example

I stick to PHP since my end goal is to have a tool to quickly audit my Laravel public routes to be sure I have the best score possible to optimize my ranking (another Dev.to article on the project I am baking is coming).

Lightship PHP is supporting PHP 8.1 and greater. The installation and usage is dead simple.

Install the package

First, start by requiring the package into your project:

composer require lightship-core/lightship-php
Enter fullscreen mode Exit fullscreen mode

Create the script

Create a PHP file, and insert this code:

use Lightship\Lightship;

require __DIR__ . "/vendor/autoload.php";

$lightship = new Lightship();

$lightship->route("https://example.com")
  ->route("https://google.com")
  ->route("https://news.google.com")
  ->analyse();

file_put_contents("report.json", $lightship->toPrettyJson());
Enter fullscreen mode Exit fullscreen mode

Execute the script

Now, just run this command on your terminal, and after a few seconds a new file "report.json" will appear with the scores and results for each of your URLs.

php index.php
Enter fullscreen mode Exit fullscreen mode

The "report.json" looks like this:

[
  {
    "url": "https:\/\/example.com",
    "durationInSeconds": 0.32,
    "scores": {
      "seo": 50,
      "security": 25,
      "performance": 100,
      "accessibility": 50
    },
    "seo": [
      {
        "name": "titlePresent",
        "passes": true
      },
      {
        "name": "langPresent",
        "passes": false
      },
      ...
    ],
    "security": [
      {
        "name": "xFrameOptionsPresent",
        "passes": false
      },
      {
        "name": "strictTransportSecurityHeaderPresent",
        "passes": false
      },
      ...
    ],
    "performance": [
      {
        "name": "textCompressionEnabled",
        "passes": true
      },
      {
        "name": "noRedirects",
        "passes": true
      },
      ...
    ],
    "accessibility": [
      {
        "name": "metaViewportPresent",
        "passes": true
      },
      {
        "name": "useLandmarkTags",
        "passes": false
      },
      ...
    ]
  },
  ...
]
Enter fullscreen mode Exit fullscreen mode

What's next?

I would like to keep going and give more for you guys!

I will create in the next days a Laravel package to be able to automatize this for you, with a nice console report.

You should also take a look at the PHP repository for Lightship PHP, you will learn:

  • How to run a script and display a console report yourself
  • How to use a lightship.json configuration file, with many more features (like query string and base domain support)

You also will play an essential role, because this package can't live without your support and feedbacks. Please let me know here in the comments what do you think, what can I improve, or all your suggestions to make it more viable for a v1!

If you want to play with it and create your own implementation, please go ahead and I will reference it on the RFC README. I think this can be a very good way to train your programming skills, I had so much fun doing the PHP implementation!

PHP repository: https://github.com/lightship-core/lightship-php
RFC repository: https://github.com/lightship-core/lightship-rfc

Happy web audit 🤓

Top comments (0)