### Installing the Tempo Library Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/guide/index.md Install the Tempo library using npm, Yarn, or pnpm package managers. This command adds the `@joggr/tempo` package to your project dependencies. ```bash $ npm install @joggr/tempo ``` ```bash $ yarn add @joggr/tempo ``` ```bash $ pnpm install @joggr/tempo ``` -------------------------------- ### Installing Tempo and dependencies Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/examples/gha.md These commands show how to install the necessary dependencies, `@joggr/tempo` and `yaml`, using different Node.js package managers. ```bash $ npm install --dev @joggr/tempo yaml ``` ```bash $ yarn add -D @joggr/tempo yaml ``` ```bash $ pnpm install --dev @joggr/tempo yaml ``` -------------------------------- ### Installing Tempo with npm Source: https://github.com/joggrdocs/tempo/blob/main/packages/tempo/README.md This snippet demonstrates how to install the Tempo library using the npm package manager. Tempo is distributed as a GitHub Package, requiring your environment to support installing internal GitHub packages. ```shell npm install @joggr/tempo ``` -------------------------------- ### Installing Tempo with Yarn Source: https://github.com/joggrdocs/tempo/blob/main/packages/tempo/README.md This snippet demonstrates how to install the Tempo library using the Yarn package manager. As a GitHub Package, ensure your application environment is configured to install internal GitHub packages. ```shell yarn add @joggr/tempo ``` -------------------------------- ### Creating a Tempo Document and Adding Content - TypeScript Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/guide/index.md Create a new Tempo document instance by calling the `tempo()` function. Then, use methods like `h1()`, `p()`, and `code()` to add markdown elements to the document. The `TempoDocument` object is stateful and methods can be chained. ```typescript const doc = tempo(); doc.h1('Hello, World!'); doc.p('This is a simple paragraph.'); doc.code('console.log(\"Hello, World!\");'); ``` -------------------------------- ### Importing the Tempo Function - TypeScript Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/guide/index.md Import the default `tempo` function from the `@joggr/tempo` package into your TypeScript/JavaScript file. This function is the entry point for creating a new Tempo document. ```typescript import tempo from '@joggr/tempo'; ``` -------------------------------- ### Define Example GitHub Action Workflow YAML Source: https://github.com/joggrdocs/tempo/blob/main/examples/gha/README.md This snippet defines a basic GitHub Actions workflow in YAML. It sets a name for the action, includes steps to check out the repository using the standard `actions/checkout@v2` action, and then demonstrates the usage of a hypothetical custom action `example@v1` with specified inputs like `message`, `environment`, and `debug`. ```yaml name: Example GitHub Action steps: - uses: actions/checkout@v2 - uses: example@v1 with: message: Hello, World! environment: production debug: false ``` -------------------------------- ### Generating Markdown String Output - TypeScript Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/guide/index.md Call the `toString()` method on the `TempoDocument` object to generate the final markdown content as a string. This string can then be used, for example, by logging it to the console or saving it to a file. ```typescript const markdown = doc.toString(); console.log(markdown); // Outputs the markdown content as a string ``` -------------------------------- ### Adding Changeset with Yarn Bash Source: https://github.com/joggrdocs/tempo/blob/main/CONTRIBUTING.md This command initiates the interactive process for creating a new changeset file. The tool will guide you through selecting which packages have been modified, specifying the type of change (major, minor, patch), and writing a brief summary of your changes, which is then used to generate the changelog entry. ```bash yarn changeset ``` -------------------------------- ### Generating Basic Markdown Document with Tempo (TypeScript) Source: https://github.com/joggrdocs/tempo/blob/main/README.md This snippet demonstrates how to use the @joggr/tempo library in TypeScript to create a simple Markdown document. It imports the `tempo` library and Node.js `fs/promises` module, builds a document with a level 1 heading and a paragraph, converts it to a string, and asynchronously writes it to a file named `test.md`. Requires the `@joggr/tempo` and Node.js installed. ```typescript import fs from 'node:fs/promises'; import tempo from '@joggr/tempo'; const doc = tempo() .h1('Hello, World!') .p('This is a test document.') .toString(); await fs.writeFile('test.md', doc); ``` -------------------------------- ### Generating Basic Markdown with Tempo (TypeScript) Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/index.md This snippet shows a fundamental use case for the tempo library. It imports the library, creates a new tempo instance, adds a heading, a paragraph, and a code block, and finally outputs the generated markdown as a string. It demonstrates the chainable API for simple markdown construction. ```ts import tempo from '@joggr/tempo'; /** * This is a simple example of using tempo to generate markdown. */ export default tempo() .h1('Hello, World!') .p('This is a paragraph.') .code('console.log("Hello, World!")') .toString(); ``` -------------------------------- ### Generating README from action.yaml using TypeScript Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/examples/gha.md This TypeScript script reads the `action.yaml` file, parses its YAML content, and uses the Tempo library to programmatically generate the `README.md` file based on the action's name, description, inputs, and outputs. ```typescript import fs from 'node:fs/promises'; import path from 'node:path'; import yaml from 'yaml'; import tempo from '@joggr/tempo'; // if you are using CJS remove the following line const __dirname = path.dirname(new URL(import.meta.url).pathname); const fileContents = await fs.readFile( path.join(__dirname, 'action.yaml'), 'utf8' ); const config = yaml.parse(fileContents); const doc = tempo() .h1(config.name) .paragraph(config.description) .codeBlock( ` name: ${config.name} steps: - uses: actions/checkout@v2 - uses: example@v1 with: ${Object.keys(config.inputs) .map( (key) => `${key}: ${config.inputs[key].default || 'example'}` ) .join('\n ')} `.trim(), 'yaml' ) .h2('Inputs') .table([ ['Name', 'Description', 'Default'], ...Object.keys(config.inputs).map((key) => [ key, config.inputs[key].description, config.inputs[key].default || 'example', ]), ]) .h2('Outputs') .table([ ['Name', 'Description'], ...Object.keys(config.outputs).map((key) => [ key, config.outputs[key].description, ]), ]); await fs.writeFile( path.join(__dirname, 'README.md'), doc.toString(), 'utf8' ); ``` -------------------------------- ### Running the README generation script Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/examples/gha.md This command executes the TypeScript script (`scripts/generate-readme.ts`) using `tsx`, a utility for running TypeScript files directly, to generate or update the `README.md` file. ```bash $ tsx scripts/generate-readme.ts ``` -------------------------------- ### Creating Markdown Template Function with Tempo (TypeScript) Source: https://github.com/joggrdocs/tempo/blob/main/docs/content/index.md This function demonstrates how to build reusable markdown templates using the tempo library. It accepts a payload object containing data for the document, dynamically adds a heading and paragraph, and optionally includes a code block based on the payload. It returns the generated markdown as a string, illustrating how tempo can be used within functions to create parameterized content. ```ts import tempo from '@joggr/tempo'; /** * This is a simple example of using tempo to generate markdown as a function (template). */ export function createDocument(payload: { title: string, description: string, example?: string }) { const doc = tempo() .h1(payload.title) .p(payload.description); if (payload.example) { doc.code(payload.example); } return doc.toString(); } ``` -------------------------------- ### Building and Saving a Markdown Document with Tempo Source: https://github.com/joggrdocs/tempo/blob/main/packages/tempo/README.md This TypeScript snippet shows how to use Tempo to programmatically construct a markdown document. It demonstrates adding headings, paragraphs with formatted text (bold, italic), and tables, then converting the result to a markdown string and writing it to a file using Node.js `fs/promises`. ```typescript import fs from 'node:fs/promises'; import tempo from '@joggr/tempo'; const result = tempo() .h1('Hello World') .paragraph('Some things') .paragraph((txt) => txt .plainText('A sentence with') .bold('bolded words') .plainText('and') .italic('italicized words') .plainText('.') .build() ) .h2((txt) => txt .plainText('A') .italic('table') ) .table([ ['name', 'email'], ['Zac', 'zac@acmecorp.com'] ]) .toString(); await fs.writeFile('myFile.md', result); ``` -------------------------------- ### Serializing a Tempo Document to JSON Source: https://github.com/joggrdocs/tempo/blob/main/packages/tempo/README.md This TypeScript snippet illustrates how to generate a Tempo document and serialize its internal structure into a JSON object using the `.toJSON()` method. This serialized representation can be stored in a database or used for other purposes (Note: API is marked as unstable). ```typescript import db from 'db/orm'; import tempo from '@joggr/tempo'; const result = tempo() .h1('Hello World') .paragraph('Some things') .paragraph((txt) => txt .plainText('A sentence with') .bold('bolded words') .plainText('and') .italic('italicized words') .plainText('.') .build() ) .toJSON(); // Example of storing a serializable data object to the DB await db.collection('tempoDoc').findAndSave(1, result); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.