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

geenee-rate

v2.1.1

Published

code generator based on geenee metadata

Downloads

119

Readme

geenee-rate

geenee-rate

code generator based on geenee metadata.

codecov Version Downloads/week License

Geenee Template

:clipboard: Why

File generation consists of three types of files. Each requires different context to generate:

  1. standard files that never change. These require no context.
  2. static files--they vary from project to project, but do not receive dynamic content. These require a static specification of info for each example in a particular generated code base.
  3. dynamic files--they contain dynamic content. These require specification for whatever query is required.

:white_check_mark: What

A single async function that generates code from a specified geenee template and settings, handling the context of all three types of files above. See Context in geenee-rate for details about the context.

geenee-rate ignores anything in the directory of the package, with the exception on a package.json file.

It will overwrite any files with the same path and name.

Because it leaves everything else, you can apply a starter first. That is useful because you can use head-starter with your same geenee template.

:wrench: Usage

Import the package:

npm i geenee-rate

Set the following in your code:

Then you can call:

const generate = require('geenee-rate')

try {
    await generate(
      codeDir, nsInfo, config, templateDir
    )
  } catch (error) {
    throw new Error(`could not generate the code: ${error}`)
  }

If you need to get the config, you can use magicalstrings. Here's an example using TypeScript:

const {getConfig} = require('magicalstrings').configs
import {Configuration} from 'magicalstrings'

let config: Configuration
...
config = await getConfig(templateDir)

:bulb: Example

Check out the usage in geenee-spell.

:zap: Creating Templates

You can create such a template easily from a code base using copykat.

Once you have created a basic template, geenee-rate has a built-in context to make the job much simpler. See the documenation of barbells for treatment of handlebars helpers and partials. You may find that you don't need to add any custom helpers.

Also, check out the Creating Templates on the geenee documentation.

package.json files

The biggest gotcha with geenee-rate is the package.json files.

It's not complicated, but you have to understand two things:

  1. package.json files are the one exception to the rule that geenee-rate doesn't know or care what was in your project directory--it will simply overwrite or ignore existing files. But the legacy package.json is updated rather than replaced;
  2. That said, what's in the template file general/packageinfo.json.hbs, takes precendence over what was in the legacy package.json. That is to say that any value for keys generated by that file will replace the values that you had before. That will be based upon what's in the ns.yml specs file. So in practice you will need to update the ns.yml file with the latest information. We may replace that with a different behavior in the future, such as an option not to regenerate the json.

Note that dependency versioning is not relevant to geenee-rate. Whatever you had before should stay the same.

Related project

A geenee template is normally used for multiple generation of code. To do that, geenee-spell stores a meta directory within the generated code base to allow for regeneration.

But geenee templates are a very powerful tool for one-time creation as well. For instance, you may not want to include a meta directory in your code. That is the reason for geenee-rate existing separately.

:ledger: API

async function generateCode(
  codeDir: string,
  nsInfo: NsInfo,
  config: Configuration,
  templateDir: string,
  addStarter: boolean = true,
  sessionIn: any = {},
)

The NsInfo and Configuration types are exposed in magicalstrings.

arguments

  • codeDir: string telling the directory where you want the code to generate.
  • nsInfo: NsInfo telling about
  • config: Configuration,
  • templateDir: string,
  • addStarter: boolean set by default to true. It means that if the code contains a head-starter startup sequence, it will be executed.
  • sessionIn: object, by default empty. It lets you apply a dynamapping session to change the values of a startup sequence dynamically if you like. codeDir is added to the session automatically, so you can insert $codeDir into your startup sequence already.