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
2 changes: 1 addition & 1 deletion .changeset/late-sloths-flash.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"scaffolder-toolkit": minor
"scaffolder-toolkit": major
---

feat: Centralize configuration management under new 'dk config' command and enhance 'dk list'
5 changes: 5 additions & 0 deletions .changeset/tiny-dogs-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"scaffolder-toolkit": minor
---

feat: Add --mode option to `dk list` and strengthen logger table
6 changes: 5 additions & 1 deletion packages/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Scaffolder comes with a set of pre-configured templates for popular frameworks a
> **Note:** All templates currently support Node.js projects and must be configured under the `javascript` key.

| Template Name | Description | Alias |
| -------------- | ------------------------------------------------------ | ------ |
| :------------- | :----------------------------------------------------- | :----- |
| `vue` | An official Vue.js project. | |
| `nuxt` | An official Nuxt.js project. | `nx` |
| `nest` | An official Nest.js project. | |
Expand Down Expand Up @@ -180,6 +180,7 @@ The `dk list` command now uses the following options to control which templates
- **`--global`**: Only list templates from the global configuration file (`~/.devkitrc`).
- **`--all`**: List templates from both the local and global configurations, merging them into a single list.
- **`--filter <string>`**: Filter templates by name or alias substring.
- **`--mode <mode>`**: Sets the display mode for the template list. Options are **`tree`** (default, detailed view) or **`table`** (compact, column-based view).

#### Examples

Expand All @@ -203,6 +204,9 @@ dk list javascript --filter react

# List javascript templates and filter by name starting or containing
dk list javascript --filter r

