Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIT-6177] Add pull --sample-data flag for variants #100

Merged
merged 2 commits into from
Feb 29, 2024
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
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