Giter Site home page Giter Site logo

hatcher's Introduction


logo

Hatcher

Registries toolbox & update notifications for your CLI

nest.land badge Eggs lint Eggs test Eggs ship Discord

notification

Inspired by the node package update-notifier.

Contents

Usage

Update Notifier

Simple

import {
  NestLand,
  UpdateNotifier,
} from "https://x.nest.land/[email protected]/mod.ts";

const notifier = new UpdateNotifier({
  name: "denon",
  registry: NestLand,
  currentVersion: "0.1.2",
});

await notifier.checkForUpdates();
notifier.notify();

Comprehensive

import {
  Github,
  UpdateNotifier,
} from "https://x.nest.land/[email protected]/mod.ts";

const notifier = new UpdateNotifier({
  name: "denon", // module name
  owner: "denosaurs", // module owner, mandatory for registries like github
  registry: Github, // registry object
  currentVersion: "0.1.2",
  updateCheckInterval: 1000 * 60 * 60, // time interval between two checks, in milliseconds
});

const update = await notifier.checkForUpdates(); // undefined if there is no update available
console.log(update);
/** {
  current: "0.1.2",
  latest: "2.4.0",
  type: "major",
  name: "denon",
  owner: "denosaurs",
  registry: "raw.githubusercontent.com"
} */

notifier.notify("my command"); // displays the default notification with a custom command

comprehensive

Adding update notification to any CLI

Suppose denon does not use hatcher to notify its users of updates.

You can install denon with hatcher built-in !

If the install command is :

deno install --allow-read --allow-run --allow-write --allow-net -f -q --unstable https://deno.land/x/[email protected]/denon.ts

You can do:

deno install -A https://x.nest.land/[email protected]/hatcher.ts
hatcher --allow-read --allow-run --allow-write --allow-net -f -q --unstable https://deno.land/x/[email protected]/denon.ts

And voila ! You will be notified as soon as an update is available.

How

Whenever you initiate the update notifier and it's not within the interval threshold, it will asynchronously check with the specified registry for available updates, then persist the result. This prevents any impact on your module startup performance.

The first time the user runs your app, it will check for an update, and even if an update is available, it will wait the specified updateCheckInterval before notifying the user (one day by default). This is done to not be annoying to the user, but might surprise you as an implementer if you're testing whether it works. Check out example.ts to quickly test out hatcher and see how you can test that it works in your app.

deno run -A https://x.nest.land/[email protected]/example.ts

Registries toolbox

import {
  getLatestVersion,
  parseURL,
} from "https://x.nest.land/[email protected]/mod.ts";

const result = parseURL("https://deno.land/x/[email protected]/src/runner.ts");
/** {
  registry: "deno.land",
  name: "denon",
  version: "1.2.0",
  parsedURL: "https://deno.land/x/denon@${version}/src/runner.ts",
  relativePath: "src/runner.ts",
  owner: ""
} */

const latestVersion = await getLatestVersion("deno.land", "denon");
console.log(latestVersion); // 0.2.4

API

notifier = UpdateNotifier({ name, owner, registry, currentVersion, updateCheckInterval})

name

required

type: string

owner

required for raw.githubusercontent.com, denopkg.com

type: string

registry

required

type: Registry

currentVersion

required

type: string | semver.SemVer

updateCheckInterval

In milliseconds, defaults to one day.

type: number

notifier.checkForUpdates(configDir)

configDir is the directory where hatcher will save some information about your module.

Defaults to ~/.deno/hatcher

Returns an Update object if there is an update available, undefined otherwise.

notifier.notify(command, overwrite)

By default, will ask the user to visit the registry.

notifier.notify();

default

command

type: string

notifier.notify("my command");

command

overwrite

type: boolean

Will overwrite the body of the notification.

notifier.notify("My custom message", true);

overwrite

Custom message

You can of course also display a fully customized message if an update is available.

