0.1.3 • Published 1 year ago

@strwatcher/suipta v0.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Suipta

Simple boilerplate-code cli generator intended to imporve your experience with Feature-Sliced Design methodology

Based on:

How-to-use

To use suipta you need one of these package managers:

  • npm
  • yarn
  • pnpm
  • volta

Installation

for npm:

npm i --save-dev @strwatcher/suipta

for yarn:

yarn add --dev @strwatcher/suipta

for pnpm:

pnpm add -D @strwatcher/suipta

for volta:

volta install @strwatcher/suipta

Simple Usage

To use suipta with out-of-box templates you need to add it to your scripts in package.json

"scripts": {
    ...
    "suipta": "suipta",
    ...
}

You can also add aliases for slice and segment generators:

"scripts": {
    ...
    "slice": "suipta slice",
    "segment": "suipta segment",
    ...
}

After that simply start suipta from command line:

  • In interactive mode:
pnpm suipta || pnpm slice || pnpm segment
  • Using arguments bypassing:
pnpm suipta slice entities user

Where:

  • slice is generator type (slice | segment)
  • entities is one of 5 preconfigured layers
  • user is custom name of creating slice

Arguments

If you wanna use not default settings of generators you can use arguments. (This feature works only in 'slice' generator at this moment):

--ui : (react | solid) --model : (effector) --language : (js | ts)

Also you can customize path to suipta config using --configPath : string

Configuration

If you need to customize behaviour of suipta you can write your own config.

Default location is root dir of your project

Configs that are resolving by default:

  • suipta.config.js
  • suipta.config.cjs
  • suipta.config.yaml
  • suipta.config.yml
  • suipta.config.json

To provide typings for config you can follow this example:

// suipta.config.js

/**
 * @type {import('suipta').SuiptaConfig}
 * **/
export default {
    layers: ['entities', 'features', 'widgets',  'pages'] // Array<string>
    segmentLayers: ['shared'] // Array<string>
    segment: ['lib', 'ui'] // Array<string>
    templatesDir?: './templates' // string which is relative path (from project root dir) to templates directory
    lang?: 'ts' // option to choose language ('js' | 'ts')
    rootDir: './src' // string whic is relative path (from project root dir) to directory where results of generation will be saved
}

Custom templates

If you need more flexibility, you can write own templates You need to place them in templates dir and set its path to templatesDir option in config.

In templates directory you need to follow next structure:

templates/
....entities/
........files which will be use in generation
....other layer in which slice will be generated/
........files which will be use in generation
....segments/
........shared/
............files which will be use in generation
........other layer in which segment will be generated/
............files which will be use in generation

Templates format

Suipta use handlebars syntax to process dynamic values in templates

Slice generator:

In templates of slice generator 2 vaiables are avaliable:

  • layer
  • slice

In segment generator 3:

  • layer
  • segment
  • component

These values can be modified using helpers:

  • pascalCase
  • camelCase
  • snakeCase
  • etc...

Example of temlate file with dynamic fields:

// templates/pages/ui.tsx

import {PageLayout} from '...'

type Props = {

}

export const {{pascalCase slice}}Page = (props: Props) => {
    return <PageLayout></PageLayout>
}

Imagine, that slice name is auth. The result of generation will be:

// src/pages/auth/ui.tsx

import {PageLayout} from '...'

type Props = {

}

export const AuthPage = (props: Props) => {
    return <PageLayout></PageLayout>
}

Contributing

Requirments:

Install tooling:

volta install node pnpm lefthook commitizen

Install dependencies:

pnpm i

Run tests:

In watch mode

pnpm test

One time

pnpm test:run

Lint code:

pnpm lint

Format code:

pnpm format

Commitizen friendly