Giter Site home page Giter Site logo

scaffdog / scaffdog Goto Github PK

View Code? Open in Web Editor NEW
671.0 3.0 23.0 20.28 MB

:dog: scaffdog is Markdown driven scaffolding tool.

Home Page: https://scaff.dog

License: MIT License

JavaScript 1.44% TypeScript 95.64% MDX 2.92%
nodejs cli scaffdog scaffold markdown template generator

scaffdog's Introduction

scaffdog

scaffdog is Markdown driven scaffolding tool.

GitHub Workflow Status npm npm MIT LICENSE

scaffdog

asciicast

Multiple files can be output in a document, and flexible scaffolding is possible with a simple but powerful template syntax ๐Ÿ•

Documentation

Visit https://scaff.dog to view the full documentation.

Features

  • ๐Ÿ“ Markdown driven
    • You can define a template with <h1> and code block.
    • It will be a Documetable template !
    • Define meta information with extended syntax using Front Matter.
  • ๐Ÿ—’๏ธ Intuitive template
    • It provides a simple yet powerful template engine inspired by ECMAScript and Go text/template.
    • Many built-in helper functions required to define templates are also provided.
  • ๐Ÿš€ Ready to use
    • You can quickly start using $ scaffdog init.
    • Other useful commands are provided for immediate scaffolding.
  • ๐Ÿ’… Prettier Integration
    • Markdown works very well with Prettier, and the templates maintain beautiful code.
    • We also offer a Prettier Plugin for scaffdog's template engine.

Requirements

  • Node.js v18.0.0+

Getting Started

Installation

scaffdog can be installed globally, but we recommend installing it locally on the project.

$ npm install --save-dev scaffdog

Quick Start

In the following tutorial you can start using scaffdog immediately !

Setup

By default, it stores the document file and configuration file in the .scaffdog directory.

Creating directories, configuration file and initial documents can be done with the init subcommand.

$ npx scaffdog init

? Please enter a document name. component

Setup of scaffdog ๐Ÿถ is complete!

  โœ” .scaffdog/config.js
  โœ” .scaffdog/component.md

Now you can do scaffold by running `$ scaffdog generate`.

Please refer to the following documents and customize it.
https://scaff.dog/docs/templates

After running the command, the .scaffdog/component.md file should have been generated. Rewrite that file as follows:

---
name: 'component'
root: '.'
output: '.'
questions:
  name: 'Please enter a component name.'
---

# `{{ inputs.name | pascal }}/index.ts`

```typescript
export * from './{{ inputs.name }}';
```

# `{{ inputs.name | pascal }}/{{ inputs.name | pascal }}.tsx`

```typescript
export type Props = React.PropsWithChildren<{}>;

export const {{ inputs.name | pascal }}: React.FC<Props> = ({ children }) => {
  return (
    <div>{children}</div>
  );
};
```

Let's scaffold using the component document!

$ npx scaffdog generate

? Please select a document. component
โ„น Output destination directory: "."
? Please enter a component name. PrettyDog

๐Ÿถ Generated 2 files!

     โœ” PrettyDog/index.ts
     โœ” PrettyDog/PrettyDog.tsx

Congratulations ๐ŸŽ‰

The first file was generated.

$ cat PrettyDog/index.ts
export * from './PrettyDog';

$ cat PrettyDog/PrettyDog.tsx
export type Props = React.PropsWithChildren<{}>;

export const PrettyDog: React.FC<Props> = ({ children }) => {
  return (
    <div>{children}</div>
  );
};

Check out our documentation site to customize your documentation ๐Ÿ‘

Migration

There are important changes in the major update.

See Migration Guide.

Contributing

See CONTRIBUTING.md.

CHANGELOG

See CHANGELOG.md.

License

MIT ยฉ wadackel

Thank you for reading!

scaffdog's People

Contributors

0918nobita avatar dependabot[bot] avatar dora1998 avatar ewreurei avatar github-actions[bot] avatar isoppp avatar konojunya avatar lcdsmao avatar naturalclar avatar renovate-bot avatar renovate[bot] avatar wadackel avatar yaakaito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scaffdog's Issues

How to generate README.md with codeblocks?

