Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Included an option to specify the content types to be migrated
Browse files Browse the repository at this point in the history
  • Loading branch information
souljuse committed Jun 9, 2020
1 parent 8f81ae8 commit a8215f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
11 changes: 6 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage:
dato migrate [--source=<environment>] [--destination=<environment>] [--inPlace] [--migrationModel=<apiKey>] [--migrationsDir=<directory>] [--token=<apiToken>]
dato maintenance (on|off) [--force] [--token=<apiToken>]
dato wp-import --token=<datoApiToken> [--environment=<datoEnvironment>] --wpUrl=<url> --wpUser=<user> --wpPassword=<password>
dato contentful-import --datoCmsToken=<apiToken> --contentfulToken=<apiToken> --contentfulSpaceId=<spaceId> [--skipContent] [(--includeOnly <contentType>...)]
dato contentful-import --datoCmsToken=<apiToken> --contentfulToken=<apiToken> --contentfulSpaceId=<spaceId> [--datoCmsEnvironment=<datoEnvironment>] [--skipContent] [(--includeOnly <contentType>...)]
dato check
dato -h | --help
dato --version
Expand Down Expand Up @@ -90,19 +90,20 @@ Options:
'--contentfulToken': contentfulToken,
'--contentfulSpaceId': contentfulSpaceId,
'--datoCmsToken': datoCmsToken,
'--datoCmsEnvironment': datoCmsEnvironment,
'--skipContent': skipContent,
'--includeOnly': includeOnly,
'<contentType>': contentType,
} = options;

contentfulImport(
return contentfulImport({
contentfulToken,
contentfulSpaceId,
datoCmsToken,
datoCmsEnvironment,
skipContent,
includeOnly,
contentType,
);
contentType: includeOnly ? contentType : false,
});
}

return false;
Expand Down
12 changes: 5 additions & 7 deletions src/contentfulImport/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@ import linkRecords from './linkRecords';
import createUploads from './createUploads';
import publishRecords from './publishRecords';

export default async (
export default async ({
contentfulToken,
contentfulSpaceId,
datoCmsToken,
datoCmsEnvironment,
skipContent,
includeOnly,
contentType,
) => {
}) => {
const client = await appClient(
contentfulToken,
contentfulSpaceId,
datoCmsToken,
datoCmsEnvironment,
);
const datoClient = client.dato;
const contentfulData = await getContentfulData(
client.contentful,
const contentfulData = await getContentfulData({
client: client.contentful,
skipContent,
includeOnly,
contentType,
);
});

await removeAllValidators({ datoClient, contentfulData });

Expand Down
16 changes: 10 additions & 6 deletions src/contentfulImport/getContentfulData.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import ora from 'ora';

export default async (client, skipContent, includeOnly, contentType) => {
export default async ({ client, skipContent, contentType }) => {
const spinner = ora('Downloading Contentful data structure').start();
const environments = await client.getEnvironments();
const environment = environments.items.find(e => e.name === 'master');
const rawLocales = await environment.getLocales();
const defaultLocale = rawLocales.items.find(locale => locale.default).code;
const locales = rawLocales.items.map(locale => locale.code);
const rawContentTypes = await environment.getContentTypes();
const includeTypes = new Set(includeOnly? contentType : null);
const contentTypes = includeOnly ?
rawContentTypes.items.filter(type => includeTypes.has(type.sys.id)) : rawContentTypes.items;
const includeTypes = new Set(contentType || null);
const contentTypes = contentType
? rawContentTypes.items.filter(type => includeTypes.has(type.sys.id))
: rawContentTypes.items;

let entries;
let assets;
Expand All @@ -19,8 +20,11 @@ export default async (client, skipContent, includeOnly, contentType) => {
const rawEntries = await environment.getEntries();
const rawAssets = await environment.getAssets();

entries = includeOnly ?
rawEntries.items.filter(entry => includeTypes.has(entry.sys.contentType.sys.id)) : rawEntries.items;
entries = contentType
? rawEntries.items.filter(entry =>
includeTypes.has(entry.sys.contentType.sys.id),
)
: rawEntries.items;
assets = rawAssets.items;
}

Expand Down

0 comments on commit a8215f4

Please sign in to comment.