example-package

A minimal template for TypeScript packages

View on GitHub

Example Package

A minimal TypeScript package template. It is designed to demonstrate how to structure, build, test, and publish a TypeScript package in a portable and easy-to-understand way.

Features:

Installation

This is a dummy package created for demonstration purposes. It does not contain any real functionality. However, it is published to NPM and you can install it using the following command:

npm install @madooei/example-package

Usage

Currently, this package only exports a simple function and a type as an example.

// TypeScript
import { example, type Person } from "@madooei/example-package";

// Type is fully supported in TypeScript
const person: Person = {
  name: "John Doe",
  age: 30,
};

example(person);

If you run the above code, it will produce the following output:

Hello, John Doe! You are 30 years old.

Cloning the Repository

To make your workflow more organized, it’s a good idea to clone this repository into a directory named example-package-workspace. This helps differentiate the workspace from the example-package located in the packages directory.

git clone https://github.com/madooei/example-package example-package-workspace

cd example-package-workspace

Repository Structure

How to Use This Repo

Using a VSCode Multi-root Workspace

With Visual Studio Code, you can enhance your development experience by using a multi-root workspace to access packages, examples, and playgrounds simultaneously. This approach is more efficient than opening the root directory, or each package or example separately.

To set up a multi-root workspace:

  1. Open Visual Studio Code.
  2. Navigate to File > Open Workspace from File....
  3. Select the example-package.code-workspace file located at the root of the repository. This action will open all specified folders in one workspace.

The example-package.code-workspace file can be customized to include different folders or settings. Here’s a typical configuration:

{
  "folders": [
    {
      "path": "packages/example-package"
    },
    {
      "path": "examples/simple"
    },
    {
      "path": "playgrounds/tsx"
    }
  ],
  "settings": {
    // Add any workspace-specific settings here, for example:
    "git.openRepositoryInParentFolders": "always"
  }
}

Developing the Package

Change to the package directory and install dependencies:

cd packages/example-package
npm install

Package Management

When you are ready to publish your package:

npm run release

This single command will:

[!TIP] For detailed information about package publishing, versioning, and local development workflows, see the NPM Package Management Guide.