@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,20 @@
|
|
|
1
|
+
import adaptSettings from '../../lib/adaptSettings.js'
|
|
2
|
+
import performEmail from './lib/email/index.js'
|
|
3
|
+
import performTextMessage from './lib/textMessage.js'
|
|
4
|
+
|
|
5
|
+
export default async ({
|
|
6
|
+
entry,
|
|
7
|
+
settings,
|
|
8
|
+
}) => {
|
|
9
|
+
adaptSettings({ settings })
|
|
10
|
+
return {
|
|
11
|
+
entry: {
|
|
12
|
+
...entry,
|
|
13
|
+
versions: await Promise.all(entry.versions.map(async _entry => {
|
|
14
|
+
let res = await performEmail({ entry: _entry, settings, })
|
|
15
|
+
res = await performTextMessage({ entry: res.entry, settings, })
|
|
16
|
+
return res.entry
|
|
17
|
+
}))
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import getActivity from '../../../../lib/activity/get.js'
|
|
2
|
+
import updateActivity from '../../../../lib/activity/updateToFile.js'
|
|
3
|
+
|
|
4
|
+
export default async ({ path, entry, fileName, attachment }) => {
|
|
5
|
+
let activity = await getActivity({ path })
|
|
6
|
+
let attachments = [
|
|
7
|
+
...((activity[entry.code] && activity[entry.code].attachments)
|
|
8
|
+
? activity[entry.code].attachments
|
|
9
|
+
: []),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
attachments = attachments.filter(a => a.id !== fileName)
|
|
13
|
+
attachments.push(attachment)
|
|
14
|
+
|
|
15
|
+
activity[entry.code] = {
|
|
16
|
+
...(activity[entry.code] ? activity[entry.code] : {}),
|
|
17
|
+
attachments
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await updateActivity({
|
|
21
|
+
path,
|
|
22
|
+
content: activity,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import upload from '../../upload.js'
|
|
2
|
+
|
|
3
|
+
import getActivity from '../../../../lib/activity/get.js'
|
|
4
|
+
import updateActivity from '../../../../lib/activity/updateToFile.js'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import checkFileExists from '../../../../../lib/fs/checkFileExists.js'
|
|
7
|
+
import _mimetype from 'mimetype'
|
|
8
|
+
import remove from '../../remove.js'
|
|
9
|
+
import addAttachment from './addAttachment.js'
|
|
10
|
+
|
|
11
|
+
export default async ({ child,
|
|
12
|
+
path,
|
|
13
|
+
settings,
|
|
14
|
+
buildPaths,
|
|
15
|
+
entry
|
|
16
|
+
}) => {
|
|
17
|
+
|
|
18
|
+
let entries = await fs.promises.readdir(`${path}/attachments`)
|
|
19
|
+
let items = entries.map(fileName => ({
|
|
20
|
+
fileName,
|
|
21
|
+
path: `${path}/attachments/${fileName}`
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
let codeDestination = `${path}/attachments/${entry.code}`
|
|
25
|
+
if ((await checkFileExists(codeDestination))) {
|
|
26
|
+
entries = await fs.promises.readdir(codeDestination)
|
|
27
|
+
items = [
|
|
28
|
+
...items,
|
|
29
|
+
...(entries.map(fileName => ({
|
|
30
|
+
fileName,
|
|
31
|
+
path: `${codeDestination}/${fileName}`
|
|
32
|
+
})))
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!items) {
|
|
37
|
+
return {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { clouds } = settings
|
|
41
|
+
|
|
42
|
+
let __activity = await getActivity({ path })
|
|
43
|
+
let previousActivity = __activity[entry.code]
|
|
44
|
+
__activity[entry.code] = {}
|
|
45
|
+
await updateActivity({
|
|
46
|
+
path,
|
|
47
|
+
content: __activity,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const uploaded = []
|
|
51
|
+
for (var i in items) {
|
|
52
|
+
const { fileName, path: folderPath } = items[i]
|
|
53
|
+
const fileNameRemote = encodeURI(fileName)
|
|
54
|
+
|
|
55
|
+
const folderPathStat = await fs.promises.stat(folderPath)
|
|
56
|
+
if (!folderPathStat) {
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isDir = folderPathStat.isDirectory()
|
|
61
|
+
if (isDir) {
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!settings.forceUploadAttachments) {
|
|
66
|
+
if (previousActivity) {
|
|
67
|
+
if (previousActivity.attachments) {
|
|
68
|
+
const attachment = previousActivity.attachments.find(a => a.id === fileName)
|
|
69
|
+
if (attachment) {
|
|
70
|
+
uploaded.push(attachment)
|
|
71
|
+
await addAttachment({ path, entry, fileName, attachment })
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const mimeType = _mimetype.lookup(folderPath)
|
|
79
|
+
let uploadResult = null
|
|
80
|
+
|
|
81
|
+
for (var i in clouds) {
|
|
82
|
+
const cloud = clouds[i]
|
|
83
|
+
uploadResult = await upload({
|
|
84
|
+
id: cloud.id,
|
|
85
|
+
sourceUrl: folderPath,
|
|
86
|
+
filename: `${buildPaths.email.attachmentsContainer}/${fileNameRemote}`,
|
|
87
|
+
auth: cloud.auth,
|
|
88
|
+
settings
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!uploadResult || !uploadResult.url) {
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const attachment = {
|
|
97
|
+
id: fileName,
|
|
98
|
+
fileName,
|
|
99
|
+
url: uploadResult.url,
|
|
100
|
+
mimeType,
|
|
101
|
+
disposition: "attachment",
|
|
102
|
+
relativeFileName: `${buildPaths.email.attachmentsContainer}/${fileNameRemote}`,
|
|
103
|
+
}
|
|
104
|
+
uploaded.push(attachment
|
|
105
|
+
)
|
|
106
|
+
await addAttachment({
|
|
107
|
+
path, entry, fileName, attachment
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const removed = []
|
|
113
|
+
for (var i in previousActivity.attachments) {
|
|
114
|
+
const item = previousActivity.attachments[i]
|
|
115
|
+
const eq = uploaded.find(a => a.id === item.id)
|
|
116
|
+
if (!eq) {
|
|
117
|
+
removed.push(item)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (var i in removed) {
|
|
122
|
+
const item = removed[i]
|
|
123
|
+
for (var i in clouds) {
|
|
124
|
+
const cloud = clouds[i]
|
|
125
|
+
await remove({
|
|
126
|
+
id: cloud.id,
|
|
127
|
+
filename: item.relativeFileName,
|
|
128
|
+
auth: cloud.auth,
|
|
129
|
+
settings
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import isRelative from 'is-relative'
|
|
3
|
+
|
|
4
|
+
export default async ({
|
|
5
|
+
url, path, }) => {
|
|
6
|
+
const sourceUrl = isRelative(url) ? fsPath.resolve(path, url) : url
|
|
7
|
+
const filename = fsPath.basename(sourceUrl)
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
filename,
|
|
11
|
+
sourceUrl
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import downloadImage from 'image-downloader'
|
|
3
|
+
|
|
4
|
+
export default async ({ url,
|
|
5
|
+
destination
|
|
6
|
+
}) => {
|
|
7
|
+
try {
|
|
8
|
+
const options = {
|
|
9
|
+
url,
|
|
10
|
+
dest: destination, // will be saved to /path/to/dest/photo
|
|
11
|
+
extractFilename: true,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const item = await downloadImage.image(options)
|
|
15
|
+
// const { filename } = item
|
|
16
|
+
const filename = fsPath.basename(item.filename)
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
filename,
|
|
20
|
+
sourceUrl: destination
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import isLocal from 'is-local'
|
|
2
|
+
import upload from '../../upload.js'
|
|
3
|
+
import treatRemoteFile from './treatRemoteFile.js'
|
|
4
|
+
import treatLocalFile from './treatLocalFile.js'
|
|
5
|
+
|
|
6
|
+
import getActivity from '../../../../lib/activity/get.js'
|
|
7
|
+
import updateActivity from '../../../../lib/activity/updateToFile.js'
|
|
8
|
+
|
|
9
|
+
export default async ({ child,
|
|
10
|
+
path,
|
|
11
|
+
settings,
|
|
12
|
+
buildPaths,
|
|
13
|
+
entry
|
|
14
|
+
}) => {
|
|
15
|
+
const { properties: {
|
|
16
|
+
src: _url,
|
|
17
|
+
} } = child
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let _activity = await getActivity({ path })
|
|
21
|
+
if (!settings.forceUploadAssets) {
|
|
22
|
+
const codeActivity = _activity[entry.code]
|
|
23
|
+
if (codeActivity) {
|
|
24
|
+
const files = codeActivity.files
|
|
25
|
+
if (files && files[_url]) {
|
|
26
|
+
const cache = files[_url]
|
|
27
|
+
return {
|
|
28
|
+
...child,
|
|
29
|
+
properties: {
|
|
30
|
+
...child.properties,
|
|
31
|
+
src: cache.url
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let result
|
|
39
|
+
const destination = `${path}/.assets`
|
|
40
|
+
if (isLocal(_url)) {
|
|
41
|
+
result = await treatLocalFile({ url: _url, path, destination })
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result = await treatRemoteFile({ url: _url, destination })
|
|
45
|
+
}
|
|
46
|
+
let { sourceUrl, filename } = result
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const { clouds } = settings
|
|
50
|
+
let uploadResult = null
|
|
51
|
+
for (var i in clouds) {
|
|
52
|
+
const cloud = clouds[i]
|
|
53
|
+
uploadResult = await upload({
|
|
54
|
+
id: cloud.id,
|
|
55
|
+
sourceUrl,
|
|
56
|
+
filename: `${buildPaths.email.assetsContainer}/${filename}`,
|
|
57
|
+
auth: cloud.auth,
|
|
58
|
+
settings
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!uploadResult || !uploadResult.url) {
|
|
63
|
+
return child
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_activity = await getActivity({ path })
|
|
67
|
+
_activity[entry.code] = {
|
|
68
|
+
...(_activity[entry.code] ? _activity[entry.code] : {}),
|
|
69
|
+
files: {
|
|
70
|
+
...((_activity[entry.code] && _activity[entry.code].files) ? _activity[entry.code].files : {}),
|
|
71
|
+
[_url]: {
|
|
72
|
+
url: uploadResult.url
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await updateActivity({
|
|
78
|
+
path,
|
|
79
|
+
content: _activity,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
...child,
|
|
85
|
+
properties: {
|
|
86
|
+
...child.properties,
|
|
87
|
+
src: uploadResult.url
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import isRelative from 'is-relative'
|
|
3
|
+
|
|
4
|
+
export default async ({
|
|
5
|
+
url, path, }) => {
|
|
6
|
+
const sourceUrl = isRelative(url) ? fsPath.resolve(path, url) : url
|
|
7
|
+
const filename = fsPath.basename(sourceUrl)
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
filename,
|
|
11
|
+
sourceUrl
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import downloadImage from 'image-downloader'
|
|
3
|
+
|
|
4
|
+
export default async ({ url,
|
|
5
|
+
destination
|
|
6
|
+
}) => {
|
|
7
|
+
try {
|
|
8
|
+
const options = {
|
|
9
|
+
url,
|
|
10
|
+
dest: destination, // will be saved to /path/to/dest/photo
|
|
11
|
+
extractFilename: true,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const item = await downloadImage.image(options)
|
|
15
|
+
// const { filename } = item
|
|
16
|
+
const filename = fsPath.basename(item.filename)
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
filename,
|
|
20
|
+
sourceUrl: destination
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import hastToHtml from '../../../../lib/remark/hastToHtml.js'
|
|
2
|
+
import treatAttachments from './attachments/index.js'
|
|
3
|
+
import treatImage from './image/index.js'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default async (props) => {
|
|
7
|
+
const { entry, settings } = props
|
|
8
|
+
const { path, email: { hast }, buildPaths } = entry
|
|
9
|
+
|
|
10
|
+
const _hast = await perform({
|
|
11
|
+
entry,
|
|
12
|
+
child: hast,
|
|
13
|
+
path,
|
|
14
|
+
settings,
|
|
15
|
+
buildPaths
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
await treatAttachments({
|
|
19
|
+
path,
|
|
20
|
+
settings,
|
|
21
|
+
buildPaths,
|
|
22
|
+
entry
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// let md = await mdastToMarkdown({ mdast })
|
|
26
|
+
let body = hastToHtml({ data: _hast })
|
|
27
|
+
// await fs.promises.writeFile(`${path}/.build/html/email.cloud.html`, html)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
entry: {
|
|
32
|
+
...entry,
|
|
33
|
+
email: {
|
|
34
|
+
...entry.email,
|
|
35
|
+
md: null,
|
|
36
|
+
body,
|
|
37
|
+
hast: _hast,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const perform = async (props) => {
|
|
44
|
+
const { child, path, buildPaths, settings, entry } = props
|
|
45
|
+
let _child = { ...child }
|
|
46
|
+
|
|
47
|
+
if (child.properties && child.properties.dataNotifilesDoNotCloudify) {
|
|
48
|
+
return child
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
switch (_child.tagName) {
|
|
52
|
+
case 'img': {
|
|
53
|
+
_child = await treatImage({
|
|
54
|
+
child: _child,
|
|
55
|
+
path,
|
|
56
|
+
settings,
|
|
57
|
+
buildPaths,
|
|
58
|
+
entry
|
|
59
|
+
})
|
|
60
|
+
} break
|
|
61
|
+
default:
|
|
62
|
+
break
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let _children = []
|
|
66
|
+
if (_child.children) {
|
|
67
|
+
_children = await Promise.all(_child.children.map(async child => perform({
|
|
68
|
+
...props,
|
|
69
|
+
child
|
|
70
|
+
})))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
..._child,
|
|
75
|
+
children: _children
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default async (props) => {
|
|
2
|
+
|
|
3
|
+
const { id, settings } = props
|
|
4
|
+
|
|
5
|
+
const cloudLibrary = settings.cloudLibrary({ id })
|
|
6
|
+
if (!cloudLibrary) {
|
|
7
|
+
return {
|
|
8
|
+
isValid: false,
|
|
9
|
+
error: new Error('Cloud not supported.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return cloudLibrary.remove(props)
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default async (props) => {
|
|
2
|
+
|
|
3
|
+
const { id, settings } = props
|
|
4
|
+
|
|
5
|
+
const cloudLibrary = settings.cloudLibrary({ id })
|
|
6
|
+
if (!cloudLibrary) {
|
|
7
|
+
return {
|
|
8
|
+
isValid: false,
|
|
9
|
+
error: new Error('Cloud not supported.')
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return cloudLibrary.upload(props)
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import perform from './lib/perform.js'
|
|
2
|
+
import getEntries from '../../lib/entries/getAtPath.js'
|
|
3
|
+
import adaptSettings from '../../lib/adaptSettings.js'
|
|
4
|
+
|
|
5
|
+
export default async ({
|
|
6
|
+
path,
|
|
7
|
+
settings
|
|
8
|
+
}) => {
|
|
9
|
+
adaptSettings({ settings })
|
|
10
|
+
let entries = await getEntries({
|
|
11
|
+
path,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
for (var i in entries) {
|
|
15
|
+
const entry = entries[i]
|
|
16
|
+
await perform({ entry, settings })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
describe.skip('cloudify', () => {
|
|
3
|
+
it('cloudifies to minio', async () => {
|
|
4
|
+
const fsPath = (await import('path')).default
|
|
5
|
+
let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
|
|
6
|
+
const operation = (await import('./path.js')).default
|
|
7
|
+
|
|
8
|
+
const result = await operation({
|
|
9
|
+
settings: {
|
|
10
|
+
clouds: [{
|
|
11
|
+
id: "minio",
|
|
12
|
+
auth: {
|
|
13
|
+
endPoint: process.env.TEST_MINIO_ENDPOINT,
|
|
14
|
+
accessKey: process.env.TEST_MINIO_ACCESS_KEY,
|
|
15
|
+
secretKey: process.env.TEST_MINIO_SECRET,
|
|
16
|
+
bucketName: process.env.TEST_MINIO_BUCKET_NAME
|
|
17
|
+
}
|
|
18
|
+
}]
|
|
19
|
+
},
|
|
20
|
+
path,
|
|
21
|
+
})
|
|
22
|
+
expect(result).toBeTruthy()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -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,63 @@
|
|
|
1
|
+
import hastToHtml from '../../../lib/remark/hastToHtml.js';
|
|
2
|
+
import treatImage from './image/index.js';
|
|
3
|
+
import ensureDirectoryExists from '../../../lib/fs/ensureDirectoryExists.js';
|
|
4
|
+
|
|
5
|
+
export default async (props) => {
|
|
6
|
+
const { entry } = props
|
|
7
|
+
const { path, email: { hast } } = entry
|
|
8
|
+
|
|
9
|
+
const destination = `${path}/.assets`
|
|
10
|
+
await ensureDirectoryExists(destination, false)
|
|
11
|
+
|
|
12
|
+
const _hast = await perform({
|
|
13
|
+
child: hast,
|
|
14
|
+
path,
|
|
15
|
+
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
let body = hastToHtml({ data: _hast })
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
entry: {
|
|
22
|
+
...entry,
|
|
23
|
+
email: {
|
|
24
|
+
...entry.email,
|
|
25
|
+
hast: _hast,
|
|
26
|
+
body
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const perform = async (props) => {
|
|
33
|
+
const { child, path } = props
|
|
34
|
+
let _child = { ...child }
|
|
35
|
+
|
|
36
|
+
if (child.properties && child.properties.dataNotifilesDoNotConsolidate) {
|
|
37
|
+
return child
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
switch (_child.tagName) {
|
|
41
|
+
case 'img': {
|
|
42
|
+
_child = await treatImage({
|
|
43
|
+
child: _child,
|
|
44
|
+
path
|
|
45
|
+
})
|
|
46
|
+
} break
|
|
47
|
+
default:
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let _children = []
|
|
52
|
+
if (_child.children) {
|
|
53
|
+
_children = await Promise.all(_child.children.map(async __child => perform({
|
|
54
|
+
...props,
|
|
55
|
+
child: __child
|
|
56
|
+
})))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
..._child,
|
|
61
|
+
children: _children
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import isLocal from 'is-local'
|
|
2
|
+
import treatLocalFile from './treatLocalFile.js'
|
|
3
|
+
import treatRemoteFile from './treatRemoteFile.js'
|
|
4
|
+
|
|
5
|
+
export default async ({ child,
|
|
6
|
+
path, entry }) => {
|
|
7
|
+
const { properties: {
|
|
8
|
+
src: url,
|
|
9
|
+
} } = child
|
|
10
|
+
|
|
11
|
+
let result
|
|
12
|
+
const destination = `${path}/.assets`
|
|
13
|
+
|
|
14
|
+
if (isLocal(url)) {
|
|
15
|
+
if (url.indexOf(destination) !== 0) {
|
|
16
|
+
return child
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
result = await treatLocalFile({ url, path, destination })
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
result = await treatRemoteFile({ url, destination })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let filename = result.filename
|
|
26
|
+
const newUrl = `.assets/${filename}`
|
|
27
|
+
return {
|
|
28
|
+
...child,
|
|
29
|
+
properties: {
|
|
30
|
+
...child.properties,
|
|
31
|
+
src: newUrl
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import isRelative from 'is-relative'
|
|
4
|
+
|
|
5
|
+
export default async ({
|
|
6
|
+
url, path, destination }) => {
|
|
7
|
+
const sourceUrl = isRelative(url) ? fsPath.resolve(path, url) : url
|
|
8
|
+
const filename = fsPath.basename(sourceUrl)
|
|
9
|
+
const _destination = `${destination}/${filename}`
|
|
10
|
+
await fs.promises.cp(sourceUrl, _destination)
|
|
11
|
+
return {
|
|
12
|
+
filename,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fsPath from 'path'
|
|
2
|
+
import downloadImage from 'image-downloader'
|
|
3
|
+
|
|
4
|
+
export default async ({ url,
|
|
5
|
+
destination
|
|
6
|
+
}) => {
|
|
7
|
+
try {
|
|
8
|
+
const options = {
|
|
9
|
+
url,
|
|
10
|
+
dest: destination, // will be saved to /path/to/dest/photo
|
|
11
|
+
extractFilename: true,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const item = await downloadImage.image(options)
|
|
15
|
+
// const { filename } = item
|
|
16
|
+
const filename = fsPath.basename(item.filename)
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
filename
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.error(e)
|
|
24
|
+
}
|
|
25
|
+
}
|