Firstly, really nice job on scaffdog. I really like how you use the markdown scaffolding files. It is clever.
I have a question (maybe I'm doing something wrong). How do I scaffold a markdown file that has code backticks?

Expected Behavior

I want to generate a markdown file with code examples (triple-backticks). Is there some way to escape the ``` such that the escapes are removed on generation? Unfortunately, I need to include images because, well, backticks.

Actual Behavior

The README.md file gets truncated.

Steps to Reproduce (including precondition)

{Please write here}

Screenshot on This Problem (if possible)

Source

image

Generated

image

Your Environment

  • OS: {Please write here}
  • scaffdog version: {Please write here}

Inject to many place in one file

I am trying to insert text in multiple places in my open api file. I am planning to write some inserts like below. however the read output.abs function does not update the file content after overwrite. Do you have any suggestions for me to achieve my expectations?
this is my scaffdog code in one md file

docs/openapi.yaml

{{ read output.abs | before "paths:" +1 }}
  /{{ inputs.modules }}:
    $ref: './paths/{{ inputs.modules | camel }}/index.yaml'
  /{{ inputs.modules }}/[{{ inputs.module }}Id]:
    $ref: './paths/{{ inputs.modules | camel }}/{{ inputs.module }}Id.yaml'
{{ read output.abs | after "paths:" }} 

docs/openapi.yaml

{{ read output.abs | before "responses:" +1 }}
    {{ inputs.module }}:
      $ref: './components/responses/{{ inputs.modules }}/{{ inputs.module }}.yaml'
    {{ inputs.modules }}:
      $ref: './components/responses/{{ inputs.modules }}/{{ inputs.modules }}.yaml'
{{ read output.abs | after "responses:" }}

docs/openapi.yaml

{{ read output.abs | before "requestBodies:" +1 }}
    {{ inputs.module }}Create:
      $ref: './components/requestBodies/{{ inputs.modules }}/{{ inputs.module }}Create.yaml'
    {{ inputs.modules }}Update:
      $ref: './components/requestBodies/{{ inputs.modules }}/{{ inputs.module }}Update.yaml'
{{ read output.abs | after "requestBodies:" }}

docs/openapi.yaml

{{ read output.abs | before "tags:" +1 }}
  - name: {{ inputs.modules }}
    description: {{ pascal(inputs.modules) }} API
{{ read output.abs | after "tags:" }}

Expected Behavior

servers:
  - url: 'http://localhost:3000/api'
    description: develop
paths:
  /players:
    $ref: './paths/players/index.yaml'
  /players/[playerId]:
    $ref: './paths/players/playerId.yaml'

components:
  schemas:
    $ref: './components/schemas.yaml'
  responses:
    player:
      $ref: './components/responses/players/player.yaml'
    players:
      $ref: './components/responses/players/players.yaml'
  requestBodies:
    playerCreate:
      $ref: './components/requestBodies/players/playerCreate.yaml'
    playersUpdate:
      $ref: './components/requestBodies/players/playerUpdate.yaml'
tags:
  - name: players
    description: Players API

Actual Behavior

servers:
  - url: 'http://localhost:3000/api'
    description: develop
paths:

components:
  schemas:
    $ref: './components/schemas.yaml'
  responses:
  requestBodies:
tags:
  - name: players
    description: Players API

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • chore: update pnpm to v9.1.1
  • chore: update dependency typescript-eslint to v7.9.0
  • chore: update dependency execa to v9
  • chore: update pnpm/action-setup action to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/actions/setup-node/action.yml
  • pnpm/action-setup v3.0.0
  • actions/setup-node v4
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/upload-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • actions/checkout v4
  • actions/download-artifact v3
  • changesets/action v1
.github/workflows/commitlint.yml
  • actions/checkout v4
  • wagoid/commitlint-github-action v6
.github/workflows/docs.yml
  • actions/checkout v4
  • actions/upload-pages-artifact v3
  • actions/deploy-pages v4
npm
package.json
  • @changesets/changelog-github 0.5.0
  • @changesets/cli 2.27.1
  • @commitlint/cli 19.3.0
  • @commitlint/config-conventional 19.2.2
  • @commitlint/config-lerna-scopes 19.0.0
  • @eslint/js 9.2.0
  • @types/mock-fs 4.13.4
  • @types/node 18.19.33
  • eslint 9.2.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • globals 15.1.0
  • husky 9.0.11
  • lint-staged 15.2.2
  • mock-fs 5.2.0
  • npm-run-all2 6.1.2
  • prettier 3.2.5
  • prettier-plugin-packagejson 2.5.0
  • rimraf 5.0.5
  • ts-morph 22.0.0
  • tsx 4.9.3
  • turbo 1.13.3
  • typescript 5.4.5
  • typescript-eslint 7.8.0
  • unbuild 1.2.1
  • vitest 1.6.0
  • zx 8.0.2
  • pnpm 9.1.0
  • ansi-regex 5.0.1
  • type-fest 4.18.2
packages/@scaffdog/config/package.json
  • jiti ^1.14.0
  • zod ^3.22.3
packages/@scaffdog/core/package.json
  • mdast-util-to-string ^4.0.0
  • remark-parse ^10.0.2
  • unified ^10.1.2
  • unist-util-visit-parents ^6.0.1
  • @types/unist 3.0.2
packages/@scaffdog/engine/package.json
  • change-case ^5.0.0
  • dayjs ^1.10.4
  • is-plain-obj ^4.1.0
  • plur 5.1.0
  • @unicode/unicode-15.0.0 1.5.2
  • regenerate 1.4.2
packages/@scaffdog/error/package.json
  • chalk ^5.3.0
  • string-length 6.0.0
packages/@scaffdog/types/package.json
  • type-fest 4.18.2
packages/prettier-plugin-scaffdog/package.json
  • minimatch ^9.0.0
  • prettier 3.2.5
packages/scaffdog/package.json
  • ansi-escapes ^7.0.0
  • chalk ^5.3.0
  • cli-truncate ^4.0.0
  • consola ^3.2.3
  • deepmerge ^4.2.2
  • figures ^6.0.0
  • front-matter ^4.0.2
  • fuse.js ^7.0.0
  • globby ^14.0.0
  • indent-string ^5.0.0
  • inquirer ^9.2.8
  • inquirer-autocomplete-prompt ^3.0.0
  • is-plain-obj ^4.1.0
  • log-symbols ^6.0.0
  • micromatch ^4.0.4
  • node-emoji ^2.1.3
  • plur ^5.0.0
  • strip-ansi 7.1.0
  • terminal-size ^4.0.0
  • update-notifier ^7.0.0
  • valid-filename ^4.0.0
  • wrap-ansi ^9.0.0
  • yargs ^17.7.2
  • zod ^3.22.3
  • @types/inquirer 9.0.7
  • @types/inquirer-autocomplete-prompt 3.0.3
  • @types/micromatch 4.0.7
  • @types/update-notifier 6.0.8
  • @types/yargs 17.0.32
  • type-fest 4.18.2
website/package.json
  • @chakra-ui/next-js ^2.1.4
  • @chakra-ui/react ^2.7.0
  • @emotion/react ^11.11.1
  • @emotion/styled ^11.11.0
  • @hookform/resolvers ^3.1.1
  • contentlayer ^0.3.3
  • date-fns ^3.0.0
  • framer-motion ^7.0.0
  • next 14.0.1
  • next-contentlayer ^0.3.3
  • pako ^2.1.0
  • prism-react-renderer ^2.0.5
  • prismjs 1.29.0
  • react 18.3.1
  • react-dom 18.3.1
  • react-hook-form ^7.44.3
  • react-hotkeys-hook ^4.4.0
  • react-simple-code-editor ^0.13.0
  • recoil ^0.7.4
  • recoil-persist ^5.1.0
  • remark-emoji ^4.0.0
  • remark-gfm ^3.0.1
  • remark-slug ^7.0.1
  • shadowrealm-api ^0.8.2
  • yup ^1.0.0
  • @babel/core 7.24.5
  • @chakra-ui/styled-system 2.9.2
  • @types/github-slugger 2.0.0
  • @types/node 18.19.33
  • @types/pako 2.0.3
  • @types/prismjs 1.26.4
  • @types/react 18.3.1
  • @types/react-dom 18.3.0
  • eslint 9.2.0
  • eslint-config-next 14.2.3
  • execa 8.0.1
  • github-slugger 2.0.0
  • next-sitemap 4.2.3
  • type-fest 4.18.2
  • typescript 5.4.5

  • Check this box to trigger a request for Renovate to run again on this repository

Parse directory of templates without having to define each individually?

Is there a simple way to parse an entire directory without having to define and then read each one individually?
For instance, I have a folder of .scss partials using CSS Custom Properties and I want to give the user an option to add a prefix to all pre-defined properties (ie --{{prefix}}-background-color: blue;) before I clone the template directory into their desired output.

I can make it work if I add a template title for each in the md file and then read() the file but that's a bit tedious. Any way to loop through the directory and read each file? I've started to write a helper function recursively using readdir however I can't see a way around having to re-write all of the writefile/mkdir/check exists functionality that you've already elegantly handled.

Any thoughts or guidance? Or maybe this is an enhancement recommendation. Really loving the script!

Your Environment

  • OS: macOS Sonoma
  • scaffdog version: 4.0

Get template from a folder of `md` files

I've been wondering if scaffdog has the ability to input multiple files of markdown and merge them before creating a scaffold. It would be nice if I can separate the files from the .config/app.md to .config/app/index.md as the main file and spread the files inside the folder with multiple folders/directory.

The use case is for generating new apps (such as custom vite app) for a certain projects in a monorepo. Currently as I assume, the whole config has to be inside a single file and it would be a long file if I want to scaffold a vite project.

Other than that, it's a huge help for a lazy devs like me.

`safe-eval` Vulnerability Issues

Thanks for the awesome library!

Now, we have a issue with the safe-eval library. It's got some unpatched security issues for about 4 years and Dependabot keeps flagging about 10 alerts because of it.
https://security.snyk.io/vuln/?search=safe-eval

Here are a couple of solutions I thought about:

  1. Replace the current implementation with a custom one, leveraging Node.js's vm.
  2. We could also consider Shadow Realms. It's still in ECMAScript Stage 3 and not completely stable, but there's a polyfill https://github.com/ambit-tsai/shadowrealm-api we can use.

Would love to know what you think. And if we decide on a path, I'm ready to help get it done ๐Ÿ™Œ

I want to solve "SyntaxError: Missing "}}".

I tried to generate a component file using the following code and got a SyntaxError: Missing "}}" error.

import { {{ inputs.name | pascal }} as {{ inputs.name | pascal }}OG } from "react-native";
import { StyledComponent } from "nativewind";

import { useTheme } from "@acme/theme";

export type {{ inputs.name | pascal }}Props = React.ComponentPropsWithoutRef<typeof {{ inputs.name | pascal }}OG>;

export function {{ inputs.name | pascal }}(props: {{ inputs.name | pascal }}Props) {
  const theme = useTheme();

  return (
    <StyledComponent
      component={{{ inputs.name | pascal }}OG}
      {...props}
      style={[props.style, { backgroundColor: theme.colorTheme.primary }]}
    />
  );
}

The component={{{ inputs.name | pascal }}OG} in the code is the problem area.

For example, if the component name is Text, I want it to be component={TextOG}.

How do I change it to achieve this?

Your Environment

  • OS: macOS Ventura 13.3.1
  • scaffdog version: 2.5.0

[Feature Request]: `scaffdog generate` accept template parameter

I was hoping if there is an option to accept template parameter with scaffdog generate in a specific case when we know what we should choose obviously.

Expected Behavior

If we have templates like

npx scaffdog list
- hello

I hope

npx scaffdog generate --template|-t hello

then, we will skip the question choosing template about ? Please select a document. (Use arrow keys).

Actual Behavior

none

Steps to Reproduce (including precondition)

none, it's not a bug.

Screenshot on This Problem (if possible)

none, it's not a bug.

Your Environment

  • OS: macOS latest
  • scaffdog version: latest

Planning v2

Breaking Changes

  • Drop support for Node.js 12 #379

Template

  • If Statement or Expression #373
  • Variable Statement / Expression #373
  • Support array values #397
  • Support helper functions for array values #400
  • Skip file generation #401

Misc

  • Document site #418
  • Playground
  • Migration guide (see)

After v2 (coming soon)

  • Conditional prompt
  • Support for flags to answer questions (Additional features will be added after v2 release)

We are considering these plans ๐Ÿถ

Insert new line at the end of file

Hi. I am a regular user of this tool. Thank you all for your work.
This time I have a question.
I want to insert one blank line at the end of an auto-generated file.
I put the blank line in the markdown, but it does not work as expected.
For example, writing a markdown like the one below will not insert a blank line at the end of the auto-generated file.

import type { VFC } from "react";

export const Profile: VFC = () => {
  return <main>Profile</main>;
};
# newline

My project requires a blank line at the end of the file, so I would like to insert it somehow.
Is there any way to solve this?

Your Environment

  • OS: MacOS Monterey 12.5
  • scaffdog version: 2.0.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.