extwee 1.5.3 → 2.0.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.
Files changed (144) hide show
  1. package/.eslintrc.json +25 -0
  2. package/.github/workflows/nodejs.yml +24 -0
  3. package/.travis.yml +13 -0
  4. package/CODE_OF_CONDUCT.md +82 -0
  5. package/LICENSE +21 -21
  6. package/README.md +36 -203
  7. package/SECURITY.md +12 -0
  8. package/babel.config.json +22 -0
  9. package/bin/extwee.js +49 -0
  10. package/index.js +31 -26
  11. package/package.json +60 -39
  12. package/src/FileReader.js +33 -0
  13. package/src/HTMLParser.js +343 -0
  14. package/src/HTMLWriter.js +196 -0
  15. package/src/Passage.js +202 -0
  16. package/src/Story.js +461 -0
  17. package/src/StoryFormat.js +300 -0
  18. package/src/StoryFormatParser.js +142 -0
  19. package/src/TweeParser.js +166 -0
  20. package/src/TweeWriter.js +98 -0
  21. package/story-formats/chapbook-1.2.0/format.js +1 -0
  22. package/story-formats/chapbook-1.2.0/logo.svg +1 -0
  23. package/story-formats/harlowe-1.2.4/format.js +1 -0
  24. package/story-formats/harlowe-1.2.4/icon.svg +78 -0
  25. package/story-formats/harlowe-2.1.0/format.js +2 -0
  26. package/story-formats/harlowe-2.1.0/icon.svg +78 -0
  27. package/story-formats/harlowe-3.1.0/format.js +3 -0
  28. package/story-formats/harlowe-3.1.0/icon.svg +78 -0
  29. package/story-formats/paperthin-1.0.0/format.js +1 -0
  30. package/story-formats/paperthin-1.0.0/icon.svg +5 -0
  31. package/story-formats/snowman-1.4.0/format.js +1 -0
  32. package/story-formats/snowman-1.4.0/icon.svg +436 -0
  33. package/story-formats/snowman-2.0.2/format.js +1 -0
  34. package/story-formats/snowman-2.0.2/icon.svg +436 -0
  35. package/story-formats/sugarcube-1.0.35/LICENSE +23 -0
  36. package/story-formats/sugarcube-1.0.35/format.js +1 -0
  37. package/story-formats/sugarcube-1.0.35/icon.svg +56 -0
  38. package/story-formats/sugarcube-2.31.1/LICENSE +22 -0
  39. package/story-formats/sugarcube-2.31.1/format.js +1 -0
  40. package/story-formats/sugarcube-2.31.1/icon.svg +56 -0
  41. package/test/CLI/example6.twee +16 -0
  42. package/test/CLI/harlowe.js +3 -0
  43. package/test/CLI/input.html +47 -0
  44. package/test/CLI/test.twee +18 -0
  45. package/test/CLI/test2.html +47 -0
  46. package/test/CLI/tweeExample.twee +17 -0
  47. package/test/CLI/twineExample.html +15 -0
  48. package/test/CLI.test.js +30 -0
  49. package/test/FileReader/t1.txt +1 -0
  50. package/test/FileReader.test.js +14 -0
  51. package/test/HTMLParser/Example1.html +53 -0
  52. package/test/HTMLParser/Tags.html +15 -0
  53. package/test/HTMLParser/lyingStartnode.html +15 -0
  54. package/test/HTMLParser/lyingTagColors.html +48 -0
  55. package/test/HTMLParser/missingCreator.html +11 -0
  56. package/test/HTMLParser/missingCreatorVersion.html +11 -0
  57. package/test/HTMLParser/missingFormat.html +11 -0
  58. package/test/HTMLParser/missingFormatVersion.html +11 -0
  59. package/test/HTMLParser/missingIFID.html +11 -0
  60. package/test/HTMLParser/missingName.html +33 -0
  61. package/test/HTMLParser/missingPID.html +15 -0
  62. package/test/HTMLParser/missingPassageName.html +15 -0
  63. package/test/HTMLParser/missingPassageTags.html +15 -0
  64. package/test/HTMLParser/missingPosition.html +15 -0
  65. package/test/HTMLParser/missingScript.html +14 -0
  66. package/test/HTMLParser/missingSize.html +35 -0
  67. package/test/HTMLParser/missingStartnode.html +11 -0
  68. package/test/HTMLParser/missingStyle.html +14 -0
  69. package/test/HTMLParser/missingZoom.html +11 -0
  70. package/test/HTMLParser/tagColors.html +31 -0
  71. package/test/HTMLParser/twineExample.html +15 -0
  72. package/test/HTMLParser/twineExample2.html +15 -0
  73. package/test/HTMLParser/twineExample3.html +15 -0
  74. package/test/HTMLParser.test.js +177 -0
  75. package/test/HTMLWriter/TestTags.html +42 -0
  76. package/test/HTMLWriter/creator.html +51 -0
  77. package/test/HTMLWriter/example6.twee +16 -0
  78. package/test/HTMLWriter/missingStoryTitle.twee +29 -0
  79. package/test/HTMLWriter/test11.html +123 -0
  80. package/test/HTMLWriter/test2.html +59 -0
  81. package/test/HTMLWriter/test3.html +50 -0
  82. package/test/HTMLWriter/test4.html +51 -0
  83. package/test/HTMLWriter/test6.html +50 -0
  84. package/test/HTMLWriter.test.js +279 -0
  85. package/test/Passage.test.js +104 -0
  86. package/test/Roundtrip/Example1.html +64 -0
  87. package/test/Roundtrip/example1.twee +21 -0
  88. package/test/Roundtrip/example2.twee +18 -0
  89. package/test/Roundtrip/harlowe.js +3 -0
  90. package/test/Roundtrip/round.html +50 -0
  91. package/test/Roundtrip.test.js +48 -0
  92. package/test/Story/startmeta.twee +29 -0
  93. package/test/Story/test.twee +25 -0
  94. package/test/Story.test.js +282 -0
  95. package/test/StoryFormat.test.js +152 -0
  96. package/test/StoryFormatParser/example.js +3 -0
  97. package/test/StoryFormatParser/example2.js +3 -0
  98. package/test/StoryFormatParser/format.js +1 -0
  99. package/test/StoryFormatParser/format_doublename.js +1 -0
  100. package/test/StoryFormatParser/harlowe.js +3 -0
  101. package/test/StoryFormatParser/missingAuthor.js +1 -0
  102. package/test/StoryFormatParser/missingDescription.js +1 -0
  103. package/test/StoryFormatParser/missingImage.js +1 -0
  104. package/test/StoryFormatParser/missingLicense.js +1 -0
  105. package/test/StoryFormatParser/missingName.js +1 -0
  106. package/test/StoryFormatParser/missingProofing.js +1 -0
  107. package/test/StoryFormatParser/missingSource.js +1 -0
  108. package/test/StoryFormatParser/missingURL.js +1 -0
  109. package/test/StoryFormatParser/missingVersion.js +1 -0
  110. package/test/StoryFormatParser/versionWrong.js +1 -0
  111. package/test/StoryFormatParser.test.js +91 -0
  112. package/test/TweeParser/emptytags.twee +2 -0
  113. package/test/TweeParser/example.twee +32 -0
  114. package/test/TweeParser/missing.twee +19 -0
  115. package/test/TweeParser/multipleScriptPassages.twee +19 -0
  116. package/test/TweeParser/multipleStyleTag.twee +19 -0
  117. package/test/TweeParser/multipletags.twee +10 -0
  118. package/test/TweeParser/noTitle.twee +2 -0
  119. package/test/TweeParser/notes.twee +16 -0
  120. package/test/TweeParser/pasagemetadataerror.twee +2 -0
  121. package/test/TweeParser/scriptPassage.twee +16 -0
  122. package/test/TweeParser/singletag.twee +13 -0
  123. package/test/TweeParser/startMetadata.twee +14 -0
  124. package/test/TweeParser/storydataerror.twee +25 -0
  125. package/test/TweeParser/stylePassage.twee +16 -0
  126. package/test/TweeParser/test.twee +25 -0
  127. package/test/TweeParser.test.js +79 -0
  128. package/test/TweeWriter/test1.twee +18 -0
  129. package/test/TweeWriter/test3.twee +12 -0
  130. package/test/TweeWriter/test4.twee +14 -0
  131. package/test/TweeWriter/test5.twee +20 -0
  132. package/test/TweeWriter.test.js +82 -0
  133. package/DirectoryReader.js +0 -128
  134. package/DirectoryWatcher.js +0 -63
  135. package/FileReader.js +0 -36
  136. package/HTMLParser.js +0 -206
  137. package/HTMLWriter.js +0 -177
  138. package/Passage.js +0 -20
  139. package/Story.js +0 -148
  140. package/StoryFormat.js +0 -41
  141. package/StoryFormatParser.js +0 -65
  142. package/TweeParser.js +0 -255
  143. package/TweeWriter.js +0 -111
  144. package/main.js +0 -103
