npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webundsoehne/nx-tools

v6.1.5

Published

Common tools for NX.

Downloads

326

Readme


@webundsoehne/nx-tools

Version Downloads/week Dependencies semantic-release

Description

This package includes @nrwl/nx some tools to be commonly used in the schematics.

All the functions are imported from the root of the project.


Tools

This library mostly compromises of tools that are useful for generating schematics. All the generic methods and types that is usually used in schematics are exported from the root of the package. You can read the generated API documentation for further explanation of individual functionality.

Schematics

Generate Exports

This schematic can be used for other schematics to generate exports based on designated patterns.

After parsing through your rules, you can add this as an individual role to go through all the files and match designated patterns and create TypeScript exported modules of matching files. All paths will be relative.

There is two use cases for this:

  • Internal processing

    This will parse your files in your tree you defined and only export them, and does not care about the real files on host. To achieve this, this rule has to come before "mergeWith" function of tree with physical files.

  • External processing

    To achieve this, this rule has to come after "mergeWith". Schematic will go through the whole real file base supplied as a tree and match the files on the physical file system as well.

Example:

import { Schema as ExportsSchema } from '@webundsoehne/nx-tools/dist/schematics/exports/main.interface'

export async function createApplicationFiles(options: NormalizedSchema, context: SchematicContext): Promise<Rule> {
  return chain([
    /** Your chain */
    /** Your chain */
    /** Your chain */

    externalSchematic<ExportsSchema>('@webundsoehne/nx-tools', 'exports', {
      silent: true,
      skipFormat: true,
      templates: {
        root: options.root,
        templates: [
          {
            cwd: options.root,
            output: 'index.ts',
            pattern: '**/*.module.ts'
          }
        ]
      }
    })
  ])
}

Through the cli it will prompt you to select an output file and and a pattern to automatically export everything with the given glob pattern.

Generic Generator

Generic generator is a generic library that allows to create a basic generator library that can work in either in the root or current working directory. It will generate the files selected on the type.

  • Create your schema from the generator.

    // main.ts
    import { generateGenericGenerator } from '@webundsoehne/nx-tools/dist/schematics/generator/main'
    import { join } from 'path'
    
    /**
     * @param  {Schema} schema
     * The schematic itself.
     */
    export default generateGenericGenerator(join(__dirname, './files'))
  • Extend the interfaces from the base rule.

    // main.interface.ts
    import { Schema as BaseSchema, NormalizedSchema as BaseNormalizedSchema } from '@webundsoehne/nx-tools/dist/schematics/generator/main.interface'
    
    import { AvailableGenerators } from '@src/interfaces'
    
    type TypedBaseSchema = BaseSchema<AvailableGenerators>
    type TypedBaseNormalizedSchema = BaseNormalizedSchema<{ test: boolean }, AvailableGenerators>
    
    export { TypedBaseSchema as Schema, TypedBaseNormalizedSchema as NormalizedSchema }
  • Create your schema.json for nx.

  • Add your files in to the given files directory in subfolders with the names of generators.

  • Add description.txt, if you want to have hint in the type selection prompt.

  • Add extra prompts if you want to inject stuff to template. Prompt options are available here. Give every prompt name property to access it like inject[name] in jinja templating. If there is a single prompt it will be just on the inject property.

    // prompts.json
    [
      { "type": "Input", "name": "test", "message": "test" },
      { "type": "Input", "name": "test2", "message": "test" }
    ]