@designsystemsinternational/email 0.0.4 → 0.0.5

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.
@@ -213,7 +213,6 @@ const preparePackageFactory =
213
213
  );
214
214
 
215
215
  const hash = hashFromString(`${data}`);
216
- console.log(hash);
217
216
 
218
217
  const filename = alt
219
218
  ? `${formatFilename(alt)}-text-${hash}.${ext}`
@@ -6,6 +6,8 @@ var removeAttributes = require('posthtml-remove-attributes');
6
6
  var matchHelper = require('posthtml-match-helper');
7
7
  var colorConvert = require('color-convert');
8
8
  var unescape = require('lodash.unescape');
9
+ var path = require('node:path');
10
+ var fs = require('node:fs');
9
11
  var compressing = require('compressing');
10
12
  var getStream = require('get-stream');
11
13
  var mailchimpAPI = require('@mailchimp/mailchimp_marketing');
@@ -201,10 +203,16 @@ const BASE64_REGEX = /data:image\/([a-zA-Z]*);base64,(.*)/;
201
203
  */
202
204
  const preparePackageFactory =
203
205
  ({ urlPrefix = '', handlePackage }) =>
204
- async (body, opts = {}) => {
206
+ async (body, _opts = {}) => {
205
207
  let counter = 0;
206
208
  const images = [];
207
209
 
210
+ const opts = Object.assign(
211
+ {},
212
+ { basePath: '', includeLocalImages: false },
213
+ _opts,
214
+ );
215
+
208
216
  const processed = await posthtml()
209
217
  .use((tree) => {
210
218
  tree.match({ tag: 'img' }, (node) => {
@@ -231,6 +239,18 @@ const preparePackageFactory =
231
239
  });
232
240
 
233
241
  counter++;
242
+ } else if (!src.startsWith('http') && opts.includeLocalImages) {
243
+ const filePath = path.join(opts.basePath, src);
244
+
245
+ const filename = src.split('/').pop();
246
+ node.attrs.src = `${urlPrefix}${filename}`;
247
+
248
+ const imgBuffer = fs.readFileSync(filePath);
249
+
250
+ images.push({
251
+ filename,
252
+ buffer: imgBuffer,
253
+ });
234
254
  }
235
255
  return node;
236
256
  });
@@ -513,7 +533,7 @@ const packageToS3 = async (body, opts = {}) => {
513
533
  },
514
534
  });
515
535
 
516
- return await runUpload(body);
536
+ return await runUpload(body, opts);
517
537
  };
518
538
 
519
539
  const sendEmailSes = async (
@@ -211,7 +211,6 @@ const preparePackageFactory =
211
211
  );
212
212
 
213
213
  const hash = hashFromString(`${data}`);
214
- console.log(hash);
215
214
 
216
215
  const filename = alt
217
216
  ? `${formatFilename(alt)}-text-${hash}.${ext}`
package/dist/esm/index.js CHANGED
@@ -4,6 +4,8 @@ import removeAttributes from 'posthtml-remove-attributes';
4
4
  import matchHelper from 'posthtml-match-helper';
5
5
  import colorConvert from 'color-convert';
6
6
  import unescape from 'lodash.unescape';
7
+ import path from 'node:path';
8
+ import fs from 'node:fs';
7
9
  import compressing from 'compressing';
8
10
  import getStream from 'get-stream';
9
11
  import mailchimpAPI from '@mailchimp/mailchimp_marketing';
@@ -199,10 +201,16 @@ const BASE64_REGEX = /data:image\/([a-zA-Z]*);base64,(.*)/;
199
201
  */
200
202
  const preparePackageFactory =
201
203
  ({ urlPrefix = '', handlePackage }) =>
202
- async (body, opts = {}) => {
204
+ async (body, _opts = {}) => {
203
205
  let counter = 0;
204
206
  const images = [];
205
207
 
208
+ const opts = Object.assign(
209
+ {},
210
+ { basePath: '', includeLocalImages: false },
211
+ _opts,
212
+ );
213
+
206
214
  const processed = await posthtml()
207
215
  .use((tree) => {
208
216
  tree.match({ tag: 'img' }, (node) => {
@@ -229,6 +237,18 @@ const preparePackageFactory =
229
237
  });
230
238
 
231
239
  counter++;
240
+ } else if (!src.startsWith('http') && opts.includeLocalImages) {
241
+ const filePath = path.join(opts.basePath, src);
242
+
243
+ const filename = src.split('/').pop();
244
+ node.attrs.src = `${urlPrefix}${filename}`;
245
+
246
+ const imgBuffer = fs.readFileSync(filePath);
247
+
248
+ images.push({
249
+ filename,
250
+ buffer: imgBuffer,
251
+ });
232
252
  }
233
253
  return node;
234
254
  });
@@ -511,7 +531,7 @@ const packageToS3 = async (body, opts = {}) => {
511
531
  },
512
532
  });
513
533
 
514
- return await runUpload(body);
534
+ return await runUpload(body, opts);
515
535
  };
516
536
 
517
537
  const sendEmailSes = async (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designsystemsinternational/email",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Make working with email more enjoyable (if possible)",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -31,7 +31,6 @@ export const preparePackageFactory =
31
31
  );
32
32
 
33
33
  const hash = hashFromString(`${data}`);
34
- console.log(hash);
35
34
 
36
35
  const filename = alt
37
36
  ? `${formatFilename(alt)}-text-${hash}.${ext}`
@@ -1,4 +1,7 @@
1
1
  // NODE.JS packacking factory
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+
2
5
  import posthtml from 'posthtml';
3
6
 
4
7
  import { BASE64_REGEX } from './constants.js';
@@ -15,10 +18,16 @@ import { formatFilename, hashFromString } from './util/string.js';
15
18
  */
16
19
  export const preparePackageFactory =
17
20
  ({ urlPrefix = '', handlePackage }) =>
18
- async (body, opts = {}) => {
21
+ async (body, _opts = {}) => {
19
22
  let counter = 0;
20
23
  const images = [];
21
24
 
25
+ const opts = Object.assign(
26
+ {},
27
+ { basePath: '', includeLocalImages: false },
28
+ _opts,
29
+ );
30
+
22
31
  const processed = await posthtml()
23
32
  .use((tree) => {
24
33
  tree.match({ tag: 'img' }, (node) => {
@@ -45,6 +54,18 @@ export const preparePackageFactory =
45
54
  });
46
55
 
47
56
  counter++;
57
+ } else if (!src.startsWith('http') && opts.includeLocalImages) {
58
+ const filePath = path.join(opts.basePath, src);
59
+
60
+ const filename = src.split('/').pop();
61
+ node.attrs.src = `${urlPrefix}${filename}`;
62
+
63
+ const imgBuffer = fs.readFileSync(filePath);
64
+
65
+ images.push({
66
+ filename,
67
+ buffer: imgBuffer,
68
+ });
48
69
  }
49
70
  return node;
50
71
  });
@@ -54,7 +54,7 @@ const packageToS3 = async (body, opts = {}) => {
54
54
  },
55
55
  });
56
56
 
57
- return await runUpload(body);
57
+ return await runUpload(body, opts);
58
58
  };
59
59
 
60
60
  export default packageToS3;