Skip to content

Commit

Permalink
Merge pull request #100 from dittowords/ash/dit-6177-add-variant-data…
Browse files Browse the repository at this point in the history
…-to-sample-data-flag

[DIT-6177] Add pull --sample-data flag for variants
  • Loading branch information
asnewman authored Feb 29, 2024
2 parents 329f864 + 20ade85 commit 9c51709
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/ditto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ const COMMANDS: CommandConfig<Command>[] = [
{
name: "pull",
description: "Sync copy from Ditto into the current working directory",
flags: {
"--sample-data": {
description: "Include sample data. Currently only supports variants.",
},
},
},
{
name: "project",
Expand Down Expand Up @@ -210,7 +215,10 @@ const executeCommand = async (
switch (command) {
case "none":
case "pull": {
return pull({ meta: processMetaOption(meta) });
return pull({
meta: processMetaOption(meta),
includeSampleData: options.sampleData || false,
});
}
case "project":
case "project add": {
Expand Down
2 changes: 1 addition & 1 deletion lib/http/fetchVariants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function fetchVariants(
const { shouldFetchComponentLibrary, validProjects } = source;

const config: AxiosRequestConfig = {
params: { ...options?.meta },
params: { ...options?.meta, showSampleData: options.includeSampleData },
};

// if we're not syncing from the component library, then we pass the project ids
Expand Down
9 changes: 7 additions & 2 deletions lib/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async function downloadAndSave(
spinner.start();

const [variants, allComponentFoldersResponse] = await Promise.all([
fetchVariants(source),
fetchVariants(source, options),
fetchComponentFolders({}),
]);

Expand Down Expand Up @@ -578,15 +578,20 @@ async function downloadAndSave(

export interface PullOptions {
meta?: Record<string, string>;
includeSampleData?: boolean;
}

export const pull = async (options?: PullOptions) => {
const meta = options ? options.meta : {};
const includeSampleData = options?.includeSampleData || false
const token = config.getToken(consts.CONFIG_FILE, consts.API_HOST);
const sourceInformation = config.parseSourceInformation();

try {
return await downloadAndSave(sourceInformation, token, { meta });
return await downloadAndSave(sourceInformation, token, {
meta,
includeSampleData,
});
} catch (e) {
const eventId = Sentry.captureException(e);
const eventStr = `\n\nError ID: ${output.info(eventId)}`;
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": "4.3.0",
"version": "4.4.0",
"description": "Command Line Interface for Ditto (dittowords.com).",
"license": "MIT",
"main": "bin/index.js",
Expand Down

0 comments on commit 9c51709

Please sign in to comment.