@tryghost/mg-fs-utils 0.14.0 → 0.14.2
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/README.md +7 -0
- package/lib/FileCache.js +22 -3
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -11,6 +11,13 @@ or
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
+
You can add `.env` file in the root of this package to set a different local cache path.
|
|
15
|
+
By default, it will create a temporary folder in the system's temp directory, but you may want to chang this to a more permanent location. Setting `CACHE_PATH` in `.env` will override the default.
|
|
16
|
+
|
|
17
|
+
```env
|
|
18
|
+
CACHE_PATH=/path/to/cache
|
|
19
|
+
```
|
|
20
|
+
|
|
14
21
|
|
|
15
22
|
## Develop
|
|
16
23
|
|
package/lib/FileCache.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {basename, dirname, extname, format, join, parse} from 'node:path';
|
|
2
|
+
import {URL} from 'node:url';
|
|
2
3
|
import {tmpdir} from 'node:os';
|
|
3
4
|
import {createHash} from 'node:crypto';
|
|
5
|
+
import * as dotenv from 'dotenv';
|
|
4
6
|
import _ from 'lodash';
|
|
5
7
|
import {writeFileSync, readdirSync, rmdir, lstatSync, existsSync} from 'node:fs';
|
|
6
8
|
import {writeFile} from 'node:fs/promises';
|
|
@@ -11,12 +13,22 @@ import transliterate from 'transliteration';
|
|
|
11
13
|
import csv from './csv.js';
|
|
12
14
|
import {cacheNameFromPath} from './utils.js';
|
|
13
15
|
|
|
16
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
|
17
|
+
|
|
18
|
+
// Define the .end path for this project, as well as parent env files
|
|
19
|
+
dotenv.config({
|
|
20
|
+
path: [
|
|
21
|
+
join(__dirname, '../', '.env'),
|
|
22
|
+
'.env'
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
|
|
14
26
|
const basePath = 'mg';
|
|
15
27
|
const knownImageExtensions = ['.jpg', '.jpeg', '.gif', '.png', '.svg', '.svgz', '.ico', 'webp'];
|
|
16
28
|
|
|
17
29
|
export default class FileCache {
|
|
18
30
|
constructor(cacheName, options = {}) {
|
|
19
|
-
this.tmpPath = options
|
|
31
|
+
this.tmpPath = options?.tmpPath ?? process?.env?.CACHE_PATH ?? false;
|
|
20
32
|
|
|
21
33
|
this.originalName = cacheName;
|
|
22
34
|
this.options = Object.assign({contentDir: true}, options);
|
|
@@ -167,7 +179,14 @@ export default class FileCache {
|
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
resolveFileName(filename, type = 'images') {
|
|
170
|
-
|
|
182
|
+
const ext = extname(filename);
|
|
183
|
+
|
|
184
|
+
// Replace any dots and spaces in the path with dashes
|
|
185
|
+
const parsedPath = parse(filename);
|
|
186
|
+
parsedPath.dir = parsedPath.dir.replace(/\./g, '-');
|
|
187
|
+
parsedPath.dir = parsedPath.dir.replace(/ /g, '-');
|
|
188
|
+
parsedPath.dir = parsedPath.dir.replace(/%20/g, '-');
|
|
189
|
+
filename = format(parsedPath);
|
|
171
190
|
|
|
172
191
|
let typeDir = null;
|
|
173
192
|
let typePath = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,16 +25,17 @@
|
|
|
25
25
|
"jest-extended": "4.0.2"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tryghost/errors": "1.3.
|
|
28
|
+
"@tryghost/errors": "1.3.2",
|
|
29
29
|
"@tryghost/image-transform": "1.3.0",
|
|
30
|
-
"@tryghost/string": "0.2.
|
|
31
|
-
"@tryghost/zip": "1.1.
|
|
32
|
-
"adm-zip": "0.5.
|
|
33
|
-
"csv-parse": "5.5.
|
|
30
|
+
"@tryghost/string": "0.2.12",
|
|
31
|
+
"@tryghost/zip": "1.1.46",
|
|
32
|
+
"adm-zip": "0.5.14",
|
|
33
|
+
"csv-parse": "5.5.6",
|
|
34
|
+
"dotenv": "16.4.5",
|
|
34
35
|
"fs-extra": "11.2.0",
|
|
35
36
|
"lodash": "4.17.21",
|
|
36
|
-
"sharp": "0.
|
|
37
|
+
"sharp": "0.33.4",
|
|
37
38
|
"transliteration": "2.3.5"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "4995b3fa8393ec37c7181e08b9cd76a49a056cb1"
|
|
40
41
|
}
|