@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,8 @@
1
+ import { toHast } from 'mdast-util-to-hast'
2
+ import { toHtml } from 'hast-util-to-html'
3
+
4
+ export default ({
5
+ mdast,
6
+ } = {}) => {
7
+ return toHtml(toHast(mdast))
8
+ }
@@ -0,0 +1,24 @@
1
+ import { unified } from 'unified'
2
+ import { toHast } from 'mdast-util-to-hast'
3
+ import { toHtml } from 'hast-util-to-html'
4
+ import rehypeParse from 'rehype-parse'
5
+ import rehypeRemark from 'rehype-remark'
6
+ import remarkStringify from 'remark-stringify'
7
+
8
+ export default async ({
9
+ mdast,
10
+ } = {}) => {
11
+
12
+ const hast = toHast(mdast)
13
+ const html = toHtml(hast)
14
+
15
+ const file = await unified()
16
+ .use(rehypeParse)
17
+ .use(rehypeRemark)
18
+ .use(remarkStringify)
19
+ .process(html)
20
+
21
+ const data = String(file)
22
+
23
+ return data
24
+ }
@@ -0,0 +1,12 @@
1
+ import { toString } from 'mdast-util-to-string'
2
+
3
+
4
+ export default async ({
5
+ mdast,
6
+ } = {}) => {
7
+
8
+ const v = toString(mdast, {
9
+
10
+ })
11
+ return v
12
+ }
@@ -0,0 +1,4 @@
1
+
2
+ export { default as isProject } from './isProject/index.js'
3
+ export { default as isProjectSync } from './isProject/sync.js'
4
+ export * as newProject from './new/index.js'
@@ -0,0 +1,26 @@
1
+ import fs from 'fs'
2
+ import fsPath from 'path'
3
+ import checkFileExists from '../../lib/fs/checkFileExists.js'
4
+
5
+ export default async (props) => {
6
+ const {
7
+ path,
8
+ } = props
9
+
10
+ if (!(await checkFileExists(path))) {
11
+ return false
12
+ }
13
+
14
+ const pathStat = await fs.promises.stat(path)
15
+ if (!pathStat) {
16
+ return false
17
+ }
18
+
19
+ const isDir = pathStat.isDirectory()
20
+ if (!isDir) {
21
+ return false
22
+ }
23
+
24
+ const manifestPath = fsPath.join(path, 'manifest.yaml')
25
+ return checkFileExists(manifestPath)
26
+ }
@@ -0,0 +1,13 @@
1
+
2
+
3
+ describe.skip('project', () => {
4
+ it('ensures a folder is a project', async () => {
5
+ const fsPath = (await import('path')).default
6
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER_ROOT)
7
+ const operation = (await import('./index.js')).default
8
+ const result = await operation({
9
+ path,
10
+ })
11
+ expect(result).toBeTruthy()
12
+ })
13
+ })
@@ -0,0 +1,18 @@
1
+ import fs from 'fs'
2
+
3
+ export default ({ path }) => {
4
+ try {
5
+ if (!path || !path.length) {
6
+ return false
7
+ }
8
+ if (!fs.lstatSync(path).isDirectory()) {
9
+ return false
10
+ }
11
+
12
+ const targetPath = `${path}/manifest.yaml`
13
+ const exists = fs.existsSync(targetPath)
14
+ return exists
15
+ } catch (e) {
16
+ return false
17
+ }
18
+ }
@@ -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
+ const defaultContent = await importJSONAsync('./defaultContent.json')
20
+
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,5 @@
1
+ {
2
+ "createdAt": "",
3
+ "updatedAt": "",
4
+ "platforms": []
5
+ }
@@ -0,0 +1,32 @@
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
+ content,
9
+ }) => {
10
+
11
+
12
+ try {
13
+
14
+ const filePath = fsPath.join(path, ".activity.json")
15
+
16
+ if (!(await checkFileExists(filePath))) {
17
+ return
18
+ }
19
+ const defaultContent = await importJSONAsync('./defaultContent.json')
20
+
21
+ let _content = {
22
+ ...defaultContent,
23
+ ...content,
24
+ }
25
+
26
+ await fs.promises.writeFile(filePath, JSON.stringify(_content, null, 2))
27
+ return true
28
+ } catch (e) {
29
+ console.error(e)
30
+ }
31
+ return false
32
+ }
@@ -0,0 +1,44 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+ import YAML from 'yaml'
5
+ import { nanoid } from 'nanoid'
6
+
7
+ export default async ({
8
+ path,
9
+ data = {}
10
+ }) => {
11
+
12
+
13
+ try {
14
+
15
+ const filePath = fsPath.join(path, "manifest.yaml")
16
+
17
+ if ((await checkFileExists(filePath))) {
18
+ return
19
+ }
20
+
21
+ let defaultManifest = YAML.parse(`
22
+ id: ${nanoid()}
23
+ createdAt: ""
24
+ updatedAt: ""
25
+ nomDePlume: ""
26
+ description: ""
27
+ license: all-rights-reserved
28
+ `)
29
+
30
+ let manifest = {
31
+ ...defaultManifest,
32
+ createdAt: (new Date()),
33
+ ...data
34
+ }
35
+
36
+ manifest = YAML.stringify(manifest)
37
+
38
+ await fs.promises.writeFile(filePath, manifest)
39
+ return true
40
+ } catch (e) {
41
+ console.error(e)
42
+ }
43
+ return false
44
+ }
@@ -0,0 +1,21 @@
1
+ import fsPath from 'path'
2
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
3
+ import importYAMLAsync from '../../../lib/fs/importYAMLAsync.js'
4
+
5
+ export default async ({
6
+ path,
7
+ }) => {
8
+ try {
9
+ const filePath = fsPath.join(path, "manifest.yaml")
10
+
11
+ if (!(await checkFileExists(filePath))) {
12
+ return null
13
+ }
14
+
15
+ const content = await importYAMLAsync(filePath)
16
+ return content
17
+ } catch (e) {
18
+ console.error(e)
19
+ }
20
+ return null
21
+ }
@@ -0,0 +1,36 @@
1
+ import read from './read.js'
2
+ import updateToFile from './updateToFile.js'
3
+ import YAML from 'yaml'
4
+
5
+ export default async ({
6
+ path,
7
+ data,
8
+ }) => {
9
+ try {
10
+ let existing = await read({ path })
11
+ if (!existing) {
12
+ existing = {}
13
+ }
14
+ const _data = data ? data : {}
15
+ let result = {
16
+ ...existing,
17
+ platforms: [
18
+ ...(existing.platforms ? existing.platforms : []),
19
+ ...(data.platforms ? data.platforms : []),
20
+ ],
21
+ clouds: [
22
+ ...(existing.clouds ? existing.clouds : []),
23
+ ...(data.clouds ? data.clouds : []),
24
+ ]
25
+ }
26
+
27
+ const content = YAML.stringify(result)
28
+ return updateToFile({
29
+ path,
30
+ content
31
+ })
32
+ } catch (e) {
33
+ console.error(e)
34
+ }
35
+ return false
36
+ }
@@ -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,2 @@
1
+
2
+ export { default as plain } from './plain.js'
@@ -0,0 +1,49 @@
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
+ name = "My new project",
10
+ description = "An authoring project for my personal usage.",
11
+ settings = {
12
+ },
13
+ force = false,
14
+ author = {
15
+ id: "",
16
+ name: ""
17
+ },
18
+ }) => {
19
+ try {
20
+ const folderPath = fsPath.join(path, name)
21
+
22
+ if ((await checkFileExists(folderPath))) {
23
+ if (!force) {
24
+ return false
25
+ }
26
+ await fs.promises.rmdir(folderPath, { recursive: true })
27
+ }
28
+
29
+ await fs.promises.mkdir(folderPath)
30
+
31
+ await createStatusIfNeeded({
32
+ path: folderPath
33
+ })
34
+
35
+ await createManifestIfNeeded({
36
+ path: folderPath,
37
+ data: {
38
+ name,
39
+ author,
40
+ description
41
+ }
42
+ })
43
+
44
+ return true
45
+ } catch (e) {
46
+ console.error(e)
47
+ }
48
+ return false
49
+ }
@@ -0,0 +1,38 @@
1
+
2
+
3
+ describe.skip('project', () => {
4
+ it('creates new to medium and dev.to platforms', async () => {
5
+ const fsPath = (await import('path')).default
6
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER_ROOT)
7
+ const operation = (await import('./plain.js')).default
8
+ const result = await operation({
9
+ settings: {
10
+ platforms: [{
11
+ id: 'medium',
12
+ auth: {
13
+ token: process.env.TEST_MEDIUM_TOKEN,
14
+ }
15
+ },
16
+ {
17
+ id: 'devto',
18
+ auth: {
19
+ token: process.env.TEST_DEVTO_TOKEN,
20
+ }
21
+ }],
22
+ clouds: {
23
+ id: "minio",
24
+ auth: {
25
+ endPoint: process.env.TEST_MINIO_ENDPOINT,
26
+ accessKey: process.env.TEST_MINIO_ACCESS_KEY,
27
+ secretKey: process.env.TEST_MINIO_SECRET,
28
+ bucketName: process.env.TEST_MINIO_BUCKET_NAME
29
+ }
30
+ }
31
+ },
32
+ name: process.env.TEST_MOCK_FOLDER_NEW_NAME,
33
+ path,
34
+ force: true
35
+ })
36
+ expect(result).toBeTruthy()
37
+ })
38
+ })
@@ -0,0 +1,37 @@
1
+ import checkFileExists from '../../lib/fs/checkFileExists.js'
2
+ import performEmail from './lib/email/index.js'
3
+ import performTextMessage from './lib/textmessage/index.js'
4
+ import fs from 'fs'
5
+
6
+ export default async ({
7
+ entry,
8
+ settings,
9
+ }) => {
10
+ const buildPath = `${entry.path}/.build`
11
+ if ((await checkFileExists(buildPath))) {
12
+ await fs.promises.rmdir(
13
+ buildPath,
14
+ { recursive: true }
15
+ )
16
+ }
17
+
18
+ const versions = await Promise.all(entry.versions.map(async _entry => {
19
+ let res = await performEmail({ entry: _entry, settings, })
20
+ res = await performTextMessage({ entry: res.entry, settings, })
21
+ return res.entry
22
+ }))
23
+
24
+ if ((await checkFileExists(`${entry.path}/.build/temp`))) {
25
+ await fs.promises.rmdir(
26
+ `${entry.path}/.build/temp`,
27
+ { recursive: true }
28
+ )
29
+ }
30
+
31
+ return {
32
+ entry: {
33
+ ...entry,
34
+ versions
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'
@@ -0,0 +1,100 @@
1
+ import { execa } from 'execa'
2
+ import fs from 'fs'
3
+ import translate from './translate.js'
4
+ import htmlToHast from '../../../../lib/remark/htmlToHast.js'
5
+
6
+ export default async (props) => {
7
+
8
+ const { entry } = props
9
+ const { path,
10
+ buildPaths,
11
+ code,
12
+ language } = entry
13
+
14
+ const { stdout } = await execa`npx react-email@2.1.4 export --pretty --plainText --dir ${path} --outDir ${path}/.build/temp/email/${code}/text`;
15
+ const { stdoutB } = await execa`npx react-email@2.1.4 export --pretty --dir ${path} --outDir ${path}/.build/temp/email/${code}/html`;
16
+
17
+ await fs.promises.cp(
18
+ `${path}/.build/temp/email/${code}/html/email.html`,
19
+ buildPaths.email.body
20
+ )
21
+
22
+ let body = await fs.promises.readFile(buildPaths.email.body, 'utf8')
23
+ body = translate({ text: body, strings: language.data })
24
+ body = body
25
+ .replaceAll('|%', '{{')
26
+ .replaceAll('%|', '}}')
27
+ .replaceAll(']]', '')
28
+ .replaceAll('[[', '')
29
+
30
+ await fs.promises.writeFile(
31
+ buildPaths.email.body,
32
+ body
33
+ )
34
+
35
+ await fs.promises.cp(
36
+ `${path}/.build/temp/email/${code}/text/email.txt`,
37
+ buildPaths.email.text
38
+ )
39
+
40
+ let text = await fs.promises.readFile(buildPaths.email.text, 'utf8')
41
+ text = translate({ text: text, strings: language.data })
42
+ text = text
43
+ .replaceAll('|%', '{{')
44
+ .replaceAll('%|', '}}')
45
+ .replaceAll(']]', '')
46
+ .replaceAll('[[', '')
47
+
48
+ await fs.promises.writeFile(
49
+ buildPaths.email.text,
50
+ text
51
+ )
52
+
53
+ await fs.promises.cp(
54
+ `${path}/email.subject.txt`,
55
+ buildPaths.email.subject
56
+ )
57
+
58
+ let subject = await fs.promises.readFile(buildPaths.email.subject, 'utf8')
59
+ subject = translate({ text: subject, strings: language.data })
60
+ subject = subject
61
+ .trim()
62
+ .replaceAll('|%', '{{')
63
+ .replaceAll('%|', '}}')
64
+ .replaceAll(']]', '')
65
+ .replaceAll('[[', '')
66
+
67
+ await fs.promises.writeFile(
68
+ buildPaths.email.subject,
69
+ subject,
70
+ 'utf-8'
71
+ )
72
+
73
+ await fs.promises.cp(
74
+ `${path}/manifest.json`,
75
+ buildPaths.manifestFileNameBuilt
76
+ )
77
+
78
+ const child = htmlToHast({ data: body })
79
+ const hast = await perform({
80
+ child,
81
+ path
82
+ })
83
+
84
+ return {
85
+ entry: {
86
+ ...entry,
87
+ email: {
88
+ text,
89
+ body,
90
+ subject,
91
+ hast,
92
+ }
93
+ },
94
+ }
95
+ }
96
+
97
+ const perform = async (props) => {
98
+ const { child, path } = props
99
+ return child
100
+ }
@@ -0,0 +1,16 @@
1
+ export default ({ text, strings }) => {
2
+ const replacer = (match, p1) => {
3
+ const str = match.trim().replace('[[', '').replace(']]', '')
4
+
5
+ if (!strings[str]) {
6
+ return match
7
+ }
8
+
9
+ const prefix = match[0] === " " ? " " : ""
10
+ const suffix = match[match.length - 1] === " " ? " " : ""
11
+ return prefix + strings[str] + suffix
12
+ }
13
+
14
+ const reg = new RegExp(/ *\[\[[^)]*\]\] */g)
15
+ return text.replaceAll(reg, replacer)
16
+ }
@@ -0,0 +1,44 @@
1
+ import fs from 'fs'
2
+ import translate from './translate.js'
3
+ import checkFileExists from '../../../../lib/fs/checkFileExists.js'
4
+
5
+ export default async (props) => {
6
+
7
+ const { entry } = props
8
+ const { path,
9
+ buildPaths,
10
+ code,
11
+ language } = entry
12
+
13
+ const textPath = `${path}/textmessage.txt`
14
+ if (!(await checkFileExists(textPath))) {
15
+ return {
16
+ entry
17
+ }
18
+ }
19
+
20
+ await fs.promises.cp(
21
+ textPath,
22
+ buildPaths.textMessage.text
23
+ )
24
+
25
+ let text = await fs.promises.readFile(buildPaths.textMessage.text, 'utf8')
26
+ text = translate({ text: text, strings: language.data })
27
+ text = text
28
+ .replaceAll('|%', '{{')
29
+ .replaceAll('%|', '}}')
30
+
31
+ await fs.promises.writeFile(
32
+ buildPaths.textMessage.text,
33
+ text
34
+ )
35
+
36
+ return {
37
+ entry: {
38
+ ...entry,
39
+ textMessage: {
40
+ text,
41
+ }
42
+ },
43
+ }
44
+ }
@@ -0,0 +1,25 @@
1
+ export default ({ text, strings }) => {
2
+ let _text = text
3
+
4
+ const firsts = _text.split('[[')
5
+ let matched = firsts.map(element => {
6
+ if (element.indexOf(']]') === -1) {
7
+ return element
8
+ }
9
+
10
+ let seconds = element.split(']]')
11
+ const key = seconds[0]
12
+ const value = strings[key]
13
+ if (!value) {
14
+ return seconds.join('')
15
+ }
16
+ seconds = seconds.length > 1
17
+ ? seconds.slice(1, seconds.length)
18
+ : seconds
19
+ return [value, seconds].join('')
20
+ })
21
+
22
+ matched = matched.join('')
23
+ return matched
24
+
25
+ }
@@ -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
+