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
4 changes: 2 additions & 2 deletions src/commands/slice-add-variation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config = {
name: { description: "Name of the variation", required: true },
},
options: {
to: { type: "string", required: true, description: "Name of the slice" },
to: { type: "string", required: true, description: "ID of the slice" },
id: { type: "string", description: "Custom ID for the variation" },
repo: { type: "string", short: "r", description: "Repository domain" },
},
Expand All @@ -30,7 +30,7 @@ export default createCommand(config, async ({ positionals, values }) => {
const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((s) => s.name === to);
const slice = slices.find((s) => s.id === to);

if (!slice) {
throw new CommandError(`Slice not found: ${to}`);
Expand Down
14 changes: 7 additions & 7 deletions src/commands/slice-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const config = {
name: "prismic slice connect",
description: "Connect a slice to a type's slice zone.",
positionals: {
name: { description: "Name of the slice", required: true },
id: { description: "ID of the slice", required: true },
},
options: {
to: {
type: "string",
required: true,
description: "Name of the content type",
description: "ID of the content type",
},
"slice-zone": {
type: "string",
Expand All @@ -28,7 +28,7 @@ const config = {
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [name] = positionals;
const [id] = positionals;
const { to, "slice-zone": sliceZone = "slices", repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
Expand All @@ -37,13 +37,13 @@ export default createCommand(config, async ({ positionals, values }) => {
const apiConfig = { repo, token, host };

const slices = await getSlices(apiConfig);
const slice = slices.find((s) => s.name === name);
const slice = slices.find((s) => s.id === id);
if (!slice) {
throw new CommandError(`Slice not found: ${name}`);
throw new CommandError(`Slice not found: ${id}`);
}

const customTypes = await getCustomTypes(apiConfig);
const customType = customTypes.find((ct) => ct.label === to);
const customType = customTypes.find((ct) => ct.id === to);
if (!customType) {
throw new CommandError(`Type not found: ${to}`);
}
Expand Down Expand Up @@ -86,5 +86,5 @@ export default createCommand(config, async ({ positionals, values }) => {
}
await adapter.generateTypes();

console.info(`Connected slice "${name}" to "${to}"`);
console.info(`Connected slice "${id}" to "${to}"`);
});
14 changes: 7 additions & 7 deletions src/commands/slice-disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const config = {
name: "prismic slice disconnect",
description: "Disconnect a slice from a type's slice zone.",
positionals: {
name: { description: "Name of the slice", required: true },
id: { description: "ID of the slice", required: true },
},
options: {
from: {
type: "string",
required: true,
description: "Name of the content type",
description: "ID of the content type",
},
"slice-zone": {
type: "string",
Expand All @@ -28,7 +28,7 @@ const config = {
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [name] = positionals;
const [id] = positionals;
const { from, "slice-zone": sliceZone = "slices", repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
Expand All @@ -37,13 +37,13 @@ export default createCommand(config, async ({ positionals, values }) => {
const apiConfig = { repo, token, host };

const slices = await getSlices(apiConfig);
const slice = slices.find((s) => s.name === name);
const slice = slices.find((s) => s.id === id);
if (!slice) {
throw new CommandError(`Slice not found: ${name}`);
throw new CommandError(`Slice not found: ${id}`);
}

const customTypes = await getCustomTypes(apiConfig);
const customType = customTypes.find((ct) => ct.label === from);
const customType = customTypes.find((ct) => ct.id === from);
if (!customType) {
throw new CommandError(`Type not found: ${from}`);
}
Expand Down Expand Up @@ -83,5 +83,5 @@ export default createCommand(config, async ({ positionals, values }) => {
}
await adapter.generateTypes();

console.info(`Disconnected slice "${name}" from "${from}"`);
console.info(`Disconnected slice "${id}" from "${from}"`);
});
18 changes: 9 additions & 9 deletions src/commands/slice-edit-variation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ const config = {
name: "prismic slice edit-variation",
description: "Edit a variation of a slice.",
positionals: {
name: { description: "Name of the variation", required: true },
id: { description: "ID of the variation", required: true },
},
options: {
"from-slice": { type: "string", required: true, description: "Name of the slice" },
"from-slice": { type: "string", required: true, description: "ID of the slice" },
name: { type: "string", short: "n", description: "New name for the variation" },
repo: { type: "string", short: "r", description: "Repository domain" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [currentName] = positionals;
const { "from-slice": sliceName, repo = await getRepositoryName() } = values;
const [id] = positionals;
const { "from-slice": sliceId, repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((s) => s.name === sliceName);
const slice = slices.find((s) => s.id === sliceId);

if (!slice) {
throw new CommandError(`Slice not found: ${sliceName}`);
throw new CommandError(`Slice not found: ${sliceId}`);
}

const variation = slice.variations.find((v) => v.name === currentName);
const variation = slice.variations.find((v) => v.id === id);

if (!variation) {
throw new CommandError(`Variation "${currentName}" not found in slice "${sliceName}".`);
throw new CommandError(`Variation "${id}" not found in slice "${sliceId}".`);
}

if ("name" in values) variation.name = values.name!;
Expand All @@ -61,5 +61,5 @@ export default createCommand(config, async ({ positionals, values }) => {
}
await adapter.generateTypes();

console.info(`Variation updated: "${variation.name}" in slice "${sliceName}"`);
console.info(`Variation updated: "${id}" in slice "${sliceId}"`);
});
8 changes: 4 additions & 4 deletions src/commands/slice-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config = {
name: "prismic slice edit",
description: "Edit a slice.",
positionals: {
name: { description: "Name of the slice", required: true },
id: { description: "ID of the slice", required: true },
},
options: {
name: { type: "string", short: "n", description: "New name for the slice" },
Expand All @@ -20,17 +20,17 @@ const config = {
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [currentName] = positionals;
const [id] = positionals;
const { repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((s) => s.name === currentName);
const slice = slices.find((s) => s.id === id);

if (!slice) {
throw new CommandError(`Slice not found: ${currentName}`);
throw new CommandError(`Slice not found: ${id}`);
}

const updatedSlice: SharedSlice = { ...slice };
Expand Down
14 changes: 7 additions & 7 deletions src/commands/slice-remove-variation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ const config = {
name: "prismic slice remove-variation",
description: "Remove a variation from a slice.",
positionals: {
name: { description: "Name of the variation", required: true },
id: { description: "ID of the variation", required: true },
},
options: {
from: { type: "string", required: true, description: "Name of the slice" },
from: { type: "string", required: true, description: "ID of the slice" },
repo: { type: "string", short: "r", description: "Repository domain" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [name] = positionals;
const [id] = positionals;
const { from, repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((s) => s.name === from);
const slice = slices.find((s) => s.id === from);

if (!slice) {
throw new CommandError(`Slice not found: ${from}`);
}

const variation = slice.variations.find((v) => v.name === name);
const variation = slice.variations.find((v) => v.id === id);

if (!variation) {
throw new CommandError(`Variation "${name}" not found in slice "${from}".`);
throw new CommandError(`Variation "${id}" not found in slice "${from}".`);
}

const updatedSlice: SharedSlice = {
Expand All @@ -61,5 +61,5 @@ export default createCommand(config, async ({ positionals, values }) => {
}
await adapter.generateTypes();

console.info(`Removed variation "${name}" from slice "${from}"`);
console.info(`Removed variation "${id}" from slice "${from}"`);
});
10 changes: 5 additions & 5 deletions src/commands/slice-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ const config = {
name: "prismic slice remove",
description: "Remove a slice.",
positionals: {
name: { description: "Name of the slice", required: true },
id: { description: "ID of the slice", required: true },
},
options: {
repo: { type: "string", short: "r", description: "Repository domain" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [name] = positionals;
const [id] = positionals;
const { repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((s) => s.name === name);
const slice = slices.find((s) => s.id === id);

if (!slice) {
throw new CommandError(`Slice not found: ${name}`);
throw new CommandError(`Slice not found: ${id}`);
}

try {
Expand All @@ -45,5 +45,5 @@ export default createCommand(config, async ({ positionals, values }) => {
} catch {}
await adapter.generateTypes();

console.info(`Slice removed: "${name}" (id: ${slice.id})`);
console.info(`Slice removed: ${id}`);
});
8 changes: 4 additions & 4 deletions src/commands/slice-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
name: "prismic slice view",
description: "View details of a slice.",
positionals: {
name: { description: "Name of the slice", required: true },
id: { description: "ID of the slice", required: true },
},
options: {
json: { type: "boolean", description: "Output as JSON" },
Expand All @@ -17,16 +17,16 @@ const config = {
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [name] = positionals;
const [id] = positionals;
const { json, repo = await getRepositoryName() } = values;

const token = await getToken();
const host = await getHost();
const slices = await getSlices({ repo, token, host });
const slice = slices.find((slice) => slice.name === name);
const slice = slices.find((slice) => slice.id === id);

if (!slice) {
throw new CommandError(`Slice not found: ${name}`);
throw new CommandError(`Slice not found: ${id}`);
}

if (json) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/type-add-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config = {
name: { description: "Name of the tab", required: true },
},
options: {
to: { type: "string", required: true, description: "Name of the content type" },
to: { type: "string", required: true, description: "ID of the content type" },
"with-slice-zone": { type: "boolean", description: "Add a slice zone to the tab" },
repo: { type: "string", short: "r", description: "Repository domain" },
},
Expand All @@ -26,7 +26,7 @@ export default createCommand(config, async ({ positionals, values }) => {
const token = await getToken();
const host = await getHost();
const customTypes = await getCustomTypes({ repo, token, host });
const type = customTypes.find((ct) => ct.label === to);
const type = customTypes.find((ct) => ct.id === to);

if (!type) {
throw new CommandError(`Type not found: ${to}`);
Expand Down
14 changes: 7 additions & 7 deletions src/commands/type-edit-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
name: { description: "Current name of the tab", required: true },
},
options: {
"from-type": { type: "string", required: true, description: "Name of the content type" },
"from-type": { type: "string", required: true, description: "ID of the content type" },
name: { type: "string", short: "n", description: "New name for the tab" },
"with-slice-zone": { type: "boolean", description: "Add a slice zone to the tab" },
"without-slice-zone": { type: "boolean", description: "Remove the slice zone from the tab" },
Expand All @@ -24,20 +24,20 @@ const config = {

export default createCommand(config, async ({ positionals, values }) => {
const [currentName] = positionals;
const { "from-type": typeName, repo = await getRepositoryName() } = values;
const { "from-type": typeId, repo = await getRepositoryName() } = values;

const adapter = await getAdapter();
const token = await getToken();
const host = await getHost();
const customTypes = await getCustomTypes({ repo, token, host });
const type = customTypes.find((ct) => ct.label === typeName);
const type = customTypes.find((ct) => ct.id === typeId);

if (!type) {
throw new CommandError(`Type not found: ${typeName}`);
throw new CommandError(`Type not found: ${typeId}`);
}

if (!(currentName in type.json)) {
throw new CommandError(`Tab "${currentName}" not found in "${typeName}".`);
throw new CommandError(`Tab "${currentName}" not found in "${typeId}".`);
}

if ("with-slice-zone" in values && "without-slice-zone" in values) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export default createCommand(config, async ({ positionals, values }) => {

if ("name" in values) {
if (values.name! in type.json) {
throw new CommandError(`Tab "${values.name}" already exists in "${typeName}".`);
throw new CommandError(`Tab "${values.name}" already exists in "${typeId}".`);
}

const newJson: CustomType["json"] = {};
Expand All @@ -109,5 +109,5 @@ export default createCommand(config, async ({ positionals, values }) => {
}
await adapter.generateTypes();

console.info(`Tab updated: "${currentName}" in "${typeName}"`);
console.info(`Tab updated: "${currentName}" in "${typeId}"`);
});
Loading