const update = await notifier.checkForUpdates();
if (update) {
  console.log(`New update! ${update.latest}`);
}

Update

{
  latest:
  string;
  current:
  string;
  type:
  semver.ReleaseType | null; // "pre" | "major" | "premajor" | "minor" | "preminor" | "patch" | "prepatch" | "prerelease" | null
  name:
  string;
  owner:
  string;
  registry:
  string;
}

Registry Class

Supported registers for the time being:

domain (string) Registry class
deno.land DenoLand
denopkg.com Denopkg
raw.githubusercontent.com Github
jspm.dev Jspm
x.nest.land NestLand
cdn.skypack.dev Skypack

You can add your own registers by adding them to registries.

import { registries } from "https://x.nest.land/[email protected]/mod.ts";

registries.push(myRegistry);

Your registry must implement the Registry object:

abstract class Registry {
  static domain: string;

  static async latestVersion(
    module: string,
    owner?: string,
  ): Promise<string | undefined>;

  static async latestStableVersion(
    module: string,
    owner?: string,
  ): Promise<string | undefined>;

  static async sortedVersions(
    module: string,
    owner?: string,
  ): Promise<string[]>;

  static parseURL(url: string): URLData;
}

latestVersion(registryDomain, module, owner)

Get latest version from supported registries

registryDomain

required

type: string

One of the supported registries domain.

module

required

type: string

owner

required for raw.githubusercontent.com, denopkg.com

type: string

return type

type: string

latestStableVersion(registryDomain, module, owner)

Same as latestVersion but get the latest stable version according to the SemVer rules.

sortedVersions(registryDomain, module, owner)

Get sorted versions from supported registries

registryDomain

required

type: string

One of the supported registries domain.

module

required

type: string

owner

required for raw.githubusercontent.com, denopkg.com

type: string

return type

type: string[]

parseURL(url)

Parse an URL from supported registries

url

required

type: string

return type

interface ProcessedURL {
  registry: string;
  name: string;
  owner: string;
  version: string;
  parsedURL: string;
  relativePath: string;
}

getRegistry(registryDomain)

Get registry object from web domain

registryDomain

required

type: string

return type

type: Registry

Contributing

GitHub Hacktoberfest combined status

All contributions are welcome! If you can think of a command or feature that might benefit nest.land, fork this repository and make a pull request from your branch with the additions. Make sure to use Conventional Commits

Contribution guide

hatcher's People

Contributors

maximousblk avatar notfilippo avatar steelalloy avatar t8 avatar umbopepato avatar zorbyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

umbopepato

hatcher's Issues

Type errors caused by semver on Deno v1.11.0

๐Ÿ› Bug Report

[email protected] - used by Hatcher - causes some type errors on the latest Deno version (v1.11.0).

To Reproduce

  1. Update Deno to v1.11.0
    $ deno upgrade --version 1.11.0
    
  2. Run any module which imports from Hatcher

Expected behavior

No type errors are thrown.

Actual Behavior

The following errors are thrown:

image

Environment

  • Eggs version: -
  • Deno version: 1.11.0
  • Operating system and version: macOS Big Sur 11.3.1 (20E241)

Additional context

#39 should fix this (upgrades semver to the latest version) ๐Ÿ™‚

Improve semantic versioning detection logic, in case the lack of the Latest version Tag

Is your feature request related to a problem? If so, please describe.
This is feature request.

$ eggs update --file .github/workflows/gh-pages.yml
Warning: could not find the latest version of pagic.

Your dependencies are already up to date!

This repository is the lack of the Latest version Tag, but do semvar so that egg should detection the latest version from all versions.
https://github.com/xcatliu/pagic/releases

Here is the point of improvement.
https://github.com/nestdotland/nest.land/blob/master/eggs/src/commands/update.ts#L67-L74

Describe the solution you'd like
Expected Diff example.(I updated manualy.)
yoshixmk/deno-x-ranking@aedc665#diff-fc6988097954f601e9f877d8b1b5baa2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.