@rohal12/twee-ts 1.14.0 → 1.15.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.
- package/dist/bin/twee-ts.js +83 -45
- package/dist/bin/twee-ts.js.map +1 -1
- package/dist/{chunk-Z2CNKPVJ.js → chunk-W3SNMQO4.js} +134 -96
- package/dist/chunk-W3SNMQO4.js.map +1 -0
- package/dist/index.cjs +104 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -42
- package/dist/index.js.map +1 -1
- package/dist/plugins/rollup.js +1 -1
- package/dist/plugins/vite.d.ts +11 -45
- package/dist/plugins/vite.js +308 -38
- package/dist/plugins/vite.js.map +1 -1
- package/package.json +17 -3
- package/dist/chunk-Z2CNKPVJ.js.map +0 -1
package/dist/bin/twee-ts.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// bin/twee-ts.ts
|
|
4
4
|
import { parseArgs } from "util";
|
|
5
5
|
import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync2, existsSync as existsSync3 } from "fs";
|
|
6
|
-
import { join as
|
|
6
|
+
import { join as join7 } from "path";
|
|
7
7
|
|
|
8
8
|
// src/compiler.ts
|
|
9
9
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
@@ -4000,17 +4000,35 @@ function loadInlineSources(story, sources, opts, diagnostics) {
|
|
|
4000
4000
|
}
|
|
4001
4001
|
const content = typeof source.content === "string" ? source.content : source.content.toString("utf-8");
|
|
4002
4002
|
const ext = normalizedFileExt(source.filename);
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4003
|
+
switch (ext) {
|
|
4004
|
+
case "":
|
|
4005
|
+
case "tw":
|
|
4006
|
+
case "twee":
|
|
4007
|
+
case "tw2":
|
|
4008
|
+
case "twee2": {
|
|
4009
|
+
const twee2 = ext === "tw2" || ext === "twee2" || opts.twee2Compat;
|
|
4010
|
+
const result = parseTwee(content, {
|
|
4011
|
+
filename: source.filename,
|
|
4012
|
+
trim: opts.trim ?? true,
|
|
4013
|
+
twee2Compat: twee2
|
|
4014
|
+
});
|
|
4015
|
+
diagnostics.push(...result.diagnostics);
|
|
4016
|
+
for (const p of result.passages) {
|
|
4017
|
+
storyAdd(story, p, diagnostics);
|
|
4018
|
+
}
|
|
4019
|
+
break;
|
|
4013
4020
|
}
|
|
4021
|
+
case "css":
|
|
4022
|
+
storyAdd(story, { name: basename(source.filename), tags: ["stylesheet"], text: content }, diagnostics);
|
|
4023
|
+
break;
|
|
4024
|
+
case "js":
|
|
4025
|
+
storyAdd(story, { name: basename(source.filename), tags: ["script"], text: content }, diagnostics);
|
|
4026
|
+
break;
|
|
4027
|
+
default:
|
|
4028
|
+
diagnostics.push({
|
|
4029
|
+
level: "warning",
|
|
4030
|
+
message: `load ${source.filename}: in-memory sources of type .${ext} are not supported; skipped.`
|
|
4031
|
+
});
|
|
4014
4032
|
}
|
|
4015
4033
|
}
|
|
4016
4034
|
}
|
|
@@ -4208,7 +4226,27 @@ function loadSourcesCached(story, filenames, opts, diagnostics, processedFiles,
|
|
|
4208
4226
|
}
|
|
4209
4227
|
|
|
4210
4228
|
// src/version.ts
|
|
4211
|
-
|
|
4229
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
4230
|
+
import { dirname, join as join3 } from "path";
|
|
4231
|
+
import { fileURLToPath } from "url";
|
|
4232
|
+
var PACKAGE_NAME = "@rohal12/twee-ts";
|
|
4233
|
+
function findPackageVersion(startDir) {
|
|
4234
|
+
let dir = startDir;
|
|
4235
|
+
for (; ; ) {
|
|
4236
|
+
try {
|
|
4237
|
+
const pkg = JSON.parse(readFileSync2(join3(dir, "package.json"), "utf-8"));
|
|
4238
|
+
if (pkg.name === PACKAGE_NAME && typeof pkg.version === "string") return pkg.version;
|
|
4239
|
+
} catch {
|
|
4240
|
+
}
|
|
4241
|
+
const parent = dirname(dir);
|
|
4242
|
+
if (parent === dir) return void 0;
|
|
4243
|
+
dir = parent;
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
function moduleDir() {
|
|
4247
|
+
return typeof __dirname === "string" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
4248
|
+
}
|
|
4249
|
+
var VERSION = findPackageVersion(moduleDir()) ?? "0.0.0";
|
|
4212
4250
|
|
|
4213
4251
|
// src/output-twine2.ts
|
|
4214
4252
|
var CREATOR_NAME = "Twee-ts";
|
|
@@ -4298,8 +4336,8 @@ function getTwine2DataChunk(story, startName, options) {
|
|
|
4298
4336
|
}
|
|
4299
4337
|
|
|
4300
4338
|
// src/output-twine1.ts
|
|
4301
|
-
import { readFileSync as
|
|
4302
|
-
import { join as
|
|
4339
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
4340
|
+
import { join as join4, dirname as dirname2 } from "path";
|
|
4303
4341
|
var CREATOR_NAME2 = "twee-ts";
|
|
4304
4342
|
function toTwine1Archive(story, _startName) {
|
|
4305
4343
|
const { data, count } = getTwine1PassageChunk(story);
|
|
@@ -4307,19 +4345,19 @@ function toTwine1Archive(story, _startName) {
|
|
|
4307
4345
|
`;
|
|
4308
4346
|
}
|
|
4309
4347
|
function toTwine1HTML(story, format, startName) {
|
|
4310
|
-
const formatDir =
|
|
4311
|
-
const parentDir =
|
|
4348
|
+
const formatDir = dirname2(format.filename);
|
|
4349
|
+
const parentDir = dirname2(formatDir);
|
|
4312
4350
|
let template = readFormatSource(format);
|
|
4313
4351
|
const { data, count } = getTwine1PassageChunk(story);
|
|
4314
|
-
template = tryReplaceComponent(template, '"USER_LIB"',
|
|
4315
|
-
template = tryReplaceComponent(template, '"ENGINE"',
|
|
4316
|
-
template = tryReplaceComponent(template, '"SUGARCANE"',
|
|
4317
|
-
template = tryReplaceComponent(template, '"JONAH"',
|
|
4352
|
+
template = tryReplaceComponent(template, '"USER_LIB"', join4(formatDir, "userlib.js"), false);
|
|
4353
|
+
template = tryReplaceComponent(template, '"ENGINE"', join4(parentDir, "engine.js"), true);
|
|
4354
|
+
template = tryReplaceComponent(template, '"SUGARCANE"', join4(formatDir, "code.js"), true);
|
|
4355
|
+
template = tryReplaceComponent(template, '"JONAH"', join4(formatDir, "code.js"), true);
|
|
4318
4356
|
if (story.twine1.settings.get("jquery") === "on") {
|
|
4319
|
-
template = tryReplaceComponent(template, '"JQUERY"',
|
|
4357
|
+
template = tryReplaceComponent(template, '"JQUERY"', join4(parentDir, "jquery.js"), true);
|
|
4320
4358
|
}
|
|
4321
4359
|
if (story.twine1.settings.get("modernizr") === "on") {
|
|
4322
|
-
template = tryReplaceComponent(template, '"MODERNIZR"',
|
|
4360
|
+
template = tryReplaceComponent(template, '"MODERNIZR"', join4(parentDir, "modernizr.js"), true);
|
|
4323
4361
|
}
|
|
4324
4362
|
const displayStart = startName === "Start" ? "" : startName;
|
|
4325
4363
|
template = template.replace('"VERSION"', `Compiled with ${CREATOR_NAME2}, ${VERSION}`);
|
|
@@ -4332,7 +4370,7 @@ function toTwine1HTML(story, format, startName) {
|
|
|
4332
4370
|
} else {
|
|
4333
4371
|
let footer;
|
|
4334
4372
|
try {
|
|
4335
|
-
footer =
|
|
4373
|
+
footer = readFileSync3(join4(formatDir, "footer.html"), "utf-8");
|
|
4336
4374
|
} catch {
|
|
4337
4375
|
footer = "</div>\n</body>\n</html>\n";
|
|
4338
4376
|
}
|
|
@@ -4362,7 +4400,7 @@ function getTwine1PassageChunk(story) {
|
|
|
4362
4400
|
function tryReplaceComponent(template, placeholder, componentPath, required) {
|
|
4363
4401
|
if (!template.includes(placeholder)) return template;
|
|
4364
4402
|
try {
|
|
4365
|
-
let content =
|
|
4403
|
+
let content = readFileSync3(componentPath, "utf-8");
|
|
4366
4404
|
if (content.charCodeAt(0) === 65279) content = content.slice(1);
|
|
4367
4405
|
return template.replace(placeholder, () => content);
|
|
4368
4406
|
} catch (e) {
|
|
@@ -4459,8 +4497,8 @@ function modifyHead(html, modulePaths, headFile, diagnostics) {
|
|
|
4459
4497
|
}
|
|
4460
4498
|
|
|
4461
4499
|
// src/remote-formats.ts
|
|
4462
|
-
import { mkdirSync, readFileSync as
|
|
4463
|
-
import { join as
|
|
4500
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync, existsSync, readdirSync as readdirSync3, statSync as statSync4, rmSync } from "fs";
|
|
4501
|
+
import { join as join5 } from "path";
|
|
4464
4502
|
import { homedir as homedir2 } from "os";
|
|
4465
4503
|
var DEFAULT_SFA_INDICES = [
|
|
4466
4504
|
"https://videlais.github.io/story-formats-archive/official/index.json",
|
|
@@ -4468,8 +4506,8 @@ var DEFAULT_SFA_INDICES = [
|
|
|
4468
4506
|
];
|
|
4469
4507
|
function getCacheDir() {
|
|
4470
4508
|
const xdg = process.env["XDG_CACHE_HOME"];
|
|
4471
|
-
const base = xdg ||
|
|
4472
|
-
return
|
|
4509
|
+
const base = xdg || join5(homedir2(), ".cache");
|
|
4510
|
+
return join5(base, "twee-ts", "storyformats");
|
|
4473
4511
|
}
|
|
4474
4512
|
var indexCache = /* @__PURE__ */ new Map();
|
|
4475
4513
|
function clearIndexCache() {
|
|
@@ -4559,9 +4597,9 @@ async function fetchAndCacheFormat(entry, downloadUrl) {
|
|
|
4559
4597
|
throw new Error(`Failed to parse format JSON from ${downloadUrl}`);
|
|
4560
4598
|
}
|
|
4561
4599
|
const cacheDir = getCacheDir();
|
|
4562
|
-
const formatDir =
|
|
4600
|
+
const formatDir = join5(cacheDir, entry.name, entry.version);
|
|
4563
4601
|
mkdirSync(formatDir, { recursive: true });
|
|
4564
|
-
const formatPath =
|
|
4602
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4565
4603
|
writeFileSync(formatPath, text, "utf-8");
|
|
4566
4604
|
return {
|
|
4567
4605
|
id,
|
|
@@ -4585,9 +4623,9 @@ async function fetchDirectFormat(url) {
|
|
|
4585
4623
|
}
|
|
4586
4624
|
const id = makeFormatId(data.name, data.version);
|
|
4587
4625
|
const cacheDir = getCacheDir();
|
|
4588
|
-
const formatDir =
|
|
4626
|
+
const formatDir = join5(cacheDir, data.name, data.version);
|
|
4589
4627
|
mkdirSync(formatDir, { recursive: true });
|
|
4590
|
-
const formatPath =
|
|
4628
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4591
4629
|
writeFileSync(formatPath, text, "utf-8");
|
|
4592
4630
|
return {
|
|
4593
4631
|
id,
|
|
@@ -4635,10 +4673,10 @@ async function resolveRemoteFormat(name, version, indices, urls) {
|
|
|
4635
4673
|
return void 0;
|
|
4636
4674
|
}
|
|
4637
4675
|
function getCachedFormat(name, version) {
|
|
4638
|
-
const formatPath =
|
|
4676
|
+
const formatPath = join5(getCacheDir(), name, version, "format.js");
|
|
4639
4677
|
try {
|
|
4640
4678
|
if (!existsSync(formatPath)) return void 0;
|
|
4641
|
-
const source =
|
|
4679
|
+
const source = readFileSync4(formatPath, "utf-8");
|
|
4642
4680
|
const id = makeFormatId(name, version);
|
|
4643
4681
|
const data = parseFormatJSON(source, id);
|
|
4644
4682
|
if (!data) return void 0;
|
|
@@ -4669,7 +4707,7 @@ function discoverCachedFormats() {
|
|
|
4669
4707
|
return formats;
|
|
4670
4708
|
}
|
|
4671
4709
|
for (const name of names) {
|
|
4672
|
-
const nameDir =
|
|
4710
|
+
const nameDir = join5(cacheDir, name);
|
|
4673
4711
|
try {
|
|
4674
4712
|
if (!statSync4(nameDir).isDirectory()) continue;
|
|
4675
4713
|
} catch {
|
|
@@ -4705,7 +4743,7 @@ function listCachedFormats() {
|
|
|
4705
4743
|
return entries;
|
|
4706
4744
|
}
|
|
4707
4745
|
for (const name of names) {
|
|
4708
|
-
const nameDir =
|
|
4746
|
+
const nameDir = join5(cacheDir, name);
|
|
4709
4747
|
try {
|
|
4710
4748
|
if (!statSync4(nameDir).isDirectory()) continue;
|
|
4711
4749
|
} catch {
|
|
@@ -4718,7 +4756,7 @@ function listCachedFormats() {
|
|
|
4718
4756
|
continue;
|
|
4719
4757
|
}
|
|
4720
4758
|
for (const version of versions) {
|
|
4721
|
-
const formatPath =
|
|
4759
|
+
const formatPath = join5(nameDir, version, "format.js");
|
|
4722
4760
|
try {
|
|
4723
4761
|
const stat = statSync4(formatPath);
|
|
4724
4762
|
entries.push({
|
|
@@ -4742,7 +4780,7 @@ function clearCachedFormats(name) {
|
|
|
4742
4780
|
rmSync(cacheDir, { recursive: true, force: true });
|
|
4743
4781
|
return count2;
|
|
4744
4782
|
}
|
|
4745
|
-
const nameDir =
|
|
4783
|
+
const nameDir = join5(cacheDir, name);
|
|
4746
4784
|
if (!existsSync(nameDir)) return 0;
|
|
4747
4785
|
let versions;
|
|
4748
4786
|
try {
|
|
@@ -5143,18 +5181,18 @@ function formatLintReport(result) {
|
|
|
5143
5181
|
}
|
|
5144
5182
|
|
|
5145
5183
|
// src/config.ts
|
|
5146
|
-
import { readFileSync as
|
|
5147
|
-
import { join as
|
|
5184
|
+
import { readFileSync as readFileSync5, existsSync as existsSync2 } from "fs";
|
|
5185
|
+
import { join as join6 } from "path";
|
|
5148
5186
|
var CONFIG_FILENAME = "twee-ts.config.json";
|
|
5149
5187
|
var VALID_OUTPUT_MODES = ["html", "twee3", "twee1", "twine2-archive", "twine1-archive", "json"];
|
|
5150
5188
|
var VALID_WORD_COUNT_METHODS = ["tweego", "whitespace"];
|
|
5151
5189
|
function loadConfig(dir) {
|
|
5152
5190
|
const base = dir ?? process.cwd();
|
|
5153
|
-
const configPath =
|
|
5191
|
+
const configPath = join6(base, CONFIG_FILENAME);
|
|
5154
5192
|
if (!existsSync2(configPath)) return null;
|
|
5155
5193
|
let raw;
|
|
5156
5194
|
try {
|
|
5157
|
-
raw =
|
|
5195
|
+
raw = readFileSync5(configPath, "utf-8");
|
|
5158
5196
|
} catch {
|
|
5159
5197
|
return null;
|
|
5160
5198
|
}
|
|
@@ -5174,7 +5212,7 @@ function loadConfig(dir) {
|
|
|
5174
5212
|
function loadConfigFile(filePath) {
|
|
5175
5213
|
let raw;
|
|
5176
5214
|
try {
|
|
5177
|
-
raw =
|
|
5215
|
+
raw = readFileSync5(filePath, "utf-8");
|
|
5178
5216
|
} catch (e) {
|
|
5179
5217
|
throw new Error(`Cannot read config file ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
5180
5218
|
}
|
|
@@ -5463,7 +5501,7 @@ function runInit() {
|
|
|
5463
5501
|
console.log("Initializing new twee-ts project...");
|
|
5464
5502
|
mkdirSync2("src", { recursive: true });
|
|
5465
5503
|
writeFileSync3(
|
|
5466
|
-
|
|
5504
|
+
join7("src", "StoryData.tw"),
|
|
5467
5505
|
`:: StoryData
|
|
5468
5506
|
{
|
|
5469
5507
|
"ifid": "${crypto.randomUUID().toUpperCase()}"
|
|
@@ -5471,7 +5509,7 @@ function runInit() {
|
|
|
5471
5509
|
`
|
|
5472
5510
|
);
|
|
5473
5511
|
writeFileSync3(
|
|
5474
|
-
|
|
5512
|
+
join7("src", "Start.tw"),
|
|
5475
5513
|
`:: Start
|
|
5476
5514
|
Welcome to your new Twine story!
|
|
5477
5515
|
|