Skip to content

Commit

Permalink
Merge pull request #38 from bertdeblock/support-all-cli-options-in-th…
Browse files Browse the repository at this point in the history
…e-gember-config-file

Support all CLI options in the gember config file
  • Loading branch information
bertdeblock authored Nov 26, 2024
2 parents 17c745b + 879f672 commit 2281bbf
Show file tree
Hide file tree
Showing 25 changed files with 587 additions and 283 deletions.
82 changes: 60 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
[![CI](https://github.com/bertdeblock/gember/workflows/CI/badge.svg)](https://github.com/bertdeblock/gember/actions?query=workflow%3ACI)
[![NPM Version](https://badge.fury.io/js/%40bertdeblock%2Fgember.svg)](https://badge.fury.io/js/%40bertdeblock%2Fgember)

Generate components, helpers, modifiers and services in v2 addons.
Generate components, helpers, modifiers and services in v1/v2 apps/addons.

Uses [scaffdog](https://scaff.dog/) underneath.

> [!NOTE]
>
> - Only supports `.gjs` (default) and `.gts` files for components
> NOTE: Only supports `.gjs` (default) and `.gts` files for components.
## Installation

Expand Down Expand Up @@ -55,6 +53,9 @@ yarn add -D @bertdeblock/gember
<summary>Generating components</summary>

```shell
pnpm gember component --help # for all available options

# examples:
pnpm gember component foo
pnpm gember component foo --class-based # or `--class`
pnpm gember component foo --path="src/-private"
Expand All @@ -67,6 +68,9 @@ pnpm gember component foo --typescript # or `--ts`
<summary>Generating helpers</summary>

```shell
pnpm gember helper --help # for all available options

# examples:
pnpm gember helper foo
pnpm gember helper foo --class-based # or `--class`
pnpm gember helper foo --path="src/-private"
Expand All @@ -79,6 +83,9 @@ pnpm gember helper foo --typescript # or `--ts`
<summary>Generating modifiers</summary>

```shell
pnpm gember modifier --help # for all available options

# examples:
pnpm gember modifier foo
pnpm gember modifier foo --class-based # or `--class`
pnpm gember modifier foo --path="src/-private"
Expand All @@ -91,6 +98,9 @@ pnpm gember modifier foo --typescript # or `--ts`
<summary>Generating services</summary>

```shell
pnpm gember service --help # for all available options

# examples:
pnpm gember service foo
pnpm gember service foo --path="src/-private"
pnpm gember service foo --typescript # or `--ts`
Expand All @@ -106,28 +116,56 @@ gember supports the following config files:
- `gember.config.cjs`
- `gember.config.mjs`

A gember config file must export a gember config object, or a sync/async function that returns a gember config object.
A gember config file must export a gember config object, or a sync/async function that returns a gember config object:

### Configuration Options
```js
// gember.config.js

#### `hooks.postGenerate`
export default {};

A hook that will be executed post generating a document.
// or:
export default () => ({});

```js
// gember.config.js
// or:
export default async () => ({});
```

import { execa } from "execa";

export default {
hooks: {
postGenerate: async ({ files }) => {
await execa("npx", [
"prettier",
"--write",
...files.map((file) => file.path),
]);
},
},
### Configuration Signature

```ts
export type Config = {
generators?: {
component?: {
classBased?: boolean;
path?: string;
typescript?: boolean;
};
helper?: {
classBased?: boolean;
path?: string;
typescript?: boolean;
};
modifier?: {
classBased?: boolean;
path?: string;
typescript?: boolean;
};
service?: {
path?: string;
typescript?: boolean;
};
};

hooks?: {
// A hook that will be executed post running a generator:
postGenerate?: (info: {
documentName: DocumentName;
entityName: string;
files: File[];
}) => Promise<void> | void;
};

// Use TypeScript by default for all generators:
typescript?: boolean;
};
```
1 change: 0 additions & 1 deletion bin/gember.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node

// eslint-disable-next-line n/no-missing-import
import "../dist/cli.js";
8 changes: 7 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ export default typescriptEslint.config(
eslint.configs.recommended,
typescriptEslint.configs.recommended,
eslintPluginNode.configs["flat/recommended-module"],
{ ignores: ["coverage", "dist", "test/output"] },
{ ignores: ["bin", "coverage", "dist", "test/output"] },
{
files: ["**/*.ts"],
rules: {
"@typescript-eslint/explicit-function-return-type": "error",
},
},
);
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@bertdeblock/gember",
"version": "0.4.0",
"description": "Generate components, helpers, modifiers and services in v2 addons.",
"description": "Generate components, helpers, modifiers and services in v1/v2 apps/addons.",
"repository": "https://github.com/bertdeblock/gember",
"license": "MIT",
"author": "Bert De Block",
Expand All @@ -26,11 +26,11 @@
"prepack": "tsc --project tsconfig.json",
"start": "pnpm build --watch",
"test": "vitest",
"test:coverage": "vitest run --coverage"
"test:coverage": "pnpm build && vitest run --coverage"
},
"dependencies": {
"chalk": "^5.3.0",
"change-case": "^5.4.4",
"consola": "^3.2.3",
"find-up": "^7.0.0",
"fs-extra": "^11.2.0",
"scaffdog": "^4.1.0",
Expand All @@ -45,6 +45,7 @@
"concurrently": "^9.1.0",
"eslint": "^9.15.0",
"eslint-plugin-n": "^17.13.2",
"execa": "^9.5.1",
"fixturify-project": "^7.1.3",
"prettier": "^3.3.3",
"recursive-copy": "^2.0.14",
Expand Down
Loading

0 comments on commit 2281bbf

Please sign in to comment.