Skip to content

Commit d8aec37

Browse files
authored
Merge pull request #52 from bertdeblock/remove-use-of-the-word-document
Remove use of the words document, documents, ...
2 parents 85a63d1 + 3b60d0c commit d8aec37

File tree

14 files changed

+38
-25
lines changed

14 files changed

+38
-25
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/coverage/
22
/dist/
3-
/documents/*.md
3+
/templates/
44
/test/output/
55
/CHANGELOG.md
66
/pnpm-lock.yaml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ export type Config = {
161161
hooks?: {
162162
// A hook that will be executed post running a generator:
163163
postGenerate?: (info: {
164-
documentName: DocumentName;
165164
entityName: string;
166165
files: File[];
166+
generatorName: GeneratorName;
167167
}) => Promise<void> | void;
168168
};
169169

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"files": [
1313
"bin/",
1414
"dist/",
15-
"documents/",
15+
"templates/",
1616
"CHANGELOG.md"
1717
],
1818
"scripts": {

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
generateModifier,
1010
generateService,
1111
} from "./generators.js";
12-
import type { DocumentName } from "./types.js";
12+
import type { GeneratorName } from "./types.js";
1313

1414
yargs(hideBin(process.argv))
1515
.command({
@@ -180,11 +180,11 @@ yargs(hideBin(process.argv))
180180
type Options = Record<string, unknown>;
181181

182182
async function applyGemberConfig(
183-
documentName: DocumentName,
183+
generatorName: GeneratorName,
184184
options: Options,
185185
): Promise<Options> {
186186
const config = await resolveConfig(cwd());
187-
const generatorConfig: Options = config.generators?.[documentName] ?? {};
187+
const generatorConfig: Options = config.generators?.[generatorName] ?? {};
188188
const result: Options = { typescript: config.typescript };
189189

190190
for (const key in options) {

src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { findUp } from "find-up";
22
import { pathToFileURL } from "node:url";
33
import { GemberError } from "./errors.js";
4-
import type { DocumentName, File } from "./types.js";
4+
import type { GeneratorName, File } from "./types.js";
55

66
export type Config = {
77
generators?: {
@@ -28,9 +28,13 @@ export type Config = {
2828

2929
hooks?: {
3030
postGenerate?: (info: {
31-
documentName: DocumentName;
31+
/**
32+
* @deprecated Please use `generatorName` instead.
33+
*/
34+
documentName: GeneratorName;
3235
entityName: string;
3336
files: File[];
37+
generatorName: GeneratorName;
3438
}) => Promise<void> | void;
3539
};
3640

src/generate.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { type GenerateInputs, loadScaffdog } from "scaffdog";
99
import { resolveConfig } from "./config.js";
1010
import { GemberError } from "./errors.js";
1111
import { isV1Addon, isV2Addon, pathCase } from "./helpers.js";
12-
import type { DocumentName } from "./types.js";
12+
import type { GeneratorName } from "./types.js";
1313

1414
export async function generate(
15-
documentName: DocumentName,
15+
generatorName: GeneratorName,
1616
entityName: string,
1717
packagePath: string,
1818
{
@@ -26,23 +26,23 @@ export async function generate(
2626
},
2727
): Promise<void> {
2828
const scaffdog = await loadScaffdog(
29-
join(dirname(fileURLToPath(import.meta.url)), "../documents"),
29+
join(dirname(fileURLToPath(import.meta.url)), "../templates"),
3030
);
3131

32-
const documents = await scaffdog.list();
33-
const document = documents.find((document) => document.name === documentName);
32+
const templates = await scaffdog.list();
33+
const template = templates.find((t) => t.name === generatorName);
3434

35-
if (document === undefined) {
36-
throw new GemberError(`[BUG] Document \`${documentName}\` not found.`);
35+
if (template === undefined) {
36+
throw new GemberError(`[BUG] Template \`${generatorName}\` not found.`);
3737
}
3838

3939
const generatePath = await resolveGeneratePath(
40-
documentName,
40+
generatorName,
4141
packagePath,
4242
path,
4343
);
4444

45-
const files = await scaffdog.generate(document, generatePath, {
45+
const files = await scaffdog.generate(template, generatePath, {
4646
inputs: {
4747
...inputs,
4848
name: {
@@ -64,24 +64,32 @@ export async function generate(
6464
await writeFile(file.path, file.content);
6565

6666
consola.success(
67-
`🫚 Generated ${documentName} \`${entityName}\` at \`${relative(cwd(), file.path)}\`.`,
67+
`🫚 Generated ${generatorName} \`${entityName}\` at \`${relative(cwd(), file.path)}\`.`,
6868
);
6969
}
7070

7171
const config = await resolveConfig(packagePath);
7272

7373
await config.hooks?.postGenerate?.({
74-
documentName,
74+
get documentName() {
75+
consola.warn(
76+
"🫚 `documentName` is deprecated. Please use `generatorName` instead.",
77+
);
78+
79+
return generatorName;
80+
},
81+
7582
entityName,
7683
files: filesToGenerate.map((file) => ({
7784
content: file.content,
7885
name: file.name,
7986
path: file.path,
8087
})),
88+
generatorName,
8189
});
8290
}
8391

84-
const DOCUMENT_DIR: Record<DocumentName, string> = {
92+
const TARGET_DIR: Record<GeneratorName, string> = {
8593
component: "components",
8694
helper: "helpers",
8795
modifier: "modifiers",
@@ -95,7 +103,7 @@ const SRC_DIR: Record<string, string> = {
95103
};
96104

97105
export async function resolveGeneratePath(
98-
documentName: DocumentName,
106+
generatorName: GeneratorName,
99107
packagePath: string,
100108
path?: string,
101109
): Promise<string> {
@@ -114,5 +122,5 @@ export async function resolveGeneratePath(
114122
? SRC_DIR.V1_ADDON
115123
: SRC_DIR.APP;
116124

117-
return join(packagePath, srcDir, DOCUMENT_DIR[documentName]);
125+
return join(packagePath, srcDir, TARGET_DIR[generatorName]);
118126
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// eslint-disable-next-line n/no-missing-import
22
import type { PackageJson } from "type-fest";
33

4-
export type DocumentName = "component" | "helper" | "modifier" | "service";
4+
export type GeneratorName = "component" | "helper" | "modifier" | "service";
55

66
export type EmberPackageJson = PackageJson & {
77
ember?: {
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)