Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A2.1 #6

Open
wants to merge 2 commits into
base: a1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _explicacoes/a2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## A2.1: Scaffolding: Automatizando a criação de novos projetos e libs internas

- https://github.com/plopjs/plop

- Quais as opções de prompt no Plop?
- https://github.com/SBoudrias/Inquirer.js/blob/main/packages/inquirer/README.md#prompt-types

- Como criar modificadores das variáveis dos prompts nas actions?
- Modificadores nativos: https://github.com/plopjs/plop?tab=readme-ov-file#case-modifiers
- Via Handlebars: https://handlebarsjs.com/guide/expressions.html#helpers
- Modificadores customizáveis: https://github.com/plopjs/plop?tab=readme-ov-file#sethelper

- https://handlebarsjs.com/playground.html
12 changes: 12 additions & 0 deletions commons/demo-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@devsoutinho/commons-demo-test",
"version": "1.0.0",
"main": "index.ts",
"scripts": {
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {}
}
18 changes: 18 additions & 0 deletions commons/generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@devsoutinho/generator",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"gen": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
Copy link
Contributor Author

@omariosouto omariosouto Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se você estiver utilizando windows é importante que o arquivo tenha aspas " ao invés de ':

Suggested change
"gen": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
"gen": "cross-env NODE_OPTIONS=\"--import tsx\" plop --plopfile=plopfile.ts",

"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"cross-env": "^7.0.3",
"plop": "^4.0.1",
"tsx": "^4.15.2"
}
}
41 changes: 41 additions & 0 deletions commons/generator/plopfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NodePlopAPI } from 'plop';
import path from "path";

const ROOT_MONOREPO = path.resolve("..", "..");

export default function (plop: NodePlopAPI) {

console.log("ROOT_MONOREPO", ROOT_MONOREPO);

// create your generators here
plop.setGenerator('basics', {
description: 'this is a skeleton plopfile',
prompts: [], // Criar perguntas pra pessoa que ta rodando o script
actions: [] // Executar ações em cima dessas perguntas
});

commonPackage(plop);
};

function commonPackage(plop: NodePlopAPI) {

console.log("DEBUG", path.resolve(ROOT_MONOREPO, "commons", "{{packageName}}", "package.json"));

plop.setGenerator('common-package', {
description: 'Create a new common package inside `./commons` folder',
prompts: [
{
type: "input",
name: "packageName",
message: "What is the pacakge name?",
}
], // Criar perguntas pra pessoa que ta rodando o script
actions: [
{
type: "add",
path: path.resolve(ROOT_MONOREPO, "commons", "{{lowerCase packageName}}", "package.json"),
templateFile: "templates/common-package/package.json.hbs"
}
] // Executar ações em cima dessas perguntas
});
}
12 changes: 12 additions & 0 deletions commons/generator/templates/common-package/package.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@devsoutinho/commons-{{ lowerCase packageName }}",
"version": "1.0.0",
"main": "index.ts",
"scripts": {
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {}
}
Loading