strapi/tests/e2e/utils/dts-export.ts

92 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

import type { Core } from '@strapi/strapi';
import dts from '@strapi/data-transfer';
import { createStrapi } from '@strapi/strapi';
import { ALLOWED_CONTENT_TYPES } from '../constants';
feat: move rw to plugin (#19937) * chore: initiate moving CM to own package * chore: refactor to handle routes * chore: init review-workflows-package * chore: fix build * chore: refactor review-workflows fe * chore: fix unit suite * feat: move rw to plugin * fix: build * fix: start up * chore: clean things up * fix: peer dependencies * chore(wip): refactor rw fe * chore: re-add admin ui * chore: fix tests & linter * chore: re-implement drag layer * fix: type * feat: review-workflow middlewares * chore: send params to CM endpoints * fix: use layout options as well, let that have the final say, just incase * feat: use doc id and locale for entity assignee and stage * fix: api tests * fix: cm updates when we update fields * chore: cleanup edit-view e2e tests * fix: build * fix: useDocumentLayout for RW options * test: fix fe tests * fix: ts * test(e2e): add review-workflow e2e tests * chore: fix bad import for cli tests * chore: delete old e2e data * chore: import EVERYTHING for DTS * chore: update dataset * fix: e2e script * fix: stage permissions * chore: remove duplicate settings menu link * fix: workflow middleware * chore: change permission * test(e2e): fix RW tests * chore: ignore dynamic attributes in DTS Co-Authored-By: Jean-Sébastien Herbaux <25851739+Convly@users.noreply.github.com> * chore: make settings rw e2e run on EE only * test(e2e): fix them all pls * fix: admin stage transition uid name * chore: fix firefox e2e ce tests --------- Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com> Co-authored-by: Jean-Sébastien Herbaux <25851739+Convly@users.noreply.github.com>
2024-04-12 10:58:38 +02:00
const {
file: {
providers: { createLocalFileDestinationProvider },
},
strapi: {
providers: { createLocalStrapiSourceProvider },
},
engine: { createTransferEngine },
} = dts;
export const exportData = async (): Promise<void> => {
const args = process.argv.slice(2);
if (args.length !== 1) {
console.error('Please provide the export file name as a parameter.');
process.exit(1);
}
const strapi = await createStrapiInstance();
const source = createSourceProvider(strapi);
const destination = createDestinationProvider(args[0]);
const engine = createTransferEngine(source, destination, {
versionStrategy: 'ignore', // for an export to file, versionStrategy will always be skipped
schemaStrategy: 'ignore', // for an export to file, schemaStrategy will always be skipped
transforms: {
links: [
{
filter(link) {
return (
ALLOWED_CONTENT_TYPES.includes(link.left.type) &&
ALLOWED_CONTENT_TYPES.includes(link.right.type)
);
},
},
],
entities: [
{
filter(entity) {
return ALLOWED_CONTENT_TYPES.includes(entity.type);
},
},
],
},
});
engine.diagnostics.onDiagnostic((diagnostic) => {
if (diagnostic.kind !== 'info') console.log(diagnostic);
});
try {
const results = await engine.transfer();
console.log(JSON.stringify(results.engine, null, 2));
} catch {
console.error('Export process failed.');
process.exit(1);
}
process.exit(0);
};
const createSourceProvider = (strapi: Core.Strapi) =>
createLocalStrapiSourceProvider({
async getStrapi() {
return strapi;
},
});
const createDestinationProvider = (filePath: string) =>
createLocalFileDestinationProvider({
file: { path: filePath },
encryption: { enabled: false },
compression: { enabled: false },
});
const createStrapiInstance = async (logLevel = 'error'): Promise<Core.Strapi> => {
feat: move rw to plugin (#19937) * chore: initiate moving CM to own package * chore: refactor to handle routes * chore: init review-workflows-package * chore: fix build * chore: refactor review-workflows fe * chore: fix unit suite * feat: move rw to plugin * fix: build * fix: start up * chore: clean things up * fix: peer dependencies * chore(wip): refactor rw fe * chore: re-add admin ui * chore: fix tests & linter * chore: re-implement drag layer * fix: type * feat: review-workflow middlewares * chore: send params to CM endpoints * fix: use layout options as well, let that have the final say, just incase * feat: use doc id and locale for entity assignee and stage * fix: api tests * fix: cm updates when we update fields * chore: cleanup edit-view e2e tests * fix: build * fix: useDocumentLayout for RW options * test: fix fe tests * fix: ts * test(e2e): add review-workflow e2e tests * chore: fix bad import for cli tests * chore: delete old e2e data * chore: import EVERYTHING for DTS * chore: update dataset * fix: e2e script * fix: stage permissions * chore: remove duplicate settings menu link * fix: workflow middleware * chore: change permission * test(e2e): fix RW tests * chore: ignore dynamic attributes in DTS Co-Authored-By: Jean-Sébastien Herbaux <25851739+Convly@users.noreply.github.com> * chore: make settings rw e2e run on EE only * test(e2e): fix them all pls * fix: admin stage transition uid name * chore: fix firefox e2e ce tests --------- Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com> Co-authored-by: Jean-Sébastien Herbaux <25851739+Convly@users.noreply.github.com>
2024-04-12 10:58:38 +02:00
const app = createStrapi();
app.log.level = logLevel;
const loadedApp = await app.load();
return loadedApp;
};