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

@zouloux/crafter

v0.2.1

Published

Scaffold code quickly from CLI

Downloads

7

Readme

crafter

Crafter is configurable and powerful file scaffolder. It can scaffold pretty much any ASCII file.

Crafter is based on :

Install

npm i -D @zouloux/crafter

Usage

craft $CRAFTER_PATH $APP_PATH
craft ./crafters/reflex/reflex-crafter.js ./src/my-app/

In package scripts

{
  "scripts" : {
	"craft-reflex": "craft ./crafters/reflex/reflex-crafter.js ./src/front/",
	"craft-route": "craft ./crafters/fastify/fastify-crafter.js ./src/back/"
  }
}

Crafter file

A Crafter file is a JS file which create craft actions. Craft actions create a menu for the user. A craft action can ask user questions and scaffold files from those questions.

crafters/reflex-crafter.js

import { askInput } from "@zouloux/cli"

// createCraftAction( crafterID:string, menuEntry:string, async (crafterRoot?:string, appPath?:string, env?:TEnv) => { ... } )
createCraftAction('symbol', 'Symbol (icons / logos ...)', async (craft, crafterRoot, appPath, env) => {
	// Ask user for category name
	const category = await askInput(
		// Uses nicePrint to style text, @see https://github.com/zouloux/cli/blob/main/src/Output.ts#L67
		// {u} -> underline
		// {/} -> remove previous styling
		// {d} -> dim
		`Symbol {u}c{/}ategory folder ? {d}(use plural) ex: icons, logos ...`,
		{ shortcuts: ['category', 'cat', 'c'], notEmpty: true }
	);
	// Ask user for symbol name
	const name = await askInput(
		`Symbol {u}n{/}ame ? {d}(use CamelCase, with category as suffix) ex : HomeIcon, BrandLogo, ...`,
		{ shortcuts: ['name', 'n'], notEmpty: true }
	);
	// Scaffold with those parameters
	// craft <GVars extends object>( vars:GVars, steps:TStep<GVars>[] )
	craft({
		// Those will be avaible in source template
		category: category.toLowerCase(),
		name: lowerCaseFirst( name ),
		Name: upperCaseFirst( name ),
	}, [
		vars => [
			// Source is templated with vars given
			// relative to $CRAFTER_PATH from cli
			`1-symbols/Name.tsx.template`,
			// And templated file is written here
			// relative to $APP_PATH from cli
			`1-symbols/${vars.category}/${vars.Name}.tsx`
		],
		// Can have other steps (other files templated)
		vars => [
			// ...
		]
	])
})

Step can also be a custom async function without auto-templating

createCraftAction('app', 'App', async (craft, crafterRoot, appPath, env) => {
	// Ask user questions
	// ...
	craft({
		name: lowerCaseFirst( name )
	}, [
		// A step can be custom if it does not return a tuple
		// Custom step ( no auto-templating, do anything you want using cli and files )
		async (vars) => {
			// Check if app already exists
			if ( await FileFinder.exists( appPath ) )
				throw new Error(`Reflex crafter, app ${vars.name} already exists`)
			// Clone app template with all directories
			const appTemplate = new Directory( path.join(crafterPath, '_app') )
			const children = await appTemplate.children('all', { dot: true })
			for ( const child of children )
				await child.copyTo( appPath )
			// Remove all gitkeeps
			const gitKeeps = await FileFinder.find('file', `src/**/.gitkeep`, { dot: true })
			for ( const gitKeep of gitKeeps )
				await gitKeep.delete()
		}
	])
})

Templates

Those files are templated with vars thanks to stach. Template delimiters are {{varName}}

crafter/1-symbols/Name.tsx.template

import { h, DefaultReflexProps } from "@zouloux/reflex";

interface Props extends DefaultReflexProps {

}

export function {{Name}} ( props:Props ) {
	return <svg fill="currentColor" viewBox="0 0 40 40"></svg>
}

Examples

See examples here :

To test example :

git clone https://github.com/zouloux/crafter
cd examples/simple
npm i
npm run craft

Legacy module loading

In case you have this error (node:56647) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

Add "type": "module" to your package.json

If this is not possible, use craft-legacy instead of craft in your package.json scripts.