An extra paragraph for good measure.
-``` - -The `buildPayloadUpdateObject` transforms this data to a structure acceptable for Payload update operations by: - -- taking the `fields.json` data and restoring `id` and `blockType` to the Payload CMS data structure; -- take an object containing HTML file names as keys with serialized Slate JSON values, and use the dot notation in the keys to merge `richText` values; and -- use the `restoreOrder` function together with the original document to ensure the order of array items and blocks is restored. diff --git a/docs/serializer.md b/docs/serializer.md deleted file mode 100644 index f5ce4c0..0000000 --- a/docs/serializer.md +++ /dev/null @@ -1,46 +0,0 @@ -# Serializer configuration - -[@slate-serializers/html](https://www.npmjs.com/package/@slate-serializers/html) is used to convert between Slate JSON in Payload CMS and HTML content on Crowdin. - -There are some scenarios where you may wish to customise the configuration of these serializers. Examples: - -- Indent formatting is not serialized. For example, customise the serializer to pass a HTML class attribute value. -- The Slate rich text editor in Payload CMS can be customised with plugins. Use serializer configuration to handle such customisations. For example, serialize Slate JSON generated by a table plugin (not included by default in the Payload CMS implementation of Slate). - -This can be done through the plugin configuration. The default options are made available for convenience. The default configuration is completely replace when passing the configuration, so take care to extend the default configuration if you only want to customise some options. - -```ts -import { crowdinSync, payloadHtmlToSlateConfig, payloadSlateToHtmlConfig } from 'payload-crowdin-sync' - -export default buildConfig({ - plugins: [ - crowdinSync({ - projectId: 323731, - directoryId: 1169, - token: process.env.CROWDIN_TOKEN, - localeMap: { - de_DE: { - crowdinId: "de", - }, - fr_FR: { - crowdinId: "fr", - }, - }, - sourceLocale: "en", - slateToHtmlConfig: { - ...payloadSlateToHtmlConfig, - elementMap: { - ...payloadSlateToHtmlConfig.elementMap, - table: "table", - ["table-row"]: "tr", - ["table-cell"]: "td", - ["table-header"]: "thead", - ["table-header-cell"]: "th", - ["table-body"]: "tbody", - }, - }, - }), - ], - // The rest of your config goes here -}); -``` diff --git a/jest.config.ts b/jest.config.ts index 194dfe4..d0dbd1b 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,18 +1,5 @@ -import type { Config } from "jest"; +import { getJestProjects } from '@nx/jest'; -const config: Config = { - verbose: true, - modulePathIgnorePatterns: ["dist"], - moduleNameMapper: { - '\\.(css|less|scss)$': 'Text for heading cell 1 | Text for heading cell 2 | Text for heading cell 3 | Text for heading cell 4 |
---|---|---|---|
Text for table cell row 1 col 1 | Text for table cell row 1 col 2 | Text for table cell row 1 col 3. | Paragraph 1 text for table cell row 1 col 4 Paragraph 2 text for table cell row 1 col 4 |
Texte pour la cellule d'en-tête 1 | Texte pour la cellule d'en-tête 2 | Texte pour la cellule d'en-tête 3 | Texte pour la cellule d'en-tête 4 |
---|---|---|---|
Texte de la cellule du tableau, ligne 1, col 1 | Texte de la cellule du tableau, ligne 1, col 2 | Texte de la cellule du tableau, ligne 1, col 3 | Texte du paragraphe 1 pour la ligne 1 de la cellule du tableau, colonne 4 Texte du paragraphe 2 pour la ligne 1 de la cellule du tableau, colonne 4 |
Rich-Text-Inhalt im Blocklayout bei Index 0.
"; const responseDeTwo = @@ -610,37 +604,37 @@ describe("Translations", () => { "Contenu de texte enrichi dans la disposition des blocs à l'index 1.
"; const translationsApi = new payloadCrowdinSyncTranslationsApi( pluginOptions, - payload as any + payload ); - const scope = nock("https://api.crowdin.com") + nock("https://api.crowdin.com") .get( "/api/v2/projects/1/translations/builds/1/download?targetLanguageId=de" ) - .reply(200, responseDeTwo) + .reply(200, responseDeOne) .get( "/api/v2/projects/1/translations/builds/1/download?targetLanguageId=de" ) - .reply(200, responseDeOne) + .reply(200, responseDeTwo) .get( "/api/v2/projects/1/translations/builds/1/download?targetLanguageId=fr" ) - .reply(200, responseFrTwo) + .reply(200, responseFrOne) .get( "/api/v2/projects/1/translations/builds/1/download?targetLanguageId=fr" ) - .reply(200, responseFrOne); - const translation = await translationsApi.updateTranslation({ - documentId: post.id, - collection: collections.nestedFields, + .reply(200, responseFrTwo); + await translationsApi.updateTranslation({ + documentId: `${post.id}`, + collection: "nested-field-collection", dryRun: false, }); // retrieve translated post from Payload const resultDe = await payload.findByID({ - collection: collections.nestedFields, - id: post.id, + collection: "nested-field-collection", + id: `${post.id}`, locale: "de_DE", }); - expect(resultDe.layout).toEqual([ + expect(resultDe["layout"]).toEqual([ { richTextField: [ { @@ -672,11 +666,11 @@ describe("Translations", () => { ]); // retrieve translated post from Payload const resultFr = await payload.findByID({ - collection: collections.nestedFields, - id: post.id, + collection: "nested-field-collection", + id: `${post.id}`, locale: "fr_FR", }); - expect(resultFr.layout).toEqual([ + expect(resultFr["layout"]).toEqual([ { richTextField: [ { @@ -736,13 +730,13 @@ describe("Translations", () => { // ensure all afterChange hooks have run? Getting test failures without this additional operation. const result = await payload.findByID({ collection: slug, - id: post.id, + id: `${post.id}`, }); const translationsApi = new payloadCrowdinSyncTranslationsApi( pluginOptions, - payload as any + payload ); - const htmlFieldSlugs = await translationsApi.getHtmlFieldSlugs(result.id); + const htmlFieldSlugs = await translationsApi.getHtmlFieldSlugs(`${result.id}`); expect(htmlFieldSlugs.length).toEqual(11) expect(htmlFieldSlugs.sort()).toEqual([ "field_0", diff --git a/dev/src/lib/utils/index.ts b/dev/src/lib/utils/index.ts index 4639573..d6cfc68 100644 --- a/dev/src/lib/utils/index.ts +++ b/dev/src/lib/utils/index.ts @@ -6,7 +6,7 @@ export const delocalizeFields = (fields: Field[]): Field[] => { const dotFields = dot.dot(field); const dotKeysNoLocalized = Object.keys(dotFields) .filter(key => !key.endsWith('localized')) - .reduce((obj, key) => { + .reduce((obj: {[key: string]: any}, key) => { obj[key] = dotFields[key]; return obj; }, {}); diff --git a/dev/tsconfig.json b/dev/tsconfig.json index 451a604..e16119d 100644 --- a/dev/tsconfig.json +++ b/dev/tsconfig.json @@ -7,7 +7,9 @@ "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "esModuleInterop": true, + "jsx": "react", }, "files": [], "include": [], @@ -18,5 +20,5 @@ { "path": "./tsconfig.spec.json" } - ] + ], } diff --git a/package-lock.json b/package-lock.json index bcbae88..156ec6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@payloadcms/db-mongodb": "^1.0.4", "@payloadcms/richtext-slate": "^1.0.6", "@slate-serializers/html": "^2.1.0", + "@swc/helpers": "^0.5.3", "@types/dot-object": "^2.1.4", "deep-equal": "^2.2.2", "dot-object": "^2.1.4", @@ -66,6 +67,7 @@ "prettier": "^2.8.8", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", "typescript": "^5.2.2", "verdaccio": "^5.0.4" } @@ -6724,6 +6726,14 @@ "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.2.tgz", "integrity": "sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==" }, + "node_modules/@swc/helpers": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.3.tgz", + "integrity": "sha512-FaruWX6KdudYloq1AHD/4nU+UsMTdNE8CKyrseXWEcgjDAbvkwJg2QGPAnfIJLIWsjZOSPLOAykK6fuYp4vp4A==", + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@swc/jest": { "version": "0.2.29", "resolved": "https://registry.npmjs.org/@swc/jest/-/jest-0.2.29.tgz", diff --git a/package.json b/package.json index 9ae99bf..5e1caec 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,9 @@ "name": "@payload-crowdin-sync-nx/source", "version": "0.0.0", "license": "MIT", - "scripts": {}, + "scripts": { + "test": "nx run-many --all --target=test" + }, "private": true, "dependencies": { "@crowdin/crowdin-api-client": "^1.25.0", @@ -10,6 +12,7 @@ "@payloadcms/db-mongodb": "^1.0.4", "@payloadcms/richtext-slate": "^1.0.6", "@slate-serializers/html": "^2.1.0", + "@swc/helpers": "^0.5.3", "@types/dot-object": "^2.1.4", "deep-equal": "^2.2.2", "dot-object": "^2.1.4", @@ -62,6 +65,7 @@ "prettier": "^2.8.8", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", "typescript": "^5.2.2", "verdaccio": "^5.0.4" }, diff --git a/plugin/jest.config.ts b/plugin/jest.config.ts index 0791b74..33fc2ae 100644 --- a/plugin/jest.config.ts +++ b/plugin/jest.config.ts @@ -3,8 +3,11 @@ export default { displayName: 'plugin', preset: '../jest.preset.js', testEnvironment: 'node', + moduleNameMapper: { + '\\.(css|less|scss|svg|png)$': '