From f10cafb721b7e0a854d3b9a11427d2f945546374 Mon Sep 17 00:00:00 2001 From: apovkh Date: Thu, 17 Oct 2024 16:27:38 +0300 Subject: [PATCH 1/9] feat: :building_construction: add docker & plop files --- .editorconfig | 20 ++++ .gitignore | 11 +++ .plop.json | 4 + Dockerfile | 5 + README.md | 23 ++++- docker-compose.yml | 7 ++ package.json | 5 + plop-templates/barel-file.ts.hbs | 2 + plop-templates/component-types.ts.hbs | 5 + plop-templates/component.vue.hbs | 65 +++++++++++++ plop-templates/i18n.ts.hbs | 3 + plop-templates/unit-test.spec.hbs | 53 +++++++++++ plopfile.ts | 126 ++++++++++++++++++++++++++ 13 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .plop.json create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 package.json create mode 100644 plop-templates/barel-file.ts.hbs create mode 100644 plop-templates/component-types.ts.hbs create mode 100644 plop-templates/component.vue.hbs create mode 100644 plop-templates/i18n.ts.hbs create mode 100644 plop-templates/unit-test.spec.hbs create mode 100644 plopfile.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dc9d64e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +# tabs 4 spaces for makefiles +[Makefile] +indent_size = 4 +indent_style = tab +[*.mk] +indent_size = 4 +indent_style = tab \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..310c160 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# phpstorm/netbeans/eclipse project files +.idea +.vscode +nbproject +.buildpath +.project +.settings + +# windows/Mac thumbnail cache +Thumbs.db +.DS_Store \ No newline at end of file diff --git a/.plop.json b/.plop.json new file mode 100644 index 0000000..6871a77 --- /dev/null +++ b/.plop.json @@ -0,0 +1,4 @@ +{ + "src": "./", + "workdir": "./" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..56633c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM node:22.6.0 +WORKDIR /usr/src/app +RUN npm install -g plop tsx cross-env typescript +CMD ['npm', 'run', 'plop'] +SHELL ["/bin/bash", "-c"] diff --git a/README.md b/README.md index b1f8052..ddf861e 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# dockerize-plop-js \ No newline at end of file +# Dockerized Plop Repository + +This repository provides a Dockerized setup for [Plop.js](https://plopjs.com/), a micro-generator framework that helps you automate the creation of files and components in your projects. + +## Features + +- **Dockerized Environment**: Run Plop.js in a containerized environment. +- **Fail-proof**: Displays error messages if the required configuration file `.plop.json` is not found. +- **Conventional Commits**: Follows a Git workflow with feature branches and conventional commits for clear versioning. +- **Changelog Generation**: Automatically generates changelogs from conventional commits. + +## Getting Started + +### Prerequisites + +- Docker installed on your machine. + +### Usage + +1. **Build the Docker image**: + ```bash + docker build -t plop_plop . diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..30ac6f3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3.3' +services: + plop: + build: . + volumes: + - .:/usr/src/app + command: tail -f /dev/null diff --git a/package.json b/package.json new file mode 100644 index 0000000..17d765c --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "plop": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts" + } +} diff --git a/plop-templates/barel-file.ts.hbs b/plop-templates/barel-file.ts.hbs new file mode 100644 index 0000000..62972f1 --- /dev/null +++ b/plop-templates/barel-file.ts.hbs @@ -0,0 +1,2 @@ +export { default as {{pascalCase name}} } from './{{pascalCase name}}.vue' +export * from './I{{pascalCase name}}Types' \ No newline at end of file diff --git a/plop-templates/component-types.ts.hbs b/plop-templates/component-types.ts.hbs new file mode 100644 index 0000000..e80deef --- /dev/null +++ b/plop-templates/component-types.ts.hbs @@ -0,0 +1,5 @@ +export { default as {{pascalCase name}} } from './{{pascalCase name}}.vue' + +export interface I{{pascalCase name}}PropTypes { + // value: string +} diff --git a/plop-templates/component.vue.hbs b/plop-templates/component.vue.hbs new file mode 100644 index 0000000..9fecc1f --- /dev/null +++ b/plop-templates/component.vue.hbs @@ -0,0 +1,65 @@ + + + + + diff --git a/plop-templates/i18n.ts.hbs b/plop-templates/i18n.ts.hbs new file mode 100644 index 0000000..d3008d0 --- /dev/null +++ b/plop-templates/i18n.ts.hbs @@ -0,0 +1,3 @@ +export default { + title: '{{pascalCase name}}', +}; diff --git a/plop-templates/unit-test.spec.hbs b/plop-templates/unit-test.spec.hbs new file mode 100644 index 0000000..3c315f9 --- /dev/null +++ b/plop-templates/unit-test.spec.hbs @@ -0,0 +1,53 @@ +import { describe, expect, it } from 'vitest'; +import { mount } from '@vue/test-utils'; +import type { I{{pascalCase name}}PropTypes } from '~/components/{{pascalCase name}}'; +import { {{pascalCase name}} } from '~/components/{{pascalCase name}}'; + +describe('{{pascalCase name}} Component', () => { + + describe('Component API', () => { + const props = {} + + it('Should add class when the "class" prop is passed', () => { + const testClass = '.{{kebabCase name}}'; + + const wrapper = mount({{pascalCase name}} as any, { + props: { + ...props, + class: testClass + } + }); + + expect(wrapper.attributes().class).toContain(testClass); + }); + + it('Should render the {{pascalCase name}} component', () => { + const wrapper = mount({{pascalCase name}} as any, { props }); + + expect(wrapper.exists()).toBe(true); + }); + }); + + describe('Emits', () => { + it('Should emit the v-model event', async () => { + const wrapper = mount({{pascalCase name}} as any, { props }); + + await wrapper.trigger('input'); + + expect(wrapper.emitted()).toHaveProperty('update:modelValue'); + }); + }); + + describe('Slots', () => { + it('Should render the default slot content', () => { + const wrapper = mount({{pascalCase name}} as any, { + props, + slots: { + default: 'Slot content' + } + }); + + expect(wrapper.html()).toContain('Slot content'); + }); + }); +}); diff --git a/plopfile.ts b/plopfile.ts new file mode 100644 index 0000000..4ebfccf --- /dev/null +++ b/plopfile.ts @@ -0,0 +1,126 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import autocompletePrompt from 'inquirer-autocomplete-prompt'; +import { NodePlopAPI, Answers } from 'plop'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export default function (plop: NodePlopAPI) { + const modulesPath = path.join(__dirname, 'modules'); + if (!fs.existsSync(modulesPath)) { + console.error(`Modules directory does not exist at path: ${modulesPath}`); + process.exit(1); + } + + const moduleDirectories = fs.readdirSync(modulesPath).filter((file) => { + return fs.statSync(path.join(modulesPath, file)).isDirectory(); + }); + + plop.setPrompt('autocomplete', autocompletePrompt); + + plop.setGenerator('module', { + description: 'Generate a module for Vue component with selected features', + prompts: [ + { + type: 'autocomplete', + name: 'module', + message: 'Select the module directory or create a new one:', + source: (_, input) => { + input = input || ''; + return new Promise((resolve) => { + const filteredModules = moduleDirectories.filter(module => + module.toLowerCase().includes(input.toLowerCase()) + ); + resolve([...filteredModules, 'Create a new module']); + }); + }, + validate: (value) => (value ? true : 'Module selection is required.'), + }, + { + type: 'input', + name: 'newModuleName', + message: 'Enter the new module name (PascalCase):', + when: (answers) => answers.module === 'Create a new module', + validate: (value) => (value ? true : 'Module name is required.'), + }, + { + type: 'input', + name: 'name', + message: 'Component name (PascalCase):', + validate: (value) => (value ? true : 'Component name must be in PascalCase.'), + }, + { + type: 'checkbox', + name: 'features', + message: 'Select features for the component:', + choices: ['props', 'state', 'computed', 'actions', 'events', 'watch'], + }, + { + type: 'confirm', + name: 'confirmCreation', + message: (answers) => { + const featuresList = answers.features.length ? answers.features.join(', ') : 'No features selected'; + const moduleName = answers.module === 'Create a new module' ? answers.newModuleName : answers.module; + return `You are about to generate the following files in module: ${plop.getHelper('pascalCase')(moduleName)}/src/ui/components/${answers.folder || ''}\n + Component: ${plop.getHelper('pascalCase')(answers.name)}.vue\n + Features: ${featuresList}\n + Do you want to proceed?`; + }, + }, + ], + actions: (data: Answers | undefined) => { + if (!data.confirmCreation) { + return []; + } + + const moduleName = data.module === 'Create a new module' ? data.newModuleName! : data.module; + const name = '{{pascalCase name}}'; + const componentFolder = `modules/${moduleName}/src/ui/components/${name}`; + + const newModulePath = path.join(modulesPath, moduleName); + if (data.module === 'Create a new module' && !fs.existsSync(newModulePath)) { + fs.mkdirSync(newModulePath, { recursive: true }); + console.log(`Created new module: ${newModulePath}`); + } + + return [ + { + type: 'add', + path: `${componentFolder}/${name}.vue`, + templateFile: './plop-template/component.vue.hbs', + data: { + props: data.features.includes('props'), + state: data.features.includes('state'), + computed: data.features.includes('computed'), + actions: data.features.includes('actions'), + events: data.features.includes('events'), + watch: data.features.includes('watch'), + }, + }, + { + type: 'add', + path: `${componentFolder}/${name}.spec.ts`, + templateFile: './plop-template/unit-test.spec.hbs', + }, + { + type: 'add', + path: `${componentFolder}/index.ts`, + templateFile: './plop-template/barel-file.ts.hbs', + }, + { + type: 'add', + path: `${componentFolder}/I${name}Types.ts`, + templateFile: './plop-template/component-types.ts.hbs', + }, + { + type: 'add', + path: `${componentFolder}/i18n.ts`, + templateFile: './plop-template/i18n.ts.hbs', + data: { name: name }, + }, + ]; + }, + }); +} From 4bce7721044181efebe7a47bb7902b06650a84cd Mon Sep 17 00:00:00 2001 From: apovkh Date: Thu, 17 Oct 2024 17:06:49 +0300 Subject: [PATCH 2/9] refactor: :recycle: add console error and move plopfile to /bin --- plopfile.ts => bin/plopfile.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) rename plopfile.ts => bin/plopfile.ts (85%) diff --git a/plopfile.ts b/bin/plopfile.ts similarity index 85% rename from plopfile.ts rename to bin/plopfile.ts index 4ebfccf..dd5e091 100644 --- a/plopfile.ts +++ b/bin/plopfile.ts @@ -8,9 +8,15 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export default function (plop: NodePlopAPI) { - const modulesPath = path.join(__dirname, 'modules'); + const plopJsonPath = path.join(__dirname, '../.plop.json'); + if (!fs.existsSync(plopJsonPath)) { + console.error('\x1b[31mError: .plop.json file not found. Please place it at the root of your repository.\x1b[0m'); + process.exit(1); + } + + const modulesPath = path.join(__dirname, '../modules'); if (!fs.existsSync(modulesPath)) { - console.error(`Modules directory does not exist at path: ${modulesPath}`); + console.error(`\x1b[31mError: Modules directory does not exist at path: ${modulesPath}\x1b[0m`); process.exit(1); } @@ -89,7 +95,7 @@ export default function (plop: NodePlopAPI) { { type: 'add', path: `${componentFolder}/${name}.vue`, - templateFile: './plop-template/component.vue.hbs', + templateFile: '../plop-template/component.vue.hbs', data: { props: data.features.includes('props'), state: data.features.includes('state'), @@ -102,22 +108,22 @@ export default function (plop: NodePlopAPI) { { type: 'add', path: `${componentFolder}/${name}.spec.ts`, - templateFile: './plop-template/unit-test.spec.hbs', + templateFile: '../plop-template/unit-test.spec.hbs', }, { type: 'add', path: `${componentFolder}/index.ts`, - templateFile: './plop-template/barel-file.ts.hbs', + templateFile: '../plop-template/barel-file.ts.hbs', }, { type: 'add', path: `${componentFolder}/I${name}Types.ts`, - templateFile: './plop-template/component-types.ts.hbs', + templateFile: '../plop-template/component-types.ts.hbs', }, { type: 'add', path: `${componentFolder}/i18n.ts`, - templateFile: './plop-template/i18n.ts.hbs', + templateFile: '../plop-template/i18n.ts.hbs', data: { name: name }, }, ]; From 0c6cf63da3fd831091090a1e2ae2f9ff56069251 Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 13:44:57 +0300 Subject: [PATCH 3/9] refactor: :recycle: remove unused files --- .plop.json | 4 - CHANGELOG.md | 0 Dockerfile | 10 +- README.md | 8 +- bin/plopfile.ts | 132 -------------------------- docker-compose.yml | 7 -- plop-templates/barel-file.ts.hbs | 2 - plop-templates/component-types.ts.hbs | 5 - plop-templates/component.vue.hbs | 65 ------------- plop-templates/i18n.ts.hbs | 3 - plop-templates/unit-test.spec.hbs | 53 ----------- package.json => plop/package.json | 0 plop/plopfile.ts | 32 +++++++ 13 files changed, 44 insertions(+), 277 deletions(-) delete mode 100644 .plop.json create mode 100644 CHANGELOG.md delete mode 100644 bin/plopfile.ts delete mode 100644 docker-compose.yml delete mode 100644 plop-templates/barel-file.ts.hbs delete mode 100644 plop-templates/component-types.ts.hbs delete mode 100644 plop-templates/component.vue.hbs delete mode 100644 plop-templates/i18n.ts.hbs delete mode 100644 plop-templates/unit-test.spec.hbs rename package.json => plop/package.json (100%) create mode 100644 plop/plopfile.ts diff --git a/.plop.json b/.plop.json deleted file mode 100644 index 6871a77..0000000 --- a/.plop.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "src": "./", - "workdir": "./" -} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile index 56633c6..c75698f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,13 @@ FROM node:22.6.0 -WORKDIR /usr/src/app + +RUN mkdir /plop +RUN mkdir /codebase RUN npm install -g plop tsx cross-env typescript +COPY ./plop/* /plop + + CMD ['npm', 'run', 'plop'] SHELL ["/bin/bash", "-c"] + +WORKDIR /plop + diff --git a/README.md b/README.md index ddf861e..2538f6f 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,6 @@ This repository provides a Dockerized setup for [Plop.js](https://plopjs.com/), ## Features - **Dockerized Environment**: Run Plop.js in a containerized environment. -- **Fail-proof**: Displays error messages if the required configuration file `.plop.json` is not found. -- **Conventional Commits**: Follows a Git workflow with feature branches and conventional commits for clear versioning. -- **Changelog Generation**: Automatically generates changelogs from conventional commits. ## Getting Started @@ -17,6 +14,7 @@ This repository provides a Dockerized setup for [Plop.js](https://plopjs.com/), ### Usage -1. **Build the Docker image**: +1. **Run the Docker image**: + You can use the local image name for now, or once finalized, use the public image URL provided by GitHub Actions: ```bash - docker build -t plop_plop . + docker run -it plop_plop diff --git a/bin/plopfile.ts b/bin/plopfile.ts deleted file mode 100644 index dd5e091..0000000 --- a/bin/plopfile.ts +++ /dev/null @@ -1,132 +0,0 @@ -import fs from 'fs'; -import path from 'path'; -import { fileURLToPath } from 'url'; -import autocompletePrompt from 'inquirer-autocomplete-prompt'; -import { NodePlopAPI, Answers } from 'plop'; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -export default function (plop: NodePlopAPI) { - const plopJsonPath = path.join(__dirname, '../.plop.json'); - if (!fs.existsSync(plopJsonPath)) { - console.error('\x1b[31mError: .plop.json file not found. Please place it at the root of your repository.\x1b[0m'); - process.exit(1); - } - - const modulesPath = path.join(__dirname, '../modules'); - if (!fs.existsSync(modulesPath)) { - console.error(`\x1b[31mError: Modules directory does not exist at path: ${modulesPath}\x1b[0m`); - process.exit(1); - } - - const moduleDirectories = fs.readdirSync(modulesPath).filter((file) => { - return fs.statSync(path.join(modulesPath, file)).isDirectory(); - }); - - plop.setPrompt('autocomplete', autocompletePrompt); - - plop.setGenerator('module', { - description: 'Generate a module for Vue component with selected features', - prompts: [ - { - type: 'autocomplete', - name: 'module', - message: 'Select the module directory or create a new one:', - source: (_, input) => { - input = input || ''; - return new Promise((resolve) => { - const filteredModules = moduleDirectories.filter(module => - module.toLowerCase().includes(input.toLowerCase()) - ); - resolve([...filteredModules, 'Create a new module']); - }); - }, - validate: (value) => (value ? true : 'Module selection is required.'), - }, - { - type: 'input', - name: 'newModuleName', - message: 'Enter the new module name (PascalCase):', - when: (answers) => answers.module === 'Create a new module', - validate: (value) => (value ? true : 'Module name is required.'), - }, - { - type: 'input', - name: 'name', - message: 'Component name (PascalCase):', - validate: (value) => (value ? true : 'Component name must be in PascalCase.'), - }, - { - type: 'checkbox', - name: 'features', - message: 'Select features for the component:', - choices: ['props', 'state', 'computed', 'actions', 'events', 'watch'], - }, - { - type: 'confirm', - name: 'confirmCreation', - message: (answers) => { - const featuresList = answers.features.length ? answers.features.join(', ') : 'No features selected'; - const moduleName = answers.module === 'Create a new module' ? answers.newModuleName : answers.module; - return `You are about to generate the following files in module: ${plop.getHelper('pascalCase')(moduleName)}/src/ui/components/${answers.folder || ''}\n - Component: ${plop.getHelper('pascalCase')(answers.name)}.vue\n - Features: ${featuresList}\n - Do you want to proceed?`; - }, - }, - ], - actions: (data: Answers | undefined) => { - if (!data.confirmCreation) { - return []; - } - - const moduleName = data.module === 'Create a new module' ? data.newModuleName! : data.module; - const name = '{{pascalCase name}}'; - const componentFolder = `modules/${moduleName}/src/ui/components/${name}`; - - const newModulePath = path.join(modulesPath, moduleName); - if (data.module === 'Create a new module' && !fs.existsSync(newModulePath)) { - fs.mkdirSync(newModulePath, { recursive: true }); - console.log(`Created new module: ${newModulePath}`); - } - - return [ - { - type: 'add', - path: `${componentFolder}/${name}.vue`, - templateFile: '../plop-template/component.vue.hbs', - data: { - props: data.features.includes('props'), - state: data.features.includes('state'), - computed: data.features.includes('computed'), - actions: data.features.includes('actions'), - events: data.features.includes('events'), - watch: data.features.includes('watch'), - }, - }, - { - type: 'add', - path: `${componentFolder}/${name}.spec.ts`, - templateFile: '../plop-template/unit-test.spec.hbs', - }, - { - type: 'add', - path: `${componentFolder}/index.ts`, - templateFile: '../plop-template/barel-file.ts.hbs', - }, - { - type: 'add', - path: `${componentFolder}/I${name}Types.ts`, - templateFile: '../plop-template/component-types.ts.hbs', - }, - { - type: 'add', - path: `${componentFolder}/i18n.ts`, - templateFile: '../plop-template/i18n.ts.hbs', - data: { name: name }, - }, - ]; - }, - }); -} diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 30ac6f3..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: '3.3' -services: - plop: - build: . - volumes: - - .:/usr/src/app - command: tail -f /dev/null diff --git a/plop-templates/barel-file.ts.hbs b/plop-templates/barel-file.ts.hbs deleted file mode 100644 index 62972f1..0000000 --- a/plop-templates/barel-file.ts.hbs +++ /dev/null @@ -1,2 +0,0 @@ -export { default as {{pascalCase name}} } from './{{pascalCase name}}.vue' -export * from './I{{pascalCase name}}Types' \ No newline at end of file diff --git a/plop-templates/component-types.ts.hbs b/plop-templates/component-types.ts.hbs deleted file mode 100644 index e80deef..0000000 --- a/plop-templates/component-types.ts.hbs +++ /dev/null @@ -1,5 +0,0 @@ -export { default as {{pascalCase name}} } from './{{pascalCase name}}.vue' - -export interface I{{pascalCase name}}PropTypes { - // value: string -} diff --git a/plop-templates/component.vue.hbs b/plop-templates/component.vue.hbs deleted file mode 100644 index 9fecc1f..0000000 --- a/plop-templates/component.vue.hbs +++ /dev/null @@ -1,65 +0,0 @@ - - - - - diff --git a/plop-templates/i18n.ts.hbs b/plop-templates/i18n.ts.hbs deleted file mode 100644 index d3008d0..0000000 --- a/plop-templates/i18n.ts.hbs +++ /dev/null @@ -1,3 +0,0 @@ -export default { - title: '{{pascalCase name}}', -}; diff --git a/plop-templates/unit-test.spec.hbs b/plop-templates/unit-test.spec.hbs deleted file mode 100644 index 3c315f9..0000000 --- a/plop-templates/unit-test.spec.hbs +++ /dev/null @@ -1,53 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { mount } from '@vue/test-utils'; -import type { I{{pascalCase name}}PropTypes } from '~/components/{{pascalCase name}}'; -import { {{pascalCase name}} } from '~/components/{{pascalCase name}}'; - -describe('{{pascalCase name}} Component', () => { - - describe('Component API', () => { - const props = {} - - it('Should add class when the "class" prop is passed', () => { - const testClass = '.{{kebabCase name}}'; - - const wrapper = mount({{pascalCase name}} as any, { - props: { - ...props, - class: testClass - } - }); - - expect(wrapper.attributes().class).toContain(testClass); - }); - - it('Should render the {{pascalCase name}} component', () => { - const wrapper = mount({{pascalCase name}} as any, { props }); - - expect(wrapper.exists()).toBe(true); - }); - }); - - describe('Emits', () => { - it('Should emit the v-model event', async () => { - const wrapper = mount({{pascalCase name}} as any, { props }); - - await wrapper.trigger('input'); - - expect(wrapper.emitted()).toHaveProperty('update:modelValue'); - }); - }); - - describe('Slots', () => { - it('Should render the default slot content', () => { - const wrapper = mount({{pascalCase name}} as any, { - props, - slots: { - default: 'Slot content' - } - }); - - expect(wrapper.html()).toContain('Slot content'); - }); - }); -}); diff --git a/package.json b/plop/package.json similarity index 100% rename from package.json rename to plop/package.json diff --git a/plop/plopfile.ts b/plop/plopfile.ts new file mode 100644 index 0000000..0270e7d --- /dev/null +++ b/plop/plopfile.ts @@ -0,0 +1,32 @@ +import { NodePlopAPI } from 'plop'; +import * as fs from 'fs'; +import * as path from 'path'; +import { fileURLToPath } from 'url'; + + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export default function (plop: NodePlopAPI) { + console.log('Please create your plop'); + console.log('Plop instance: ', plop); + + plop.setGenerator('Show README', { + description: 'Show the content of README.md', + actions: [ + () => { + const readmePath = path.resolve(__dirname, 'README.md'); + + if (fs.existsSync(readmePath)) { + const readmeContent = fs.readFileSync(readmePath, 'utf8'); + console.log('Content of README.md:\n'); + console.log(readmeContent); + } else { + console.log('README.md file not found!'); + } + + return 'README.md content displayed in console.'; + } + ] + }); +} From 0a944f6fecddcd6e0da6605e3a2fa1bb7fd345be Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 15:40:08 +0300 Subject: [PATCH 4/9] refactor: :art: change readme & plopfile --- README.md | 3 ++- plop/plopfile.ts | 20 +++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2538f6f..ace2b48 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,5 @@ This repository provides a Dockerized setup for [Plop.js](https://plopjs.com/), 1. **Run the Docker image**: You can use the local image name for now, or once finalized, use the public image URL provided by GitHub Actions: ```bash - docker run -it plop_plop + docker run --rm -it plop_plop + ``` diff --git a/plop/plopfile.ts b/plop/plopfile.ts index 0270e7d..7b6c384 100644 --- a/plop/plopfile.ts +++ b/plop/plopfile.ts @@ -3,29 +3,27 @@ import * as fs from 'fs'; import * as path from 'path'; import { fileURLToPath } from 'url'; - const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export default function (plop: NodePlopAPI) { - console.log('Please create your plop'); - console.log('Plop instance: ', plop); - plop.setGenerator('Show README', { description: 'Show the content of README.md', actions: [ () => { - const readmePath = path.resolve(__dirname, 'README.md'); + const readmePath = path.join(__dirname, 'README.md'); if (fs.existsSync(readmePath)) { - const readmeContent = fs.readFileSync(readmePath, 'utf8'); - console.log('Content of README.md:\n'); - console.log(readmeContent); + const content = fs.readFileSync(readmePath, 'utf-8'); + console.log(content); + return 'README.md content displayed in console.'; } else { - console.log('README.md file not found!'); + console.log(` + No real generators available. \n + To use docker image, mount your plopfile sources in /plop directory.` + ); + return 'README.md file not found!'; } - - return 'README.md content displayed in console.'; } ] }); From fd18ac52471927ec45a6ab2b889a1ce914dfbf11 Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 17:43:10 +0300 Subject: [PATCH 5/9] fix: :memo: plop console info --- plop/plopfile.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/plop/plopfile.ts b/plop/plopfile.ts index 7b6c384..ddb13b4 100644 --- a/plop/plopfile.ts +++ b/plop/plopfile.ts @@ -1,29 +1,15 @@ import { NodePlopAPI } from 'plop'; -import * as fs from 'fs'; -import * as path from 'path'; -import { fileURLToPath } from 'url'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); export default function (plop: NodePlopAPI) { plop.setGenerator('Show README', { description: 'Show the content of README.md', actions: [ () => { - const readmePath = path.join(__dirname, 'README.md'); - - if (fs.existsSync(readmePath)) { - const content = fs.readFileSync(readmePath, 'utf-8'); - console.log(content); - return 'README.md content displayed in console.'; - } else { - console.log(` - No real generators available. \n - To use docker image, mount your plopfile sources in /plop directory.` - ); - return 'README.md file not found!'; - } + console.log(` + No real generators available. \n + To use docker image, mount your plopfile sources in /plop directory.` + ); } ] }); From c3e985a7ad19b5205c1e731a3268fe80790cbd0d Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 19:03:58 +0300 Subject: [PATCH 6/9] feat: :memo: add changelog-config --- changelog-config.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 changelog-config.php diff --git a/changelog-config.php b/changelog-config.php new file mode 100644 index 0000000..33d2d6a --- /dev/null +++ b/changelog-config.php @@ -0,0 +1,18 @@ + 'CHANGELOG.md', + 'headerTitle' => 'Changelog', + 'headerDescription' => 'All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +---', + 'ignoreTypes' => ['build', 'chore', 'ci', 'docs', 'perf', 'refactor', 'revert', 'style', 'test', 'bug'], + + 'hiddenHash' => true, +]; \ No newline at end of file From a31ef9cb20abbc289108c5dabb6c53a2ea3e9dd6 Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 19:05:59 +0300 Subject: [PATCH 7/9] build: :memo: add Makefile for changelog --- Makefile | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b6144b --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +.PHONY: default install uninstall chl chl-first + +default: + @echo 'Git extras installation helper from JustCoded' + +install: + sudo cp -f ./bin/* /usr/local/bin/ + sudo chmod +x /usr/local/bin/git-* + +uninstall: + sudo rm /usr/local/bin/git-* + +## +# CHANGELOG vars and targets +## +CONV_CHL_IMAGE := justcoded/php-conventional-changelog:latest +CONV_CHL_DR := docker run -it --rm --volume "$$PWD":/codebase ${CONV_CHL_IMAGE} bash +CONV_CHL_CMD := conventional-changelog --config changelog-config.php + +## +# @command chl Generate changelog based on conventional commits +## +chl: + ${CONV_CHL_DR} \ + -c "${CONV_CHL_CMD}" + +## +# @command chl-first Generate changelog based on conventional commits, first version +## +chl-first: + ${CONV_CHL_DR} \ + -c "${CONV_CHL_CMD} --first-release" \ No newline at end of file From 2c41902abb8c18e919726c1114cc06e92cdde978 Mon Sep 17 00:00:00 2001 From: apovkh Date: Fri, 18 Oct 2024 21:41:13 +0300 Subject: [PATCH 8/9] docs: :loud_sound: add first changelog --- CHANGELOG.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..b29fd98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ + +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +--- + + +## [0.1.0](https://github.com/justcoded/dockerize-plop-js/compare/c11fb61e0409ea1d33490caa0d420a7768bd1286...v1.0.0) (2024-10-18) +### Features + +* :building_construction: add docker & plop files +* :memo: add changelog-config + +### Bug Fixes + +* :memo: plop console info + + +--- + From fd0870d4bef989268b09987322e1c5ab087713b7 Mon Sep 17 00:00:00 2001 From: apovkh Date: Mon, 21 Oct 2024 11:34:17 +0300 Subject: [PATCH 9/9] fix: help message, un/install commands --- Makefile | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 3b6144b..e6e1cac 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,7 @@ -.PHONY: default install uninstall chl chl-first +.PHONY: default chl chl-first default: - @echo 'Git extras installation helper from JustCoded' - -install: - sudo cp -f ./bin/* /usr/local/bin/ - sudo chmod +x /usr/local/bin/git-* - -uninstall: - sudo rm /usr/local/bin/git-* + @echo 'Plop helper from JustCoded' ## # CHANGELOG vars and targets @@ -29,4 +22,4 @@ chl: ## chl-first: ${CONV_CHL_DR} \ - -c "${CONV_CHL_CMD} --first-release" \ No newline at end of file + -c "${CONV_CHL_CMD} --first-release"