occam-file-system 5.0.13 → 5.0.15

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.
Files changed (68) hide show
  1. package/README.md +4 -4
  2. package/lib/browser.js +63 -0
  3. package/lib/constants.js +13 -1
  4. package/lib/dependencies.js +81 -0
  5. package/lib/dependency.js +89 -0
  6. package/lib/directory.js +100 -0
  7. package/lib/entries.js +228 -0
  8. package/lib/file.js +141 -0
  9. package/lib/fileNames.js +38 -0
  10. package/lib/files.js +121 -0
  11. package/lib/loadProjects.js +1 -1
  12. package/lib/loadReleases.js +18 -0
  13. package/lib/main.js +103 -0
  14. package/lib/messages.js +13 -0
  15. package/lib/mixins/bnf.js +47 -0
  16. package/lib/mixins/entries.js +31 -0
  17. package/lib/mixins/files.js +41 -0
  18. package/lib/mixins/pattern.js +47 -0
  19. package/lib/project.js +123 -0
  20. package/lib/projects.js +112 -0
  21. package/lib/release.js +127 -0
  22. package/lib/releases.js +112 -0
  23. package/lib/shortenedVersion.js +125 -0
  24. package/lib/types.js +22 -0
  25. package/lib/utilities/content.js +34 -0
  26. package/lib/utilities/filePath.js +63 -0
  27. package/lib/utilities/fileSystem.js +130 -12
  28. package/lib/utilities/files.js +95 -0
  29. package/lib/utilities/metaJSON.js +80 -0
  30. package/lib/utilities/name.js +25 -4
  31. package/lib/utilities/query.js +48 -0
  32. package/lib/version.js +163 -0
  33. package/package.json +5 -3
  34. package/src/browser.js +14 -0
  35. package/src/constants.js +3 -0
  36. package/src/dependencies.js +46 -0
  37. package/src/dependency.js +52 -0
  38. package/src/directory.js +54 -0
  39. package/src/entries.js +192 -0
  40. package/src/file.js +95 -0
  41. package/src/fileNames.js +8 -0
  42. package/src/files.js +78 -0
  43. package/src/loadProjects.js +1 -1
  44. package/src/loadReleases.js +13 -0
  45. package/src/main.js +25 -0
  46. package/src/messages.js +3 -0
  47. package/src/mixins/bnf.js +59 -0
  48. package/src/mixins/entries.js +18 -0
  49. package/src/mixins/files.js +52 -0
  50. package/src/mixins/pattern.js +59 -0
  51. package/src/project.js +92 -0
  52. package/src/projects.js +66 -0
  53. package/src/release.js +97 -0
  54. package/src/releases.js +66 -0
  55. package/src/shortenedVersion.js +109 -0
  56. package/src/types.js +4 -0
  57. package/src/utilities/content.js +12 -0
  58. package/src/utilities/filePath.js +36 -0
  59. package/src/utilities/fileSystem.js +186 -15
  60. package/src/utilities/files.js +103 -0
  61. package/src/utilities/metaJSON.js +82 -0
  62. package/src/utilities/name.js +17 -0
  63. package/src/utilities/query.js +36 -0
  64. package/src/version.js +151 -0
  65. package/lib/index.js +0 -55
  66. package/lib/utilities/pathMaps.js +0 -31
  67. package/src/index.js +0 -11
  68. package/src/utilities/pathMaps.js +0 -21
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ import { asynchronousUtilities } from "necessary";
4
+
5
+ import Release from "./release";
6
+
7
+ const { forEach } = asynchronousUtilities;
8
+
9
+ export default class Releases {
10
+ constructor(array) {
11
+ this.array = array;
12
+ }
13
+
14
+ getLength() {
15
+ return this.array.length;
16
+ }
17
+
18
+ addRelease(release) {
19
+ this.array.push(release);
20
+ }
21
+
22
+ mapRelease(callback) {
23
+ return this.array.map(callback);
24
+ }
25
+
26
+ reduceRelease(callback, initialValue) {
27
+ return this.array.reduce(callback, initialValue);
28
+ }
29
+
30
+ forEachRelease(callback) {
31
+ this.array.forEach(callback);
32
+ }
33
+
34
+ asynchronousForEachRelease(callback, done) {
35
+ forEach(this.array, callback, done);
36
+ }
37
+
38
+ toJSON() {
39
+ const json = this.array.map((release) => {
40
+ const releaseJSON = release.toJSON();
41
+
42
+ return releaseJSON;
43
+ });
44
+
45
+ return json;
46
+ }
47
+
48
+ static fromJSON(json) {
49
+ const array = json.map((json) => { ///
50
+ const release = Release.fromJSON(json);
51
+
52
+ return release;
53
+ }),
54
+ releases = new Releases(array);
55
+
56
+ return releases;
57
+ }
58
+
59
+ static fromNothing() {
60
+ const array = [],
61
+ releases = new Releases(array);
62
+
63
+ return releases;
64
+ }
65
+ }
66
+
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ const { second } = arrayUtilities;
6
+
7
+ export default class ShortenedVersion {
8
+ constructor(majorNumber, minorNumber) {
9
+ this.majorNumber = majorNumber;
10
+ this.minorNumber = minorNumber;
11
+ }
12
+
13
+ getMajorNumber() {
14
+ return this.majorNumber;
15
+ }
16
+
17
+ getMinorNumber() {
18
+ return this.minorNumber;
19
+ }
20
+
21
+ toString() {
22
+ const string = `${this.majorNumber}.${this.minorNumber}`;
23
+
24
+ return string;
25
+ }
26
+
27
+ asNumber() {
28
+ const number = this.majorNumber * 1e12 + this.minorNumber * 1e6; ///
29
+
30
+ return number;
31
+ }
32
+
33
+ toJSON() {
34
+ const majorNumber = this.majorNumber,
35
+ minorNumber = this.minorNumber,
36
+ json = {
37
+ majorNumber,
38
+ minorNumber
39
+ };
40
+
41
+ return json;
42
+ }
43
+
44
+ static fromJSON(json) {
45
+ const { majorNumber, minorNumber } = json,
46
+ shortenedVersion = new ShortenedVersion(majorNumber, minorNumber);
47
+
48
+ return shortenedVersion;
49
+ }
50
+
51
+ static fromString(string) {
52
+ const majorNumber = majorNumberFromString(string),
53
+ minorNumber = minorNumberFromString(string),
54
+ shortenedVersion = new ShortenedVersion(majorNumber, minorNumber);
55
+
56
+ return shortenedVersion;
57
+ }
58
+
59
+ static fromVersionNumber(versionNumber) {
60
+ const number = versionNumber, ///
61
+ majorNumber = majorNumberFromNumber(number),
62
+ minorNumber = minorNumberFromNumber(number),
63
+ shortenedVersion = new ShortenedVersion(majorNumber, minorNumber);
64
+
65
+ return shortenedVersion;
66
+ }
67
+ }
68
+
69
+ function majorNumberFromNumber(number) {
70
+ const majorNumber = (number !== null) ?
71
+ Math.floor(number / 1e12) :
72
+ 0; ///
73
+
74
+ return majorNumber;
75
+ }
76
+
77
+ function minorNumberFromNumber(number) {
78
+ const minorNumber = (number !== null) ?
79
+ Math.floor(number / 1e6) :
80
+ 0; ///
81
+
82
+ return minorNumber;
83
+ }
84
+
85
+ function majorNumberFromString(string) {
86
+ let majorNumber = 0;
87
+
88
+ if (string) {
89
+ const matches = string.match(/^(\d+)\.\d+$/),
90
+ secondMatch = second(matches);
91
+
92
+ majorNumber = secondMatch; ///
93
+ }
94
+
95
+ return majorNumber;
96
+ }
97
+
98
+ function minorNumberFromString(string) {
99
+ let minorNumber = 0;
100
+
101
+ if (string) {
102
+ const matches = string.match(/^\d+\.(\d+)$/),
103
+ secondMatch = second(matches);
104
+
105
+ minorNumber = secondMatch; ///
106
+ }
107
+
108
+ return minorNumber;
109
+ }
package/src/types.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export const FILE_TYPE = "File";
4
+ export const DIRECTORY_TYPE = "Directory";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ import { EMPTY_STRING, DOUBLE_SPACE } from "../constants";
4
+
5
+ export function trimDoubleQuotes(content) { return content.replace(/(^"|"$)/g, EMPTY_STRING); } ///
6
+
7
+ export function convertContentTabsToWhitespace(content) { return content.replace(/\t/g, DOUBLE_SPACE); } ///
8
+
9
+ export default {
10
+ trimDoubleQuotes,
11
+ convertContentTabsToWhitespace
12
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ const readmeFilePathPattern = "^(?:[^\\/]+\\/){1}README\\.md$",
4
+ florenceFilePathPattern = "^(?:[^\\/]+\\/){1,}[^\\.]+\\.fls$",
5
+ metaJSONFilePathPattern = "^(?:[^\\/]+\\/){1}meta\\.json$",
6
+ customGrammarBNFFilePathPattern = "^(?:[^\\/]+\\/){1}(term|statement|metastatement)\\.bnf$",
7
+ customGrammarPatternFilePathPattern = "^(?:[^\\/]+\\/){1}(type|symbol|operator)\\.ptn$",
8
+ recognisedFilePathPattern = `${readmeFilePathPattern}|${florenceFilePathPattern}|${metaJSONFilePathPattern}|${customGrammarBNFFilePathPattern}|${customGrammarPatternFilePathPattern}`;
9
+
10
+ const readmeFilePathRegularExpression = new RegExp(readmeFilePathPattern),
11
+ florenceFilePathRegularExpression = new RegExp(florenceFilePathPattern),
12
+ metaJSONFilePathRegularExpression = new RegExp(metaJSONFilePathPattern),
13
+ recognisedFilePathRegularExpression = new RegExp(recognisedFilePathPattern),
14
+ customGrammarBNFFilePathRegularExpression = new RegExp(customGrammarBNFFilePathPattern),
15
+ customGrammarPatternFilePathRegularExpression = new RegExp(customGrammarPatternFilePathPattern);
16
+
17
+ export function isFilePathReadmeFilePath(filePath) { return readmeFilePathRegularExpression.test(filePath); }
18
+
19
+ export function isFilePathFlorenceFilePath(filePath) { return florenceFilePathRegularExpression.test(filePath); }
20
+
21
+ export function isFilePathMetaJSONFilePath(filePath) { return metaJSONFilePathRegularExpression.test(filePath); }
22
+
23
+ export function isFilePathRecognisedFilePath(filePath) { return recognisedFilePathRegularExpression.test(filePath); }
24
+
25
+ export function isFilePathCustomGrammarBNFFilePath(filePath) { return customGrammarBNFFilePathRegularExpression.test(filePath); }
26
+
27
+ export function isFilePathCustomGrammarPatternFilePath(filePath) { return customGrammarPatternFilePathRegularExpression.test(filePath); }
28
+
29
+ export default {
30
+ isFilePathReadmeFilePath,
31
+ isFilePathFlorenceFilePath,
32
+ isFilePathMetaJSONFilePath,
33
+ isFilePathRecognisedFilePath,
34
+ isFilePathCustomGrammarBNFFilePath,
35
+ isFilePathCustomGrammarPatternFilePath
36
+ };
@@ -2,15 +2,30 @@
2
2
 
3
3
  import mkdirp from "mkdirp";
4
4
 
5
+ import { MetaJSONLexer, MetaJSONParser } from "occam-grammars";
5
6
  import { pathUtilities, fileSystemUtilities } from "necessary";
6
- import { File, Files, Project, Projects, nameUtilities, entriesUtilities, contentUtilities } from "occam-open-cli";
7
7
 
8
- const { isNameHiddenName } = nameUtilities,
9
- { convertContentTabsToWhitespace } = contentUtilities,
10
- { entriesFromTopmostDirectoryName } = entriesUtilities,
11
- { concatenatePaths, topmostDirectoryPathFromPath } = pathUtilities,
8
+ import File from "../file";
9
+ import Files from "../files";
10
+ import Entries from "../entries";
11
+ import Project from "../project";
12
+ import Projects from "../projects";
13
+ import Releases from "../releases";
14
+ import Directory from "../directory";
15
+
16
+ import { PERIOD } from "../constants";
17
+ import { isNameHiddenName } from "../utilities/name";
18
+ import { isFilePathRecognisedFilePath } from "../utilities/filePath";
19
+ import { convertContentTabsToWhitespace } from "../utilities/content";
20
+ import { metaJSONFileFromFiles, readmeFileFromFiles } from "../utilities/files";
21
+ import { versionFromNode, repositoryFromNode, dependenciesFromNode } from "./metaJSON";
22
+
23
+ const { concatenatePaths, topmostDirectoryPathFromPath } = pathUtilities,
12
24
  { readFile, writeFile, isEntryFile, readDirectory, isEntryDirectory } = fileSystemUtilities;
13
25
 
26
+ const metaJSONLexer = MetaJSONLexer.fromNothing(),
27
+ metaJSONParser = MetaJSONParser.fromNothing();
28
+
14
29
  export function loadFile(path, projectsDirectoryPath) {
15
30
  let file = null;
16
31
 
@@ -23,7 +38,7 @@ export function loadFile(path, projectsDirectoryPath) {
23
38
 
24
39
  content = convertContentTabsToWhitespace(content); ///
25
40
 
26
- file = new File(path, content);
41
+ file = File.fromPathAndContent(path, content);
27
42
  }
28
43
  } catch (error) {
29
44
  ///
@@ -44,8 +59,7 @@ export function saveFile(file, projectsDirectoryPath) {
44
59
  }
45
60
 
46
61
  export function loadFiles(paths, projectsDirectoryPath) {
47
- const array = [],
48
- files = new Files(array);
62
+ const files = Files.fromNothing();
49
63
 
50
64
  paths.forEach((path) => {
51
65
  const file = loadFile(path, projectsDirectoryPath);
@@ -62,23 +76,89 @@ export function saveFiles(files, projectsDirectoryPath) {
62
76
  });
63
77
  }
64
78
 
79
+ export function loadEntries(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories) {
80
+ const entries = Entries.fromNothing(),
81
+ relativeDirectoryPath = topmostDirectoryName; ///
82
+
83
+ entriesFromRelativeDirectoryPath(entries, relativeDirectoryPath, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories);
84
+
85
+ return entries;
86
+ }
87
+
88
+ export function loadRelease(topmostDirectoryName, projectsDirectoryPath = PERIOD) {
89
+ let release = null;
90
+
91
+ const name = topmostDirectoryName, ///
92
+ loadOnlyRecognisedFiles = true,
93
+ doNotLoadHiddenFilesAndDirectories = true,
94
+ entries = loadEntries(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories),
95
+ files = entries.getFiles(),
96
+ readmeFile = readmeFileFromFiles(files),
97
+ metaJSONFile = metaJSONFileFromFiles(files);
98
+
99
+ if ((readmeFile !== null) && (metaJSONFile !== null)) {
100
+ const metaJSONNode = metaJSONNodeFromMetaJSONFile(metaJSONFile);
101
+
102
+ if (metaJSONNode !== null) {
103
+ const node = metaJSONNode, ///
104
+ version = versionFromNode(node),
105
+ repository = repositoryFromNode(node),
106
+ dependencies = dependenciesFromNode(node);
107
+
108
+ release = Release.fromNameEntriesVersionRepositoryAndDependencies(name, entries, version, repository, dependencies);
109
+ }
110
+ }
111
+
112
+ return release;
113
+ }
114
+
65
115
  export function loadProject(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories) {
66
116
  const name = topmostDirectoryName, ///
67
- entries = entriesFromTopmostDirectoryName(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories),
68
- project = new Project(name, entries);
117
+ entries = loadEntries(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories),
118
+ files = entries.getFiles(),
119
+ metaJSONFile = metaJSONFileFromFiles(files);
120
+
121
+ let repository = null,
122
+ dependencies = [];
123
+
124
+ if (metaJSONFile !== null) {
125
+ const metaJSONNode = metaJSONNodeFromMetaJSONFile(metaJSONFile),
126
+ node = metaJSONNode;
127
+
128
+ repository = repositoryFromNode(node);
129
+ dependencies = dependenciesFromNode(node);
130
+ }
131
+
132
+ const project = Project.fromNameEntriesRepositoryAndDependencies(name, entries, repository, dependencies);
69
133
 
70
134
  return project;
71
135
  }
72
136
 
73
- export function loadProjects(projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories) {
74
- let projects;
137
+ export function loadReleases(projectsDirectoryPath) {
138
+ let releases;
75
139
 
76
140
  try {
77
- const array = [];
141
+ const releases = Releases.fromNothing(),
142
+ topmostFileNames = topmostFileNamesFromProjectsDirectoryPath(projectsDirectoryPath);
143
+
144
+ topmostFileNames.forEach((topmostFileName) => {
145
+ const release = loadRelease(topmostFileName, projectsDirectoryPath);
78
146
 
79
- projects = new Projects(array);
147
+ releases.addRelease(release);
148
+ });
149
+ } catch (error) {
150
+ releases = null;
151
+ }
152
+
153
+ return releases;
154
+ }
155
+
156
+ export function loadProjects(projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories) {
157
+ let projects;
80
158
 
81
- const topmostDirectoryNames = topmostDirectoryNamesFromProjectsDirectoryPath(projectsDirectoryPath, doNotLoadHiddenFilesAndDirectories);
159
+ try {
160
+ const projects = Projects.fromNothing(),
161
+ topmostDirectoryNames = topmostDirectoryNamesFromProjectsDirectoryPath(projectsDirectoryPath, doNotLoadHiddenFilesAndDirectories);
82
162
 
83
163
  topmostDirectoryNames.forEach((topmostDirectoryName) => {
84
164
  const project = loadProject(topmostDirectoryName, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories);
@@ -92,6 +172,97 @@ export function loadProjects(projectsDirectoryPath, loadOnlyRecognisedFiles, doN
92
172
  return projects;
93
173
  }
94
174
 
175
+ export function loadDirectory(path, projectsDirectoryPath) {
176
+ let directory = null;
177
+
178
+ try {
179
+ const absolutePath = concatenatePaths(projectsDirectoryPath, path),
180
+ entryDirectory = isEntryDirectory(absolutePath);
181
+
182
+ if (entryDirectory) {
183
+ directory = Directory.fromPath(path);
184
+ }
185
+ } catch (error) {
186
+ ///
187
+ }
188
+
189
+ return directory;
190
+ }
191
+
192
+ function metaJSONNodeFromMetaJSONFile(metaJSONFile) {
193
+ const content = metaJSONFile.getContent(),
194
+ tokens = metaJSONLexer.tokenise(content),
195
+ node = metaJSONParser.parse(tokens),
196
+ metaJSONNode = node; ///
197
+
198
+ return metaJSONNode;
199
+ }
200
+
201
+ function entriesFromRelativeDirectoryPath(entries, relativeDirectoryPath, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories) {
202
+ const absoluteDirectoryPath = concatenatePaths(projectsDirectoryPath, relativeDirectoryPath),
203
+ subEntryNames = readDirectory(absoluteDirectoryPath);
204
+
205
+ subEntryNames.forEach((subEntryName) => {
206
+ const subEntryNameHiddenName = isNameHiddenName(subEntryName),
207
+ subEntryNameNotHiddenName = !subEntryNameHiddenName,
208
+ loadHiddenFilesAndDirectories = !doNotLoadHiddenFilesAndDirectories,
209
+ loadUnrecognisedFilesAndDirectories = !loadOnlyRecognisedFiles;
210
+
211
+ if (subEntryNameNotHiddenName || loadHiddenFilesAndDirectories) {
212
+ const path = concatenatePaths(relativeDirectoryPath, subEntryName),
213
+ directory = loadDirectory(path, projectsDirectoryPath);
214
+
215
+ if (directory !== null) {
216
+ const directoryPath = path; ///
217
+
218
+ if (loadUnrecognisedFilesAndDirectories) {
219
+ entries.addDirectory(directory);
220
+ }
221
+
222
+ entriesFromRelativeDirectoryPath(entries, directoryPath, projectsDirectoryPath, loadOnlyRecognisedFiles, doNotLoadHiddenFilesAndDirectories); ///
223
+ } else {
224
+ const file = loadFile(path, projectsDirectoryPath);
225
+
226
+ if (file !== null) {
227
+ const filePath = file.getPath(),
228
+ filePathRecognisedFilePath = isFilePathRecognisedFilePath(filePath),
229
+ fileRecognisedFile = filePathRecognisedFilePath; ///
230
+
231
+ if (fileRecognisedFile || loadUnrecognisedFilesAndDirectories) {
232
+ entries.addFile(file);
233
+ }
234
+ }
235
+ }
236
+ }
237
+ });
238
+ }
239
+
240
+ function topmostFileNamesFromProjectsDirectoryPath(projectsDirectoryPath) {
241
+ let topmostFileNames;
242
+
243
+ const subEntryNames = readDirectory(projectsDirectoryPath);
244
+
245
+ topmostFileNames = subEntryNames.reduce((topmostFileNames, subEntryName) => {
246
+ const absoluteSubEntryPath = concatenatePaths(projectsDirectoryPath, subEntryName),
247
+ subEntryNameHiddenName = isNameHiddenName(subEntryName),
248
+ subEntryNameNotHiddenName = !subEntryNameHiddenName;
249
+
250
+ if (subEntryNameNotHiddenName) {
251
+ const subEntryFile = isEntryFile(absoluteSubEntryPath);
252
+
253
+ if (subEntryFile) {
254
+ const topmostFileName = subEntryName; ///
255
+
256
+ topmostFileNames.push(topmostFileName)
257
+ }
258
+ }
259
+
260
+ return topmostFileNames;
261
+ }, []);
262
+
263
+ return topmostFileNames;
264
+ }
265
+
95
266
  function topmostDirectoryNamesFromProjectsDirectoryPath(projectsDirectoryPath, doNotLoadHiddenFilesAndDirectories) {
96
267
  let topmostDirectoryNames;
97
268
 
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ import { isFilePathReadmeFilePath,
4
+ isFilePathFlorenceFilePath,
5
+ isFilePathMetaJSONFilePath,
6
+ isFilePathCustomGrammarBNFFilePath,
7
+ isFilePathCustomGrammarPatternFilePath } from "../utilities/filePath";
8
+
9
+ export function readmeFileFromFiles(files) {
10
+ let readmeFile = null;
11
+
12
+ files.someFile((file) => {
13
+ const filePath = file.getPath(),
14
+ filePathReadmeFilePath = isFilePathReadmeFilePath(filePath);
15
+
16
+ if (filePathReadmeFilePath) {
17
+ readmeFile = file; ///
18
+
19
+ return true;
20
+ }
21
+ });
22
+
23
+ return readmeFile;
24
+ }
25
+
26
+ export function metaJSONFileFromFiles(files) {
27
+ let metaJSONFile = null;
28
+
29
+ files.someFile((file) => {
30
+ const filePath = file.getPath(),
31
+ filePathMetaJSONFilePath = isFilePathMetaJSONFilePath(filePath);
32
+
33
+ if (filePathMetaJSONFilePath) {
34
+ metaJSONFile = file; ///
35
+
36
+ return true;
37
+ }
38
+ });
39
+
40
+ return metaJSONFile;
41
+ }
42
+
43
+ export function florenceFilesFromFiles(files) {
44
+ const florenceFiles = files.reduceFile((florenceFiles, file) => {
45
+ const filePath = file.getPath(),
46
+ filePathFlorenceFilePath = isFilePathFlorenceFilePath(filePath),
47
+ fileFlorenceFile = filePathFlorenceFilePath; ///
48
+
49
+ if (fileFlorenceFile) {
50
+ const florenceFile = file; ///
51
+
52
+ florenceFiles.push(florenceFile);
53
+ }
54
+
55
+ return florenceFiles;
56
+ }, []);
57
+
58
+ return florenceFiles;
59
+ }
60
+
61
+ export function customGrammarBNFFilesFromFiles(files) {
62
+ const customGrammarBNFFiles = files.reduceFile((customGrammarBNFFiles, file) => {
63
+ const filePath = file.getPath(),
64
+ filePathCustomGrammarBNFFilePath = isFilePathCustomGrammarBNFFilePath(filePath),
65
+ fileCustomGrammarBNFFile = filePathCustomGrammarBNFFilePath; ///
66
+
67
+ if (fileCustomGrammarBNFFile) {
68
+ const customGrammarBNFFile = file; ///
69
+
70
+ customGrammarBNFFiles.push(customGrammarBNFFile);
71
+ }
72
+
73
+ return customGrammarBNFFiles;
74
+ }, []);
75
+
76
+ return customGrammarBNFFiles;
77
+ }
78
+
79
+ export function customGrammarPatternFilesFromFiles(files) {
80
+ const customGrammarPatternFiles = files.reduceFile((customGrammarPatternFiles, file) => {
81
+ const filePath = file.getPath(),
82
+ filePathCustomGrammarPatternFilePath = isFilePathCustomGrammarPatternFilePath(filePath),
83
+ fileCustomGrammarPatternFile = filePathCustomGrammarPatternFilePath; ///
84
+
85
+ if (fileCustomGrammarPatternFile) {
86
+ const customGrammarPatternFile = file; ///
87
+
88
+ customGrammarPatternFiles.push(customGrammarPatternFile);
89
+ }
90
+
91
+ return customGrammarPatternFiles;
92
+ }, []);
93
+
94
+ return customGrammarPatternFiles;
95
+ }
96
+
97
+ export default {
98
+ readmeFileFromFiles,
99
+ metaJSONFileFromFiles,
100
+ florenceFilesFromFiles,
101
+ customGrammarBNFFilesFromFiles,
102
+ customGrammarPatternFilesFromFiles
103
+ };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ import Version from "../version";
4
+ import Dependency from "../dependency";
5
+ import ShortenedVersion from "../shortenedVersion";
6
+
7
+ import { trimDoubleQuotes } from "../utilities/content";
8
+ import { nodeQuery, nodesQuery } from "../utilities/query";
9
+
10
+ const dependencyNodesQuery = nodesQuery("//dependencies/dependency"),
11
+ repositoryTerminalNodeQuery = nodeQuery("//repository!/@*!"),
12
+ versionNumberTerminalNodeQuery = nodeQuery("//version!/versionNumber!/@*!"),
13
+ dependencyNameTerminalNodeQuery = nodeQuery("/dependency/name!/@*!"),
14
+ shortenedVersionNumberTerminalNodeQuery = nodeQuery("//dependency/shortenedVersionNumber/@*!");
15
+
16
+ export function versionFromNode(node) {
17
+ let version = null;
18
+
19
+ if (node !== null) {
20
+ const versionNumberTerminalNode = versionNumberTerminalNodeQuery(node),
21
+ versionNumberTerminalNodeContent = versionNumberTerminalNode.getContent(),
22
+ versionNumber = trimDoubleQuotes(versionNumberTerminalNodeContent); //
23
+
24
+ version = Version.fromVersionNumber(versionNumber);
25
+ }
26
+
27
+ return version;
28
+ }
29
+
30
+ export function repositoryFromNode(node) {
31
+ let repository = null;
32
+
33
+ if (node !== null) {
34
+ const repositoryTerminalNode = repositoryTerminalNodeQuery(node),
35
+ repositoryTerminalNodeContent = repositoryTerminalNode.getContent();
36
+
37
+ repository = trimDoubleQuotes(repositoryTerminalNodeContent); //
38
+ }
39
+
40
+ return repository;
41
+ }
42
+
43
+ export function dependenciesFromNode(node) {
44
+ const dependencies = [];
45
+
46
+ if (node !== null) {
47
+ const dependencyNodes = dependencyNodesQuery(node);
48
+
49
+ dependencyNodes.forEach((dependencyNode) => {
50
+ const dependencyNameTerminalNode = dependencyNameTerminalNodeQuery(dependencyNode),
51
+ shortenedVersionNumberTerminalNode = shortenedVersionNumberTerminalNodeQuery(dependencyNode),
52
+ dependencyNameTerminalNodeContent = dependencyNameTerminalNode.getContent(),
53
+ shortenedVersionNumberTerminalNodeContent = shortenedVersionNumberTerminalNode.getContent(),
54
+ string = trimDoubleQuotes(shortenedVersionNumberTerminalNodeContent), ///
55
+ name = trimDoubleQuotes(dependencyNameTerminalNodeContent),///
56
+ shortenedVersion = ShortenedVersion.fromString(string),
57
+ dependency = Dependency.fromNameAndShortenedVersion(name, shortenedVersion);
58
+
59
+ dependencies.push(dependency);
60
+ });
61
+ }
62
+
63
+ return dependencies;
64
+ }
65
+
66
+ export function dependencyNamesFromNode(node) {
67
+ const dependencies = this.dependenciesFromNode(node),
68
+ dependencyNames = dependencies.map((dependency) => {
69
+ const dependencyName = dependency.getName();
70
+
71
+ return dependencyName;
72
+ })
73
+
74
+ return dependencyNames;
75
+ }
76
+
77
+ export default {
78
+ versionFromNode,
79
+ repositoryFromNode,
80
+ dependenciesFromNode,
81
+ dependencyNamesFromNode
82
+ };
@@ -1,9 +1,26 @@
1
1
  "use strict";
2
2
 
3
+ import { pathUtilities } from "necessary";
4
+
3
5
  const hiddenNameRegularExpression = /^\..+/;
4
6
 
7
+ const { bottommostNameFromPath } = pathUtilities;
8
+
5
9
  export function isNameHiddenName(name) {
6
10
  const nameHiddenName = hiddenNameRegularExpression.test(name);
7
11
 
8
12
  return nameHiddenName;
9
13
  }
14
+
15
+ export function fileNameFromFilePath(filePath) {
16
+ const path = filePath, ///
17
+ bottommostName = bottommostNameFromPath(path),
18
+ fileName = bottommostName; //
19
+
20
+ return fileName;
21
+ }
22
+
23
+ export default {
24
+ isNameHiddenName,
25
+ fileNameFromFilePath
26
+ };