@kieran-osgood/scribe
v0.4.1
Published
Scribe is a file templating CLI based on Mustache Templates.
Downloads
5
Readme
scribe
Bootstrap your common files with Mustache templates.
Quick Start
We can handle setup via built in commands to bootstrap out the initial config, you'll need to edit it to add in some of your domains file requirements before your first run (see below, or examples)
Install
npm i -D @kieran-osgood/scribe
pnpm i -D @kieran-osgood/scribe
yarn add -D @kieran-osgood/scribe
bun i -D @kieran-osgood/scribe
Initialise Config file
scribe init
Getting Started
A simple use-case is a creating a single file from a template, but each CLI run can be configured to output multiple files.
As an example, if you're creating a React Component, you can output test files, sub-component barrel files, storybook files etc.
Example
Given a config and scribe files in the root of the repository (See examples for this setup)
// scribe.config.ts -- this is the config file we'll read the settings from
import type { ScribeConfig } from '@scribe/config';
const config = {
options: {
rootOutDir: '.',
templatesDirectories: ['./examples'],
},
templates: {
// Keys within the templates object correspond to what interactive mode will display, or --template flag will accept
screen: {
outputs: [
{
// the templateFileKey screen corresponds to the template `screen.scribe` shown below
templateFileKey: 'screen',
output: {
directory: 'examples/src/screens',
fileName: '{{Name}}.ts',
},
},
{
// the templateFileKey screen corresponds to the template `screen.test.scribe` shown below
templateFileKey: 'screen.test',
output: {
directory: 'examples/src/screens',
fileName: '{{Name}}.test.ts',
},
},
],
},
},
} satisfies ScribeConfig;
export default config;
// ./screen.scribe -- This is the template file that we will generate from
import * as React from 'react';
type {{Name}}Props = {}
function {{Name}}Screen() {
return (
<></>
)
}
// ./screen.test.scribe -- This is the template file that we will generate from
describe('{{Name}}', function() {
it('should ', function() {
});
});
When you run the following command
# Interactive mode!
scribe
# Non-Interactive mode
scribe --template screen --name Login
# Partially Interactive mode - will prompt for additional args!
scribe --template screen
# or
scribe --name Login
Note: you can either run in interactive mode, or pass the flags in directly, each of these commands allow you to get to the same end result
Given the above CLI run with the files and paths all setup appropriately, you should see the output of two files in the following directories
// ✅ File Created: `examples/src/screens/Login.ts`
import * as React from 'react';
type LoginProps = {}
function LoginScreen() {
return (
<></>
);
}
// ✅ File Created: `examples/src/screens/Login.test.ts`
describe('Login', function() {
it('should ', function() {
});
});