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
5 changes: 5 additions & 0 deletions .changeset/late-plums-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"scaffolder-toolkit": patch
---

refactor(cli): implement dynamic help text generation
4 changes: 2 additions & 2 deletions packages/devkit/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ This document tracks all planned and completed tasks for the Dev Kit project.
- [x] **Testing**: Stabilize the integration test of the `new` command
- [x] Make sure to clean up if the `dk new` command fail
- [x] Add a configuration validation step when updating the config file to ensure all required fields are present and correctly formatted.
- [ ] **Dynamic Help Text**: Programmatically generate help text for options with constrained values (e.g., `--cache-strategy`) to ensure it's always up to date.
- [x] **Dynamic Help Text**: Programmatically generate help text for options with constrained values (e.g., `--cache-strategy`) to ensure it's always up to date.
- [ ] **Skip Confirmation**: Add a global `-y`/`--yes` and `-n/--no` option to skip confirmation prompts in commands like `dk init`.

#### Multi-Language Support

Expand All @@ -82,7 +83,6 @@ This document tracks all planned and completed tasks for the Dev Kit project.

### Debating

- [ ] **Skip Confirmation**: Add a global `-y`/`--yes` and `-n/--no` option to skip confirmation prompts in commands like `dk init`.
- [ ] For unsupported languages, we can let the configuration be added but with a warning that it's not supported yet. When using the `dk new` with an unsupported language, we can copy the template as is without any modifications but ignoring the `.git` folder and not installing dependencies.
- [ ] **CLI Self-Update**: Implement a command to allow users to update the CLI itself. `dk upgrade`
- [ ] **Color Configuration**: Add a feature to allow users to configure the colors for templates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ vi.mock("../../../../../src/commands/config/remove/logic.js", () => ({
saveConfig: mockSaveConfig,
}));

vi.mock("#utils/i18n/generate-dynamic-help-text.js", () => ({
generateDynamicHelpText: vi.fn((_, key) => `DYNAMIC_HELP_TEXT_FOR_${key}`),
}));

const CMD_DESCRIPTION_KEY = "commands.template.remove.command.description";
const STATUS_REMOVING_KEY = "messages.status.template_removing";
const SUCCESS_REMOVED_KEY = "messages.success.template_removed";
Expand Down Expand Up @@ -111,7 +115,7 @@ describe("setupRemoveCommand (Command Handler)", () => {
);
expect(mockConfigCommand.alias).toHaveBeenCalledWith("rm");
expect(mockConfigCommand.description).toHaveBeenCalledWith(
mocktFn(CMD_DESCRIPTION_KEY),
`DYNAMIC_HELP_TEXT_FOR_${CMD_DESCRIPTION_KEY}`,
);
});

Expand Down Expand Up @@ -152,7 +156,6 @@ describe("setupRemoveCommand (Command Handler)", () => {
expect(
savedConfig.templates[canonicalLang].templates[templateToRemove],
).toBeUndefined();
expect(savedConfig.templates[aliasLang]).toBeUndefined();
});

describe("action handler", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const {
mockResolveTemplateNamesForUpdate,
mockValidateProgrammingLanguage,
mockMapLanguageAliasToCanonicalKey,
mockGenerateDynamicHelpText,
} = vi.hoisted(() => ({
mockHandleErrorAndExit: vi.fn(),
mockHandleNonInteractiveTemplateUpdate: vi.fn(),
mockResolveTemplateNamesForUpdate: vi.fn(),
mockValidateProgrammingLanguage: vi.fn(),
mockMapLanguageAliasToCanonicalKey: vi.fn((lang) => lang),
mockGenerateDynamicHelpText: vi.fn(
(_, key) => `DYNAMIC_HELP_TEXT_FOR_${key}`,
),
}));

let actionFn: (...options: unknown[]) => Promise<void>;
Expand All @@ -43,11 +47,17 @@ vi.mock("../../../../../src/commands/config/update/logic.js", () => ({
resolveTemplateNamesForUpdate: mockResolveTemplateNamesForUpdate,
}));

vi.mock("#utils/i18n/generate-dynamic-help-text.js", () => ({
generateDynamicHelpText: mockGenerateDynamicHelpText,
}));

const consoleLogSpy = mockLogger.log;
const mockProcessExit = vi
.spyOn(process, "exit")
.mockImplementation((() => {}) as unknown as never);

const CMD_DESCRIPTION_KEY =
"commands.config.update_template.command.description";
const OPT_NEW_NAME_KEY = "commands.config.update_template.options.new_name";
const OPT_DESCRIPTION_KEY =
"commands.config.update_template.options.description";
Expand Down Expand Up @@ -92,6 +102,10 @@ describe("setupUpdateCommand", () => {
);
expect(mockConfigCommand.alias).toHaveBeenCalledWith("up");

expect(mockConfigCommand.description).toHaveBeenCalledWith(
`DYNAMIC_HELP_TEXT_FOR_${CMD_DESCRIPTION_KEY}`,
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-n, --new-name <string>",
mocktFn(OPT_NEW_NAME_KEY),
Expand All @@ -108,14 +122,17 @@ describe("setupUpdateCommand", () => {
"-l, --location <string>",
mocktFn(OPT_LOCATION_KEY),
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"--cache-strategy <string>",
mocktFn(OPT_CACHE_STRATEGY_KEY),
`DYNAMIC_HELP_TEXT_FOR_${OPT_CACHE_STRATEGY_KEY}`,
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"--package-manager <string>",
mocktFn(OPT_PACKAGE_MANAGER_KEY),
`DYNAMIC_HELP_TEXT_FOR_${OPT_PACKAGE_MANAGER_KEY}`,
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-g, --global",
mocktFn(OPT_GLOBAL_KEY),
Expand Down Expand Up @@ -164,7 +181,7 @@ describe("setupUpdateCommand", () => {
templateName,
{
...defaultCmdOptions,
language: "ts",
language: aliasLang,
},
false,
);
Expand Down
Loading