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/better-geese-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"scaffolder-toolkit": patch
---

refactor: restructure json translation for better organization
2 changes: 1 addition & 1 deletion packages/devkit/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ This document tracks all planned and completed tasks for the Dev Kit project.
- [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
- [ ] Better json structure for languages
- [x] Better json structure for languages translation

#### Multi-Language Support

Expand Down
8 changes: 4 additions & 4 deletions packages/devkit/__tests__/integrations/config/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe("dk config add", () => {
);
});

it("should fail to add a template if a language is not found", async () => {
it("should fail to add a template if the programming language language is not found", async () => {
await fs.writeJson(path.join(tempDir, LOCAL_CONFIG_FILE_NAME), localConfig);
const { exitCode, all } = await execute(
"bun",
Expand All @@ -226,7 +226,7 @@ describe("dk config add", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Invalid value for language. Valid options are: javascript",
"[DEV]>> Devkit encountered an unexpected internal issue: Invalid value for Programming Language. Valid options are: javascript",
);
});

Expand All @@ -250,7 +250,7 @@ describe("dk config add", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Template 'react-ts' already exists in the configuration. Use 'devkit config set' to update it.",
"::[DEV]>> Devkit encountered an unexpected internal issue: Template 'react-ts' already exists in the configuration. Use 'devkit config set' to update it.",
);
});

Expand Down Expand Up @@ -283,7 +283,7 @@ describe("dk config add", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Alias 'rt' already exists for another template in this language. Please choose a different alias.",
"::[DEV]>> Devkit encountered an unexpected internal issue: Alias 'rt' already exists for another template in this language. Please choose a different alias.",
);
});
});
10 changes: 5 additions & 5 deletions packages/devkit/__tests__/integrations/config/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("dk config", () => {

expect(exitCode).toBe(0);
expect(all).toContain("language: fr");
expect(all).toContain("Configuration chargée avec succès !");
expect(all).toContain("Configuration mise à jour avec succès !");
});

