extwee 1.6.0 → 2.0.2
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/.eslintrc.json +25 -0
- package/.github/workflows/nodejs.yml +24 -25
- package/.travis.yml +13 -13
- package/CODE_OF_CONDUCT.md +82 -0
- package/LICENSE +21 -21
- package/README.md +36 -205
- package/SECURITY.md +12 -0
- package/babel.config.json +22 -0
- package/bin/extwee.js +49 -0
- package/index.js +31 -26
- package/package.json +59 -37
- package/src/FileReader.js +33 -36
- package/src/HTMLParser.js +343 -206
- package/src/HTMLWriter.js +227 -177
- package/src/Passage.js +202 -20
- package/src/Story.js +461 -148
- package/src/StoryFormat.js +300 -41
- package/src/StoryFormatParser.js +142 -65
- package/src/TweeParser.js +161 -255
- package/src/TweeWriter.js +98 -111
- package/story-formats/chapbook-1.2.0/format.js +1 -0
- package/story-formats/chapbook-1.2.0/logo.svg +1 -0
- package/story-formats/harlowe-1.2.4/format.js +1 -0
- package/story-formats/harlowe-1.2.4/icon.svg +78 -0
- package/story-formats/harlowe-2.1.0/format.js +2 -0
- package/story-formats/harlowe-2.1.0/icon.svg +78 -0
- package/story-formats/harlowe-3.1.0/format.js +3 -0
- package/story-formats/harlowe-3.1.0/icon.svg +78 -0
- package/story-formats/paperthin-1.0.0/format.js +1 -0
- package/story-formats/paperthin-1.0.0/icon.svg +5 -0
- package/story-formats/snowman-1.4.0/format.js +1 -0
- package/story-formats/snowman-1.4.0/icon.svg +436 -0
- package/story-formats/snowman-2.0.2/format.js +1 -0
- package/story-formats/snowman-2.0.2/icon.svg +436 -0
- package/story-formats/sugarcube-1.0.35/LICENSE +23 -0
- package/story-formats/sugarcube-1.0.35/format.js +1 -0
- package/story-formats/sugarcube-1.0.35/icon.svg +56 -0
- package/story-formats/sugarcube-2.31.1/LICENSE +22 -0
- package/story-formats/sugarcube-2.31.1/format.js +1 -0
- package/story-formats/sugarcube-2.31.1/icon.svg +56 -0
- package/test/{HTMLWriter/example7.twee → CLI/example6.twee} +16 -16
- package/test/CLI/harlowe.js +3 -0
- package/test/CLI/input.html +47 -0
- package/test/CLI/test.twee +18 -0
- package/test/CLI/test2.html +47 -0
- package/test/CLI/tweeExample.twee +17 -0
- package/test/CLI/twineExample.html +15 -0
- package/test/CLI.test.js +30 -0
- package/test/FileReader.test.js +14 -0
- package/test/HTMLParser/Example1.html +53 -0
- package/test/HTMLParser/Tags.html +15 -0
- package/test/HTMLParser/lyingStartnode.html +15 -0
- package/test/HTMLParser/lyingTagColors.html +48 -0
- package/test/HTMLParser/missingCreator.html +11 -0
- package/test/HTMLParser/missingCreatorVersion.html +11 -0
- package/test/HTMLParser/missingFormat.html +11 -0
- package/test/HTMLParser/missingFormatVersion.html +11 -0
- package/test/HTMLParser/missingIFID.html +11 -0
- package/test/HTMLParser/missingName.html +33 -0
- package/test/HTMLParser/missingPID.html +15 -0
- package/test/HTMLParser/missingPassageName.html +15 -0
- package/test/HTMLParser/missingPassageTags.html +15 -0
- package/test/HTMLParser/missingPosition.html +15 -0
- package/test/HTMLParser/missingScript.html +14 -0
- package/test/HTMLParser/missingSize.html +35 -0
- package/test/HTMLParser/missingStartnode.html +11 -0
- package/test/HTMLParser/missingStyle.html +14 -0
- package/test/HTMLParser/missingZoom.html +11 -0
- package/test/HTMLParser/tagColors.html +31 -0
- package/test/HTMLParser/twineExample.html +15 -46
- package/test/HTMLParser/twineExample2.html +15 -0
- package/test/HTMLParser/twineExample3.html +15 -0
- package/test/HTMLParser.test.js +177 -0
- package/test/HTMLWriter/TestTags.html +42 -0
- package/test/HTMLWriter/{test10.html → creator.html} +8 -5
- package/test/HTMLWriter/example6.twee +16 -16
- package/test/HTMLWriter/{example.twee → missingStoryTitle.twee} +29 -29
- package/test/HTMLWriter/test11.html +123 -0
- package/test/HTMLWriter/test2.html +15 -12
- package/test/HTMLWriter/test3.html +7 -13
- package/test/HTMLWriter/test4.html +8 -5
- package/test/HTMLWriter/test6.html +7 -5
- package/test/HTMLWriter.test.js +289 -0
- package/test/Passage.test.js +104 -0
- package/test/Roundtrip/Example1.html +64 -0
- package/test/Roundtrip/example1.twee +21 -0
- package/test/Roundtrip/example2.twee +18 -0
- package/test/Roundtrip/harlowe.js +3 -0
- package/test/Roundtrip/round.html +50 -0
- package/test/Roundtrip.test.js +48 -0
- package/test/Story/startmeta.twee +29 -29
- package/test/Story/test.twee +25 -25
- package/test/Story.test.js +282 -0
- package/test/StoryFormat.test.js +152 -0
- package/test/StoryFormatParser/example.js +3 -0
- package/test/StoryFormatParser/{test2.js → example2.js} +3 -3
- package/test/StoryFormatParser/format_doublename.js +1 -0
- package/test/StoryFormatParser/harlowe.js +2 -2
- package/test/StoryFormatParser/missingAuthor.js +1 -0
- package/test/StoryFormatParser/missingDescription.js +1 -0
- package/test/StoryFormatParser/missingImage.js +1 -0
- package/test/StoryFormatParser/missingLicense.js +1 -0
- package/test/StoryFormatParser/missingName.js +1 -0
- package/test/StoryFormatParser/missingProofing.js +1 -0
- package/test/StoryFormatParser/missingSource.js +1 -0
- package/test/StoryFormatParser/missingURL.js +1 -0
- package/test/StoryFormatParser/missingVersion.js +1 -0
- package/test/StoryFormatParser/versionWrong.js +1 -0
- package/test/StoryFormatParser.test.js +91 -0
- package/test/TweeParser/emptytags.twee +2 -2
- package/test/TweeParser/example.twee +32 -29
- package/test/TweeParser/missing.twee +19 -0
- package/test/{HTMLWriter/example5.twee → TweeParser/multipleScriptPassages.twee} +19 -13
- package/test/{HTMLWriter/example4.twee → TweeParser/multipleStyleTag.twee} +19 -13
- package/test/TweeParser/multipletags.twee +10 -2
- package/test/TweeParser/noTitle.twee +2 -0
- package/test/TweeParser/notes.twee +16 -0
- package/test/TweeParser/pasagemetadataerror.twee +2 -2
- package/test/{HTMLWriter/example2.twee → TweeParser/scriptPassage.twee} +16 -13
- package/test/TweeParser/singletag.twee +13 -2
- package/test/TweeParser/startMetadata.twee +14 -0
- package/test/TweeParser/storydataerror.twee +25 -25
- package/test/{HTMLWriter/example3.twee → TweeParser/stylePassage.twee} +16 -13
- package/test/TweeParser/test.twee +25 -25
- package/test/TweeParser.test.js +79 -0
- package/test/TweeWriter/test1.twee +14 -9
- package/test/TweeWriter/test3.twee +7 -10
- package/test/TweeWriter/test4.twee +14 -0
- package/test/TweeWriter/test5.twee +20 -0
- package/test/TweeWriter.test.js +85 -0
- package/main.js +0 -106
- package/src/DirectoryReader.js +0 -107
- package/src/DirectoryWatcher.js +0 -92
- package/test/DirectoryReader/css/test.css +0 -3
- package/test/DirectoryReader1/js/Site.js +0 -1
- package/test/DirectoryReader2/error.js +0 -1
- package/test/DirectoryReader2/example.css +0 -3
- package/test/DirectoryReader2/index.twee +0 -6
- package/test/DirectoryReader3/twee/index.twee +0 -6
- package/test/DirectoryWatcher/example.txt +0 -0
- package/test/DirectoryWatcher/test.txt +0 -0
- package/test/DirectoryWatcher/test1.txt +0 -0
- package/test/HTMLWriter/test5.html +0 -48
- package/test/HTMLWriter/test7.html +0 -48
- package/test/HTMLWriter/test8.html +0 -48
- package/test/HTMLWriter/test9.html +0 -48
- package/test/StoryFormatParser/test.js +0 -2
- package/test/TweeParser/test.twee3 +0 -11
- package/test/TweeWriter/metatest.twee +0 -12
- package/test/TweeWriter/test2.twee +0 -15
- package/test/test.js +0 -722
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserScript [script]
|
|
8
|
+
1
|
|
9
|
+
|
|
10
|
+
:: UserScript2 [script]
|
|
11
|
+
2
|
|
12
|
+
|
|
13
|
+
:: StoryData
|
|
14
|
+
{
|
|
15
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
16
|
+
"format": "Harlowe",
|
|
17
|
+
"formatVersion": "2.1.0",
|
|
18
|
+
"zoom": "1"
|
|
19
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
:: Start
|
|
2
|
+
Content
|
|
3
|
+
|
|
4
|
+
:: StoryTitle
|
|
5
|
+
Title
|
|
6
|
+
|
|
7
|
+
:: UserStylesheet1 [stylesheet]
|
|
8
|
+
1
|
|
9
|
+
|
|
10
|
+
:: UserStylesheet2 [stylesheet]
|
|
11
|
+
2
|
|
12
|
+
|
|
13
|
+
:: StoryData
|
|
14
|
+
{
|
|
15
|
+
"ifid": "2B68ECD6-348F-4CF5-96F8-549A512A8128",
|
|
16
|
+
"format": "Harlowe",
|
|
17
|
+
"formatVersion": "2.1.0",
|
|
18
|
+
"zoom": "1"
|
|
19
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
:: Start {"position}
|
|
2
|
-
Some content
|
|
1
|
+
:: Start {"position}
|
|
2
|
+
Some content
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
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,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.
|
|
@@ -1,25 +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;}
|
|
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;}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
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
|
+
}
|
|
@@ -1,25 +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;}
|
|
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', () => {
|
|
5
|
+
describe('#parse()', () => {
|
|
6
|
+
it('Should throw error if non-string is used', () => {
|
|
7
|
+
expect(() => { TweeParser.parse(1); }).toThrow();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('Should throw error if empty string is used', () => {
|
|
11
|
+
expect(() => { TweeParser.parse(); }).toThrow();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('Should throw error if no passages are present', () => {
|
|
15
|
+
expect(() => { TweeParser.parse('()()'); }).toThrow();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Should throw error if it detects malformed passage headers', () => {
|
|
19
|
+
expect(() => { TweeParser.parse('::{}[]\nNo name'); }).toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Should cut notes before passages', () => {
|
|
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
|
+
it('Should be able to parse Twee file for Story Name', () => {
|
|
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
|
+
it('Should parse single tag on Start passage', () => {
|
|
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
|
+
it('Should parse multiple tag', () => {
|
|
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
|
+
it('Should parse single script passage', () => {
|
|
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
|
+
it('Should parse single stylesheet passage', () => {
|
|
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
|
+
it('Should parse StoryTitle', () => {
|
|
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
|
+
it('Should parse StoryAuthor', () => {
|
|
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
|
+
});
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
Unknown
|
|
3
|
-
|
|
4
1
|
:: StoryData
|
|
5
|
-
|
|
6
|
-
"ifid": "",
|
|
7
|
-
"format": "",
|
|
8
|
-
"
|
|
9
|
-
"zoom":
|
|
10
|
-
"start": ""
|
|
2
|
+
{
|
|
3
|
+
"ifid": "2FD7F838-1F14-40A9-BF9B-C40CFE9698F1",
|
|
4
|
+
"format": "Test",
|
|
5
|
+
"format-version": "1.2.3",
|
|
6
|
+
"zoom": 1,
|
|
7
|
+
"start": "Untitled"
|
|
11
8
|
}
|
|
12
9
|
|
|
10
|
+
:: StoryTitle
|
|
11
|
+
Title
|
|
12
|
+
|
|
13
13
|
:: Start
|
|
14
|
+
Content
|
|
15
|
+
|
|
16
|
+
:: Untitled
|
|
17
|
+
Some stuff
|
|
18
|
+
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
:: StoryTitle
|
|
2
|
-
TweeWriter
|
|
3
|
-
|
|
4
1
|
:: StoryData
|
|
5
|
-
|
|
6
|
-
"ifid": "",
|
|
7
|
-
"
|
|
8
|
-
"formatVersion": "",
|
|
9
|
-
"zoom": "",
|
|
10
|
-
"start": ""
|
|
2
|
+
{
|
|
3
|
+
"ifid": "DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A",
|
|
4
|
+
"start": "Start"
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
:: Start [
|
|
7
|
+
:: Start [tag tags]
|
|
14
8
|
|
|
15
9
|
|
|
10
|
+
:: StoryTitle
|
|
11
|
+
Title
|
|
12
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
:: StoryData
|
|
2
|
+
{
|
|
3
|
+
"ifid": "ED4FC315-6691-46D6-A217-063773B54E74",
|
|
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,85 @@
|
|
|
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', () => {
|
|
8
|
+
describe('#write()', () => {
|
|
9
|
+
let s = null;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
s = new Story();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('Should throw error if object passed is not instanceof Story', () => {
|
|
16
|
+
expect(() => { TweeWriter.write({}); }).toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Should throw error if output file invalid', () => {
|
|
20
|
+
expect(() => { TweeWriter.write(new Story(), ''); }).toThrow();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('Should write Twee file', () => {
|
|
24
|
+
s.addPassage(new Passage('StoryData', '{}'));
|
|
25
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
26
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
27
|
+
TweeWriter.write(s, 'test/TweeWriter/test1.twee');
|
|
28
|
+
const fr = FileReader.read('test/TweeWriter/test1.twee');
|
|
29
|
+
const story = TweeParser.parse(fr);
|
|
30
|
+
const p = story.getPassageByName('StoryTitle');
|
|
31
|
+
expect(p.text).toBe('Title');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Should correctly write Twee file with passage tags', () => {
|
|
35
|
+
s.addPassage(new Passage('Start', '', ['tag', 'tags']));
|
|
36
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
37
|
+
// Verify only one passage.
|
|
38
|
+
expect(s.size()).toBe(2);
|
|
39
|
+
|
|
40
|
+
// Set an ifid property
|
|
41
|
+
s.IFID = 'DE7DF8AD-E4CD-499E-A4E7-C5B98B73449A';
|
|
42
|
+
|
|
43
|
+
// Write contents to file.
|
|
44
|
+
TweeWriter.write(s, 'test/TweeWriter/test3.twee');
|
|
45
|
+
// Read file.
|
|
46
|
+
const fr = FileReader.read('test/TweeWriter/test3.twee');
|
|
47
|
+
// Parse file.
|
|
48
|
+
const tp = TweeParser.parse(fr);
|
|
49
|
+
// Verify only two passages
|
|
50
|
+
expect(tp.size()).toBe(2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('Should write format, formatVersion, zoom, and start', () => {
|
|
54
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
55
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
56
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
57
|
+
|
|
58
|
+
s.format = 'Test';
|
|
59
|
+
s.formatVersion = '1.2.3';
|
|
60
|
+
s.zoom = 1;
|
|
61
|
+
s.start = 'Untitled';
|
|
62
|
+
|
|
63
|
+
TweeWriter.write(s, 'test/TweeWriter/test1.twee');
|
|
64
|
+
const fr = FileReader.read('test/TweeWriter/test1.twee');
|
|
65
|
+
const story2 = TweeParser.parse(fr);
|
|
66
|
+
console.log(story2);
|
|
67
|
+
expect(story2.format).toBe('Test');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('Should write tag colors', () => {
|
|
71
|
+
s.addPassage(new Passage('StoryTitle', 'Title'));
|
|
72
|
+
s.addPassage(new Passage('Start', 'Content'));
|
|
73
|
+
s.addPassage(new Passage('Untitled', 'Some stuff'));
|
|
74
|
+
s.tagColors = {
|
|
75
|
+
bar: 'green',
|
|
76
|
+
foo: 'red',
|
|
77
|
+
qaz: 'blue'
|
|
78
|
+
};
|
|
79
|
+
TweeWriter.write(s, 'test/TweeWriter/test5.twee');
|
|
80
|
+
const fr = FileReader.read('test/TweeWriter/test5.twee');
|
|
81
|
+
const story2 = TweeParser.parse(fr);
|
|
82
|
+
expect(story2.tagColors.bar).toBe('green');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
package/main.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
const argv = require('yargs')
|
|
2
|
-
.describe('i', 'Source')
|
|
3
|
-
.describe('v', 'Version')
|
|
4
|
-
.describe('f', 'Story Format')
|
|
5
|
-
.describe('d', 'File to decompile')
|
|
6
|
-
.describe('o', 'Output File')
|
|
7
|
-
.describe('r', 'Directory')
|
|
8
|
-
.describe('w', 'Watch')
|
|
9
|
-
.alias('v', 'version')
|
|
10
|
-
.alias('i', 'input')
|
|
11
|
-
.alias('f', 'format')
|
|
12
|
-
.alias('d', 'decompile')
|
|
13
|
-
.alias('o', 'output')
|
|
14
|
-
.alias('h', 'help')
|
|
15
|
-
.alias('r', 'dir')
|
|
16
|
-
.alias('w', 'watch')
|
|
17
|
-
.argv;
|
|
18
|
-
|
|
19
|
-
const FileReader = require('./src/FileReader.js');
|
|
20
|
-
const TweeParser = require('./src/TweeParser.js');
|
|
21
|
-
const TweeWriter = require('./src/TweeWriter.js');
|
|
22
|
-
const StoryFormatParser = require('./src/StoryFormatParser.js');
|
|
23
|
-
const HTMLParser = require('./src/HTMLParser.js');
|
|
24
|
-
const HTMLWriter = require('./src/HTMLWriter.js');
|
|
25
|
-
const DirectoryReader = require('./src/DirectoryReader.js');
|
|
26
|
-
const DirectoryWatcher = require('./src/DirectoryWatcher.js');
|
|
27
|
-
|
|
28
|
-
if(argv.hasOwnProperty("input") ) {
|
|
29
|
-
|
|
30
|
-
if(argv.hasOwnProperty("format") ) {
|
|
31
|
-
|
|
32
|
-
if(argv.hasOwnProperty("output") ) {
|
|
33
|
-
|
|
34
|
-
let fr = new FileReader(argv.input);
|
|
35
|
-
let tp = new TweeParser(fr.contents);
|
|
36
|
-
let sfp = new StoryFormatParser(argv.format);
|
|
37
|
-
let hw = new HTMLWriter(argv.output, tp.story, sfp.storyformat);
|
|
38
|
-
|
|
39
|
-
} else {
|
|
40
|
-
throw new Error("Missing output file!");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
} else {
|
|
44
|
-
throw new Error("Missing format file");
|
|
45
|
-
}
|
|
46
|
-
} else if(argv.hasOwnProperty("decompile") ) {
|
|
47
|
-
|
|
48
|
-
if(argv.hasOwnProperty("output") )
|
|
49
|
-
{
|
|
50
|
-
let fr = new FileReader(argv.decompile);
|
|
51
|
-
let hd = new HTMLParser(fr.contents);
|
|
52
|
-
let tw = new TweeWriter(hd.story, argv.output);
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
throw new Error("Missing output file!");
|
|
56
|
-
}
|
|
57
|
-
} else if(argv.hasOwnProperty("dir") ) {
|
|
58
|
-
|
|
59
|
-
const dir = new DirectoryReader(argv.dir);
|
|
60
|
-
|
|
61
|
-
if(argv.hasOwnProperty("format") ) {
|
|
62
|
-
|
|
63
|
-
if(argv.hasOwnProperty("output") ) {
|
|
64
|
-
|
|
65
|
-
dir.watch();
|
|
66
|
-
let tp = new TweeParser(dir.tweeContents);
|
|
67
|
-
let sfp = new StoryFormatParser(argv.format);
|
|
68
|
-
let hw = new HTMLWriter(argv.output, tp.story, sfp.storyformat, dir.CSScontents, dir.JScontents);
|
|
69
|
-
|
|
70
|
-
} else {
|
|
71
|
-
throw new Error("Missing output file!");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
} else {
|
|
75
|
-
throw new Error("Missing format file");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
} else if(argv.hasOwnProperty("watch") ) {
|
|
79
|
-
|
|
80
|
-
if(argv.hasOwnProperty("format") ) {
|
|
81
|
-
|
|
82
|
-
if(argv.hasOwnProperty("output") ) {
|
|
83
|
-
|
|
84
|
-
let dir = new DirectoryReader(argv.watch);
|
|
85
|
-
|
|
86
|
-
let dw = new DirectoryWatcher(argv.watch, () => {
|
|
87
|
-
|
|
88
|
-
console.info("Re-building files.");
|
|
89
|
-
dir.update();
|
|
90
|
-
let tp = new TweeParser(dir.tweeContents);
|
|
91
|
-
let sfp = new StoryFormatParser(argv.format);
|
|
92
|
-
let hw = new HTMLWriter(argv.output, tp.story, sfp.storyformat, dir.CSScontents, dir.JScontents);
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
dw.watch();
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
throw new Error("Missing output file!");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error("Missing format file");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|