auto-organize 1.0.0 → 1.1.0
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/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { getFilesFromDirectory, ensureDirectoryExists, moveFile } from '../utils/fsHelpers.js';
|
|
2
|
+
import { getFilesFromDirectory, ensureDirectoryExists, fileExists, moveFile } from '../utils/fsHelpers.js';
|
|
3
3
|
import { getFolderNameByExtensionType } from '../rules/byType.js';
|
|
4
4
|
import { shouldSkipFile } from '../utils/filesFilters.js';
|
|
5
5
|
import { renderEmptyFolderText } from '../cli/renderEmptyFolderText.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
6
7
|
|
|
7
8
|
function organizeDirectory(baseDir, cliFlags = {}) {
|
|
8
9
|
try{
|
|
@@ -37,10 +38,14 @@ function organizeDirectory(baseDir, cliFlags = {}) {
|
|
|
37
38
|
|
|
38
39
|
if (folderByExtensionTypeWasCreated) folderByExtensionTypeCreated = true;
|
|
39
40
|
|
|
41
|
+
if (fileExists(filePathByExtension)){
|
|
42
|
+
throw new Error(`File collision detected: "${chalk.red(file.name)}" already exists in "${chalk.blueBright(folderNameByExtensionType)}/"`);
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
moveFile(file.path, filePathByExtension);
|
|
41
46
|
});
|
|
42
47
|
|
|
43
|
-
return
|
|
48
|
+
return{
|
|
44
49
|
foldersByExtensionType: outputFoldersSummary,
|
|
45
50
|
folderWasCreated: folderByExtensionTypeCreated,
|
|
46
51
|
previewMode: cliFlags.preview,
|
package/src/utils/fsHelpers.js
CHANGED
|
@@ -26,8 +26,12 @@ function ensureDirectoryExists(dirPath) {
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function fileExists(filePath) {
|
|
30
|
+
return fs.existsSync(filePath);
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
function moveFile(sourcePath, targetPath) {
|
|
30
34
|
fs.renameSync(sourcePath, targetPath);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export { getFilesFromDirectory, ensureDirectoryExists, moveFile };
|
|
37
|
+
export { getFilesFromDirectory, ensureDirectoryExists, fileExists, moveFile };
|