@notifiles/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/index.modern.cjs +856 -0
  4. package/dist/index.modern.cjs.map +1 -0
  5. package/dist/index.modern.modern.js +690 -0
  6. package/dist/index.modern.modern.js.map +1 -0
  7. package/package.json +152 -0
  8. package/src/cloud/add/index.js +38 -0
  9. package/src/cloud/add/index.test.js +38 -0
  10. package/src/cloud/add/lib/validate.js +16 -0
  11. package/src/cloud/index.js +3 -0
  12. package/src/cloud/list/index.js +18 -0
  13. package/src/cloud/list/index.test.js +13 -0
  14. package/src/email/build copy/lib/perform/email.js +52 -0
  15. package/src/index.js +3 -0
  16. package/src/lib/adaptSettings.js +12 -0
  17. package/src/lib/cloudLibrary/bunny/index.js +2 -0
  18. package/src/lib/cloudLibrary/bunny/isValid.js +32 -0
  19. package/src/lib/cloudLibrary/bunny/upload.js +35 -0
  20. package/src/lib/cloudLibrary/index.js +20 -0
  21. package/src/lib/cloudLibrary/minio/index.js +4 -0
  22. package/src/lib/cloudLibrary/minio/isValid.js +33 -0
  23. package/src/lib/cloudLibrary/minio/remove.js +58 -0
  24. package/src/lib/cloudLibrary/minio/upload.js +61 -0
  25. package/src/lib/cloudLibrary/minio/uploadFolder.js +26 -0
  26. package/src/lib/entries/getAtPath.js +105 -0
  27. package/src/lib/entries/isPathEntry.js +29 -0
  28. package/src/lib/entries.js +144 -0
  29. package/src/lib/fs/checkFileExists.js +6 -0
  30. package/src/lib/fs/directoryFilesRecursive.js +83 -0
  31. package/src/lib/fs/ensureDirectoryExists.js +10 -0
  32. package/src/lib/fs/getFileCallerURL.js +12 -0
  33. package/src/lib/fs/importFileAsText.js +15 -0
  34. package/src/lib/fs/importJSONAsync.js +16 -0
  35. package/src/lib/fs/importYAMLAsync.js +14 -0
  36. package/src/lib/remark/hastToHtml.js +6 -0
  37. package/src/lib/remark/htmlToHast.js +6 -0
  38. package/src/lib/remark/htmlToMarkdown copy.js +12 -0
  39. package/src/lib/remark/htmlToMarkdown.js +23 -0
  40. package/src/lib/remark/htmlToMdast.js +13 -0
  41. package/src/lib/remark/htmlToMdast_.js +21 -0
  42. package/src/lib/remark/htmlToMdast_3.js +21 -0
  43. package/src/lib/remark/markdownToHTML.js +22 -0
  44. package/src/lib/remark/markdownToLexer.js +19 -0
  45. package/src/lib/remark/mdastToHTML.js +8 -0
  46. package/src/lib/remark/mdastToMarkdown.js +24 -0
  47. package/src/lib/remark/mdastToString.js +12 -0
  48. package/src/project/index.js +4 -0
  49. package/src/project/isProject/index.js +26 -0
  50. package/src/project/isProject/index.test.js +13 -0
  51. package/src/project/isProject/sync.js +18 -0
  52. package/src/project/lib/activity/createFileIfNeeded.js +33 -0
  53. package/src/project/lib/activity/defaultContent.json +5 -0
  54. package/src/project/lib/activity/updateToFile.js +32 -0
  55. package/src/project/lib/manifest/createFileIfNeeded.js +44 -0
  56. package/src/project/lib/manifest/read.js +21 -0
  57. package/src/project/lib/manifest/update.js +36 -0
  58. package/src/project/lib/manifest/updateToFile.js +22 -0
  59. package/src/project/new/index.js +2 -0
  60. package/src/project/new/plain.js +49 -0
  61. package/src/project/new/plain.test.js +38 -0
  62. package/src/template/build/entry.js +37 -0
  63. package/src/template/build/index.js +2 -0
  64. package/src/template/build/lib/email/index.js +100 -0
  65. package/src/template/build/lib/email/translate.js +16 -0
  66. package/src/template/build/lib/textmessage/index.js +44 -0
  67. package/src/template/build/lib/textmessage/translate.js +25 -0
  68. package/src/template/build/path.js +18 -0
  69. package/src/template/build/path.test.js +29 -0
  70. package/src/template/cloudify/entry.js +20 -0
  71. package/src/template/cloudify/index.js +2 -0
  72. package/src/template/cloudify/lib/email/attachments/addAttachment.js +24 -0
  73. package/src/template/cloudify/lib/email/attachments/index.js +137 -0
  74. package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +13 -0
  75. package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +26 -0
  76. package/src/template/cloudify/lib/email/image/index.js +90 -0
  77. package/src/template/cloudify/lib/email/image/treatLocalFile.js +13 -0
  78. package/src/template/cloudify/lib/email/image/treatRemoteFile.js +26 -0
  79. package/src/template/cloudify/lib/email/index.js +77 -0
  80. package/src/template/cloudify/lib/remove.js +14 -0
  81. package/src/template/cloudify/lib/textMessage.js +9 -0
  82. package/src/template/cloudify/lib/upload.js +14 -0
  83. package/src/template/cloudify/path.js +20 -0
  84. package/src/template/cloudify/path.test.js +24 -0
  85. package/src/template/consolidate/entry.js +18 -0
  86. package/src/template/consolidate/index.js +2 -0
  87. package/src/template/consolidate/lib/email.js +63 -0
  88. package/src/template/consolidate/lib/image/index.js +35 -0
  89. package/src/template/consolidate/lib/image/treatLocalFile.js +14 -0
  90. package/src/template/consolidate/lib/image/treatRemoteFile.js +25 -0
  91. package/src/template/consolidate/lib/textMessage.js +5 -0
  92. package/src/template/consolidate/path.js +18 -0
  93. package/src/template/consolidate/path.test.js +14 -0
  94. package/src/template/format/entry.js +57 -0
  95. package/src/template/format/index.js +2 -0
  96. package/src/template/format/path.js +18 -0
  97. package/src/template/format/path.test.js +29 -0
  98. package/src/template/index.js +8 -0
  99. package/src/template/lib/activity/createFileIfNeeded.js +33 -0
  100. package/src/template/lib/activity/defaultContent.json +4 -0
  101. package/src/template/lib/activity/get.js +20 -0
  102. package/src/template/lib/activity/updateToFile.js +33 -0
  103. package/src/template/lib/manifest/createFileIfNeeded.js +41 -0
  104. package/src/template/lib/manifest/read.js +22 -0
  105. package/src/template/lib/manifest/update.js +18 -0
  106. package/src/template/lib/manifest/updateToFile.js +22 -0
  107. package/src/template/new/index.js +66 -0
  108. package/src/template/new/index.test.js +19 -0
  109. package/src/template/optimize/entry.js +18 -0
  110. package/src/template/optimize/index.js +2 -0
  111. package/src/template/optimize/lib/email.js +58 -0
  112. package/src/template/optimize/lib/image/index.js +40 -0
  113. package/src/template/optimize/lib/textMessage.js +8 -0
  114. package/src/template/optimize/path.js +18 -0
  115. package/src/template/optimize/path.test.js +16 -0
  116. package/src/template/sync/entry.js +18 -0
  117. package/src/template/sync/index.js +2 -0
  118. package/src/template/sync/lib/email.js +86 -0
  119. package/src/template/sync/lib/textMessage.js +80 -0
  120. package/src/template/sync/lib/upload.js +14 -0
  121. package/src/template/sync/path.js +18 -0
  122. package/src/template/sync/path.test.js +29 -0
  123. package/src/template/update/index.js +1 -0
  124. package/src/template/update/path.js +41 -0
  125. package/src/template/update/path.test.js +46 -0
  126. package/src/template/version/entry.js +10 -0
  127. package/src/template/version/index.js +2 -0
  128. package/src/template/version/lib/perform.js +74 -0
  129. package/src/template/version/lib/reset.js +16 -0
  130. package/src/template/version/lib/updatePost.js +16 -0
  131. package/src/template/version/path.js +20 -0
  132. package/src/template/version/path.test.js +16 -0
