@jungvonmatt/contentful-ssg 1.0.5 → 1.0.6
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/dist/lib/file-manager.js
CHANGED
|
@@ -2,6 +2,7 @@ import { dirname, resolve, relative, join } from 'path';
|
|
|
2
2
|
import ignore from 'ignore';
|
|
3
3
|
import { readFile, readdir, lstat } from 'fs/promises';
|
|
4
4
|
import { remove, outputFile } from 'fs-extra';
|
|
5
|
+
import { existsSync } from 'fs';
|
|
5
6
|
export class FileManager {
|
|
6
7
|
ignoreBase = process.cwd();
|
|
7
8
|
ignore;
|
|
@@ -25,7 +26,7 @@ export class FileManager {
|
|
|
25
26
|
const ignorePatterns = await readFile(gitignore);
|
|
26
27
|
this.ignore = ignore().add(ignorePatterns.toString('utf8'));
|
|
27
28
|
}
|
|
28
|
-
const existing = await globby(`${this.config.directory}/**/*.*`);
|
|
29
|
+
const existing = await globby([`${this.config.directory}/**/*.*`, `data/**/*.*`]);
|
|
29
30
|
this.files = new Set(existing.map((file) => resolve(file)));
|
|
30
31
|
}
|
|
31
32
|
async writeFile(file, data, options) {
|
|
@@ -51,7 +52,7 @@ export class FileManager {
|
|
|
51
52
|
await Promise.all(recursiveRemovalPromises);
|
|
52
53
|
fileNames = await readdir(directory);
|
|
53
54
|
}
|
|
54
|
-
if (fileNames.length === 0 &&
|
|
55
|
+
if (fileNames.length === 0 && ![this.config.directory, 'data'].includes(directory)) {
|
|
55
56
|
await remove(directory);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -59,6 +60,9 @@ export class FileManager {
|
|
|
59
60
|
const promises = [...this.ignoredFiles].map(async (file) => this.deleteFile(file));
|
|
60
61
|
await Promise.allSettled(promises);
|
|
61
62
|
await this.removeEmptyDirectories(this.config.directory);
|
|
63
|
+
if (existsSync('data')) {
|
|
64
|
+
await this.removeEmptyDirectories('data');
|
|
65
|
+
}
|
|
62
66
|
return true;
|
|
63
67
|
}
|
|
64
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-ssg",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -143,5 +143,5 @@
|
|
|
143
143
|
"module": "es2020"
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
|
-
"gitHead": "
|
|
146
|
+
"gitHead": "72fea365aa247c8942d01c499becf8548874b09d"
|
|
147
147
|
}
|
package/src/lib/file-manager.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { dirname, resolve, relative, join } from 'path';
|
|
|
4
4
|
import ignore from 'ignore';
|
|
5
5
|
import { readFile, readdir, lstat } from 'fs/promises';
|
|
6
6
|
import { remove, outputFile } from 'fs-extra';
|
|
7
|
+
import { existsSync } from 'fs';
|
|
7
8
|
|
|
8
9
|
export class FileManager {
|
|
9
10
|
ignoreBase: string = process.cwd();
|
|
@@ -39,7 +40,7 @@ export class FileManager {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
// Create set of existing files
|
|
42
|
-
const existing = await globby(`${this.config.directory}/**/*.*`);
|
|
43
|
+
const existing = await globby([`${this.config.directory}/**/*.*`, `data/**/*.*`]);
|
|
43
44
|
|
|
44
45
|
this.files = new Set(existing.map((file) => resolve(file)));
|
|
45
46
|
}
|
|
@@ -91,7 +92,7 @@ export class FileManager {
|
|
|
91
92
|
fileNames = await readdir(directory);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
if (fileNames.length === 0 &&
|
|
95
|
+
if (fileNames.length === 0 && ![this.config.directory, 'data'].includes(directory)) {
|
|
95
96
|
await remove(directory);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -101,6 +102,10 @@ export class FileManager {
|
|
|
101
102
|
|
|
102
103
|
await Promise.allSettled(promises);
|
|
103
104
|
await this.removeEmptyDirectories(this.config.directory);
|
|
105
|
+
if (existsSync('data')) {
|
|
106
|
+
await this.removeEmptyDirectories('data');
|
|
107
|
+
}
|
|
108
|
+
|
|
104
109
|
return true;
|
|
105
110
|
}
|
|
106
111
|
}
|