extwee 1.6.2 → 2.0.3
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 -24
- package/.github/workflows/nodejs.yml +24 -24
- 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 -45
- package/src/FileReader.js +33 -35
- package/src/HTMLParser.js +343 -206
- package/src/HTMLWriter.js +231 -172
- package/src/Passage.js +202 -24
- package/src/Story.js +490 -122
- package/src/StoryFormat.js +300 -28
- package/src/StoryFormatParser.js +142 -59
- package/src/TweeParser.js +161 -207
- package/src/TweeWriter.js +98 -96
- 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 +14 -11
- 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 +369 -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 -32
- 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 -114
- package/src/DirectoryWatcher.js +0 -87
- 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 -736
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
|
-
}
|
package/src/DirectoryReader.js
DELETED
|
@@ -1,114 +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 CleanCSS = require('clean-css');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @class DirectoryReader
|
|
10
|
-
* @module DirectoryReader
|
|
11
|
-
*/
|
|
12
|
-
class DirectoryReader {
|
|
13
|
-
/**
|
|
14
|
-
* @function DirectoryReader
|
|
15
|
-
* @class
|
|
16
|
-
* @param {string} directory - Directory to read
|
|
17
|
-
*/
|
|
18
|
-
constructor (directory) {
|
|
19
|
-
try {
|
|
20
|
-
this.directory = fs.realpathSync(directory);
|
|
21
|
-
} catch (event) {
|
|
22
|
-
throw new Error('Error: Cannot resolve to real path!');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.CSScontents = '';
|
|
26
|
-
this.JScontents = '';
|
|
27
|
-
this.tweeContents = '';
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Start watching
|
|
31
|
-
*
|
|
32
|
-
* @function watch
|
|
33
|
-
* @returns {void}
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
watch () {
|
|
37
|
-
// Reset content
|
|
38
|
-
this.CSScontents = this.JScontents = this.tweeContents = '';
|
|
39
|
-
|
|
40
|
-
// Look for CSS files
|
|
41
|
-
this.CSScontents = this.processCSS();
|
|
42
|
-
// Look for JS files
|
|
43
|
-
this.JScontents = this.processJS();
|
|
44
|
-
// Look for Twee files
|
|
45
|
-
this.tweeContents = this.processTwee();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Process JavaScript files
|
|
50
|
-
*
|
|
51
|
-
* @function processJS
|
|
52
|
-
* @returns {void}
|
|
53
|
-
*/
|
|
54
|
-
processJS () {
|
|
55
|
-
let fileContents = '';
|
|
56
|
-
|
|
57
|
-
console.info('Processing JS files...');
|
|
58
|
-
|
|
59
|
-
shell.ls('-R', this.directory + '/**/*.js').forEach(function (value) {
|
|
60
|
-
console.info(' Loading ' + value);
|
|
61
|
-
const file = new FileReader(value);
|
|
62
|
-
fileContents += file.contents;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return fileContents;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Process CSS files
|
|
70
|
-
*
|
|
71
|
-
* @function processCSS
|
|
72
|
-
* @returns {void}
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
processCSS () {
|
|
76
|
-
let fileContents = '';
|
|
77
|
-
|
|
78
|
-
console.info('Processing CSS files...');
|
|
79
|
-
shell.ls('-R', this.directory + '/**/*.css').forEach(function (value) {
|
|
80
|
-
console.info(' Loading ' + value);
|
|
81
|
-
const file = new FileReader(value);
|
|
82
|
-
fileContents += file.contents;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const output = new CleanCSS({ level: 2 });
|
|
86
|
-
const { styles } = output.minify(fileContents);
|
|
87
|
-
return styles;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Process Twee files
|
|
92
|
-
*
|
|
93
|
-
* @function processTwee
|
|
94
|
-
* @returns {void}
|
|
95
|
-
*/
|
|
96
|
-
processTwee () {
|
|
97
|
-
const fileType = ['tw', 'tw2', 'twee', 'twee2', 'tw3', 'twee3'];
|
|
98
|
-
|
|
99
|
-
let fileContents = '';
|
|
100
|
-
|
|
101
|
-
console.info('Processing Twee files...');
|
|
102
|
-
for (let i = 0; i < fileType.length; i++) {
|
|
103
|
-
shell.ls('-R', this.directory + '/**/*.' + fileType[i]).forEach(function (value) {
|
|
104
|
-
const file = new FileReader(value);
|
|
105
|
-
console.info(' Loading ' + value);
|
|
106
|
-
fileContents += file.contents;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return fileContents;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
module.exports = DirectoryReader;
|
package/src/DirectoryWatcher.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const chokidar = require('chokidar');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @class DirectoryWatcher
|
|
6
|
-
* @module DirectoryWatcher
|
|
7
|
-
*/
|
|
8
|
-
class DirectoryWatcher {
|
|
9
|
-
/**
|
|
10
|
-
* @function DirectoryWatcher
|
|
11
|
-
* @class
|
|
12
|
-
* @param {string} directory - Directory to watch
|
|
13
|
-
* @param {Function} callback - Function to call when a file event happens
|
|
14
|
-
*/
|
|
15
|
-
constructor (directory, callback) {
|
|
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
|
-
throw new Error('Error: Expected function!');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
this.directory = fs.realpathSync(this.directory);
|
|
27
|
-
} catch (event) {
|
|
28
|
-
throw new Error('Error: Directory does not exist!');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Begin to watch files
|
|
34
|
-
*
|
|
35
|
-
* @function watch
|
|
36
|
-
* @returns {void}
|
|
37
|
-
*/
|
|
38
|
-
watch () {
|
|
39
|
-
console.info('Watching ' + this.directory + ' for changes.');
|
|
40
|
-
console.info('Press CTRL+C to stop.');
|
|
41
|
-
|
|
42
|
-
// Setup the Chokidar watcher
|
|
43
|
-
this.watcher = chokidar.watch(this.directory, {
|
|
44
|
-
ignored: /.html/,
|
|
45
|
-
persistent: true,
|
|
46
|
-
ignoreInitial: false
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Catch initial scan
|
|
50
|
-
this.watcher.on('ready', () => {
|
|
51
|
-
this.callback('ready');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Catch change events
|
|
55
|
-
this.watcher.on('change', (path) => {
|
|
56
|
-
console.info('Change detected on ' + path);
|
|
57
|
-
this.callback('change');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Catch add events
|
|
61
|
-
this.watcher.on('add', (path) => {
|
|
62
|
-
console.info('Addition detected on ' + path);
|
|
63
|
-
this.callback('add');
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Stop watching files
|
|
69
|
-
*
|
|
70
|
-
* @function stopWatching
|
|
71
|
-
* @returns {void}
|
|
72
|
-
*/
|
|
73
|
-
stopWatching () {
|
|
74
|
-
if (this.watcher == null) {
|
|
75
|
-
throw new Error('Invalid watcher object!');
|
|
76
|
-
} else {
|
|
77
|
-
// If this is a function, call it
|
|
78
|
-
if (typeof this.watcher.close === 'function') {
|
|
79
|
-
this.watcher.close().then(() => {
|
|
80
|
-
console.log('Stopped watching.');
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports = DirectoryWatcher;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("Test")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log("Example!");
|
|
File without changes
|
|
File without changes
|
|
File without changes
|