Code Monkey home page Code Monkey logo

create-snippet's Introduction

Installation

To install the create-snippet package, run the command:

npm i -D create-snippet

Basic commands

  1. npx create-snippet --help or -h will show hints
  2. npx create-snippet --init or -i initializes the project
  3. npx create-snippet --generate or -g generates a new snippet
  4. npx create-snippet --clear-cache or -cc clear cache

New snippet

When creating a new snippet, create a directory inside the directory .create-snippet with an arbitrary name, create the required number of files and directories inside this directory.

SnippetName

The strings snippetName specified inside the file or in the file name will be converted to a custom string when generating a new snippet.

PrefixName

The strings prefixName specified inside the file when generating a new snippet will be converted to custom strings.

SuffixName

The strings suffixName specified inside the file when generating a new snippet will be converted to custom strings.

Supported cases for strings

  1. camelCase
  2. PascalCase
  3. lower_snake_case
  4. UPPER_SNAKE_CASE
  5. lower-kebab-case
  6. UPPER-KEBAB-CASE

Specifying parameters via the console

  1. snippet - any string
  2. name - any string in the format lower-kebab-case
  3. path - any string
  4. prefix - any string in the format lower-kebab-case
  5. suffix - any string in the format lower-kebab-case

create-snippet's People

Contributors

zharinov-nikita avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

create-snippet's Issues

formatSnippet - refactoring

private formatSnippet(pathToSnippet: string) {
const unformattedSnippet = JSON.stringify(fs.readFileSync(nodePath.join(pathToSnippet), 'utf-8'))
const formattedSnippet = unformattedSnippet
.replaceAll(enumSnippetName.camelCase, `${this.moduleString.toCamelCase(this.options.name)}`)
.replaceAll(enumSnippetName.pascalCase, `${this.moduleString.toPascalCase(this.options.name)}`)
.replaceAll(enumSnippetName.lowerSnakeCase, `${this.moduleString.toLowerSnakeCase(this.options.name)}`)
.replaceAll(enumSnippetName.upperSnakeCase, `${this.moduleString.toUpperSnakeCase(this.options.name)}`)
.replaceAll(enumSnippetName.lowerKebabCase, `${this.moduleString.toLowerKebabCase(this.options.name)}`)
.replaceAll(enumSnippetName.upperKebabCase, `${this.moduleString.toUpperKebabCase(this.options.name)}`)
.replaceAll(enumPrefixName.camelCase, `${this.moduleString.toCamelCase(this.options.prefix)}`)
.replaceAll(enumPrefixName.pascalCase, `${this.moduleString.toPascalCase(this.options.prefix)}`)
.replaceAll(enumPrefixName.lowerSnakeCase, `${this.moduleString.toLowerSnakeCase(this.options.prefix)}`)
.replaceAll(enumPrefixName.upperSnakeCase, `${this.moduleString.toUpperSnakeCase(this.options.prefix)}`)
.replaceAll(enumPrefixName.lowerKebabCase, `${this.moduleString.toLowerKebabCase(this.options.prefix)}`)
.replaceAll(enumPrefixName.upperKebabCase, `${this.moduleString.toUpperKebabCase(this.options.prefix)}`)
.replaceAll(enumSuffixName.camelCase, `${this.moduleString.toCamelCase(this.options.suffix)}`)
.replaceAll(enumSuffixName.pascalCase, `${this.moduleString.toPascalCase(this.options.suffix)}`)
.replaceAll(enumSuffixName.lowerSnakeCase, `${this.moduleString.toLowerSnakeCase(this.options.suffix)}`)
.replaceAll(enumSuffixName.upperSnakeCase, `${this.moduleString.toUpperSnakeCase(this.options.suffix)}`)
.replaceAll(enumSuffixName.lowerKebabCase, `${this.moduleString.toLowerKebabCase(this.options.suffix)}`)
.replaceAll(enumSuffixName.upperKebabCase, `${this.moduleString.toUpperKebabCase(this.options.suffix)}`)
return JSON.parse(formattedSnippet)
}

Flat

Создание файлов без дополнительной директории

loading

Статус загрузки в момент создания компонента

github-actions (npm published)

При пуше нового тега обновить версию в package.json и отправить пакет в npm

  • 1. Обновить версию в package.json при создании нового тега
  • 2. При пуше в репозиторий тега сделать сборку и отправить в npm

run command

Выполнить массив команд переданных через консоль

Добавить подсказки (any-string-in-kebab-case)

private async addOptions() {
const data = async () => [
{
type: 'select',
name: 'snippetName',
message: 'Pick a snippet',
choices: fs.readdirSync(this.rootDirConfig).map((path) => {
return { title: path, value: path }
}),
initial: 0,
},
{ type: 'text', name: 'name', message: 'Pick a name' },
{ type: 'text', name: 'path', message: 'Pick a path' },
{
type: 'toggle',
name: 'isFlat',
message: 'Create a flat file structure?',
initial: false,
active: 'yes',
inactive: 'no',
},
{
type: async (_: any, values: TypeOptionsSnippetGeneration) => {
return (await this.check(values.snippetName)).isPrefix ? 'text' : null
},
name: 'prefix',
message: 'Pick a prefix',
},
{
type: async (_: any, values: TypeOptionsSnippetGeneration) => {
return (await this.check(values.snippetName)).isSuffix ? 'text' : null
},
name: 'suffix',
message: 'Pick a suffix',
},
]

PrefixName и SuffixName

Добавить возможность в файлах вместе с TemplateName использовать PreffixName

[is]-snippet-name

Если передать название снипепета как is-snippet-name, то будет предложен выбор (true/false) для его создания

JSON.stringify

Заменить метод JSON.stringify на точное копирование строки 🤔

Передавать через настройки путь к верхней директории

  1. Чтобы создать все файлы за один проход, достаточно указать путь к папке ui
  2. Чтобы создать определенный файл, достаточно указать путь к определенному файлу или массив файлов ["ui/template-name.hook.ts", "index.ts"]
📁ui
├──📁template-name.component.ts
├──📁temlate-name.hook.ts
└──📁index.ts

Refactoring (ModuleSnippet)

if (new RegExp(enumPrefixName.camelCase).test(data)) prefix += 1
if (new RegExp(enumPrefixName.lowerKebabCase).test(data)) prefix += 1
if (new RegExp(enumPrefixName.lowerSnakeCase).test(data)) prefix += 1
if (new RegExp(enumPrefixName.pascalCase).test(data)) prefix += 1
if (new RegExp(enumPrefixName.upperKebabCase).test(data)) prefix += 1
if (new RegExp(enumPrefixName.upperSnakeCase).test(data)) prefix += 1
if (new RegExp(enumSuffixName.camelCase).test(data)) suffix += 1
if (new RegExp(enumSuffixName.lowerKebabCase).test(data)) suffix += 1
if (new RegExp(enumSuffixName.lowerSnakeCase).test(data)) suffix += 1
if (new RegExp(enumSuffixName.pascalCase).test(data)) suffix += 1
if (new RegExp(enumSuffixName.upperKebabCase).test(data)) suffix += 1
if (new RegExp(enumSuffixName.upperSnakeCase).test(data)) suffix += 1

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.