@tryghost/mg-fs-utils 0.12.3 → 0.12.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.
- package/index.js +3 -1
- package/lib/FileCache.js +2 -2
- package/lib/csv.js +11 -8
- package/lib/utils.js +15 -0
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -3,11 +3,13 @@ import zip from './lib/zip.js';
|
|
|
3
3
|
import {readZipEntries} from './lib/read-zip.js';
|
|
4
4
|
import ghostJSON from './lib/ghostJSON.js';
|
|
5
5
|
import csv from './lib/csv.js';
|
|
6
|
+
import * as utils from './lib/utils.js';
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
FileCache,
|
|
9
10
|
zip,
|
|
10
11
|
ghostJSON,
|
|
11
12
|
csv,
|
|
12
|
-
readZipEntries
|
|
13
|
+
readZipEntries,
|
|
14
|
+
utils
|
|
13
15
|
};
|
package/lib/FileCache.js
CHANGED
|
@@ -9,6 +9,7 @@ import imageTransform from '@tryghost/image-transform';
|
|
|
9
9
|
import errors from '@tryghost/errors';
|
|
10
10
|
import transliterate from 'transliteration';
|
|
11
11
|
import csv from './csv.js';
|
|
12
|
+
import {cacheNameFromPath} from './utils.js';
|
|
12
13
|
|
|
13
14
|
const basePath = 'mg';
|
|
14
15
|
const knownImageExtensions = ['.jpg', '.jpeg', '.gif', '.png', '.svg', '.svgz', '.ico', 'webp'];
|
|
@@ -21,8 +22,7 @@ class FileCache {
|
|
|
21
22
|
this.options = Object.assign({contentDir: true}, options);
|
|
22
23
|
|
|
23
24
|
// Remove any extension, handles removing TLDs as well if the name is based on a URL
|
|
24
|
-
|
|
25
|
-
this.cacheName = basename(cacheName, ext);
|
|
25
|
+
this.cacheName = cacheNameFromPath(cacheName);
|
|
26
26
|
|
|
27
27
|
if (options.batchName) {
|
|
28
28
|
this.batchName = options.batchName;
|
package/lib/csv.js
CHANGED
|
@@ -99,18 +99,21 @@ const writeCSV = async (data, filePath, fileName) => {
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Check if a CSV has the required keys
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {
|
|
102
|
+
* @param {object} data
|
|
103
|
+
* @param {string} data.filePath Path to CSV file
|
|
104
|
+
* @param {array} data.required Array of keys the CSV must include
|
|
105
|
+
* @param {array} data.blocked Array of keys the CSV must include
|
|
104
106
|
* @returns {boolean}
|
|
105
107
|
*/
|
|
106
|
-
const hasKeys = async (filePath,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const hasKeys = async ({filePath, required = [], blocked = []}) => {
|
|
109
|
+
const parsed = await parseCSV(filePath);
|
|
110
|
+
const firstRow = parsed[0];
|
|
111
|
+
const colKeys = Object.keys(firstRow);
|
|
110
112
|
|
|
111
|
-
|
|
113
|
+
const hasRequiredKeys = required.every(v => colKeys.includes(v));
|
|
114
|
+
const hasBlockedKeys = colKeys.some(r => blocked.includes(r));
|
|
112
115
|
|
|
113
|
-
return hasRequiredKeys;
|
|
116
|
+
return hasRequiredKeys && !hasBlockedKeys;
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
export default {
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {extname, basename} from 'node:path';
|
|
2
|
+
import {slugify} from '@tryghost/string';
|
|
3
|
+
|
|
4
|
+
const cacheNameFromPath = (path) => {
|
|
5
|
+
let ext = extname(path);
|
|
6
|
+
let base = basename(path, ext);
|
|
7
|
+
let slug = slugify(base);
|
|
8
|
+
let noUnderscore = slug.replace(/_/g, '-');
|
|
9
|
+
|
|
10
|
+
return noUnderscore;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
cacheNameFromPath
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/errors": "1.2.20",
|
|
29
29
|
"@tryghost/image-transform": "1.2.3",
|
|
30
|
+
"@tryghost/string": "0.2.3",
|
|
30
31
|
"@tryghost/zip": "1.1.32",
|
|
31
32
|
"adm-zip": "0.5.10",
|
|
32
33
|
"csv-parse": "5.3.6",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"sharp": "0.31.3",
|
|
38
39
|
"transliteration": "2.3.5"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "1cf2e5fd70c7275c24eb956d13cbaabdde17eddb"
|
|
41
42
|
}
|