@notifiles/sdk 1.0.0 → 1.1.1

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 (37) hide show
  1. package/package.json +2 -1
  2. package/src/lib/cloudLibrary/minio/index.js +1 -0
  3. package/src/lib/cloudLibrary/minio/syncFolder.js +72 -0
  4. package/src/lib/entries/getAtPath.js +4 -4
  5. package/src/lib/fs/dirFilesRescursivePure.js +21 -0
  6. package/src/template/attach/entry.js +22 -0
  7. package/src/template/attach/index.js +2 -0
  8. package/src/template/attach/lib/email.js +59 -0
  9. package/src/template/attach/lib/pushNotification.js +9 -0
  10. package/src/template/attach/lib/textMessage.js +9 -0
  11. package/src/template/attach/path.js +20 -0
  12. package/src/template/attach/path.test.js +24 -0
  13. package/src/template/build/entry.js +2 -0
  14. package/src/template/build/lib/pushnotification/index.js +44 -0
  15. package/src/template/build/lib/pushnotification/translate.js +25 -0
  16. package/src/template/cloudify/entry.js +2 -0
  17. package/src/template/cloudify/lib/email/index.js +5 -9
  18. package/src/template/cloudify/lib/pushNotification.js +9 -0
  19. package/src/template/consolidate/entry.js +2 -0
  20. package/src/template/consolidate/lib/email.js +7 -1
  21. package/src/template/consolidate/lib/pushNotification.js +5 -0
  22. package/src/template/format/entry.js +11 -0
  23. package/src/template/optimize/entry.js +2 -0
  24. package/src/template/optimize/lib/email.js +7 -1
  25. package/src/template/optimize/lib/pushNotification.js +8 -0
  26. package/src/template/sync/entry.js +2 -0
  27. package/src/template/sync/lib/email.js +8 -29
  28. package/src/template/sync/lib/pushNotification.js +73 -0
  29. package/src/template/{cloudify/lib/remove.js → sync/lib/syncFolder.js} +1 -1
  30. package/src/template/sync/lib/textMessage.js +4 -11
  31. package/src/template/update/path.js +6 -1
  32. package/src/email/build copy/lib/perform/email.js +0 -52
  33. package/src/template/cloudify/lib/email/attachments/addAttachment.js +0 -24
  34. package/src/template/cloudify/lib/email/attachments/index.js +0 -137
  35. package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +0 -13
  36. package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +0 -26
  37. package/src/template/sync/lib/upload.js +0 -14
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notifiles/sdk",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -116,6 +116,7 @@
116
116
  "twitter": "^1.7.1",
117
117
  "underscore": "^1.13.6",
118
118
  "unified": "^11.0.4",
119
+ "walk": "^2.3.15",
119
120
  "yaml": "^2.4.2"
120
121
  },
