occam-server 2.0.1 → 7.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.
- package/.swcrc +5 -0
- package/README.md +40 -30
- package/lib/constants.js +26 -0
- package/lib/createProjectEntries.js +63 -0
- package/lib/index.js +75 -0
- package/lib/loadFile.js +18 -0
- package/lib/loadFiles.js +18 -0
- package/lib/loadProject.js +18 -0
- package/lib/loadProjects.js +18 -0
- package/lib/loadRelease.js +18 -0
- package/lib/loadReleases.js +18 -0
- package/lib/moveProjectEntries.js +77 -0
- package/lib/removeProjectEntries.js +68 -0
- package/lib/removeRelease.js +32 -0
- package/lib/renameProjectEntries.js +74 -0
- package/lib/saveFile.js +19 -0
- package/lib/utilities/fileSystem.js +255 -0
- package/lib/utilities/http.js +76 -0
- package/lib/utilities/name.js +16 -0
- package/lib/utilities/pathMap.js +58 -0
- package/license.txt +48 -0
- package/package.json +20 -22
- package/src/constants.js +5 -0
- package/src/createProjectEntries.js +71 -0
- package/src/index.js +16 -0
- package/src/loadFile.js +15 -0
- package/src/loadFiles.js +15 -0
- package/src/loadProject.js +15 -0
- package/src/loadProjects.js +14 -0
- package/src/loadRelease.js +14 -0
- package/src/loadReleases.js +13 -0
- package/src/moveProjectEntries.js +102 -0
- package/src/removeProjectEntries.js +79 -0
- package/src/removeRelease.js +35 -0
- package/src/renameProjectEntries.js +101 -0
- package/src/saveFile.js +14 -0
- package/src/utilities/fileSystem.js +364 -0
- package/src/utilities/http.js +71 -0
- package/src/utilities/name.js +7 -0
- package/src/utilities/pathMap.js +39 -0
- package/es6/handler/importProject.js +0 -23
- package/es6/handler/loadFile.js +0 -27
- package/es6/handler/loadFiles.js +0 -25
- package/es6/handler/loadProjects.js +0 -29
- package/es6/handler/moveProjectEntries.js +0 -24
- package/es6/handler/removeProjectEntries.js +0 -24
- package/es6/handler/saveFile.js +0 -26
- package/es6/handler/saveFiles.js +0 -26
- package/es6/handlers.js +0 -67
- package/es6/httpResponse.js +0 -46
- package/es6/main.js +0 -36
- package/es6/middleware/error.js +0 -11
- package/es6/paths.js +0 -7
- package/es6/routers.js +0 -47
- package/es6/uris.js +0 -25
- package/es6/utilities/query.js +0 -15
- package/index.js +0 -3
- package/lib/handler/importProject.js +0 -26
- package/lib/handler/loadFile.js +0 -29
- package/lib/handler/loadFiles.js +0 -28
- package/lib/handler/loadProjects.js +0 -31
- package/lib/handler/moveProjectEntries.js +0 -29
- package/lib/handler/removeProjectEntries.js +0 -29
- package/lib/handler/saveFile.js +0 -31
- package/lib/handler/saveFiles.js +0 -31
- package/lib/handlers.js +0 -81
- package/lib/httpResponse.js +0 -47
- package/lib/main.js +0 -41
- package/lib/middleware/error.js +0 -12
- package/lib/paths.js +0 -8
- package/lib/routers.js +0 -52
- package/lib/uris.js +0 -26
- package/lib/utilities/query.js +0 -16
package/package.json
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "occam-server",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"homepage": "https://github.com/
|
|
7
|
-
"description": "Occam's server
|
|
4
|
+
"version": "7.0.5",
|
|
5
|
+
"license": "MIT, Anti-996",
|
|
6
|
+
"homepage": "https://github.com/djalbat/occam-server",
|
|
7
|
+
"description": "Occam's server side functionality.",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/
|
|
10
|
+
"url": "https://github.com/djalbat/occam-server"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"necessary": "^3.4.0",
|
|
16
|
-
"occam-file-system": "^2.0.1",
|
|
17
|
-
"occam-open-cli": "^1.5.34"
|
|
13
|
+
"necessary": "^17.0.9",
|
|
14
|
+
"occam-model": "^1.0.495"
|
|
18
15
|
},
|
|
19
16
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"babel-cli": "^6.7.5",
|
|
23
|
-
"babel-preset-es2015": "^6.6.0",
|
|
24
|
-
"chokidar-cli": "^1.2.0"
|
|
17
|
+
"@swc/core": "1.13.20",
|
|
18
|
+
"watchful-cli": "^1.7.67"
|
|
25
19
|
},
|
|
26
20
|
"scripts": {
|
|
27
21
|
"clean": "rm -rf ./lib",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
22
|
+
"watchful": "watchful -m --transpiler=swc --source-directory=./src --lib-directory=./lib",
|
|
23
|
+
"batch": "npm run watchful batch --",
|
|
24
|
+
"batch-debug": "npm run watchful batch -- --debug",
|
|
25
|
+
"incremental": "npm run watchful incremental --",
|
|
26
|
+
"incremental-debug": "npm run watchful incremental -- --debug",
|
|
27
|
+
"build": "npm run clean && npm run batch",
|
|
28
|
+
"build-debug": "npm run clean && npm run batch-debug",
|
|
29
|
+
"watch": "npm run clean && npm run batch && npm run incremental",
|
|
30
|
+
"watch-debug": "npm run clean && npm run batch-debug && npm run incremental-debug"
|
|
31
|
+
},
|
|
32
|
+
"main": "./lib/index.js"
|
|
35
33
|
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { nullifyTargetEntryPath } from "./utilities/pathMap";
|
|
4
|
+
import { pathUtilities, fileSystemUtilities } from "necessary";
|
|
5
|
+
|
|
6
|
+
const { concatenatePaths } = pathUtilities,
|
|
7
|
+
{ createFile, createDirectory, checkEntryExists: checkFileExists, checkEntryExists: checkDirectoryExists } = fileSystemUtilities;
|
|
8
|
+
|
|
9
|
+
export default function createProjectEntries(projectsDirectoryPath, json, callback) {
|
|
10
|
+
const { pathMaps } = json;
|
|
11
|
+
|
|
12
|
+
pathMaps.forEach((pathMap) => {
|
|
13
|
+
createProjectEntry(projectsDirectoryPath, pathMap);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
json = {
|
|
17
|
+
pathMaps
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
callback(json);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createProjectEntry(projectsDirectoryPath, pathMap) {
|
|
24
|
+
const { entryDirectory } = pathMap;
|
|
25
|
+
|
|
26
|
+
entryDirectory ?
|
|
27
|
+
createProjectDirectory(projectsDirectoryPath, pathMap) :
|
|
28
|
+
createProjectFile(projectsDirectoryPath, pathMap);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createProjectFile(projectsDirectoryPath, pathMap) {
|
|
32
|
+
const { targetEntryPath } = pathMap,
|
|
33
|
+
targetFilePath = targetEntryPath, ///
|
|
34
|
+
absoluteTargetFilePath = concatenatePaths(projectsDirectoryPath, targetFilePath),
|
|
35
|
+
targetFileExists = checkFileExists(absoluteTargetFilePath);
|
|
36
|
+
|
|
37
|
+
if (targetFileExists) {
|
|
38
|
+
nullifyTargetEntryPath(pathMap);
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const filePath = absoluteTargetFilePath; ///
|
|
45
|
+
|
|
46
|
+
createFile(filePath);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
nullifyTargetEntryPath(pathMap);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createProjectDirectory(projectsDirectoryPath, pathMap) {
|
|
53
|
+
const { targetEntryPath } = pathMap,
|
|
54
|
+
targetDirectoryPath = targetEntryPath, ///
|
|
55
|
+
absoluteTargetDirectoryPath = concatenatePaths(projectsDirectoryPath, targetDirectoryPath),
|
|
56
|
+
targetDirectoryExists = checkDirectoryExists(absoluteTargetDirectoryPath);
|
|
57
|
+
|
|
58
|
+
if (targetDirectoryExists) {
|
|
59
|
+
nullifyTargetEntryPath(pathMap);
|
|
60
|
+
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const directoryPath = absoluteTargetDirectoryPath; ///
|
|
66
|
+
|
|
67
|
+
createDirectory(directoryPath);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
nullifyTargetEntryPath(pathMap);
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export { default as loadFile } from "./loadFile";
|
|
4
|
+
export { default as saveFile } from "./saveFile";
|
|
5
|
+
export { default as loadFiles } from "./loadFiles";
|
|
6
|
+
export { default as loadProject } from "./loadProject";
|
|
7
|
+
export { default as loadRelease } from "./loadRelease";
|
|
8
|
+
export { default as loadProjects } from "./loadProjects";
|
|
9
|
+
export { default as loadReleases } from "./loadReleases";
|
|
10
|
+
export { default as removeRelease } from "./removeRelease";
|
|
11
|
+
export { default as httpUtilities } from "./utilities/http";
|
|
12
|
+
export { default as moveProjectEntries } from "./moveProjectEntries";
|
|
13
|
+
export { default as fileSystemUtilities } from "./utilities/fileSystem";
|
|
14
|
+
export { default as removeProjectEntries } from "./removeProjectEntries";
|
|
15
|
+
export { default as renameProjectEntries } from "./renameProjectEntries";
|
|
16
|
+
export { default as createProjectEntries } from "./createProjectEntries";
|
package/src/loadFile.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadFile as loadFileEx } from "./utilities/fileSystem"
|
|
4
|
+
|
|
5
|
+
export default function loadFile(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const { filePath } = json,
|
|
7
|
+
path = filePath, ///
|
|
8
|
+
file = loadFileEx(path, projectsDirectoryPath);
|
|
9
|
+
|
|
10
|
+
json = (file !== null) ? ///
|
|
11
|
+
file.toJSON():
|
|
12
|
+
null;
|
|
13
|
+
|
|
14
|
+
return callback(json);
|
|
15
|
+
}
|
package/src/loadFiles.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadFiles as loadFilesEx } from "./utilities/fileSystem"
|
|
4
|
+
|
|
5
|
+
export default function loadFiles(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const { filePaths } = json,
|
|
7
|
+
paths = filePaths, ///
|
|
8
|
+
files = loadFilesEx(paths, projectsDirectoryPath);
|
|
9
|
+
|
|
10
|
+
json = (files !== null) ? ///
|
|
11
|
+
files.toJSON() :
|
|
12
|
+
null;
|
|
13
|
+
|
|
14
|
+
return callback(json);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadProject as loadProjectEx } from "./utilities/fileSystem"
|
|
4
|
+
|
|
5
|
+
export default function loadProject(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const { projectName } = json,
|
|
7
|
+
loadOnlyRecognisedFiles = false, ///
|
|
8
|
+
project = loadProjectEx(projectName, projectsDirectoryPath, loadOnlyRecognisedFiles);
|
|
9
|
+
|
|
10
|
+
json = (project !== null) ? ///
|
|
11
|
+
project.toJSON():
|
|
12
|
+
null;
|
|
13
|
+
|
|
14
|
+
return callback(json);
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadProjects as loadProjectsEx } from "./utilities/fileSystem";
|
|
4
|
+
|
|
5
|
+
export default function loadProjects(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const loadOnlyRecognisedFiles = false, ///
|
|
7
|
+
projects = loadProjectsEx(projectsDirectoryPath, loadOnlyRecognisedFiles);
|
|
8
|
+
|
|
9
|
+
json = (projects !== null) ? ///
|
|
10
|
+
projects.toJSON():
|
|
11
|
+
null;
|
|
12
|
+
|
|
13
|
+
callback(json);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadRelease as loadReleaseEx } from "./utilities/fileSystem"
|
|
4
|
+
|
|
5
|
+
export default function loadRelease(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const { releaseName } = json,
|
|
7
|
+
release = loadReleaseEx(releaseName, projectsDirectoryPath);
|
|
8
|
+
|
|
9
|
+
json = (release !== null) ? ///
|
|
10
|
+
release.toJSON():
|
|
11
|
+
null;
|
|
12
|
+
|
|
13
|
+
return callback(json);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { loadReleases as loadReleasesEx } from "./utilities/fileSystem";
|
|
4
|
+
|
|
5
|
+
export default function loadReleases(projectsDirectoryPath, json, callback) {
|
|
6
|
+
const releases = loadReleasesEx(projectsDirectoryPath);
|
|
7
|
+
|
|
8
|
+
json = (releases !== null) ? ///
|
|
9
|
+
releases.toJSON():
|
|
10
|
+
null;
|
|
11
|
+
|
|
12
|
+
callback(json);
|
|
13
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { pathUtilities, fileSystemUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
import { removeProjectEntry } from "./removeProjectEntries";
|
|
6
|
+
import { nullifyEntryPaths, nullifyTargetEntryPath } from "./utilities/pathMap";
|
|
7
|
+
|
|
8
|
+
const { concatenatePaths } = pathUtilities,
|
|
9
|
+
{ moveEntry, isDirectoryEmpty, checkEntryExists, checkEntryExists: checkFileExists, checkEntryExists: checkDirectoryExists } = fileSystemUtilities;
|
|
10
|
+
|
|
11
|
+
export default function moveProjectEntries(projectsDirectoryPath, json, callback) {
|
|
12
|
+
const { pathMaps } = json;
|
|
13
|
+
|
|
14
|
+
pathMaps.forEach((pathMap) => {
|
|
15
|
+
moveProjectEntry(projectsDirectoryPath, pathMap);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
json = {
|
|
19
|
+
pathMaps
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
callback(json);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function moveProjectEntry(projectsDirectoryPath, pathMap) {
|
|
26
|
+
const { targetEntryPath } = pathMap;
|
|
27
|
+
|
|
28
|
+
if (targetEntryPath === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { sourceEntryPath } = pathMap,
|
|
33
|
+
absoluteSourceEntryPath = concatenatePaths(projectsDirectoryPath, sourceEntryPath),
|
|
34
|
+
sourceEntryExists = checkEntryExists(absoluteSourceEntryPath);
|
|
35
|
+
|
|
36
|
+
if (!sourceEntryExists) {
|
|
37
|
+
nullifyTargetEntryPath(pathMap);
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { entryDirectory } = pathMap;
|
|
43
|
+
|
|
44
|
+
entryDirectory ?
|
|
45
|
+
moveProjectDirectory(projectsDirectoryPath, pathMap) :
|
|
46
|
+
moveProjectFile(projectsDirectoryPath, pathMap);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function moveProjectFile(projectsDirectoryPath, pathMap) {
|
|
50
|
+
const { sourceEntryPath, targetEntryPath } = pathMap,
|
|
51
|
+
sourceFilePath = sourceEntryPath, ///
|
|
52
|
+
targetFilePath = targetEntryPath, ///
|
|
53
|
+
absoluteSourceFilePath = concatenatePaths(projectsDirectoryPath, sourceFilePath),
|
|
54
|
+
absoluteTargetFilePath = concatenatePaths(projectsDirectoryPath, targetFilePath),
|
|
55
|
+
targetFileExists = checkFileExists(absoluteTargetFilePath);
|
|
56
|
+
|
|
57
|
+
if (targetFileExists) {
|
|
58
|
+
nullifyEntryPaths(pathMap);
|
|
59
|
+
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const oldEntryPath = absoluteSourceFilePath, ///
|
|
65
|
+
newEntryPath = absoluteTargetFilePath; ///
|
|
66
|
+
|
|
67
|
+
moveEntry(oldEntryPath, newEntryPath);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
nullifyEntryPaths(pathMap);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function moveProjectDirectory(projectsDirectoryPath, pathMap) {
|
|
74
|
+
const { sourceEntryPath, targetEntryPath } = pathMap,
|
|
75
|
+
sourceDirectoryPath = sourceEntryPath, ///
|
|
76
|
+
targetDirectoryPath = targetEntryPath, ///
|
|
77
|
+
absoluteSourceDirectoryPath = concatenatePaths(projectsDirectoryPath, sourceDirectoryPath),
|
|
78
|
+
absoluteTargetDirectoryPath = concatenatePaths(projectsDirectoryPath, targetDirectoryPath),
|
|
79
|
+
targetDirectoryExists = checkDirectoryExists(absoluteTargetDirectoryPath),
|
|
80
|
+
directoryEmpty = isDirectoryEmpty(absoluteSourceDirectoryPath);
|
|
81
|
+
|
|
82
|
+
if (!directoryEmpty) {
|
|
83
|
+
nullifyEntryPaths(pathMap);
|
|
84
|
+
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (targetDirectoryExists) {
|
|
89
|
+
removeProjectEntry(projectsDirectoryPath, pathMap);
|
|
90
|
+
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const oldEntryPath = absoluteSourceDirectoryPath, ///
|
|
96
|
+
newEntryPath = absoluteTargetDirectoryPath; ///
|
|
97
|
+
|
|
98
|
+
moveEntry(oldEntryPath, newEntryPath);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
nullifyEntryPaths(pathMap);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { pathUtilities, fileSystemUtilities } from "necessary";
|
|
4
|
+
import { nullifyEntryPaths, nullifyTargetEntryPath } from "./utilities/pathMap";
|
|
5
|
+
|
|
6
|
+
const { concatenatePaths } = pathUtilities,
|
|
7
|
+
{ removeEntry, checkEntryExists, isDirectoryEmpty } = fileSystemUtilities;
|
|
8
|
+
|
|
9
|
+
export default function removeProjectEntries(projectsDirectoryPath, json, callback) {
|
|
10
|
+
const { pathMaps } = json;
|
|
11
|
+
|
|
12
|
+
pathMaps.forEach((pathMap) => {
|
|
13
|
+
removeProjectEntry(projectsDirectoryPath, pathMap);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
json = {
|
|
17
|
+
pathMaps
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
callback(json);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function removeProjectEntry(projectsDirectoryPath, pathMap) {
|
|
24
|
+
const { sourceEntryPath } = pathMap;
|
|
25
|
+
|
|
26
|
+
if (sourceEntryPath === null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const absoluteSourceEntryPath = concatenatePaths(projectsDirectoryPath, sourceEntryPath),
|
|
31
|
+
sourceEntryExists = checkEntryExists(absoluteSourceEntryPath);
|
|
32
|
+
|
|
33
|
+
if (!sourceEntryExists) {
|
|
34
|
+
nullifyTargetEntryPath(pathMap);
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { entryDirectory } = pathMap;
|
|
40
|
+
|
|
41
|
+
entryDirectory ?
|
|
42
|
+
removeProjectDirectory(projectsDirectoryPath, pathMap) :
|
|
43
|
+
removeProjectFile(projectsDirectoryPath, pathMap);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function removeProjectFile(projectsDirectoryPath, pathMap) {
|
|
47
|
+
const { sourceEntryPath } = pathMap,
|
|
48
|
+
sourceFilePath = sourceEntryPath, ///
|
|
49
|
+
absoluteSourceFilePath = concatenatePaths(projectsDirectoryPath, sourceFilePath);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const entryPath = absoluteSourceFilePath; ///
|
|
53
|
+
|
|
54
|
+
removeEntry(entryPath);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
nullifyEntryPaths(pathMap);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function removeProjectDirectory(projectsDirectoryPath, pathMap) {
|
|
61
|
+
const { sourceEntryPath } = pathMap,
|
|
62
|
+
sourceDirectoryPath = sourceEntryPath, ///
|
|
63
|
+
absoluteSourceDirectoryPath = concatenatePaths(projectsDirectoryPath, sourceDirectoryPath),
|
|
64
|
+
directoryEmpty = isDirectoryEmpty(absoluteSourceDirectoryPath);
|
|
65
|
+
|
|
66
|
+
if (!directoryEmpty) {
|
|
67
|
+
nullifyEntryPaths(pathMap);
|
|
68
|
+
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const entryPath = absoluteSourceDirectoryPath; ///
|
|
74
|
+
|
|
75
|
+
removeEntry(entryPath);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
nullifyEntryPaths(pathMap);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { arrayUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
import { removeProjectEntry } from "./removeProjectEntries";
|
|
6
|
+
|
|
7
|
+
const { last } = arrayUtilities;
|
|
8
|
+
|
|
9
|
+
export default function removeRelease(projectsDirectoryPath, json, callback) {
|
|
10
|
+
let entryDirectory;
|
|
11
|
+
|
|
12
|
+
const { pathMaps } = json,
|
|
13
|
+
lastPathMap = last(pathMaps),
|
|
14
|
+
pathMap = lastPathMap; ///
|
|
15
|
+
|
|
16
|
+
entryDirectory = false;
|
|
17
|
+
|
|
18
|
+
Object.assign(pathMap, {
|
|
19
|
+
entryDirectory
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
removeProjectEntry(projectsDirectoryPath, pathMap);
|
|
23
|
+
|
|
24
|
+
entryDirectory = true;
|
|
25
|
+
|
|
26
|
+
Object.assign(pathMap, {
|
|
27
|
+
entryDirectory
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
json = {
|
|
31
|
+
pathMaps
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
callback(json);
|
|
35
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { pathUtilities, arrayUtilities, fileSystemUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
import { nullifyEntryPaths, nullifyTargetEntryPath, nullifyTargetEntryPaths } from "./utilities/pathMap";
|
|
6
|
+
|
|
7
|
+
const { last } = arrayUtilities,
|
|
8
|
+
{ concatenatePaths } = pathUtilities,
|
|
9
|
+
{ renameEntry, checkEntryExists, checkEntryExists: checkFileExists, checkEntryExists: checkDirectoryExists } = fileSystemUtilities;
|
|
10
|
+
|
|
11
|
+
export default function renameProjectEntries(projectsDirectoryPath, json, callback) {
|
|
12
|
+
const { pathMaps } = json,
|
|
13
|
+
lastPathMap = last(pathMaps),
|
|
14
|
+
pathMap = lastPathMap; ///
|
|
15
|
+
|
|
16
|
+
renameProjectEntry(projectsDirectoryPath, pathMap);
|
|
17
|
+
|
|
18
|
+
const { targetEntryPath } = pathMap;
|
|
19
|
+
|
|
20
|
+
if (targetEntryPath === null) {
|
|
21
|
+
nullifyTargetEntryPaths(pathMaps);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
json = {
|
|
25
|
+
pathMaps
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
callback(json);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function renameProjectEntry(projectsDirectoryPath, pathMap) {
|
|
32
|
+
const { targetEntryPath } = pathMap;
|
|
33
|
+
|
|
34
|
+
if (targetEntryPath === null) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const { sourceEntryPath } = pathMap,
|
|
39
|
+
absoluteSourceEntryPath = concatenatePaths(projectsDirectoryPath, sourceEntryPath),
|
|
40
|
+
sourceEntryExists = checkEntryExists(absoluteSourceEntryPath);
|
|
41
|
+
|
|
42
|
+
if (!sourceEntryExists) {
|
|
43
|
+
nullifyTargetEntryPath(pathMap);
|
|
44
|
+
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { entryDirectory } = pathMap;
|
|
49
|
+
|
|
50
|
+
entryDirectory ?
|
|
51
|
+
renameProjectDirectory(projectsDirectoryPath, pathMap) :
|
|
52
|
+
renameProjectFile(projectsDirectoryPath, pathMap);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function renameProjectFile(projectsDirectoryPath, pathMap) {
|
|
56
|
+
const { sourceEntryPath, targetEntryPath } = pathMap,
|
|
57
|
+
sourceFilePath = sourceEntryPath, ///
|
|
58
|
+
targetFilePath = targetEntryPath, ///
|
|
59
|
+
absoluteSourceFilePath = concatenatePaths(projectsDirectoryPath, sourceFilePath),
|
|
60
|
+
absoluteTargetFilePath = concatenatePaths(projectsDirectoryPath, targetFilePath),
|
|
61
|
+
targetFileExists = checkFileExists(absoluteTargetFilePath);
|
|
62
|
+
|
|
63
|
+
if (targetFileExists) {
|
|
64
|
+
nullifyEntryPaths(pathMap);
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const oldEntryPath = absoluteSourceFilePath, ///
|
|
71
|
+
newEntryPath = absoluteTargetFilePath; ///
|
|
72
|
+
|
|
73
|
+
renameEntry(oldEntryPath, newEntryPath); ///
|
|
74
|
+
} catch (error) {
|
|
75
|
+
nullifyEntryPaths(pathMap);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function renameProjectDirectory(projectsDirectoryPath, pathMap) {
|
|
80
|
+
const { sourceEntryPath, targetEntryPath } = pathMap,
|
|
81
|
+
sourceDirectoryPath = sourceEntryPath, ///
|
|
82
|
+
targetDirectoryPath = targetEntryPath, ///
|
|
83
|
+
absoluteSourceDirectoryPath = concatenatePaths(projectsDirectoryPath, sourceDirectoryPath),
|
|
84
|
+
absoluteTargetDirectoryPath = concatenatePaths(projectsDirectoryPath, targetDirectoryPath),
|
|
85
|
+
targetDirectoryExists = checkDirectoryExists(absoluteTargetDirectoryPath);
|
|
86
|
+
|
|
87
|
+
if (targetDirectoryExists) {
|
|
88
|
+
nullifyEntryPaths(pathMap);
|
|
89
|
+
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const oldEntryPath = absoluteSourceDirectoryPath, ///
|
|
95
|
+
newEntryPath = absoluteTargetDirectoryPath; ///
|
|
96
|
+
|
|
97
|
+
renameEntry(oldEntryPath, newEntryPath); ///
|
|
98
|
+
} catch (error) {
|
|
99
|
+
nullifyEntryPaths(pathMap);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/saveFile.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { File } from "occam-model";
|
|
4
|
+
|
|
5
|
+
import { saveFile as saveFileEx } from "./utilities/fileSystem"
|
|
6
|
+
|
|
7
|
+
export default function saveFile(projectsDirectoryPath, json, callback) {
|
|
8
|
+
const file = File.fromJSON(json),
|
|
9
|
+
success = saveFileEx(file, projectsDirectoryPath);
|
|
10
|
+
|
|
11
|
+
json = success; ///
|
|
12
|
+
|
|
13
|
+
callback(json);
|
|
14
|
+
}
|