@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.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.modern.cjs +856 -0
- package/dist/index.modern.cjs.map +1 -0
- package/dist/index.modern.modern.js +690 -0
- package/dist/index.modern.modern.js.map +1 -0
- package/package.json +152 -0
- package/src/cloud/add/index.js +38 -0
- package/src/cloud/add/index.test.js +38 -0
- package/src/cloud/add/lib/validate.js +16 -0
- package/src/cloud/index.js +3 -0
- package/src/cloud/list/index.js +18 -0
- package/src/cloud/list/index.test.js +13 -0
- package/src/email/build copy/lib/perform/email.js +52 -0
- package/src/index.js +3 -0
- package/src/lib/adaptSettings.js +12 -0
- package/src/lib/cloudLibrary/bunny/index.js +2 -0
- package/src/lib/cloudLibrary/bunny/isValid.js +32 -0
- package/src/lib/cloudLibrary/bunny/upload.js +35 -0
- package/src/lib/cloudLibrary/index.js +20 -0
- package/src/lib/cloudLibrary/minio/index.js +4 -0
- package/src/lib/cloudLibrary/minio/isValid.js +33 -0
- package/src/lib/cloudLibrary/minio/remove.js +58 -0
- package/src/lib/cloudLibrary/minio/upload.js +61 -0
- package/src/lib/cloudLibrary/minio/uploadFolder.js +26 -0
- package/src/lib/entries/getAtPath.js +105 -0
- package/src/lib/entries/isPathEntry.js +29 -0
- package/src/lib/entries.js +144 -0
- package/src/lib/fs/checkFileExists.js +6 -0
- package/src/lib/fs/directoryFilesRecursive.js +83 -0
- package/src/lib/fs/ensureDirectoryExists.js +10 -0
- package/src/lib/fs/getFileCallerURL.js +12 -0
- package/src/lib/fs/importFileAsText.js +15 -0
- package/src/lib/fs/importJSONAsync.js +16 -0
- package/src/lib/fs/importYAMLAsync.js +14 -0
- package/src/lib/remark/hastToHtml.js +6 -0
- package/src/lib/remark/htmlToHast.js +6 -0
- package/src/lib/remark/htmlToMarkdown copy.js +12 -0
- package/src/lib/remark/htmlToMarkdown.js +23 -0
- package/src/lib/remark/htmlToMdast.js +13 -0
- package/src/lib/remark/htmlToMdast_.js +21 -0
- package/src/lib/remark/htmlToMdast_3.js +21 -0
- package/src/lib/remark/markdownToHTML.js +22 -0
- package/src/lib/remark/markdownToLexer.js +19 -0
- package/src/lib/remark/mdastToHTML.js +8 -0
- package/src/lib/remark/mdastToMarkdown.js +24 -0
- package/src/lib/remark/mdastToString.js +12 -0
- package/src/project/index.js +4 -0
- package/src/project/isProject/index.js +26 -0
- package/src/project/isProject/index.test.js +13 -0
- package/src/project/isProject/sync.js +18 -0
- package/src/project/lib/activity/createFileIfNeeded.js +33 -0
- package/src/project/lib/activity/defaultContent.json +5 -0
- package/src/project/lib/activity/updateToFile.js +32 -0
- package/src/project/lib/manifest/createFileIfNeeded.js +44 -0
- package/src/project/lib/manifest/read.js +21 -0
- package/src/project/lib/manifest/update.js +36 -0
- package/src/project/lib/manifest/updateToFile.js +22 -0
- package/src/project/new/index.js +2 -0
- package/src/project/new/plain.js +49 -0
- package/src/project/new/plain.test.js +38 -0
- package/src/template/build/entry.js +37 -0
- package/src/template/build/index.js +2 -0
- package/src/template/build/lib/email/index.js +100 -0
- package/src/template/build/lib/email/translate.js +16 -0
- package/src/template/build/lib/textmessage/index.js +44 -0
- package/src/template/build/lib/textmessage/translate.js +25 -0
- package/src/template/build/path.js +18 -0
- package/src/template/build/path.test.js +29 -0
- package/src/template/cloudify/entry.js +20 -0
- package/src/template/cloudify/index.js +2 -0
- package/src/template/cloudify/lib/email/attachments/addAttachment.js +24 -0
- package/src/template/cloudify/lib/email/attachments/index.js +137 -0
- package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +13 -0
- package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +26 -0
- package/src/template/cloudify/lib/email/image/index.js +90 -0
- package/src/template/cloudify/lib/email/image/treatLocalFile.js +13 -0
- package/src/template/cloudify/lib/email/image/treatRemoteFile.js +26 -0
- package/src/template/cloudify/lib/email/index.js +77 -0
- package/src/template/cloudify/lib/remove.js +14 -0
- package/src/template/cloudify/lib/textMessage.js +9 -0
- package/src/template/cloudify/lib/upload.js +14 -0
- package/src/template/cloudify/path.js +20 -0
- package/src/template/cloudify/path.test.js +24 -0
- package/src/template/consolidate/entry.js +18 -0
- package/src/template/consolidate/index.js +2 -0
- package/src/template/consolidate/lib/email.js +63 -0
- package/src/template/consolidate/lib/image/index.js +35 -0
- package/src/template/consolidate/lib/image/treatLocalFile.js +14 -0
- package/src/template/consolidate/lib/image/treatRemoteFile.js +25 -0
- package/src/template/consolidate/lib/textMessage.js +5 -0
- package/src/template/consolidate/path.js +18 -0
- package/src/template/consolidate/path.test.js +14 -0
- package/src/template/format/entry.js +57 -0
- package/src/template/format/index.js +2 -0
- package/src/template/format/path.js +18 -0
- package/src/template/format/path.test.js +29 -0
- package/src/template/index.js +8 -0
- package/src/template/lib/activity/createFileIfNeeded.js +33 -0
- package/src/template/lib/activity/defaultContent.json +4 -0
- package/src/template/lib/activity/get.js +20 -0
- package/src/template/lib/activity/updateToFile.js +33 -0
- package/src/template/lib/manifest/createFileIfNeeded.js +41 -0
- package/src/template/lib/manifest/read.js +22 -0
- package/src/template/lib/manifest/update.js +18 -0
- package/src/template/lib/manifest/updateToFile.js +22 -0
- package/src/template/new/index.js +66 -0
- package/src/template/new/index.test.js +19 -0
- package/src/template/optimize/entry.js +18 -0
- package/src/template/optimize/index.js +2 -0
- package/src/template/optimize/lib/email.js +58 -0
- package/src/template/optimize/lib/image/index.js +40 -0
- package/src/template/optimize/lib/textMessage.js +8 -0
- package/src/template/optimize/path.js +18 -0
- package/src/template/optimize/path.test.js +16 -0
- package/src/template/sync/entry.js +18 -0
- package/src/template/sync/index.js +2 -0
- package/src/template/sync/lib/email.js +86 -0
- package/src/template/sync/lib/textMessage.js +80 -0
- package/src/template/sync/lib/upload.js +14 -0
- package/src/template/sync/path.js +18 -0
- package/src/template/sync/path.test.js +29 -0
- package/src/template/update/index.js +1 -0
- package/src/template/update/path.js +41 -0
- package/src/template/update/path.test.js +46 -0
- package/src/template/version/entry.js +10 -0
- package/src/template/version/index.js +2 -0
- package/src/template/version/lib/perform.js +74 -0
- package/src/template/version/lib/reset.js +16 -0
- package/src/template/version/lib/updatePost.js +16 -0
- package/src/template/version/path.js +20 -0
- package/src/template/version/path.test.js +16 -0
|
@@ -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,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,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,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,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
|
+
|