Skip to content

Commit

Permalink
feat(crystallize-cli-next): update libs and add options to dump order…
Browse files Browse the repository at this point in the history
…s and customers
  • Loading branch information
Plopix committed Feb 23, 2023
1 parent 67fe1e0 commit 1847bf2
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 533 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crystallize/cli-next",
"version": "4.10.0",
"version": "4.11.0",
"description": "Crystallize CLI",
"main": "./build/index.js",
"repository": "https://github.com/CrystallizeAPI/crystallize-cli-next",
Expand Down Expand Up @@ -45,8 +45,8 @@
"bump": "yarn tsc && yarn version --no-git-tag-version --new-version"
},
"dependencies": {
"@crystallize/import-utilities": "^1.17.0",
"@crystallize/js-api-client": "^1.6.0",
"@crystallize/import-utilities": "^1.19.4",
"@crystallize/js-api-client": "^1.9.1",
"chalk": "^5.2",
"cli-spinners": "^2.7.0",
"dotenv": "^16.0.3",
Expand Down
10 changes: 10 additions & 0 deletions src/command/dump-tenant.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createSpecDefaults } from '@crystallize/import-utilities/dist/bootstrap-tenant/bootstrapper/index.js';
import { Box, Newline, render, Text } from 'ink';
import React from 'react';
import { colors } from '../config/colors.js';
Expand All @@ -13,6 +14,8 @@ export default async (args: string[], flags: any): Promise<number> => {
const isVerbose = flags.verbose;
const isInteractive = flags.interactive;
const multiLingual = flags.multiLingual;
const excludeOrders = flags.excludeOrders;
const excludeCustomers = flags.excludeCustomers;

await createFolderOrFail(folder, 'Please provide a folder to dump the tenant into.');

Expand All @@ -31,6 +34,11 @@ export default async (args: string[], flags: any): Promise<number> => {
emit: (eventName: string, message: string) => {
output.log(eventName, message);
},
specOptions: {
...createSpecDefaults,
orders: !excludeOrders,
customers: !excludeCustomers,
},
});
output.log(styles.info('Tenant dumped.'));
return 0;
Expand All @@ -49,6 +57,8 @@ export default async (args: string[], flags: any): Promise<number> => {
multiLingual={multiLingual}
tenantIdentifier={tenantIdentifier}
isVerbose={isVerbose}
excludeOrders={excludeOrders}
excludeCustomers={excludeCustomers}
/>
</Box>
</Box>
Expand Down
4 changes: 3 additions & 1 deletion src/command/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Options
--bootstrap-tenant, -b Bootstrap tenant (default: false)
--verbose, -v Verbose output (defaut: false)
--interactive, -i Interactive mode (default: true)
--multi-lingual, -m Multi lingual mode (default: false)
--multi-lingual, Multilingual dump and import mode (default: true)
--exclude-orders, Exclude orders in dump (default: true)
--exclude-customers, Exclude customers in dump (default: true)
Examples
$ @crystallize/cli install ~/my-projects/my-ecommerce
Expand Down
10 changes: 9 additions & 1 deletion src/core/journeys/dump-tenant/DumpTenantJourney.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JsonSpec } from '@crystallize/import-utilities';
import { createSpecDefaults } from '@crystallize/import-utilities/dist/bootstrap-tenant/bootstrapper/index.js';
import { Text, useApp } from 'ink';
import React, { useEffect, useReducer } from 'react';
import { PimAuthenticatedUser, PimCredentials } from '../../../types.js';
Expand Down Expand Up @@ -27,7 +28,9 @@ export const DumpTenantJourney: React.FC<{
tenantIdentifier: string;
isVerbose?: boolean;
multiLingual?: boolean;
}> = ({ folder, tenantIdentifier, multiLingual = false }) => {
excludeOrders?: boolean;
excludeCustomers?: boolean;
}> = ({ folder, tenantIdentifier, multiLingual = true, excludeOrders = true, excludeCustomers = true }) => {
const { exit } = useApp();
const [state, dispatch] = useReducer(Reducer, {
isDumping: false,
Expand Down Expand Up @@ -62,6 +65,11 @@ export const DumpTenantJourney: React.FC<{
emit: (eventName: string, message: string) => {
dispatch({ type: 'ADD_MESSAGE', message: `${eventName}: ${message}` });
},
specOptions: {
...createSpecDefaults,
orders: !excludeOrders,
customers: !excludeCustomers,
},
}).then((spec: JsonSpec) => {
dispatch({ type: 'DUMPING_DONE' });
exit();
Expand Down
10 changes: 8 additions & 2 deletions src/core/use-cases/dumpTenant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Bootstrapper, EVENT_NAMES, JsonSpec } from '@crystallize/import-utilities';
import {
createSpecDefaults,
ICreateSpec,
} from '@crystallize/import-utilities/dist/bootstrap-tenant/bootstrapper/index.js';
import { PimCredentials } from '../../types.js';
import { saveFile } from '../utils/fs-utils.js';

Expand All @@ -8,13 +12,15 @@ type Props = {
credentials: PimCredentials;
emit: (eventName: string, message: string) => void;
multiLingual?: boolean;
specOptions?: ICreateSpec;
};
export default async ({
tenantIdentifier,
folder,
credentials,
emit,
multiLingual = false,
multiLingual = true,
specOptions = createSpecDefaults,
}: Props): Promise<JsonSpec> => {
const bootstrapper = new Bootstrapper();
bootstrapper.setTenantIdentifier(tenantIdentifier);
Expand All @@ -29,7 +35,7 @@ export default async ({
emit(EVENT_NAMES.ERROR, `${status.error}`);
}
});
const spec = await bootstrapper.createSpec();
const spec = await bootstrapper.createSpec(specOptions);
await saveFile(`${folder}/spec-${Date.now()}.json`, JSON.stringify(spec));
return spec;
};
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ const cli = meow(helpText, {
},
multiLingual: {
type: 'boolean',
alias: 'm',
default: false,
default: true,
},
excludeOrders: {
type: 'boolean',
default: true,
},
excludeCustomers: {
type: 'boolean',
default: true,
},
},
});
Expand Down
Loading

0 comments on commit 1847bf2

Please sign in to comment.