# List templates in a compact table format
dk list --mode table
```

---
Expand Down
30 changes: 16 additions & 14 deletions packages/devkit/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This document tracks all planned and completed tasks for the Dev Kit project.

#### Core CLI & Configuration

- **Improved `add-template` Command:** Added an interactive, guided flow that uses command-line options to pre-fill prompts. This enhancement is now marked as complete.
- **Improved `add-template` Command:** Added an interactive, guided flow that uses command-line options to pre-fill prompts. This enhancement is now marked as complete. (Deactivate for now to focus on the automate part)
- **Enhanced `list` Command:** The command now includes a filter option and has improved output for better readability.
- **Auto-Detect Package Manager:** The CLI now automatically detects the user's default package manager at initialization and saves it to the configuration file.
- **Refactor `new` Command:** The command now accepts language and project name as arguments with a `--template` option.
Expand Down Expand Up @@ -47,29 +47,26 @@ This document tracks all planned and completed tasks for the Dev Kit project.

#### Core CLI & Configuration

- [ ] **CLI Self-Update**: Implement a command to allow users to update the CLI itself. `dk upgrade`
- [x] `dk info`: A command to display system and environment information that could be useful for debugging issues.
- [x] change the `config` alias from `cf` to `conf`
- [x] **Unified `config` Command**: Complete the refactoring of all configuration-related commands into the new `git`-like pattern under `dk config`. This includes implementing:
- **Core Operations**: `dk config <key> [value]` for set and get.
- **Subcommands**: `dk config add`, `dk config update`, and `dk config remove` to manage templates.
- **Listing**: `dk config --list` with `--all` and `--global` flags.
- [ ] **Enhance `list` Command**: Add support for **different display modes** (e.g., table or tree structure). Also, add options to **filter by property** (e.g., `packageManager`)
- [ ] Add a configuration validation step when initializing or updating the config file to ensure all required fields are present and correctly formatted.
- [ ]: Enhance interactivity with the `dk config add` command
- [ ] **Enhance `list` Command**: Add flag to also see default config `--with-defaults`.
- [ ] ** Enhance for organization Purpose **: Add new language `Typescript` with same code as javascript, also support for nodejs template name for those who prefer it than the language
- [ ] Add wildcard support for template name in the `dk config update` and `dk config remove` commands.
- [ ] Use the interactive approach for the `dk config add` command (code already there)
- [ ] **Dynamic Error Messages**: Update error handling to dynamically generate lists of valid options (e.g., package managers, cache strategies) in error messages.
- [ ] **Skip Confirmation**: Add a global `-y` or `--yes` option to skip confirmation prompts in commands like `dk init`.
- [ ] **Color Configuration**: Add a feature to allow users to configure the colors for templates.
- [ ] **Dynamic Help Text**: Programmatically generate help text for options with constrained values (e.g., `--cache-strategy`) to ensure it's always up to date.
- [ ] **Testing**: Stabilize the integration test of the `new` command
- [x] **Centralize Utilities**: Move `chalk` and `ora` to a single, centralized file for better code organization.
- [x] Enable GitHub discussions
- [x] Refactor and restructure the utilities
- [x] Better json structure for languages translation
- [x] **Enhance `list` Command**: Add support for **different display modes** (e.g., table or tree structure). `tree` as default
- [ ] **Enhance `list` Command**: Add options to **filter by properties** (e.g., `packageManager`, `alias`, etc.).
- [ ] **Enhance `list` Command**: Add flag to also see default config `--with-defaults`.
- [ ] Add wildcard support for template name in the `dk config update` and `dk config remove` commands.
- [ ] ** Enhance for organization Purpose **: Add new language `Typescript` with same code as javascript, also support for nodejs template name for those who prefer it than the language
- [ ] Add a configuration validation step when initializing or 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.
- [ ] **Skip Confirmation**: Add a global `-y` or `--yes` option to skip confirmation prompts in commands like `dk init`.
- [ ] **CLI Self-Update**: Implement a command to allow users to update the CLI itself. `dk upgrade`
- [ ] **Testing**: Stabilize the integration test of the `new` command

#### Multi-Language Support

Expand All @@ -81,6 +78,11 @@ This document tracks all planned and completed tasks for the Dev Kit project.
- [ ] **Security Documentation**: Add a new section to the documentation outlining the security measures taken to prevent supply chain attacks.
- [x] **Package Updates**: Ensure the root `package.json` includes all new packages and that any corrupted packages are replaced.

### Debating

- [ ] **Color Configuration**: Add a feature to allow users to configure the colors for templates.
- [ ] Use the interactive approach for the `dk config add` command (code already there)

---

# **New**
Expand Down
81 changes: 81 additions & 0 deletions packages/devkit/__tests__/integrations/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,85 @@ describe("dk list", () => {
"Using templates from both local and global configurations.",
);
});

describe("dk list (`Table` mode)", () => {
it("should list templates from local config by default when it exists", async () => {
await fs.writeJson(
path.join(tempDir, LOCAL_CONFIG_FILE_NAME),
localConfig,
);
await fs.writeJson(
path.join(globalConfigDir, GLOBAL_CONFIG_FILE_NAME),
globalConfig,
);

const { all, exitCode } = await execa(
"bun",
[CLI_PATH, "list", "--mode", "table"],
{
all: true,
env: { HOME: globalConfigDir },
},
);

expect(exitCode).toBe(0);
expect(all).toContain("Using local configuration.");
expect(all).toContain("Available Templates:");
expect(all).toContain("Javascript");
expect(all).toContain("Node");
expect(all).not.toContain("Python");
});

it("should handle both local and global configs being empty", async () => {
await fs.writeJson(path.join(tempDir, LOCAL_CONFIG_FILE_NAME), {
templates: {},
});
await fs.writeJson(path.join(globalConfigDir, GLOBAL_CONFIG_FILE_NAME), {
templates: {},
});

const { all, exitCode } = await execa(
"bun",
[CLI_PATH, "list", "--all", "--mode", "table"],
{
all: true,
env: { HOME: globalConfigDir },
},
);

expect(exitCode).toBe(0);
expect(all).toContain("No templates found in the configuration file.");
expect(all).toContain(
"Using templates from both local and global configurations.",
);
});

it("should filter templates by name when --filter is used", async () => {
await fs.writeJson(
path.join(tempDir, LOCAL_CONFIG_FILE_NAME),
localConfig,
);
await fs.writeJson(
path.join(globalConfigDir, GLOBAL_CONFIG_FILE_NAME),
globalConfig,
);

const { all, exitCode } = await execa(
"bun",
[CLI_PATH, "list", "--filter", "vue", "--mode", "table"],
{
all: true,
env: { HOME: globalConfigDir },
},
);

expect(exitCode).toBe(0);
expect(all).toContain("Using local configuration.");
expect(all).toContain("Javascript");
expect(all).toContain("vue-basic");
expect(all).not.toContain("react-ts");
expect(all).not.toContain("NODE");
expect(all).not.toContain("PYTHON");
});
});
});
37 changes: 17 additions & 20 deletions packages/devkit/__tests__/units/commands/config/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ describe("setupListCommand", () => {
expect(consoleLogSpy).toHaveBeenCalledWith(
mockLogger.colors.bold("\n" + mocktFn(TEMPLATES_HEADER)),
);
expect(mockPrintTemplates).toHaveBeenCalledWith(
"javascript",
sampleConfig.templates.javascript.templates,
);
expect(mockPrintTemplates).toHaveBeenCalledWith(
"typescript",
sampleConfig.templates.typescript.templates,
);

expect(mockPrintTemplates).toHaveBeenCalledTimes(2);
expect(mockPrintTemplates).toHaveBeenCalledWith([
["javascript", sampleConfig.templates.javascript.templates],
]);
expect(mockPrintTemplates).toHaveBeenCalledWith([
["typescript", sampleConfig.templates.typescript.templates],
]);
expect(mockSpinner.stop).toHaveBeenCalled();
});

Expand All @@ -156,10 +156,9 @@ describe("setupListCommand", () => {
mocktFn(CONFIG_SOURCE_GLOBAL),
);
expect(mockPrintSettings).toHaveBeenCalledWith(sampleConfig.settings);
expect(mockPrintTemplates).toHaveBeenCalledWith(
"javascript",
sampleConfig.templates.javascript.templates,
);
expect(mockPrintTemplates).toHaveBeenCalledWith([
["javascript", sampleConfig.templates.javascript.templates],
]);
});

it("should display both local and global configs with --all flag", async () => {
Expand All @@ -177,14 +176,12 @@ describe("setupListCommand", () => {
mocktFn(CONFIG_SOURCE_MERGED),
);
expect(mockPrintSettings).toHaveBeenCalledWith(sampleConfig.settings);
expect(mockPrintTemplates).toHaveBeenCalledWith(
"javascript",
sampleConfig.templates.javascript.templates,
);
expect(mockPrintTemplates).toHaveBeenCalledWith(
"typescript",
sampleConfig.templates.typescript.templates,
);
expect(mockPrintTemplates).toHaveBeenCalledWith([
["javascript", sampleConfig.templates.javascript.templates],
]);
expect(mockPrintTemplates).toHaveBeenCalledWith([
["typescript", sampleConfig.templates.typescript.templates],
]);
});

it("should handle no templates found gracefully", async () => {
Expand Down
Loading