gerar 0.0.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,8 +38,10 @@ CPF 1) Com Máscara: 123.456.789-00 - Sem Máscara: 12345678900
38
38
  | ------------------------------------------------- | ----------- |
39
39
  | CPF | ✅ Completo |
40
40
  | CNPJ | ✅ Completo |
41
+ | Flag nos comandos para gerar com ou sem máscara | ✅ Completo |
41
42
  | Cartão de crédito com base na bandeira | ⏳ Pendente |
42
43
  | Endereço | ⏳ Pendente |
44
+ | Chassi e Placa | ⏳ Pendente |
43
45
  | UUID v4 | ⏳ Pendente |
44
46
  | UUID v7 | ⏳ Pendente |
45
47
  | Autocomplete no Terminal | ⏳ Pendente |
@@ -1,2 +1,2 @@
1
- import { CommandStructure } from "../../shared/utils/command-structure";
2
- export declare const cnpjCommand: CommandStructure;
1
+ import { Command } from "commander";
2
+ export declare const registerCnpjCommand: (program: Command) => Command;
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cnpjCommand = void 0;
3
+ exports.registerCnpjCommand = void 0;
4
+ const command_builder_1 = require("../../shared/utils/command-builder");
4
5
  const utils_1 = require("./utils");
5
- exports.cnpjCommand = {
6
- name: "cnpj",
7
- description: "Gera um CNPJ fictício válido.",
8
- action: (options) => {
9
- const generatedCnpjs = Array.from({ length: options.amount ?? 1 }, utils_1.generateCnpj);
10
- generatedCnpjs.forEach((generatedCnpj, index) => {
11
- console.log(`CNPJ ${index + 1}) Com Máscara: ${generatedCnpj.withMask} - Sem Máscara: ${generatedCnpj.withoutMask}`);
12
- });
13
- },
6
+ const result_logger_1 = require("../../shared/utils/result-logger");
7
+ const registerCnpjCommand = (program) => {
8
+ return (0, command_builder_1.buildCommand)(program, {
9
+ name: "cnpj",
10
+ description: "Gera um CNPJ fictício válido.",
11
+ action: (options) => {
12
+ const generatedCnpjs = Array.from({ length: options.amount ?? 1 }, utils_1.generateCnpj);
13
+ generatedCnpjs.forEach((generatedCnpj, index) => {
14
+ (0, result_logger_1.logResult)({
15
+ label: "CNPJ",
16
+ index,
17
+ showIndex: true,
18
+ result: generatedCnpj,
19
+ options,
20
+ });
21
+ });
22
+ },
23
+ });
14
24
  };
25
+ exports.registerCnpjCommand = registerCnpjCommand;
15
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/cnpj/index.ts"],"names":[],"mappings":";;;AACA,mCAAuC;AAE1B,QAAA,WAAW,GAAqB;IAC3C,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,+BAA+B;IAC5C,MAAM,EAAE,CAAC,OAA4B,EAAE,EAAE;QACvC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAC/B,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,EAC/B,oBAAY,CACb,CAAC;QAEF,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,EAAE,EAAE;YAC9C,OAAO,CAAC,GAAG,CACT,QAAQ,KAAK,GAAG,CAAC,kBACf,aAAa,CAAC,QAChB,mBAAmB,aAAa,CAAC,WAAW,EAAE,CAC/C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/cnpj/index.ts"],"names":[],"mappings":";;;AACA,wEAAkE;AAClE,mCAAuC;AAEvC,oEAA6D;AAEtD,MAAM,mBAAmB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACtD,OAAO,IAAA,8BAAY,EAAC,OAAO,EAAE;QAC3B,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,+BAA+B;QAC5C,MAAM,EAAE,CAAC,OAAuB,EAAE,EAAE;YAClC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAC/B,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,EAC/B,oBAAY,CACb,CAAC;YAEF,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,EAAE,EAAE;gBAC9C,IAAA,yBAAS,EAAC;oBACR,KAAK,EAAE,MAAM;oBACb,KAAK;oBACL,SAAS,EAAE,IAAI;oBACf,MAAM,EAAE,aAAa;oBACrB,OAAO;iBACR,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B"}
@@ -1,2 +1,2 @@
1
- import { CommandStructure } from "../../shared/utils/command-structure";
2
- export declare const cpfCommand: CommandStructure;
1
+ import { Command } from "commander";
2
+ export declare const registerCpfCommand: (program: Command) => Command;
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cpfCommand = void 0;
3
+ exports.registerCpfCommand = void 0;
4
+ const command_builder_1 = require("../../shared/utils/command-builder");
4
5
  const utils_1 = require("./utils");
5
- exports.cpfCommand = {
6
- name: "cpf",
7
- description: "Gera um CPF fictício válido.",
8
- action: (options) => {
9
- const generatedCpfs = Array.from({ length: options.amount ?? 1 }, utils_1.generateCpf);
10
- generatedCpfs.forEach((generatedCpf, index) => {
11
- console.log(`CPF ${index + 1}) Com Máscara: ${generatedCpf.withMask} - Sem Máscara: ${generatedCpf.withoutMask}`);
12
- });
13
- },
6
+ const result_logger_1 = require("../../shared/utils/result-logger");
7
+ const registerCpfCommand = (program) => {
8
+ return (0, command_builder_1.buildCommand)(program, {
9
+ name: "cpf",
10
+ description: "Gera um CPF fictício válido.",
11
+ action: (options) => {
12
+ const generatedCpfs = Array.from({ length: options.amount ?? 1 }, utils_1.generateCpf);
13
+ generatedCpfs.forEach((generatedCpf, index) => {
14
+ (0, result_logger_1.logResult)({
15
+ label: "CPF",
16
+ index,
17
+ showIndex: true,
18
+ result: generatedCpf,
19
+ options,
20
+ });
21
+ });
22
+ },
23
+ });
14
24
  };
25
+ exports.registerCpfCommand = registerCpfCommand;
15
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/cpf/index.ts"],"names":[],"mappings":";;;AACA,mCAAsC;AAEzB,QAAA,UAAU,GAAqB;IAC1C,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,8BAA8B;IAC3C,MAAM,EAAE,CAAC,OAA4B,EAAE,EAAE;QACvC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAC9B,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,EAC/B,mBAAW,CACZ,CAAC;QAEF,aAAa,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;YAC5C,OAAO,CAAC,GAAG,CACT,OAAO,KAAK,GAAG,CAAC,kBACd,YAAY,CAAC,QACf,mBAAmB,YAAY,CAAC,WAAW,EAAE,CAC9C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/cpf/index.ts"],"names":[],"mappings":";;;AACA,wEAAkE;AAClE,mCAAsC;AAEtC,oEAA6D;AAEtD,MAAM,kBAAkB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACrD,OAAO,IAAA,8BAAY,EAAC,OAAO,EAAE;QAC3B,IAAI,EAAE,KAAK;QACX,WAAW,EAAE,8BAA8B;QAC3C,MAAM,EAAE,CAAC,OAAuB,EAAE,EAAE;YAClC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAC9B,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,EAC/B,mBAAW,CACZ,CAAC;YAEF,aAAa,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;gBAC5C,IAAA,yBAAS,EAAC;oBACR,KAAK,EAAE,KAAK;oBACZ,KAAK;oBACL,SAAS,EAAE,IAAI;oBACf,MAAM,EAAE,YAAY;oBACpB,OAAO;iBACR,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AArBW,QAAA,kBAAkB,sBAqB7B"}
package/dist/index.js CHANGED
@@ -11,15 +11,7 @@ program
11
11
  .version("0.0.1");
12
12
  program.helpCommand("help", "Exibe informações de ajuda do CLI.");
13
13
  // TODO: Create automatic registration for commands.
14
- program
15
- .command(cpf_1.cpfCommand.name)
16
- .description(cpf_1.cpfCommand.description)
17
- .option("-a, --amount <amount>", "Quantidade a ser gerado.", (value) => Number(value))
18
- .action(cpf_1.cpfCommand.action);
19
- program
20
- .command(cnpj_1.cnpjCommand.name)
21
- .description(cnpj_1.cnpjCommand.description)
22
- .option("-a, --amount <amount>", "Quantidade a ser gerado.", (value) => Number(value))
23
- .action(cnpj_1.cnpjCommand.action);
14
+ (0, cpf_1.registerCpfCommand)(program);
15
+ (0, cnpj_1.registerCnpjCommand)(program);
24
16
  program.parse();
25
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,wCAA4C;AAC5C,0CAA8C;AAE9C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,wDAAwD,CAAC;KACrE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;AAElE,oDAAoD;AACpD,OAAO;KACJ,OAAO,CAAC,gBAAU,CAAC,IAAI,CAAC;KACxB,WAAW,CAAC,gBAAU,CAAC,WAAW,CAAC;KACnC,MAAM,CACL,uBAAuB,EACvB,0BAA0B,EAC1B,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CACjC;KACA,MAAM,CAAC,gBAAU,CAAC,MAAM,CAAC,CAAC;AAE7B,OAAO;KACJ,OAAO,CAAC,kBAAW,CAAC,IAAI,CAAC;KACzB,WAAW,CAAC,kBAAW,CAAC,WAAW,CAAC;KACpC,MAAM,CACL,uBAAuB,EACvB,0BAA0B,EAC1B,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CACjC;KACA,MAAM,CAAC,kBAAW,CAAC,MAAM,CAAC,CAAC;AAE9B,OAAO,CAAC,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,wCAAoD;AACpD,0CAAsD;AAEtD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,wDAAwD,CAAC;KACrE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;AAElE,oDAAoD;AACpD,IAAA,wBAAkB,EAAC,OAAO,CAAC,CAAC;AAC5B,IAAA,0BAAmB,EAAC,OAAO,CAAC,CAAC;AAE7B,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Command } from "commander";
2
+ import { CommandBaseOptions } from "./command-options";
3
+ export type CommandStructure = {
4
+ name: string;
5
+ description: string;
6
+ action: (this: Command, ...args: any[]) => void | Promise<void>;
7
+ };
8
+ type CommandBuilderOptions = {
9
+ omitOptions?: CommandBaseOptions[];
10
+ };
11
+ export declare const buildCommand: (program: Command, command: CommandStructure, options?: CommandBuilderOptions) => Command;
12
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCommand = void 0;
4
+ const command_options_1 = require("./command-options");
5
+ const buildCommand = (program, command, options = {}) => {
6
+ const commandInstance = program
7
+ .command(command.name)
8
+ .description(command.description);
9
+ const baseOptionsKeys = Object.keys(command_options_1.commandBaseOptions).filter((option) => !options.omitOptions?.includes(option));
10
+ const baseOptions = baseOptionsKeys.map((option) => command_options_1.commandBaseOptions[option]);
11
+ baseOptions.forEach((option) => {
12
+ if ("validator" in option) {
13
+ commandInstance.option(option.flag, option.description, option.validator);
14
+ return;
15
+ }
16
+ commandInstance.option(option.flag, option.description);
17
+ });
18
+ return commandInstance.action(command.action);
19
+ };
20
+ exports.buildCommand = buildCommand;
21
+ //# sourceMappingURL=command-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-builder.js","sourceRoot":"","sources":["../../../src/shared/utils/command-builder.ts"],"names":[],"mappings":";;;AACA,uDAA2E;AAYpE,MAAM,YAAY,GAAG,CAC1B,OAAgB,EAChB,OAAyB,EACzB,UAAiC,EAAE,EACnC,EAAE;IACF,MAAM,eAAe,GAAG,OAAO;SAC5B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;SACrB,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,oCAAkB,CAAC,CAAC,MAAM,CAC5D,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,MAA4B,CAAC,CACzE,CAAC;IACF,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CACrC,CAAC,MAAM,EAAE,EAAE,CAAC,oCAAkB,CAAC,MAA4B,CAAC,CAC7D,CAAC;IAEF,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC7B,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC;YAC1B,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YAC1E,OAAO;QACT,CAAC;QAED,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC,CAAC;AA1BW,QAAA,YAAY,gBA0BvB"}
@@ -0,0 +1,25 @@
1
+ export declare const commandBaseOptions: {
2
+ readonly amount: {
3
+ readonly flag: "-a, --amount <amount>";
4
+ readonly description: "Quantidade a ser gerado.";
5
+ readonly validator: (value: string) => number;
6
+ };
7
+ readonly masked: {
8
+ readonly flag: "-m, --masked";
9
+ readonly description: "Gera o resultado com máscara.";
10
+ };
11
+ readonly unmasked: {
12
+ readonly flag: "-u, --unmasked";
13
+ readonly description: "Gera o resultado sem máscara.";
14
+ };
15
+ readonly copy: {
16
+ readonly flag: "-c, --copy";
17
+ readonly description: "Copia o resultado para a área de transferência.";
18
+ };
19
+ };
20
+ export type CommandBaseOptions = keyof typeof commandBaseOptions;
21
+ export type CommandOptions = Partial<{
22
+ [Option in CommandBaseOptions]: (typeof commandBaseOptions)[Option] extends {
23
+ validator: (value: string) => infer ValidatorReturnType;
24
+ } ? ValidatorReturnType : boolean;
25
+ }>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commandBaseOptions = void 0;
4
+ exports.commandBaseOptions = {
5
+ amount: {
6
+ flag: "-a, --amount <amount>",
7
+ description: "Quantidade a ser gerado.",
8
+ validator: (value) => Number(value),
9
+ },
10
+ masked: {
11
+ flag: "-m, --masked",
12
+ description: "Gera o resultado com máscara.",
13
+ },
14
+ unmasked: {
15
+ flag: "-u, --unmasked",
16
+ description: "Gera o resultado sem máscara.",
17
+ },
18
+ copy: {
19
+ flag: "-c, --copy",
20
+ description: "Copia o resultado para a área de transferência.",
21
+ },
22
+ };
23
+ //# sourceMappingURL=command-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.js","sourceRoot":"","sources":["../../../src/shared/utils/command-options.ts"],"names":[],"mappings":";;;AAMa,QAAA,kBAAkB,GAAG;IAChC,MAAM,EAAE;QACN,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,0BAA0B;QACvC,SAAS,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;KAC5C;IACD,MAAM,EAAE;QACN,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,+BAA+B;KAC7C;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,+BAA+B;KAC7C;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,iDAAiD;KAC/D;CAC0D,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { CommandOptions } from "./command-options";
2
+ type ResultWithMask = {
3
+ withMask: string;
4
+ withoutMask: string;
5
+ };
6
+ type ResultWithoutMask = string;
7
+ type LogResultOptions = {
8
+ label: string;
9
+ index?: number;
10
+ showIndex?: boolean;
11
+ result: ResultWithMask | ResultWithoutMask;
12
+ options: CommandOptions;
13
+ };
14
+ export declare const logResult: ({ label, index, showIndex, result, options, }: LogResultOptions) => void;
15
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logResult = void 0;
7
+ const clipboardy_1 = __importDefault(require("clipboardy"));
8
+ const logResult = ({ label, index = 0, showIndex = false, result, options, }) => {
9
+ const indexText = showIndex ? ` ${index + 1})` : ":";
10
+ if (typeof result === "string") {
11
+ console.log(`${label}${indexText} ${result}`);
12
+ return;
13
+ }
14
+ if (options.copy) {
15
+ const maskToCopy = options.unmasked ? result.withoutMask : result.withMask;
16
+ const valueToCopy = options.masked || options.unmasked
17
+ ? maskToCopy
18
+ : `${result.withMask} - ${result.withoutMask}`;
19
+ clipboardy_1.default.write(valueToCopy);
20
+ console.log(`Resultado copiado para a área de transferência.`);
21
+ }
22
+ if (options.unmasked) {
23
+ console.log(`${label}${indexText} Sem Máscara: ${result.withoutMask}`);
24
+ return;
25
+ }
26
+ if (options.masked) {
27
+ console.log(`${label}${indexText} Com Máscara: ${result.withMask}`);
28
+ return;
29
+ }
30
+ console.log(`${label}${indexText} Com Máscara: ${result.withMask} - Sem Máscara: ${result.withoutMask}`);
31
+ };
32
+ exports.logResult = logResult;
33
+ //# sourceMappingURL=result-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-logger.js","sourceRoot":"","sources":["../../../src/shared/utils/result-logger.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAmC;AAkB5B,MAAM,SAAS,GAAG,CAAC,EACxB,KAAK,EACL,KAAK,GAAG,CAAC,EACT,SAAS,GAAG,KAAK,EACjB,MAAM,EACN,OAAO,GACU,EAAQ,EAAE;IAC3B,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAErD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC3E,MAAM,WAAW,GACf,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ;YAChC,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;QAEnD,oBAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,SAAS,iBAAiB,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QAEvE,OAAO;IACT,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,SAAS,iBAAiB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEpE,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CACT,GAAG,KAAK,GAAG,SAAS,iBAAiB,MAAM,CAAC,QAAQ,mBAAmB,MAAM,CAAC,WAAW,EAAE,CAC5F,CAAC;AACJ,CAAC,CAAC;AAxCW,QAAA,SAAS,aAwCpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gerar",
3
- "version": "0.0.3",
3
+ "version": "1.0.0",
4
4
  "description": "CLI brasileiro para gerar dados fictícios para testes.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Victor Ribeiro Boechat",
@@ -17,6 +17,7 @@
17
17
  "keywords": [],
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
+ "clipboardy": "^5.0.2",
20
21
  "commander": "^14.0.2"
21
22
  },
22
23
  "devDependencies": {
@@ -25,5 +26,10 @@
25
26
  "typescript": "^5.9.3",
26
27
  "vitest": "^4.0.13"
27
28
  },
28
- "packageManager": "pnpm@10.20.0"
29
+ "packageManager": "pnpm@10.20.0",
30
+ "pnpm": {
31
+ "overrides": {
32
+ "npm-run-path": "5.1.0"
33
+ }
34
+ }
29
35
  }
@@ -1,21 +1,28 @@
1
- import { CommandStructure } from "../../shared/utils/command-structure";
1
+ import { Command } from "commander";
2
+ import { buildCommand } from "../../shared/utils/command-builder";
2
3
  import { generateCnpj } from "./utils";
4
+ import { CommandOptions } from "../../shared/utils/command-options";
5
+ import { logResult } from "../../shared/utils/result-logger";
3
6
 
4
- export const cnpjCommand: CommandStructure = {
5
- name: "cnpj",
6
- description: "Gera um CNPJ fictício válido.",
7
- action: (options: { amount?: number }) => {
8
- const generatedCnpjs = Array.from(
9
- { length: options.amount ?? 1 },
10
- generateCnpj
11
- );
12
-
13
- generatedCnpjs.forEach((generatedCnpj, index) => {
14
- console.log(
15
- `CNPJ ${index + 1}) Com Máscara: ${
16
- generatedCnpj.withMask
17
- } - Sem Máscara: ${generatedCnpj.withoutMask}`
7
+ export const registerCnpjCommand = (program: Command) => {
8
+ return buildCommand(program, {
9
+ name: "cnpj",
10
+ description: "Gera um CNPJ fictício válido.",
11
+ action: (options: CommandOptions) => {
12
+ const generatedCnpjs = Array.from(
13
+ { length: options.amount ?? 1 },
14
+ generateCnpj
18
15
  );
19
- });
20
- },
16
+
17
+ generatedCnpjs.forEach((generatedCnpj, index) => {
18
+ logResult({
19
+ label: "CNPJ",
20
+ index,
21
+ showIndex: true,
22
+ result: generatedCnpj,
23
+ options,
24
+ });
25
+ });
26
+ },
27
+ });
21
28
  };
@@ -1,21 +1,28 @@
1
- import { CommandStructure } from "../../shared/utils/command-structure";
1
+ import { Command } from "commander";
2
+ import { buildCommand } from "../../shared/utils/command-builder";
2
3
  import { generateCpf } from "./utils";
4
+ import { CommandOptions } from "../../shared/utils/command-options";
5
+ import { logResult } from "../../shared/utils/result-logger";
3
6
 
4
- export const cpfCommand: CommandStructure = {
5
- name: "cpf",
6
- description: "Gera um CPF fictício válido.",
7
- action: (options: { amount?: number }) => {
8
- const generatedCpfs = Array.from(
9
- { length: options.amount ?? 1 },
10
- generateCpf
11
- );
12
-
13
- generatedCpfs.forEach((generatedCpf, index) => {
14
- console.log(
15
- `CPF ${index + 1}) Com Máscara: ${
16
- generatedCpf.withMask
17
- } - Sem Máscara: ${generatedCpf.withoutMask}`
7
+ export const registerCpfCommand = (program: Command) => {
8
+ return buildCommand(program, {
9
+ name: "cpf",
10
+ description: "Gera um CPF fictício válido.",
11
+ action: (options: CommandOptions) => {
12
+ const generatedCpfs = Array.from(
13
+ { length: options.amount ?? 1 },
14
+ generateCpf
18
15
  );
19
- });
20
- },
16
+
17
+ generatedCpfs.forEach((generatedCpf, index) => {
18
+ logResult({
19
+ label: "CPF",
20
+ index,
21
+ showIndex: true,
22
+ result: generatedCpf,
23
+ options,
24
+ });
25
+ });
26
+ },
27
+ });
21
28
  };
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
- import { cpfCommand } from "./commands/cpf";
4
- import { cnpjCommand } from "./commands/cnpj";
3
+ import { registerCpfCommand } from "./commands/cpf";
4
+ import { registerCnpjCommand } from "./commands/cnpj";
5
5
 
6
6
  const program = new Command();
7
7
 
@@ -13,24 +13,7 @@ program
13
13
  program.helpCommand("help", "Exibe informações de ajuda do CLI.");
14
14
 
15
15
  // TODO: Create automatic registration for commands.
16
- program
17
- .command(cpfCommand.name)
18
- .description(cpfCommand.description)
19
- .option(
20
- "-a, --amount <amount>",
21
- "Quantidade a ser gerado.",
22
- (value: string) => Number(value)
23
- )
24
- .action(cpfCommand.action);
25
-
26
- program
27
- .command(cnpjCommand.name)
28
- .description(cnpjCommand.description)
29
- .option(
30
- "-a, --amount <amount>",
31
- "Quantidade a ser gerado.",
32
- (value: string) => Number(value)
33
- )
34
- .action(cnpjCommand.action);
16
+ registerCpfCommand(program);
17
+ registerCnpjCommand(program);
35
18
 
36
19
  program.parse();
@@ -0,0 +1,40 @@
1
+ import { Command } from "commander";
2
+ import { CommandBaseOptions, commandBaseOptions } from "./command-options";
3
+
4
+ export type CommandStructure = {
5
+ name: string;
6
+ description: string;
7
+ action: (this: Command, ...args: any[]) => void | Promise<void>;
8
+ };
9
+
10
+ type CommandBuilderOptions = {
11
+ omitOptions?: CommandBaseOptions[];
12
+ };
13
+
14
+ export const buildCommand = (
15
+ program: Command,
16
+ command: CommandStructure,
17
+ options: CommandBuilderOptions = {}
18
+ ) => {
19
+ const commandInstance = program
20
+ .command(command.name)
21
+ .description(command.description);
22
+
23
+ const baseOptionsKeys = Object.keys(commandBaseOptions).filter(
24
+ (option) => !options.omitOptions?.includes(option as CommandBaseOptions)
25
+ );
26
+ const baseOptions = baseOptionsKeys.map(
27
+ (option) => commandBaseOptions[option as CommandBaseOptions]
28
+ );
29
+
30
+ baseOptions.forEach((option) => {
31
+ if ("validator" in option) {
32
+ commandInstance.option(option.flag, option.description, option.validator);
33
+ return;
34
+ }
35
+
36
+ commandInstance.option(option.flag, option.description);
37
+ });
38
+
39
+ return commandInstance.action(command.action);
40
+ };
@@ -0,0 +1,34 @@
1
+ type CommandBaseOptionsObject = {
2
+ flag: string;
3
+ description: string;
4
+ validator?: (value: string) => any;
5
+ };
6
+
7
+ export const commandBaseOptions = {
8
+ amount: {
9
+ flag: "-a, --amount <amount>",
10
+ description: "Quantidade a ser gerado.",
11
+ validator: (value: string) => Number(value),
12
+ },
13
+ masked: {
14
+ flag: "-m, --masked",
15
+ description: "Gera o resultado com máscara.",
16
+ },
17
+ unmasked: {
18
+ flag: "-u, --unmasked",
19
+ description: "Gera o resultado sem máscara.",
20
+ },
21
+ copy: {
22
+ flag: "-c, --copy",
23
+ description: "Copia o resultado para a área de transferência.",
24
+ },
25
+ } as const satisfies Record<string, CommandBaseOptionsObject>;
26
+
27
+ export type CommandBaseOptions = keyof typeof commandBaseOptions;
28
+ export type CommandOptions = Partial<{
29
+ [Option in CommandBaseOptions]: (typeof commandBaseOptions)[Option] extends {
30
+ validator: (value: string) => infer ValidatorReturnType;
31
+ }
32
+ ? ValidatorReturnType
33
+ : boolean;
34
+ }>;
@@ -0,0 +1,59 @@
1
+ import clipboard from "clipboardy";
2
+ import { CommandOptions } from "./command-options";
3
+
4
+ type ResultWithMask = {
5
+ withMask: string;
6
+ withoutMask: string;
7
+ };
8
+
9
+ type ResultWithoutMask = string;
10
+
11
+ type LogResultOptions = {
12
+ label: string;
13
+ index?: number;
14
+ showIndex?: boolean;
15
+ result: ResultWithMask | ResultWithoutMask;
16
+ options: CommandOptions;
17
+ };
18
+
19
+ export const logResult = ({
20
+ label,
21
+ index = 0,
22
+ showIndex = false,
23
+ result,
24
+ options,
25
+ }: LogResultOptions): void => {
26
+ const indexText = showIndex ? ` ${index + 1})` : ":";
27
+
28
+ if (typeof result === "string") {
29
+ console.log(`${label}${indexText} ${result}`);
30
+ return;
31
+ }
32
+
33
+ if (options.copy) {
34
+ const maskToCopy = options.unmasked ? result.withoutMask : result.withMask;
35
+ const valueToCopy =
36
+ options.masked || options.unmasked
37
+ ? maskToCopy
38
+ : `${result.withMask} - ${result.withoutMask}`;
39
+
40
+ clipboard.write(valueToCopy);
41
+ console.log(`Resultado copiado para a área de transferência.`);
42
+ }
43
+
44
+ if (options.unmasked) {
45
+ console.log(`${label}${indexText} Sem Máscara: ${result.withoutMask}`);
46
+
47
+ return;
48
+ }
49
+
50
+ if (options.masked) {
51
+ console.log(`${label}${indexText} Com Máscara: ${result.withMask}`);
52
+
53
+ return;
54
+ }
55
+
56
+ console.log(
57
+ `${label}${indexText} Com Máscara: ${result.withMask} - Sem Máscara: ${result.withoutMask}`
58
+ );
59
+ };
@@ -1,6 +0,0 @@
1
- import { Command } from "commander";
2
- export type CommandStructure = {
3
- name: string;
4
- description: string;
5
- action: (this: Command, ...args: any[]) => void | Promise<void>;
6
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=command-structure.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command-structure.js","sourceRoot":"","sources":["../../../src/shared/utils/command-structure.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { Command } from "commander";
2
-
3
- export type CommandStructure = {
4
- name: string;
5
- description: string;
6
- action: (this: Command, ...args: any[]) => void | Promise<void>;
7
- };