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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The default file looks like this:
```yml
projects: []
variants: []
statuses: []
components:
folders: []
outputs:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/commands/pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const createMockTextItem = (overrides: Partial<TextItem> = {}) => ({
id: "text-1",
text: "Plain text content",
richText: "<p>Rich <strong>HTML</strong> content</p>",
status: "active",
status: "FINAL",
notes: "",
tags: [],
variableIds: [],
Expand All @@ -34,7 +34,7 @@ const createMockComponent = (overrides: Partial<Component> = {}) => ({
id: "component-1",
text: "Plain text content",
richText: "<p>Rich <strong>HTML</strong> content</p>",
status: "active",
status: "FINAL",
notes: "",
tags: [],
variableIds: [],
Expand Down
10 changes: 10 additions & 0 deletions lib/src/formatters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default class JSONFormatter extends applyMixins(
let filters: PullFilters = {
projects: this.projectConfig.projects,
variants: this.projectConfig.variants,
statuses: this.projectConfig.statuses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be available on the output filters as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely, this was an oversight with not understanding the override capabilities of output

Example of this working after a change

Image

};

if (this.output.projects) {
Expand All @@ -99,13 +100,18 @@ export default class JSONFormatter extends applyMixins(
filters.variants = this.output.variants;
}

if (this.output.statuses) {
filters.statuses = this.output.statuses;
}

return filters;
}

private generateComponentPullFilter() {
let filters: PullFilters = {
...(this.projectConfig.components?.folders && { folders: this.projectConfig.components.folders }),
variants: this.projectConfig.variants,
statuses: this.projectConfig.statuses
};

if (this.output.components) {
Expand All @@ -116,6 +122,10 @@ export default class JSONFormatter extends applyMixins(
filters.variants = this.output.variants;
}

if (this.output.statuses) {
filters.statuses = this.output.statuses;
}

return filters;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/http/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("fetchComponents", () => {
id: "text1",
text: "Plain text",
richText: "<p>Rich <strong>HTML</strong> text</p>",
status: "active",
status: "FINAL",
notes: "Test note",
tags: ["tag1"],
variableIds: ["var1"],
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("fetchComponents", () => {
{
id: "text1",
text: "Plain text only",
status: "active",
status: "FINAL",
notes: "",
tags: [],
variableIds: [],
Expand Down
8 changes: 4 additions & 4 deletions lib/src/http/textItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("fetchText", () => {
id: "text1",
text: "Plain text",
richText: "<p>Rich <strong>HTML</strong> text</p>",
status: "active",
status: "FINAL",
notes: "Test note",
tags: ["tag1"],
variableIds: ["var1"],
Expand All @@ -49,7 +49,7 @@ describe("fetchText", () => {
id: "text1",
text: "Plain text",
richText: "<p>Rich <strong>HTML</strong> text</p>",
status: "active",
status: "FINAL",
notes: "Test note",
tags: ["tag1"],
variableIds: ["var1"],
Expand All @@ -65,7 +65,7 @@ describe("fetchText", () => {
{
id: "text1",
text: "Plain text only",
status: "active",
status: "FINAL",
notes: "",
tags: [],
variableIds: [],
Expand All @@ -90,7 +90,7 @@ describe("fetchText", () => {
id: "text1",
text: "Plain text only",
richText: undefined,
status: "active",
status: "FINAL",
notes: "",
tags: [],
variableIds: [],
Expand Down
3 changes: 3 additions & 0 deletions lib/src/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ export interface PullFilters {
excludeNestedFolders?: boolean;
}[];
variants?: { id: string }[];
statuses?: ITextStatus[];
}

export interface PullQueryParams {
filter: string; // Stringified PullFilters
richText?: "html";
}
export const ZTextStatus = z.enum(["NONE", "WIP", "REVIEW", "FINAL"]);
export type ITextStatus = z.infer<typeof ZTextStatus>;

const ZBaseTextEntity = z.object({
id: z.string(),
Expand Down
20 changes: 14 additions & 6 deletions lib/src/outputs/shared.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { z } from "zod";
import { ZTextStatus } from "../http/types";

/**
* These filters that are common to all outputs, used to filter the text items and components that are fetched from the API.
* They are all optional by default unless otherwise specified in the output config.
*/
export const ZBaseOutputFilters = z.object({
projects: z.array(z.object({ id: z.string() })).optional(),
components: z.object({
folders: z.array(z.object({
id: z.string(),
excludeNestedFolders: z.boolean().optional(),
})).optional(),
}).optional(),
components: z
.object({
folders: z
.array(
z.object({
id: z.string(),
excludeNestedFolders: z.boolean().optional(),
})
)
.optional(),
})
.optional(),
statuses: z.array(ZTextStatus).optional(),
variants: z.array(z.object({ id: z.string() })).optional(),
outDir: z.string().optional(),
richText: z.union([z.literal("html"), z.literal(false)]).optional(),
Expand Down
1 change: 1 addition & 0 deletions lib/src/services/projectConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ProjectConfigYAML = z.infer<typeof ZProjectConfigYAML>;
export const DEFAULT_PROJECT_CONFIG_JSON: ProjectConfigYAML = {
projects: [],
variants: [],
statuses: [],
components: {
folders: [],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dittowords/cli",
"version": "5.1.0",
"version": "5.2.0",
"description": "Command Line Interface for Ditto (dittowords.com).",
"license": "MIT",
"main": "bin/ditto.js",
Expand Down