@@ -0,0 +1,18 @@
1
+ import perform from './lib/perform.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+
4
+ export default async ({
5
+ path,
6
+ settings
7
+ }) => {
8
+ let entries = await getEntries({
9
+ path,
10
+ })
11
+
12
+ for (var i in entries) {
13
+ const entry = entries[i]
14
+ await perform({ entry, settings })
15
+ }
16
+
17
+ return true
18
+ }
@@ -0,0 +1,14 @@
1
+ describe.skip('consolidate', () => {
2
+ test('consolidate', async () => {
3
+ const fsPath = (await import('path')).default
4
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
5
+ const operation = (await import('./path.js')).default
6
+
7
+ const result = await operation({
8
+ settings: {
9
+ },
10
+ path,
11
+ })
12
+ expect(result).toBeTruthy()
13
+ })
14
+ })
@@ -0,0 +1,57 @@
1
+
2
+ export default async ({
3
+ entry,
4
+ settings = {},
5
+ }) => {
6
+ const { email, path, i18n = {} } = entry
7
+ let _i18n = i18n
8
+ if (!_i18n[settings.defaultLocale]) {
9
+ _i18n[settings.defaultLocale] = {}
10
+ }
11
+
12
+ const keys = Object.keys(_i18n)
13
+ const versions = keys.map(language => {
14
+ const code = language
15
+ return {
16
+ ...entry,
17
+ language: {
18
+ code,
19
+ data: _i18n[language]
20
+ },
21
+ code,
22
+ buildPaths: {
23
+ email: {
24
+ container: `${path}/.build/email/${code}`,
25
+ body: `${path}/.build/email/${code}/body.html`,
26
+ bodyFileName: `${entry.slug}/email/${code}/body.html`,
27
+ text: `${path}/.build/email/${code}/text.txt`,
28
+ textFileName: `${entry.slug}/email/${code}/text.txt`,
29
+ subject: `${path}/.build/email/${code}/subject.txt`,
30
+ subjectFileName: `${entry.slug}/email/${code}/subject.txt`,
31
+ assetsContainer: `${entry.slug}/email/${code}/assets`,
32
+ attachmentsContainer: `${entry.slug}/email/${code}/attachments`,
33
+ manifestFileNameBuilt: `${path}/.build/email/${code}/manifest.json`,
34
+ manifestFileName: `${entry.slug}/email/${code}/manifest.json`,
35
+ },
36
+ textMessage: {
37
+ container: `${path}/.build/textmessage/${code}`,
38
+ text: `${path}/.build/textmessage/${code}/textmessage.txt`,
39
+ textFileName: `${entry.slug}/textmessage/${code}/textmessage.txt`,
40
+ assetsContainer: `${entry.slug}/textmessage/${code}/assets`,
41
+ manifestFileNameBuilt: `${path}/.build/textmessage/${code}/manifest.json`,
42
+ manifestFileName: `${entry.slug}/textmessage/${code}/manifest.json`,
43
+ },
44
+ manifestFileNameBuilt: `${path}/.build/manifest.json`,
45
+ manifestFileName: `${entry.slug}/manifest.json`,
46
+ activityPath: `${path}/.activity.json`,
47
+ }
48
+ }
49
+ })
50
+
51
+ return {
52
+ entry: {
53
+ ...entry,
54
+ versions
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'
@@ -0,0 +1,18 @@
1
+ import perform from './lib/perform/email.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+
4
+ export default async ({
5
+ path,
6
+ settings
7
+ }) => {
8
+ let entries = await getEntries({
9
+ path,
10
+ })
11
+
12
+ for (var i in entries) {
13
+ const entry = entries[i]
14
+ await perform({ entry, settings })
15
+ }
16
+
17
+ return true
18
+ }
@@ -0,0 +1,29 @@
1
+
2
+ test.skip('build posts', async () => {
3
+ const fsPath = (await import('path')).default
4
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
5
+ const operation = (await import('./path.js')).default
6
+
7
+ const result = await operation({
8
+ settings: {
9
+ platforms: [{
10
+ id: 'medium',
11
+ auth: {
12
+ token: process.env.TEST_MEDIUM_TOKEN,
13
+ }
14
+ }],
15
+ storage: {
16
+ type: "cdn",
17
+ auth: {
18
+ key: '',
19
+ secret: '',
20
+ bucketName: ''
21
+ }
22
+ }
23
+ },
24
+ path,
25
+ })
26
+ expect(result).toBeTruthy()
27
+ })
28
+
29
+
@@ -0,0 +1,8 @@
1
+
2
+ export * as build from './build/index.js'
3
+ export * as cloudify from './cloudify/index.js'
4
+ export * as consolidate from './consolidate/index.js'
5
+ export * as contain from './consolidate/index.js'
6
+ export * as sync from './sync/index.js'
7
+ export * as update from './update/index.js'
8
+ export { default as create } from './new/index.js'
@@ -0,0 +1,33 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
5
+
6
+ export default async ({
7
+ path,
8
+ status = "draft",
9
+ }) => {
10
+
11
+
12
+ try {
13
+
14
+ const filePath = fsPath.join(path, ".activity.json")
15
+
16
+ if ((await checkFileExists(filePath))) {
17
+ return
18
+ }
19
+
20
+ const defaultContent = await importJSONAsync('./defaultContent.json')
21
+ let content = {
22
+ ...defaultContent,
23
+ createdAt: (new Date()),
24
+ status,
25
+ }
26
+
27
+ await fs.promises.writeFile(filePath, JSON.stringify(content, null, 2))
28
+ return true
29
+ } catch (e) {
30
+ console.error(e)
31
+ }
32
+ return false
33
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "createdAt": "",
3
+ "updatedAt": ""
4
+ }
@@ -0,0 +1,20 @@
1
+ import fsPath from 'path'
2
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
3
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
4
+
5
+ export default async ({
6
+ path,
7
+ }) => {
8
+ try {
9
+ const filePath = fsPath.join(path, ".activity.json")
10
+
11
+ if (!(await checkFileExists(filePath))) {
12
+ return null
13
+ }
14
+
15
+ return importJSONAsync(filePath)
16
+ } catch (e) {
17
+ console.error(e)
18
+ }
19
+ return null
20
+ }
@@ -0,0 +1,33 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
5
+
6
+
7
+ export default async ({
8
+ path,
9
+ content,
10
+ }) => {
11
+
12
+
13
+ try {
14
+
15
+ const filePath = fsPath.join(path, ".activity.json")
16
+
17
+ if (!(await checkFileExists(filePath))) {
18
+ return
19
+ }
20
+
21
+ const defaultContent = await importJSONAsync('./defaultContent.json')
22
+ let _content = {
23
+ ...defaultContent,
24
+ ...content,
25
+ }
26
+
27
+ await fs.promises.writeFile(filePath, JSON.stringify(_content, null, 2))
28
+ return true
29
+ } catch (e) {
30
+ console.error(e)
31
+ }
32
+ return false
33
+ }
@@ -0,0 +1,41 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+ import YAML from 'yaml'
5
+
6
+ export default async ({
7
+ path,
8
+ data = {}
9
+ }) => {
10
+
11
+
12
+ try {
13
+
14
+ const filePath = fsPath.join(path, "manifest.yaml")
15
+
16
+ if ((await checkFileExists(filePath))) {
17
+ return
18
+ }
19
+
20
+
21
+ let defaultManifest = YAML.parse(`
22
+ status: draft
23
+ skip: false
24
+ license: all-rights-reserved
25
+ `)
26
+
27
+ let manifest = {
28
+ ...defaultManifest,
29
+ createdAt: (new Date()),
30
+ ...data
31
+ }
32
+
33
+ manifest = YAML.stringify(manifest)
34
+
35
+ await fs.promises.writeFile(filePath, manifest)
36
+ return true
37
+ } catch (e) {
38
+ console.error(e)
39
+ }
40
+ return false
41
+ }
@@ -0,0 +1,22 @@
1
+ import fsPath from 'path'
2
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
3
+ import importYAMLAsync from '../../../lib/fs/importYAMLAsync.js'
4
+
5
+
6
+ export default async ({
7
+ path,
8
+ }) => {
9
+ try {
10
+ const filePath = fsPath.join(path, "manifest.yaml")
11
+
12
+ if (!(await checkFileExists(filePath))) {
13
+ return null
14
+ }
15
+
16
+ const content = await importYAMLAsync(manifestPath)
17
+ return content
18
+ } catch (e) {
19
+ console.error(e)
20
+ }
21
+ return null
22
+ }
@@ -0,0 +1,18 @@
1
+ import updateToFile from './updateToFile.js'
2
+ import YAML from 'yaml'
3
+
4
+ export default async ({
5
+ path,
6
+ manifest,
7
+ }) => {
8
+ try {
9
+ const content = YAML.stringify(manifest)
10
+ return updateToFile({
11
+ path,
12
+ content
13
+ })
14
+ } catch (e) {
15
+ console.error(e)
16
+ }
17
+ return false
18
+ }
@@ -0,0 +1,22 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+
5
+ export default async ({
6
+ path,
7
+ content,
8
+ }) => {
9
+
10
+ try {
11
+ const filePath = fsPath.join(path, "manifest.yaml")
12
+ if (!(await checkFileExists(filePath))) {
13
+ return
14
+ }
15
+
16
+ await fs.promises.writeFile(filePath, content)
17
+ return true
18
+ } catch (e) {
19
+ console.error(e)
20
+ }
21
+ return false
22
+ }
@@ -0,0 +1,66 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../lib/fs/checkFileExists.js'
4
+ import createStatusIfNeeded from '../lib/activity/createFileIfNeeded.js'
5
+ import createManifestIfNeeded from '../lib/manifest/createFileIfNeeded.js'
6
+
7
+ export default async ({
8
+ path,
9
+ title = "My new post",
10
+ platforms = [],
11
+ status = "draft",
12
+ canonicalUrl = "",
13
+ tags,
14
+ author = {
15
+ id: "",
16
+ name: ""
17
+ },
18
+ force = false
19
+ }) => {
20
+ try {
21
+ const folderPath = fsPath.join(path, title)
22
+
23
+ if ((await checkFileExists(folderPath))) {
24
+ if (!force) {
25
+ return false
26
+ }
27
+ await fs.promises.rmdir(folderPath, { recursive: true })
28
+ }
29
+
30
+ await fs.promises.mkdir(folderPath)
31
+ await fs.promises.mkdir(`${folderPath}/.assets`)
32
+ // await fs.promises.mkdir(`${folderPath}/artefacts`)
33
+ await fs.promises.mkdir(`${folderPath}/.build`)
34
+
35
+
36
+ await createStatusIfNeeded({
37
+ path: folderPath
38
+ })
39
+
40
+ await createManifestIfNeeded({
41
+ path: folderPath,
42
+ data: {
43
+ name: title,
44
+ platforms,
45
+ canonicalUrl,
46
+ status,
47
+ author,
48
+ tags
49
+ }
50
+ })
51
+
52
+
53
+ const postPath = fsPath.join(folderPath, "post.md")
54
+ const post = `# ${title}`
55
+ await fs.promises.writeFile(postPath, post, 'utf8')
56
+
57
+ const excerptPath = fsPath.join(folderPath, "excerpt.md")
58
+ const excerpt = ``
59
+ await fs.promises.writeFile(excerptPath, excerpt, 'utf8')
60
+
61
+ return true
62
+ } catch (e) {
63
+ console.error(e)
64
+ }
65
+ return false
66
+ }
@@ -0,0 +1,19 @@
1
+
2
+ test.skip('creates a new post', async () => {
3
+ const fsPath = (await import('path')).default
4
+ let path = fsPath.resolve("__mock__/adoucoure/Development")
5
+ const operation = (await import('./new.js')).default
6
+
7
+ const result = await operation({
8
+ platforms: [{
9
+ id: 'medium',
10
+ }],
11
+ path,
12
+ title: "Sample test post",
13
+ force: true
14
+ })
15
+
16
+ expect(result).toBeTruthy()
17
+ })
18
+
19
+
@@ -0,0 +1,18 @@
1
+ import performEmail from './lib/email.js'
2
+ import performTextMessage from './lib/textMessage.js'
3
+
4
+ export default async ({
5
+ entry,
6
+ settings,
7
+ }) => {
8
+ return {
9
+ entry: {
10
+ ...entry,
11
+ versions: await Promise.all(entry.versions.map(async _entry => {
12
+ let res = await performEmail({ entry: _entry, settings, })
13
+ res = await performTextMessage({ entry: res.entry, settings, })
14
+ return res.entry
15
+ }))
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'
@@ -0,0 +1,58 @@
1
+ import hastToHtml from '../../../lib/remark/hastToHtml.js'
2
+ import treatImage from './image/index.js'
3
+
4
+ export default async (props) => {
5
+ const { entry } = props
6
+ const { path, email: { hast } } = entry
7
+
8
+ let _hast = await perform({
9
+ child: hast,
10
+ path
11
+ })
12
+
13
+ let body = hastToHtml({ data: _hast })
14
+
15
+ return {
16
+ entry: {
17
+ ...entry,
18
+ email: {
19
+ ...entry.email,
20
+ hast: _hast,
21
+ body
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ const perform = async (props) => {
28
+ const { child, path } = props
29
+ let _child = { ...child }
30
+
31
+ if (child.properties && _child.properties.dataNotifilesDoNotOptimize) {
32
+ return child
33
+ }
34
+
35
+ switch (_child.tagName) {
36
+ case 'img': {
37
+ _child = await treatImage({
38
+ child: _child,
39
+ path
40
+ })
41
+ } break
42
+ default:
43
+ break
44
+ }
45
+
46
+ let _children = []
47
+ if (_child.children) {
48
+ _children = await Promise.all(_child.children.map(async child => perform({
49
+ ...props,
50
+ child
51
+ })))
52
+ }
53
+
54
+ return {
55
+ ..._child,
56
+ children: _children
57
+ }
58
+ }
@@ -0,0 +1,40 @@
1
+ import fsPath from 'path'
2
+ import isLocal from 'is-local'
3
+ import isRelative from 'is-relative'
4
+ import sharp from 'sharp'
5
+
6
+ export default async ({ child,
7
+ path, }) => {
8
+ const { properties: {
9
+ src: url,
10
+ } } = child
11
+
12
+ if (!isLocal(url)) {
13
+ return child
14
+ }
15
+
16
+ const sourceUrl = isRelative(url) ? fsPath.resolve(path, url) : url
17
+ const extension = fsPath.parse(sourceUrl).ext
18
+ switch (extension) {
19
+ case '.svg': {
20
+ return child
21
+ }
22
+ default: break
23
+ }
24
+
25
+ const filename = `_${fsPath.parse(sourceUrl).name}.webp`
26
+ const destination = `${path}/.assets/${filename}`
27
+
28
+ await sharp(sourceUrl)
29
+ .webp({ quality: 90 })
30
+ .toFile(destination)
31
+
32
+ const newUrl = `.assets/${filename}`
33
+ return {
34
+ ...child,
35
+ properties: {
36
+ ...child.properties,
37
+ src: newUrl
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,8 @@
1
+
2
+ export default async (props) => {
3
+ const { entry } = props
4
+
5
+ return {
6
+ entry
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ import perform from './lib/perform.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+
4
+ export default async ({
5
+ path,
6
+ settings
7
+ }) => {
8
+ let entries = await getEntries({
9
+ path,
10
+ })
11
+
12
+ for (var i in entries) {
13
+ const entry = entries[i]
14
+ await perform({ entry, settings })
15
+ }
16
+
17
+ return true
18
+ }
@@ -0,0 +1,16 @@
1
+
2
+ test.skip('sync to medium platform', async () => {
3
+ const fsPath = (await import('path')).default
4
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
5
+ const operation = (await import('./path.js')).default
6
+
7
+ const result = await operation({
8
+ settings: {
9
+ assets: {
10
+ optimize: true
11
+ }
12
+ },
13
+ path,
14
+ })
15
+ expect(result).toBeTruthy()
16
+ })
@@ -0,0 +1,18 @@
1
+ import performEmail from './lib/email.js'
2
+ import performTextMessage from './lib/textMessage.js'
3
+
4
+ export default async ({
5
+ entry,
6
+ settings,
7
+ }) => {
8
+ return {
9
+ entry: {
10
+ ...entry,
11
+ versions: await Promise.all(entry.versions.map(async _entry => {
12
+ let res = await performEmail({ entry: _entry, settings, })
13
+ res = await performTextMessage({ entry: res.entry, settings, })
14
+ return res.entry
15
+ }))
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'