-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changelog: * Fixed an issue with the `selected` keyword in the `<<cycle>>` and `<<listbox>>` macros' `<<option>>` tags. * Fixed instances where using the `[img[]]` markup as an argument to macros would drop the `link-image` class. * Fixed `Config.history.maxStates` to disallow unlimited states (value: `0`). * Added the `init` special tag that, similar to `StoryInit`, allows pre-story-start initialization tasks. Intended for add-on/library use. * Added a `data-init-passage` content attribute to `StoryInterface` that allows content to be updated only once at initialization. * Added the `State.metadata.entries()` and `State.metadata.keys()` static methods. * Added a `once` keyword to the `<<cycle>>` macro that ends the cycle upon reaching the final option. * Added the `<Array>.countWith()` method. * Added the `Save` Events API. * Added support for template literals within TwineScript. * Added various accessibility improvements. * Updated the `<<done>>` macro to better serve when used to wait for DOM updates. * `<<widget>>` macro updates: * Added a `container` keyword that allows non-void/container widgets and an associated `_contents` special variable. * Added a new special arguments variable, `_args`, and deprecated the old variable, `$args`. * Updated the default value of `Config.history.maxStates` from `100` to `40`. * Updated passage objects to maintain the order of passage tags as specified in the data chunk. * Deprecated the `Config.saves.onLoad` and `Config.saves.onSave` settings in favor of the `Save` Events API. * Updated bundled library: `jQuery` to v3.6.0. * Updates to locale files: * Updated the localization template. Translators are asked to updated the locale files as necessary. * Added `nl.js` – Dutch. * Various documentation updates. * Various internal improvements. * Build system updates.
- Loading branch information
Showing
61 changed files
with
8,720 additions
and
5,662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
#!/usr/bin/env node | ||
/*********************************************************************************************************************** | ||
build.js (v1.4.18, 2020-11-08) | ||
build.js (v1.6.0, 2021-12-19) | ||
A Node.js-hosted build script for SugarCube. | ||
Copyright © 2013–2020 Thomas Michael Edwards <[email protected]>. All rights reserved. | ||
Copyright © 2013–2021 Thomas Michael Edwards <[email protected]>. All rights reserved. | ||
Use of this source code is governed by a BSD 2-clause "Simplified" License, which may be found in the LICENSE file. | ||
***********************************************************************************************************************/ | ||
/* eslint-env node, es6 */ | ||
/* eslint-disable strict */ | ||
'use strict'; | ||
|
||
/******************************************************************************* | ||
|
@@ -142,11 +141,18 @@ const CONFIG = { | |
the replacement strings (e.g. '$&' within the application source). | ||
*/ | ||
|
||
const _fs = require('fs'); | ||
const { | ||
log, | ||
die, | ||
fileExists, | ||
makePath, | ||
copyFile, | ||
readFileContents, | ||
writeFileContents, | ||
concatFiles | ||
} = require('./scripts/build-utils'); | ||
const _path = require('path'); | ||
|
||
const _indent = ' -> '; | ||
const _opt = require('node-getopt').create([ | ||
const _opt = require('node-getopt').create([ | ||
['b', 'build=VERSION', 'Build only for Twine major version: 1 or 2; default: build for all.'], | ||
['d', 'debug', 'Keep debugging code; gated by DEBUG symbol.'], | ||
['u', 'unminified', 'Suppress minification stages.'], | ||
|
@@ -186,7 +192,7 @@ if (_opt.options.build) { | |
console.log('Starting builds...'); | ||
|
||
// Create the build ID file, if nonexistent. | ||
if (!_fs.existsSync('.build')) { | ||
if (!fileExists('.build')) { | ||
writeFileContents('.build', '0'); | ||
} | ||
|
||
|
@@ -203,7 +209,7 @@ if (_opt.options.build) { | |
patch : semver.patch(version), | ||
prerelease : prerelease && prerelease.length > 0 ? prerelease.join('.') : null, | ||
build : Number(readFileContents('.build')) + 1, | ||
date : (new Date()).toISOString(), | ||
date : new Date().toISOString(), | ||
|
||
toString() { | ||
const prerelease = this.prerelease ? `-${this.prerelease}` : ''; | ||
|
@@ -277,93 +283,6 @@ console.log('\nBuilds complete! (check the "build" directory)'); | |
/******************************************************************************* | ||
Utility Functions | ||
*******************************************************************************/ | ||
function log(message, indent) { | ||
console.log('%s%s', indent ? indent : _indent, message); | ||
} | ||
|
||
// function warn(message) { | ||
// console.warn('%swarning: %s', _indent, message); | ||
// } | ||
|
||
function die(message, error) { | ||
if (error) { | ||
console.error('error: %s\n[@: %d/%d] Trace:\n', message, error.line, error.col, error.stack); | ||
} | ||
else { | ||
console.error('error: %s', message); | ||
} | ||
|
||
process.exit(1); | ||
} | ||
|
||
function makePath(pathname) { | ||
const pathBits = _path.normalize(pathname).split(_path.sep); | ||
|
||
for (let i = 0; i < pathBits.length; ++i) { | ||
const dirPath = i === 0 ? pathBits[i] : pathBits.slice(0, i + 1).join(_path.sep); | ||
|
||
if (!_fs.existsSync(dirPath)) { | ||
_fs.mkdirSync(dirPath); | ||
} | ||
} | ||
} | ||
|
||
function copyFile(srcFilename, destFilename) { | ||
const srcPath = _path.normalize(srcFilename); | ||
const destPath = _path.normalize(destFilename); | ||
let buf; | ||
|
||
try { | ||
buf = _fs.readFileSync(srcPath); | ||
} | ||
catch (ex) { | ||
die(`cannot open file "${srcPath}" for reading (reason: ${ex.message})`); | ||
} | ||
|
||
try { | ||
_fs.writeFileSync(destPath, buf); | ||
} | ||
catch (ex) { | ||
die(`cannot open file "${destPath}" for writing (reason: ${ex.message})`); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function readFileContents(filename) { | ||
const filepath = _path.normalize(filename); | ||
|
||
try { | ||
// the replace() is necessary because Node.js only offers binary mode file | ||
// access, regardless of platform, so we convert DOS-style line terminators | ||
// to UNIX-style, just in case someone adds/edits a file and gets DOS-style | ||
// line termination all over it | ||
return _fs.readFileSync(filepath, { encoding : 'utf8' }).replace(/\r\n/g, '\n'); | ||
} | ||
catch (ex) { | ||
die(`cannot open file "${filepath}" for reading (reason: ${ex.message})`); | ||
} | ||
} | ||
|
||
function writeFileContents(filename, data) { | ||
const filepath = _path.normalize(filename); | ||
|
||
try { | ||
_fs.writeFileSync(filepath, data, { encoding : 'utf8' }); | ||
} | ||
catch (ex) { | ||
die(`cannot open file "${filepath}" for writing (reason: ${ex.message})`); | ||
} | ||
} | ||
|
||
function concatFiles(filenames, callback) { | ||
const output = filenames.map(filename => { | ||
const contents = readFileContents(filename); | ||
return typeof callback === 'function' ? callback(contents, filename) : contents; | ||
}); | ||
return output.join('\n'); | ||
} | ||
|
||
function assembleLibraries(filenames) { | ||
log('assembling libraries...'); | ||
|
||
|
@@ -397,37 +316,24 @@ function compileJavaScript(filenameObj, options) { | |
].join(';\n') + ';\n' + jsSource; | ||
} | ||
|
||
try { | ||
const uglifyjs = require('uglify-js'); | ||
const uglified = uglifyjs.minify(jsSource, { | ||
fromString : true, | ||
compress : { | ||
global_defs : { | ||
TWINE1 : !!options.twine1, | ||
DEBUG : _opt.options.debug || false | ||
}, | ||
screw_ie8 : true | ||
}, | ||
mangle : { | ||
screw_ie8 : true | ||
const uglifyjs = require('uglify-js'); | ||
const minified = uglifyjs.minify(jsSource, { | ||
compress : { | ||
global_defs : { | ||
TWINE1 : !!options.twine1, | ||
DEBUG : _opt.options.debug || false | ||
}, | ||
output : { | ||
screw_ie8 : true | ||
} | ||
}); | ||
return uglified.code; | ||
} | ||
catch (ex) { | ||
let mesg = 'uglification error'; | ||
|
||
if (ex.line > 0) { | ||
const begin = ex.line > 4 ? ex.line - 4 : 0; | ||
const end = ex.line + 3 < jsSource.length ? ex.line + 3 : jsSource.length; | ||
mesg += ':\n >> ' + jsSource.split(/\n/).slice(begin, end).join('\n >> '); | ||
} | ||
keep_infinity : true | ||
}, | ||
mangle : false | ||
}); | ||
|
||
die(mesg, ex); | ||
if (minified.error) { | ||
const { message, line, col, pos } = minified.error; | ||
die(`JavaScript minification error: ${message}\n[@: ${line}/${col}/${pos}]`); | ||
} | ||
|
||
return minified.code; | ||
/* eslint-enable camelcase, prefer-template */ | ||
} | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.