@wheatstalk/lit-snip
TypeScript icon, indicating that this package has built-in type declarations

0.0.107 • Public • Published

Lit Snipper

A small tool to snip and format sections of code for markdown-based literature.

Usage

Let's say we have a file called my-example.lit.ts with this content:

import * as cdk from '@aws-cdk/core';
import { IntrinsicValidator, Validation } from '..';
import { TestLambdas } from './test-lambdas';

/** @internal */
export class ItLitLambda extends cdk.Stack {
  constructor(scope_: cdk.Construct, props: cdk.StackProps = {}) {
    super(scope_, 'ItLitLambda', props);

    const testLambdas = new TestLambdas(this, 'TestLambdas');
    const lambdaFunction = testLambdas.alwaysSucceeds;

    // Lit code uses 'scope'
    const scope = this;

    // ::SNIP
    new IntrinsicValidator(scope, 'IntrinsicValidator', {
      validations: [
        Validation.lambdaInvokeSucceeds({
          lambdaFunction,
        }),
      ],
    });
    // ::END-SNIP
  }
}

When you run the lit-snip like this:

npx -p @wheatstalk/lit-snip lit-snip ./my-example.lit.ts

The script will output all the lines between ::SNIP and ::END-SNIP and it will adjust the indentation to match the ::SNIP line's comment, wrapping the example in a markdown code block like this:

new IntrinsicValidator(scope, 'IntrinsicValidator', {
  validations: [
    Validation.lambdaInvokeSucceeds({
      lambdaFunction,
    }),
  ],
});

You might find this useful in conjunction with markmac to keep your README.md code examples in sync with tests that prove the examples work.

Readme

Keywords

none

Package Sidebar

Install

npm i @wheatstalk/lit-snip

Weekly Downloads

86

Version

0.0.107

License

Apache-2.0

Unpacked Size

23.2 kB

Total Files

10

Last publish

Collaborators

  • misterjoshua