it("should get multiple settings from the local config", async () => {
Expand All @@ -114,7 +114,7 @@ describe("dk config", () => {
expect(exitCode).toBe(0);
expect(all).toContain("language: fr");
expect(all).toContain("cacheStrategy: always-refresh");
expect(all).toContain("Configuration chargée avec succès !");
expect(all).toContain("Configuration mise à jour avec succès !");
});

it("should get a setting from the global config with --global flag", async () => {
Expand All @@ -128,7 +128,7 @@ describe("dk config", () => {

expect(exitCode).toBe(0);
expect(all).toContain("language: en");
expect(all).toContain("Configuration chargée avec succès !");
expect(all).toContain("Configuration mise à jour avec succès !");
});

it("should set a single setting in the local config", async () => {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("dk config", () => {

expect(exitCode).toBe(0);
expect(all).toContain(
"Les valeurs pour l'option '--set' doivent être une série de paires clé-valeur (par ex. --set key1 value1 key2 value2).",
"Les valeurs pour l'option '--set' doivent être une série de paires clé-valeur (par ex., --set key1 value1 key2 value2).",
);
});

Expand All @@ -228,7 +228,7 @@ describe("dk config", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: No local configuration file found. Run 'devkit config init --local' to create one.",
"::[DEV]>> Devkit encountered an unexpected internal issue: No local configuration file found. Run 'devkit config init --local' to create one.",
);
});
});
2 changes: 1 addition & 1 deletion packages/devkit/__tests__/integrations/config/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe("dk config list", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Global configuration file not found.",
"::[DEV]>> Devkit encountered an unexpected internal issue: Global configuration file not found.",
);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/devkit/__tests__/integrations/config/remove.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe("dk config remove", () => {
"Successfully removed 1 template(s) (vue-basic) from javascript.",
);
expect(all).toContain(
"⚠️ Warning: The following templates were not found: not-found",
"⚠️ The following templates were not found: not-found",
);
expect(
updatedConfig.templates.javascript.templates["vue-basic"],
Expand All @@ -215,7 +215,7 @@ describe("dk config remove", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Template 'not-found-1, not-found-2' not found in configuration.",
"::[DEV]>> Devkit encountered an unexpected internal issue: Template 'not-found-1, not-found-2' not found in configuration.",
);
});

Expand All @@ -229,7 +229,7 @@ describe("dk config remove", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
" Devkit encountered an unexpected internal issue: Invalid value for language. Valid options are: javascript",
"::[DEV]>> Devkit encountered an unexpected internal issue: Invalid value for Programming Language. Valid options are: javascript",
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe("dk config update", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
"Failed to update 'ts-template': Programming language 'typescript' not found in configuration",
"Failed to update 'ts-template': Invalid value for Programming Language. Valid options are: javascript",
);
});

Expand Down
10 changes: 5 additions & 5 deletions packages/devkit/__tests__/integrations/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("dk list", () => {
});

expect(exitCode).toBe(0);
expect(all).toContain("Using templates from local configuration.");
expect(all).toContain("Using local configuration.");
expect(all).toContain("Available Templates:");
expect(all).toContain("JAVASCRIPT");
expect(all).toContain("NODE");
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("dk list", () => {
);

expect(exitCode).toBe(0);
expect(all).toContain("Using templates from local configuration.");
expect(all).toContain("Using local configuration.");
expect(all).toContain("JAVASCRIPT");
expect(all).toContain("react-ts");
expect(all).toContain("vue-basic");
Expand All @@ -196,7 +196,7 @@ describe("dk list", () => {
);

expect(exitCode).toBe(0);
expect(all).toContain("Using templates from local configuration.");
expect(all).toContain("Using local configuration.");
expect(all).toContain("JAVASCRIPT");
expect(all).toContain("vue-basic");
expect(all).not.toContain("react-ts");
Expand All @@ -221,7 +221,7 @@ describe("dk list", () => {
);

expect(exitCode).toBe(0);
expect(all).toContain("Using templates from local configuration.");
expect(all).toContain("Using local configuration.");
expect(all).toContain("JAVASCRIPT");
expect(all).toContain("react-ts");
expect(all).not.toContain("vue-basic");
Expand All @@ -239,7 +239,7 @@ describe("dk list", () => {

expect(exitCode).toBe(1);
expect(all).toContain(
"Invalid value for language. Valid options are: javascript",
"::[DEV]>> Devkit encountered an unexpected internal issue: Invalid value for Programming Language. Valid options are: javascript",
);
});

Expand Down
28 changes: 19 additions & 9 deletions packages/devkit/__tests__/units/commands/config/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
mockValidateProgrammingLanguage: vi.fn(),
}));

let actionFn: any;
let actionFn: (...options: unknown[]) => Promise<void>;

vi.mock("#utils/errors/handler.js", () => ({
handleErrorAndExit: mockHandleErrorAndExit,
Expand All @@ -36,6 +36,14 @@ vi.mock("../../../../src/commands/config/validate-and-save.js", () => ({
describe("setupAddCommand", () => {
let mockConfigCommand: any;

const ADD_DESC_KEY = "commands.template.add.description";
const DESC_OPT_KEY = "commands.template.add.options.description";
const LOC_OPT_KEY = "commands.template.add.prompts.location";
const ALIAS_OPT_KEY = "commands.template.add.options.alias";
const CACHE_OPT_KEY = "commands.template.add.options.cache";
const PM_OPT_KEY = "commands.template.add.options.package_manager";
const MISSING_REQUIRED_KEY = "errors.command.missing_required_options";

beforeEach(() => {
vi.clearAllMocks();
actionFn = vi.fn();
Expand All @@ -59,31 +67,33 @@ describe("setupAddCommand", () => {

expect(mockConfigCommand.alias).toHaveBeenCalledWith("a");
expect(mockConfigCommand.description).toHaveBeenCalledWith(
mocktFn("cli.add_template.description"),
mocktFn(ADD_DESC_KEY),
);
expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-d, --description <string>",
mocktFn("cli.add_template.options.description"),
mocktFn(DESC_OPT_KEY),
"",
);
expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-o, --location <string>",
mocktFn("new.project.template.option.description"),
mocktFn(LOC_OPT_KEY),
"",
);
expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-a, --alias <string>",
mocktFn("cli.add_template.options.alias"),
mocktFn(ALIAS_OPT_KEY),
"",
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-c, --cache-strategy <string>",
mocktFn("cli.add_template.options.cache"),
mocktFn(CACHE_OPT_KEY),
"",
);

expect(mockConfigCommand.option).toHaveBeenCalledWith(
"-p, --package-manager <string>",
mocktFn("cli.add_template.options.package_manager"),
mocktFn(PM_OPT_KEY),
"",
);
});
Expand Down Expand Up @@ -141,7 +151,7 @@ describe("setupAddCommand", () => {
expect(mockHandleErrorAndExit).toHaveBeenCalledOnce();
expect(mockHandleErrorAndExit).toHaveBeenCalledWith(
new DevkitError(
mocktFn("error.missing_required_options.add_template", {
mocktFn(MISSING_REQUIRED_KEY, {
fields: "--description, --location",
}),
),
Expand All @@ -157,7 +167,7 @@ describe("setupAddCommand", () => {

expect(mockHandleErrorAndExit).toHaveBeenCalledWith(
new DevkitError(
mocktFn("error.missing_required_options.add_template", {
mocktFn(MISSING_REQUIRED_KEY, {
fields: "--description, --location",
}),
),
Expand Down
Loading