121
122
  "devDependencies": {
@@ -1,4 +1,5 @@
1
1
  export { default as isValid } from './isValid.js'
2
2
  export { default as upload } from './upload.js'
3
+ export { default as syncFolder } from './syncFolder.js'
3
4
  export { default as remove } from './remove.js'
4
5
  // export { default as uploadFolder } from './uploadFolder.js'
@@ -0,0 +1,72 @@
1
+ import * as Minio from 'minio'
2
+ import { walk } from 'walk'
3
+
4
+ export default async ({
5
+ sourceUrl,
6
+ destinationPath,
7
+ auth,
8
+ // contentType = 'image/png'
9
+ }) => {
10
+
11
+ try {
12
+ const {
13
+ endPoint,
14
+ accessKey,
15
+ secretKey,
16
+ bucketName
17
+ } = auth
18
+
19
+ const minioClient = new Minio.Client({
20
+ endPoint,
21
+ // port,
22
+ // useSSL,
23
+ accessKey,
24
+ secretKey,
25
+ })
26
+
27
+ const exists = await minioClient.bucketExists(bucketName)
28
+ if (!exists) {
29
+ return null
30
+ // await minioClient.makeBucket(bucketName, 'us-east-1')
31
+ // console.log('Bucket ' + bucketName + ' created in "us-east-1".')
32
+ }
33
+
34
+ const metaData = {
35
+ // 'Content-Type': contentType,
36
+ }
37
+
38
+ const walker = walk(sourceUrl)
39
+ const result = await new Promise((resolve, reject) => {
40
+ walker.on('file', (root, fileStats, next) => {
41
+ const filePath = `${root}/${fileStats.name}`
42
+ const postSourceURl = root.split(sourceUrl)[1]
43
+ let destination = `${destinationPath}/${postSourceURl}/${fileStats.name}`
44
+ destination = destination.replaceAll('//', '/')
45
+ console.log('Upload', filePath)
46
+
47
+ minioClient.fPutObject(
48
+ bucketName,
49
+ destination,
50
+ filePath,
51
+ err => {
52
+ console.log(filePath, 'uploaded')
53
+ if (err) {
54
+ console.error(err)
55
+ reject(err)
56
+ }
57
+ next()
58
+ })
59
+ })
60
+
61
+ walker.on('end', function () {
62
+ console.log('End upload')
63
+ resolve()
64
+ })
65
+ })
66
+
67
+ return {}
68
+ } catch (e) {
69
+ console.error(e)
70
+ }
71
+ return null
72
+ }
@@ -46,7 +46,7 @@ const perform = async (props) => {
46
46
 
47
47
 
48
48
  let testMessagePath = fsPath.join(folderPath, 'textmessage.txt')
49
- let pushPath = fsPath.join(folderPath, 'push.txt')
49
+ let pushPath = fsPath.join(folderPath, 'pushnotification.txt')
50
50
  const i18nPath = fsPath.join(folderPath, 'i18n.json')
51
51
  let manifest = await importJSONAsync(fsPath.join(folderPath, 'manifest.json'))
52
52
 
@@ -63,7 +63,7 @@ const perform = async (props) => {
63
63
 
64
64
  // const module = await import(emailPath)
65
65
  let textMessage = null
66
- let push = null
66
+ let pushNotification = null
67
67
  let i18n = null
68
68
 
69
69
  if (await checkFileExists(testMessagePath)) {
@@ -71,7 +71,7 @@ const perform = async (props) => {
71
71
  }
72
72
 
73
73
  if (await checkFileExists(pushPath)) {
74
- push = await fs.promises.readFile(pushPath, 'utf8')
74
+ pushNotification = await fs.promises.readFile(pushPath, 'utf8')
75
75
  }
76
76
 
77
77
  if (await checkFileExists(i18nPath)) {
@@ -85,7 +85,7 @@ const perform = async (props) => {
85
85
  path: folderPath,
86
86
  // email: module,
87
87
  textMessage,
88
- push,
88
+ pushNotification,
89
89
  i18n: i18n ? i18n : {},
90
90
  manifest,
91
91
  activity
@@ -0,0 +1,21 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ const walk = async (dir, filelist = []) => {
5
+ const files = await fs.promises.readdir(dir);
6
+
7
+ for (file of files) {
8
+ const filepath = path.join(dir, file)
9
+ const stat = await fs.promises.stat(filepath)
10
+
11
+ if (stat.isDirectory()) {
12
+ filelist = await walk(filepath, filelist)
13
+ } else {
14
+ filelist.push(file)
15
+ }
16
+ }
17
+
18
+ return filelist;
19
+ }
20
+
21
+ export default walk
@@ -0,0 +1,22 @@
1
+ import adaptSettings from '../../lib/adaptSettings.js'
2
+ import performEmail from './lib/email.js'
3
+ import performTextMessage from './lib/textMessage.js'
4
+ import performPushNotification from './lib/pushNotification.js'
5
+
6
+ export default async ({
7
+ entry,
8
+ settings,
9
+ }) => {
10
+ adaptSettings({ settings })
11
+ return {
12
+ entry: {
13
+ ...entry,
14
+ versions: await Promise.all(entry.versions.map(async _entry => {
15
+ let res = await performEmail({ entry: _entry, settings, })
16
+ res = await performTextMessage({ entry: res.entry, settings, })
17
+ res = await performPushNotification({ entry: res.entry, settings, })
18
+ return res.entry
19
+ }))
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'
@@ -0,0 +1,59 @@
1
+ import fs from 'fs'
2
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
3
+ import fsPath from 'path'
4
+
5
+ export default async (props) => {
6
+ const { entry, settings } = props
7
+ const {
8
+ path,
9
+ buildPaths,
10
+ code,
11
+ } = entry
12
+
13
+ const sharedItemsPath = `${path}/attachments`
14
+ let sharedItems = await fs.promises.readdir(sharedItemsPath)
15
+ let items = (await Promise.all(sharedItems.map(async item => {
16
+ const folderPath = fsPath.join(sharedItemsPath, item)
17
+ const folderPathStat = await fs.promises.stat(folderPath)
18
+ if (!folderPathStat) {
19
+ return null
20
+ }
21
+
22
+ const isDir = folderPathStat.isDirectory()
23
+ if (isDir) {
24
+ return null
25
+ }
26
+ return {
27
+ fileName: item,
28
+ path: `${sharedItemsPath}/${item}`
29
+ }
30
+ }))).filter(a => a)
31
+
32
+ const codeOwnItemsPath = `${path}/attachments/${entry.code}`
33
+
34
+ if ((await checkFileExists(codeOwnItemsPath))) {
35
+ let codeOwnItems = await fs.promises.readdir(codeOwnItemsPath)
36
+ items = [
37
+ ...items,
38
+ ...(codeOwnItems.map(fileName => ({
39
+ fileName,
40
+ path: `${codeOwnItemsPath}/${fileName}`
41
+ })))
42
+ ]
43
+ }
44
+
45
+ if (!items) {
46
+ return { entry }
47
+ }
48
+
49
+ await Promise.all(items.map(async ({ fileName, path: filePath }) => {
50
+ return fs.promises.cp(
51
+ filePath,
52
+ `${path}/.build/email/${code}/attachments/${fileName}`,
53
+ )
54
+ }))
55
+
56
+ return {
57
+ entry
58
+ }
59
+ }
@@ -0,0 +1,9 @@
1
+
2
+ export default async (props) => {
3
+
4
+ const { entry } = props
5
+
6
+ return {
7
+ entry
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+
2
+ export default async (props) => {
3
+
4
+ const { entry } = props
5
+
6
+ return {
7
+ entry
8
+ }
9
+ }
@@ -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
+ })
@@ -1,6 +1,7 @@
1
1
  import checkFileExists from '../../lib/fs/checkFileExists.js'
2
2
  import performEmail from './lib/email/index.js'
3
3
  import performTextMessage from './lib/textmessage/index.js'
4
+ import performPushNotification from './lib/pushnotification/index.js'
4
5
  import fs from 'fs'
5
6
 
6
7
  export default async ({
@@ -18,6 +19,7 @@ export default async ({
18
19
  const versions = await Promise.all(entry.versions.map(async _entry => {
19
20
  let res = await performEmail({ entry: _entry, settings, })
20
21
  res = await performTextMessage({ entry: res.entry, settings, })
22
+ res = await performPushNotification({ entry: res.entry, settings, })
21
23
  return res.entry
22
24
  }))
23
25
 
@@ -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}/pushnotification.txt`
14
+ if (!(await checkFileExists(textPath))) {
15
+ return {
16
+ entry
17
+ }
18
+ }
19
+
20
+ await fs.promises.cp(
21
+ textPath,
22
+ buildPaths.pushNotification.text
23
+ )
24
+
25
+ let text = await fs.promises.readFile(buildPaths.pushNotification.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.pushNotification.text,
33
+ text
34
+ )
35
+
36
+ return {
37
+ entry: {
38
+ ...entry,
39
+ pushNotification: {
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
+ }
@@ -1,6 +1,7 @@
1
1
  import adaptSettings from '../../lib/adaptSettings.js'
2
2
  import performEmail from './lib/email/index.js'
3
3
  import performTextMessage from './lib/textMessage.js'
4
+ import performPushNotification from './lib/pushNotification.js'
4
5
 
5
6
  export default async ({
6
7
  entry,
@@ -13,6 +14,7 @@ export default async ({
13
14
  versions: await Promise.all(entry.versions.map(async _entry => {
14
15
  let res = await performEmail({ entry: _entry, settings, })
15
16
  res = await performTextMessage({ entry: res.entry, settings, })
17
+ res = await performPushNotification({ entry: res.entry, settings, })
16
18
  return res.entry
17
19
  }))
18
20
  }
@@ -1,7 +1,6 @@
1
1
  import hastToHtml from '../../../../lib/remark/hastToHtml.js'
2
- import treatAttachments from './attachments/index.js'
3
2
  import treatImage from './image/index.js'
4
-
3
+ import fs from 'fs'
5
4
 
6
5
  export default async (props) => {
7
6
  const { entry, settings } = props
@@ -15,17 +14,14 @@ export default async (props) => {
15
14
  buildPaths
16
15
  })
17
16
 
18
- await treatAttachments({
19
- path,
20
- settings,
21
- buildPaths,
22
- entry
23
- })
24
-
25
17
  // let md = await mdastToMarkdown({ mdast })
26
18
  let body = hastToHtml({ data: _hast })
27
19
  // await fs.promises.writeFile(`${path}/.build/html/email.cloud.html`, html)
28
20
 
21
+ await fs.promises.writeFile(
22
+ buildPaths.email.body,
23
+ body
24
+ )
29
25
 
30
26
  return {
31
27
  entry: {
@@ -0,0 +1,9 @@
1
+
2
+ export default async (props) => {
3
+
4
+ const { entry } = props
5
+
6
+ return {
7
+ entry
8
+ }
9
+ }
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -1,10 +1,11 @@
1
1
  import hastToHtml from '../../../lib/remark/hastToHtml.js';
2
2
  import treatImage from './image/index.js';
3
3
  import ensureDirectoryExists from '../../../lib/fs/ensureDirectoryExists.js';
4
+ import fs from 'fs';
4
5
 
5
6
  export default async (props) => {
6
7
  const { entry } = props
7
- const { path, email: { hast } } = entry
8
+ const { path, email: { hast }, buildPaths } = entry
8
9
 
9
10
  const destination = `${path}/.assets`
10
11
  await ensureDirectoryExists(destination, false)
@@ -17,6 +18,11 @@ export default async (props) => {
17
18
 
18
19
  let body = hastToHtml({ data: _hast })
19
20
 
21
+ await fs.promises.writeFile(
22
+ buildPaths.email.body,
23
+ body
24
+ )
25
+
20
26
  return {
21
27
  entry: {
22
28
  ...entry,
@@ -0,0 +1,5 @@
1
+
2
+ export default async (props) => {
3
+ const { entry } = props
4
+ return { entry }
5
+ }
@@ -22,6 +22,7 @@ export default async ({
22
22
  buildPaths: {
23
23
  email: {
24
24
  container: `${path}/.build/email/${code}`,
25
+ containerRemote: `${entry.slug}/email/${code}`,
25
26
  body: `${path}/.build/email/${code}/body.html`,
26
27
  bodyFileName: `${entry.slug}/email/${code}/body.html`,
27
28
  text: `${path}/.build/email/${code}/text.txt`,
@@ -35,12 +36,22 @@ export default async ({
35
36
  },
36
37
  textMessage: {
37
38
  container: `${path}/.build/textmessage/${code}`,
39
+ containerRemote: `${entry.slug}/textmessage/${code}`,
38
40
  text: `${path}/.build/textmessage/${code}/textmessage.txt`,
39
41
  textFileName: `${entry.slug}/textmessage/${code}/textmessage.txt`,
40
42
  assetsContainer: `${entry.slug}/textmessage/${code}/assets`,
41
43
  manifestFileNameBuilt: `${path}/.build/textmessage/${code}/manifest.json`,
42
44
  manifestFileName: `${entry.slug}/textmessage/${code}/manifest.json`,
43
45
  },
46
+ pushNotification: {
47
+ container: `${path}/.build/pushnotification/${code}`,
48
+ containerRemote: `${entry.slug}/pushnotification/${code}`,
49
+ text: `${path}/.build/pushnotification/${code}/pushnotification.txt`,
50
+ textFileName: `${entry.slug}/pushnotification/${code}/pushnotification.txt`,
51
+ assetsContainer: `${entry.slug}/pushnotification/${code}/assets`,
52
+ manifestFileNameBuilt: `${path}/.build/pushnotification/${code}/manifest.json`,
53
+ manifestFileName: `${entry.slug}/pushnotification/${code}/manifest.json`,
54
+ },
44
55
  manifestFileNameBuilt: `${path}/.build/manifest.json`,
45
56
  manifestFileName: `${entry.slug}/manifest.json`,
46
57
  activityPath: `${path}/.activity.json`,
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -1,9 +1,10 @@
1
1
  import hastToHtml from '../../../lib/remark/hastToHtml.js'
2
2
  import treatImage from './image/index.js'
3
+ import fs from 'fs'
3
4
 
4
5
  export default async (props) => {
5
6
  const { entry } = props
6
- const { path, email: { hast } } = entry
7
+ const { path, email: { hast }, buildPaths } = entry
7
8
 
8
9
  let _hast = await perform({
9
10
  child: hast,
@@ -12,6 +13,11 @@ export default async (props) => {
12
13
 
13
14
  let body = hastToHtml({ data: _hast })
14
15
 
16
+ await fs.promises.writeFile(
17
+ buildPaths.email.body,
18
+ body
19
+ )
20
+
15
21
  return {
16
22
  entry: {
17
23
  ...entry,
@@ -0,0 +1,8 @@
1
+
2
+ export default async (props) => {
3
+ const { entry } = props
4
+
5
+ return {
6
+ entry
7
+ }
8
+ }
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -1,4 +1,4 @@
1
- import upload from './upload.js'
1
+ import syncFolder from './syncFolder.js'
2
2
  import fs from 'fs'
3
3
  import updateActivity from '../../lib/activity/updateToFile.js'
4
4
  import getActivity from '../../lib/activity/get.js'
@@ -10,10 +10,10 @@ export default async (props) => {
10
10
  const { path, email, buildPaths, } = entry
11
11
  const { body, } = email
12
12
 
13
- await fs.promises.writeFile(
14
- buildPaths.email.body,
15
- body
16
- )
13
+ // await fs.promises.writeFile(
14
+ // buildPaths.email.body,
15
+ // body
16
+ // )
17
17
 
18
18
  let manifest = await importJSONAsync(
19
19
  buildPaths.manifestFileNameBuilt,
@@ -38,31 +38,10 @@ export default async (props) => {
38
38
  let uploadResult = null
39
39
  for (var i in clouds) {
40
40
  const cloud = clouds[i]
41
- uploadResult = await upload({
42
- id: cloud.id,
43
- sourceUrl: buildPaths.email.body,
44
- filename: buildPaths.email.bodyFileName,
45
- auth: cloud.auth,
46
- settings
47
- })
48
- uploadResult = await upload({
49
- id: cloud.id,
50
- sourceUrl: buildPaths.email.text,
51
- filename: buildPaths.email.textFileName,
52
- auth: cloud.auth,
53
- settings
54
- })
55
- uploadResult = await upload({
56
- id: cloud.id,
57
- sourceUrl: buildPaths.email.subject,
58
- filename: buildPaths.email.subjectFileName,
59
- auth: cloud.auth,
60
- settings
61
- })
62
- uploadResult = await upload({
41
+ uploadResult = await syncFolder({
63
42
  id: cloud.id,
64
- sourceUrl: buildPaths.email.manifestFileNameBuilt,
65
- filename: buildPaths.email.manifestFileName,
43
+ sourceUrl: buildPaths.email.container,
44
+ destinationPath: buildPaths.email.containerRemote,
66
45
  auth: cloud.auth,
67
46
  settings
68
47
  })
@@ -0,0 +1,73 @@
1
+ import fs from 'fs'
2
+ import updateActivity from '../../lib/activity/updateToFile.js'
3
+ import getActivity from '../../lib/activity/get.js'
4
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
5
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
6
+ import syncFolder from './syncFolder.js'
7
+
8
+ export default async (props) => {
9
+
10
+ const { entry, settings } = props
11
+ const { path, pushNotification, buildPaths, } = entry
12
+ const { text, } = pushNotification
13
+
14
+ const textPath = `${path}/pushnotification.txt`
15
+ if (!(await checkFileExists(textPath))) {
16
+ return {
17
+ entry
18
+ }
19
+ }
20
+
21
+ await fs.promises.writeFile(
22
+ buildPaths.pushNotification.text,
23
+ text
24
+ )
25
+
26
+ let manifest = await importJSONAsync(
27
+ buildPaths.manifestFileNameBuilt,
28
+ )
29
+
30
+ let activity = await importJSONAsync(
31
+ buildPaths.activityPath,
32
+ )
33
+
34
+ manifest =
35
+ {
36
+ ...manifest,
37
+ ...activity[entry.code]
38
+ }
39
+
40
+ await fs.promises.writeFile(
41
+ buildPaths.pushNotification.manifestFileNameBuilt,
42
+ JSON.stringify(manifest, null, 2)
43
+ )
44
+
45
+ const { clouds } = settings
46
+ let uploadResult = null
47
+ for (var i in clouds) {
48
+ const cloud = clouds[i]
49
+ uploadResult = await syncFolder({
50
+ id: cloud.id,
51
+ sourceUrl: buildPaths.pushNotification.container,
52
+ destinationPath: buildPaths.pushNotification.containerRemote,
53
+ auth: cloud.auth,
54
+ settings
55
+ })
56
+ }
57
+
58
+ const _activity = await getActivity({ path })
59
+
60
+ _activity[entry.code] = {
61
+ ...(_activity[entry.code] ? _activity[entry.code] : {}),
62
+ status: "published"
63
+ }
64
+
65
+ await updateActivity({
66
+ path,
67
+ content: _activity,
68
+ })
69
+
70
+ return {
71
+ entry
72
+ }
73
+ }
@@ -10,5 +10,5 @@ export default async (props) => {
10
10
  }
11
11
  }
12
12
 
13
- return cloudLibrary.remove(props)
13
+ return cloudLibrary.syncFolder(props)
14
14
  }
@@ -1,9 +1,9 @@
1
- import upload from './upload.js'
2
1
  import fs from 'fs'
3
2
  import updateActivity from '../../lib/activity/updateToFile.js'
4
3
  import getActivity from '../../lib/activity/get.js'
5
4
  import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
6
5
  import checkFileExists from '../../../lib/fs/checkFileExists.js'
6
+ import syncFolder from './syncFolder.js'
7
7
 
8
8
  export default async (props) => {
9
9
 
@@ -46,17 +46,10 @@ export default async (props) => {
46
46
  let uploadResult = null
47
47
  for (var i in clouds) {
48
48
  const cloud = clouds[i]
49
- uploadResult = await upload({
49
+ uploadResult = await syncFolder({
50
50
  id: cloud.id,
51
- sourceUrl: buildPaths.textMessage.text,
52
- filename: buildPaths.textMessage.textFileName,
53
- auth: cloud.auth,
54
- settings
55
- })
56
- uploadResult = await upload({
57
- id: cloud.id,
58
- sourceUrl: buildPaths.textMessage.manifestFileNameBuilt,
59
- filename: buildPaths.textMessage.manifestFileName,
51
+ sourceUrl: buildPaths.textMessage.container,
52
+ destinationPath: buildPaths.textMessage.containerRemote,
60
53
  auth: cloud.auth,
61
54
  settings
62
55
  })
@@ -7,6 +7,7 @@ import optimize from '../optimize/entry.js'
7
7
  import version from '../version/entry.js'
8
8
  import cloudify from '../cloudify/entry.js'
9
9
  import adaptSettings from '../../lib/adaptSettings.js'
10
+ import attach from '../attach/entry.js'
10
11
 
11
12
  export default async ({
12
13
  path,
@@ -32,7 +33,11 @@ export default async ({
32
33
  entry = (await consolidate({ entry, settings })).entry
33
34
  entry = (await optimize({ entry, settings })).entry
34
35
  entry = (await cloudify({ entry, settings })).entry
35
- entry = (await sync({ entry, settings })).entry
36
+ entry = (await attach({ entry, settings })).entry
37
+ if (!settings.dryRun) {
38
+ entry = (await sync({ entry, settings })).entry
39
+ }
40
+
36
41
 
37
42
  await version({})
38
43
  }
@@ -1,52 +0,0 @@
1
- import htmlToMdast from '../../../../lib/remark/htmlToMdast_.js'
2
- import mdastToMarkdown from '../../../../lib/remark/mdastToMarkdown.js'
3
- import reset from '../reset.js'
4
- import { render } from '@react-email/render'
5
-
6
- export default async (props) => {
7
-
8
- const { entry } = props
9
- const { path, email } = entry
10
- const { default: Template, } = email
11
- await reset({ path })
12
-
13
- let html = render(<Template />, {
14
- pretty: true,
15
- })
16
-
17
- const text = render(<Template />, {
18
- plainText: true,
19
- })
20
-
21
- const child = await htmlToMdast({ data: html })
22
- const mdast = await perform({
23
- child,
24
- path
25
- })
26
-
27
- let md = await mdastToMarkdown({ mdast })
28
-
29
- // await updatePost({
30
- // path,
31
- // md,
32
- // html
33
- // })
34
-
35
- return {
36
- entry: {
37
- ...entry,
38
- email: {
39
- text,
40
- html,
41
- mdast,
42
- md
43
- }
44
- },
45
-
46
- }
47
- }
48
-
49
- const perform = async (props) => {
50
- const { child, path } = props
51
- return child
52
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,137 +0,0 @@
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
-
@@ -1,13 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }