Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:coverage": "pnpm build && vitest run --coverage"
},
"dependencies": {
"@napi-rs/clipboard": "^1.1.3",
"change-case": "^5.4.4",
"citty": "^0.1.6",
"consola": "^3.4.2",
Expand Down
100 changes: 100 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Clipboard } from "@napi-rs/clipboard";
import { camelCase, pascalCase, pathCase } from "change-case";
import consola from "consola";
import { ensureDir, pathExists, readJson } from "fs-extra/esm";
Expand Down Expand Up @@ -52,7 +53,7 @@ export function defineGenerator({
name,
}: GeneratorOptions): Generator {
const generatorName = name;
const generatorArgs = [log(), ...args]
const generatorArgs = [copy(), log(), ...args]
.map((argFactory) => argFactory(generatorName))
.sort((a, b) => a.name.localeCompare(b.name));

Expand Down Expand Up @@ -124,7 +125,15 @@ export function defineGenerator({
: "ember-qunit",
});

if (resolvedArgs.log) {
if (resolvedArgs.copy) {
const clipboard = new Clipboard();

clipboard.setText(templateCompiled);

consola.success(
`🫚 Generated and copied ${generatorName} \`${entityName}\` to the clipboard.`,
);
} else if (resolvedArgs.log) {
const border = "─".repeat(
Math.max(...templateCompiled.split("\n").map((line) => line.length)),
);
Expand Down Expand Up @@ -215,6 +224,14 @@ export function classBased({
});
}

export function copy(): GeneratorArgFactory {
return (generatorName) => ({
description: `Copy the generated ${generatorName} to the clipboard, instead of writing it to disk`,
name: "copy",
type: "boolean",
});
}

export function log(): GeneratorArgFactory {
return (generatorName) => ({
description: `Log the generated ${generatorName} to the console, instead of writing it to disk`,
Expand Down
Loading