@@ -0,0 +1,16 @@
1
+ /**
2
+ These are some notes at the top of the file
3
+ */
4
+ :: StoryTitle
5
+ twineExample
6
+
7
+ :: Start {"position":"102,104","size":"100,100"}
8
+ Start passage
9
+
10
+ :: StoryData
11
+ {
12
+ "ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
13
+ "format": "Harlowe",
14
+ "formatVersion": "2.1.0",
15
+ "zoom": "1"
16
+ }
@@ -0,0 +1,2 @@
1
+ :: Start {"position}
2
+ Some content
@@ -0,0 +1,16 @@
1
+ :: Start
2
+ Content
3
+
4
+ :: StoryTitle
5
+ Title
6
+
7
+ :: UserScript [script]
8
+ window.example = {}
9
+
10
+ :: StoryData
11
+ {
12
+ "ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
13
+ "format": "Harlowe",
14
+ "formatVersion": "2.1.0",
15
+ "zoom": "1"
16
+ }
@@ -0,0 +1,13 @@
1
+ :: Start [tag]
2
+ Content
3
+
4
+ :: StoryTitle
5
+ Title
6
+
7
+ :: StoryData
8
+ {
9
+ "ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
10
+ "format": "Harlowe",
11
+ "formatVersion": "2.1.0",
12
+ "zoom": "1"
13
+ }
@@ -0,0 +1,14 @@
1
+ :: StoryTitle
2
+ Example
3
+
4
+ :: StoryData
5
+ {
6
+ "ifid": "A74F654F-3F85-44DE-8A87-9845AECD04B0",
7
+ "format": "Harlowe",
8
+ "formatVersion": "3.2.1",
9
+ "zoom": "1",
10
+ "start": "Untitled Passage"
11
+ }
12
+
13
+ :: Untitled Passage {"position":"100,99","size":"100,100"}
14
+ Double-click this passage to edit it.
@@ -0,0 +1,25 @@
1
+ :: StoryTitle
2
+ twineExample
3
+
4
+ :: Start
5
+ Some content.
6
+
7
+ :: StoryData
8
+ {
9
+ "ifid": 2B68ECD6-348F-4CF5-96F8-549A512A8128",
10
+ "format": "Harlowe",
11
+ "formatVersion": "2.1.0",
12
+ "zoom": "1"
13
+ }
14
+
15
+ :: Script1 [script]
16
+ // Some code
17
+
18
+ :: Script2 [script]
19
+ //More code here!
20
+
21
+ :: Style1 [stylesheet]
22
+ body {font-size: 1.2em}
23
+
24
+ :: Style2 [stylesheet]
25
+ p {font-style: italic;}
@@ -0,0 +1,16 @@
1
+ :: Start
2
+ Content
3
+
4
+ :: StoryTitle
5
+ Title
6
+
7
+ :: UserStylesheet [stylesheet]
8
+ 1
9
+
10
+ :: StoryData
11
+ {
12
+ "ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
13
+ "format": "Harlowe",
14
+ "formatVersion": "2.1.0",
15
+ "zoom": "1"
16
+ }
@@ -0,0 +1,25 @@
1
+ :: StoryTitle
2
+ twineExample
3
+
4
+ :: Start
5
+ Some content.
6
+
7
+ :: StoryData
8
+ {
9
+ "ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
10
+ "format": "Harlowe",
11
+ "formatVersion": "2.1.0",
12
+ "zoom": "1"
13
+ }
14
+
15
+ :: Script1 [script]
16
+ // Some code
17
+
18
+ :: Script2 [script]
19
+ //More code here!
20
+
21
+ :: Style1 [stylesheet]
22
+ body {font-size: 1.2em}
23
+
24
+ :: Style2 [stylesheet]
25
+ p {font-style: italic;}
@@ -0,0 +1,79 @@
1
+ import FileReader from '../src/FileReader.js';
2
+ import TweeParser from '../src/TweeParser.js';
3
+
4
+ describe('TweeParser', function () {
5
+ describe('#parse()', function () {
6
+ test('Should throw error if non-string is used', function () {
7
+ expect(() => { TweeParser.parse(1); }).toThrow();
8
+ });
9
+
10
+ test('Should throw error if empty string is used', function () {
11
+ expect(() => { TweeParser.parse(); }).toThrow();
12
+ });
13
+
14
+ test('Should throw error if no passages are present', function () {
15
+ expect(() => { TweeParser.parse('()()'); }).toThrow();
16
+ });
17
+
18
+ test('Should throw error if it detects malformed passage headers', function () {
19
+ expect(() => { TweeParser.parse('::{}[]\nNo name'); }).toThrow();
20
+ });
21
+
22
+ test('Should cut notes before passages', function () {
23
+ const fr = FileReader.read('test/TweeParser/notes.twee');
24
+ const story = TweeParser.parse(fr);
25
+ const p = story.getPassageByName('StoryTitle');
26
+ expect(p.text).toBe('twineExample');
27
+ });
28
+
29
+ test('Should be able to parse Twee file for Story Name', function () {
30
+ const fr = FileReader.read('test/TweeParser/example.twee');
31
+ const story = TweeParser.parse(fr);
32
+ const p = story.getPassageByName('StoryTitle');
33
+ expect(p.text).toBe('twineExample');
34
+ });
35
+
36
+ test('Should parse single tag on Start passage', function () {
37
+ const fr = FileReader.read('test/TweeParser/singletag.twee');
38
+ const story = TweeParser.parse(fr);
39
+ const start = story.getPassageByName('Start');
40
+ expect(start.tags).toHaveLength(1);
41
+ });
42
+
43
+ test('Should parse multiple tag', function () {
44
+ const fr = FileReader.read('test/TweeParser/multipletags.twee');
45
+ const story = TweeParser.parse(fr);
46
+ const start = story.getPassageByName('Start');
47
+ expect(start.tags).toHaveLength(2);
48
+ });
49
+
50
+ test('Should parse single script passage', function () {
51
+ const fr = FileReader.read('test/TweeParser/scriptPassage.twee');
52
+ const story = TweeParser.parse(fr);
53
+ const p = story.getPassageByName('UserScript');
54
+ expect(p.tags).toHaveLength(1);
55
+ });
56
+
57
+ test('Should parse single stylesheet passage', function () {
58
+ const fr = FileReader.read('test/TweeParser/stylePassage.twee');
59
+ const story = TweeParser.parse(fr);
60
+ const p = story.getPassageByName('UserStylesheet');
61
+ expect(p.tags).toHaveLength(1);
62
+ expect(p.name).toBe('UserStylesheet');
63
+ });
64
+
65
+ test('Should parse StoryTitle', function () {
66
+ const fr = FileReader.read('test/TweeParser/test.twee');
67
+ const story = TweeParser.parse(fr);
68
+ const p = story.getPassageByName('StoryTitle');
69
+ expect(p).not.toBe(null);
70
+ });
71
+
72
+ test('Should parse StoryAuthor', function () {
73
+ const fr = FileReader.read('test/TweeParser/example.twee');
74
+ const story = TweeParser.parse(fr);
75
+ const p = story.getPassageByName('StoryAuthor');
76
+ expect(p).not.toBe(null);
77
+ });
78
+ });
79
+ });
@@ -0,0 +1,18 @@
1
+ :: StoryData
2
+ {
3
+ "ifid": "DD03696D-5967-4E01-A955-885CDFEA2FE1",
4
+ "format": "Test",
5
+ "format-version": "1.2.3",
6
+ "zoom": 1,
7
+ "start": "Untitled"
8
+ }
9
+
10
+ :: StoryTitle
11
+ Title
12
+
13
+ :: Start
14
+ Content
15
+
16
+ :: Untitled
17
+ Some stuff
18
+
@@ -0,0 +1,12 @@
1
+ :: StoryData
2
+ {
3
+ "ifid": "DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A",
4
+ "start": "Start"
5
+ }
6
+
7
+ :: Start [tag tags]
8
+
9
+
10
+ :: StoryTitle
11
+ Title
12
+
@@ -0,0 +1,14 @@
1
+ :: StoryData
2
+ {
3
+ "ifid": "D5D54A73-4E5F-4186-9276-EBDE28110006"
4
+ }
5
+
6
+ :: StoryTitle
7
+ Title
8
+
9
+ :: Start
10
+ Content
11
+
12
+ :: Untitled
13
+ Some stuff
14
+
@@ -0,0 +1,20 @@
1
+ :: StoryData
2
+ {
3
+ "ifid": "FFA1527D-3700-4697-BCD1-386E4A6AE902",
4
+ "start": "Start",
5
+ "tag-colors": {
6
+ "bar": "green",
7
+ "foo": "red",
8
+ "qaz": "blue"
9
+ }
10
+ }
11
+
12
+ :: StoryTitle
13
+ Title
14
+
15
+ :: Start
16
+ Content
17
+
18
+ :: Untitled
19
+ Some stuff
20
+
@@ -0,0 +1,82 @@
1
+ import FileReader from '../src/FileReader.js';
2
+ import Story from '../src/Story.js';
3
+ import Passage from '../src/Passage.js';
4
+ import TweeWriter from '../src/TweeWriter.js';
5
+ import TweeParser from '../src/TweeParser.js';
6
+
7
+ describe('TweeWriter', function () {
8
+ describe('#write()', function () {
9
+ test('Should throw error if object passed is not instanceof Story', function () {
10
+ expect(() => { TweeWriter.write({}); }).toThrow();
11
+ });
12
+
13
+ test('Should throw error if output file invalid', function () {
14
+ expect(() => { TweeWriter.write(new Story(), ''); }).toThrow();
15
+ });
16
+
17
+ test('Should write Twee file', function () {
18
+ const s = new Story();
19
+ s.addPassage(new Passage('StoryData', '{}'));
20
+ s.addPassage(new Passage('StoryTitle', 'Title'));
21
+ s.addPassage(new Passage('Start', 'Content'));
22
+ TweeWriter.write(s, 'test/TweeWriter/test1.twee');
23
+ const fr = FileReader.read('test/TweeWriter/test1.twee');
24
+ const story = TweeParser.parse(fr);
25
+ const p = story.getPassageByName('StoryTitle');
26
+ expect(p.text).toBe('Title');
27
+ });
28
+
29
+ test('Should correctly write Twee file with passage tags', function () {
30
+ const s = new Story();
31
+ s.addPassage(new Passage('Start', '', ['tag', 'tags']));
32
+ s.addPassage(new Passage('StoryTitle', 'Title'));
33
+ // Verify only one passage.
34
+ expect(s.size()).toBe(2);
35
+
36
+ // Set an ifid property
37
+ s.IFID = 'DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A';
38
+
39
+ // Write contents to file.
40
+ TweeWriter.write(s, 'test/TweeWriter/test3.twee');
41
+ // Read file.
42
+ const fr = FileReader.read('test/TweeWriter/test3.twee');
43
+ // Parse file.
44
+ const tp = TweeParser.parse(fr);
45
+ // Verify only two passages
46
+ expect(tp.size()).toBe(2);
47
+ });
48
+
49
+ test('Should write format, formatVersion, zoom, and start', function () {
50
+ const s = new Story();
51
+ s.addPassage(new Passage('StoryTitle', 'Title'));
52
+ s.addPassage(new Passage('Start', 'Content'));
53
+ s.addPassage(new Passage('Untitled', 'Some stuff'));
54
+
55
+ s.format = 'Test';
56
+ s.formatVersion = '1.2.3';
57
+ s.zoom = 1;
58
+ s.start = 'Untitled';
59
+
60
+ TweeWriter.write(s, 'test/TweeWriter/test1.twee');
61
+ const fr = FileReader.read('test/TweeWriter/test1.twee');
62
+ const story2 = TweeParser.parse(fr);
63
+ expect(story2.format).toBe('Test');
64
+ });
65
+
66
+ test('Should write tag colors', function () {
67
+ const s = new Story();
68
+ s.addPassage(new Passage('StoryTitle', 'Title'));
69
+ s.addPassage(new Passage('Start', 'Content'));
70
+ s.addPassage(new Passage('Untitled', 'Some stuff'));
71
+ s.tagColors = {
72
+ bar: 'green',
73
+ foo: 'red',
74
+ qaz: 'blue'
75
+ };
76
+ TweeWriter.write(s, 'test/TweeWriter/test5.twee');
77
+ const fr = FileReader.read('test/TweeWriter/test5.twee');
78
+ const story2 = TweeParser.parse(fr);
79
+ expect(story2.tagColors.bar).toBe('green');
80
+ });
81
+ });
82
+ });
@@ -1,128 +0,0 @@
1
- const fs = require("fs");
2
- const FileReader = require('./FileReader.js');
3
- const shell = require('shelljs');
4
- // Tell shelljs to be quiet about warnings
5
- shell.config.silent = true;
6
- const UglifyJS = require('uglify-js');
7
- const CleanCSS = require('clean-css');
8
- const babel = require("@babel/core");
9
-
10
- /**
11
- * @class DirectoryReader
12
- * @module DirectoryReader
13
- */
14
- class DirectoryReader {
15
- /**
16
- * @method DirectoryReader
17
- * @constructor
18
- */
19
- constructor (directory) {
20
-
21
- try {
22
-
23
- this.directory = fs.realpathSync(directory);
24
-
25
- } catch(event) {
26
-
27
- throw new Error("Error: Cannot resolve to real path!");
28
-
29
- }
30
-
31
- this.CSScontents = "";
32
- this.JScontents = "";
33
- this.tweeContents = "";
34
-
35
- // Read the directory
36
- this.update();
37
-
38
- }
39
-
40
- update() {
41
-
42
- // Reset
43
- this.CSScontents = this.JScontents = this.tweeContents = "";
44
-
45
- // Look for CSS files
46
- this.CSScontents += this.processCSS();
47
- // Look for JS files
48
- this.JScontents += this.processJS();
49
- // Look for Twee files
50
- this.tweeContents += this.processTwee();
51
-
52
- }
53
-
54
- processJS() {
55
-
56
- let fileContents = "";
57
-
58
- console.info("Processing JS files...");
59
- shell.ls('-R', this.directory + '/**/*.js').forEach(function (value) {
60
- console.info(" Loading " + value);
61
- const file = new FileReader(value);
62
-
63
- let babelResult = {
64
- code: ""
65
- };
66
-
67
- try {
68
-
69
- babelResult = babel.transformSync(file.contents, {
70
- "presets": ["@babel/preset-env"],
71
- });
72
-
73
- } catch(event) {
74
-
75
- console.info("Error Babel processing " + value + ". Skipping contents.");
76
-
77
- }
78
-
79
- let uglyResult = UglifyJS.minify(babelResult.code);
80
-
81
- fileContents += uglyResult.code;
82
-
83
- });
84
-
85
- return fileContents;
86
-
87
- }
88
-
89
- processCSS() {
90
-
91
- let fileContents = "";
92
-
93
- console.info("Processing CSS files...");
94
- shell.ls('-R', this.directory + '/**/*.css').forEach(function (value) {
95
- console.info(" Loading " + value);
96
- const file = new FileReader(value);
97
- fileContents += file.contents;
98
- });
99
-
100
- const output = new CleanCSS({level: 2}).minify(fileContents);
101
- return output.styles;
102
-
103
- }
104
-
105
- processTwee() {
106
-
107
- let fileType = ["tw", "tw2", "twee", "twee2", "tw3", "twee3"];
108
-
109
- let fileContents = "";
110
-
111
- console.info("Processing Twee files...");
112
- for(let i = 0; i < fileType.length; i++) {
113
-
114
- shell.ls('-R', this.directory + '/**/*.' + fileType[i]).forEach(function (value) {
115
- const file = new FileReader(value);
116
- console.info(" Loading " + value);
117
- fileContents += file.contents;
118
- });
119
-
120
- }
121
-
122
- return fileContents;
123
-
124
- }
125
-
126
- }
127
-
128
- module.exports = DirectoryReader;
@@ -1,63 +0,0 @@
1
- const fs = require("fs");
2
- const FileReader = require('./FileReader.js');
3
- const chokidar = require('chokidar');
4
-
5
- /**
6
- * @class DirectoryWatcher
7
- * @module DirectoryWatcher
8
- */
9
- class DirectoryWatcher {
10
- /**
11
- * @method DirectoryWatcher
12
- * @constructor
13
- */
14
- constructor (directory, callback) {
15
-
16
- this.directory = directory;
17
- this.watcher = null;
18
- this.callback = callback;
19
-
20
- // Test if callback is a function or not
21
- if( !(this.callback instanceof Function) ) {
22
-
23
- throw new Error("Error: Expected function!");
24
-
25
- }
26
-
27
- try {
28
-
29
- this.directory = fs.realpathSync(this.directory);
30
-
31
- } catch(event) {
32
-
33
- throw new Error("Error: Directory does not exist!");
34
-
35
- }
36
-
37
- console.info("Watching " + this.directory + " for changes.");
38
- console.info("Press CTRL+C to stop.");
39
-
40
- // Setup the Chokidar watcher
41
- this.watcher = chokidar.watch(this.directory, {
42
- ignored: /.html/,
43
- persistent: true,
44
- ignoreInitial: false
45
- });
46
-
47
- // Catch change events
48
- this.watcher.on('change', (path) => {
49
- console.info("Change detected on " + path);
50
- callback();
51
- });
52
-
53
- // Catch add events
54
- this.watcher.on('add', (path) => {
55
- console.info("Addition detected on " + path);
56
- callback();
57
- });
58
-
59
- }
60
-
61
- }
62
-
63
- module.exports = DirectoryWatcher;
package/FileReader.js DELETED
@@ -1,36 +0,0 @@
1
- const fs = require("fs");
2
- const path = require('path');
3
- /**
4
- * @class FileReader
5
- * @module FileReader
6
- */
7
- class FileReader {
8
- /**
9
- * @method FileReader
10
- * @constructor
11
- */
12
- constructor (file) {
13
-
14
- this.contents = "";
15
- this.readFile(file);
16
- }
17
-
18
- readFile(file) {
19
-
20
- // Attempt to find the file
21
- if(fs.existsSync(file) ) {
22
-
23
- // The file exists.
24
- this.contents = fs.readFileSync(file, 'utf8');
25
-
26
- } else {
27
-
28
- throw new Error("Error: File not found!");
29
-
30
- }
31
-
32
- }
33
-
34
- }
35
-
36
- module.exports = FileReader;