@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/index.js
CHANGED
|
@@ -4033,17 +4033,35 @@ function loadInlineSources(story, sources, opts, diagnostics) {
|
|
|
4033
4033
|
}
|
|
4034
4034
|
const content = typeof source.content === "string" ? source.content : source.content.toString("utf-8");
|
|
4035
4035
|
const ext = normalizedFileExt(source.filename);
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4036
|
+
switch (ext) {
|
|
4037
|
+
case "":
|
|
4038
|
+
case "tw":
|
|
4039
|
+
case "twee":
|
|
4040
|
+
case "tw2":
|
|
4041
|
+
case "twee2": {
|
|
4042
|
+
const twee2 = ext === "tw2" || ext === "twee2" || opts.twee2Compat;
|
|
4043
|
+
const result = parseTwee(content, {
|
|
4044
|
+
filename: source.filename,
|
|
4045
|
+
trim: opts.trim ?? true,
|
|
4046
|
+
twee2Compat: twee2
|
|
4047
|
+
});
|
|
4048
|
+
diagnostics.push(...result.diagnostics);
|
|
4049
|
+
for (const p of result.passages) {
|
|
4050
|
+
storyAdd(story, p, diagnostics);
|
|
4051
|
+
}
|
|
4052
|
+
break;
|
|
4046
4053
|
}
|
|
4054
|
+
case "css":
|
|
4055
|
+
storyAdd(story, { name: basename(source.filename), tags: ["stylesheet"], text: content }, diagnostics);
|
|
4056
|
+
break;
|
|
4057
|
+
case "js":
|
|
4058
|
+
storyAdd(story, { name: basename(source.filename), tags: ["script"], text: content }, diagnostics);
|
|
4059
|
+
break;
|
|
4060
|
+
default:
|
|
4061
|
+
diagnostics.push({
|
|
4062
|
+
level: "warning",
|
|
4063
|
+
message: `load ${source.filename}: in-memory sources of type .${ext} are not supported; skipped.`
|
|
4064
|
+
});
|
|
4047
4065
|
}
|
|
4048
4066
|
}
|
|
4049
4067
|
}
|
|
@@ -4241,7 +4259,27 @@ function loadSourcesCached(story, filenames, opts, diagnostics, processedFiles,
|
|
|
4241
4259
|
}
|
|
4242
4260
|
|
|
4243
4261
|
// src/version.ts
|
|
4244
|
-
|
|
4262
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
4263
|
+
import { dirname, join as join3 } from "path";
|
|
4264
|
+
import { fileURLToPath } from "url";
|
|
4265
|
+
var PACKAGE_NAME = "@rohal12/twee-ts";
|
|
4266
|
+
function findPackageVersion(startDir) {
|
|
4267
|
+
let dir = startDir;
|
|
4268
|
+
for (; ; ) {
|
|
4269
|
+
try {
|
|
4270
|
+
const pkg = JSON.parse(readFileSync2(join3(dir, "package.json"), "utf-8"));
|
|
4271
|
+
if (pkg.name === PACKAGE_NAME && typeof pkg.version === "string") return pkg.version;
|
|
4272
|
+
} catch {
|
|
4273
|
+
}
|
|
4274
|
+
const parent = dirname(dir);
|
|
4275
|
+
if (parent === dir) return void 0;
|
|
4276
|
+
dir = parent;
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
function moduleDir() {
|
|
4280
|
+
return typeof __dirname === "string" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
4281
|
+
}
|
|
4282
|
+
var VERSION = findPackageVersion(moduleDir()) ?? "0.0.0";
|
|
4245
4283
|
|
|
4246
4284
|
// src/output-twine2.ts
|
|
4247
4285
|
var CREATOR_NAME = "Twee-ts";
|
|
@@ -4331,8 +4369,8 @@ function getTwine2DataChunk(story, startName, options) {
|
|
|
4331
4369
|
}
|
|
4332
4370
|
|
|
4333
4371
|
// src/output-twine1.ts
|
|
4334
|
-
import { readFileSync as
|
|
4335
|
-
import { join as
|
|
4372
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
4373
|
+
import { join as join4, dirname as dirname2 } from "path";
|
|
4336
4374
|
var CREATOR_NAME2 = "twee-ts";
|
|
4337
4375
|
function toTwine1Archive(story, _startName) {
|
|
4338
4376
|
const { data, count } = getTwine1PassageChunk(story);
|
|
@@ -4340,19 +4378,19 @@ function toTwine1Archive(story, _startName) {
|
|
|
4340
4378
|
`;
|
|
4341
4379
|
}
|
|
4342
4380
|
function toTwine1HTML(story, format, startName) {
|
|
4343
|
-
const formatDir =
|
|
4344
|
-
const parentDir =
|
|
4381
|
+
const formatDir = dirname2(format.filename);
|
|
4382
|
+
const parentDir = dirname2(formatDir);
|
|
4345
4383
|
let template = readFormatSource(format);
|
|
4346
4384
|
const { data, count } = getTwine1PassageChunk(story);
|
|
4347
|
-
template = tryReplaceComponent(template, '"USER_LIB"',
|
|
4348
|
-
template = tryReplaceComponent(template, '"ENGINE"',
|
|
4349
|
-
template = tryReplaceComponent(template, '"SUGARCANE"',
|
|
4350
|
-
template = tryReplaceComponent(template, '"JONAH"',
|
|
4385
|
+
template = tryReplaceComponent(template, '"USER_LIB"', join4(formatDir, "userlib.js"), false);
|
|
4386
|
+
template = tryReplaceComponent(template, '"ENGINE"', join4(parentDir, "engine.js"), true);
|
|
4387
|
+
template = tryReplaceComponent(template, '"SUGARCANE"', join4(formatDir, "code.js"), true);
|
|
4388
|
+
template = tryReplaceComponent(template, '"JONAH"', join4(formatDir, "code.js"), true);
|
|
4351
4389
|
if (story.twine1.settings.get("jquery") === "on") {
|
|
4352
|
-
template = tryReplaceComponent(template, '"JQUERY"',
|
|
4390
|
+
template = tryReplaceComponent(template, '"JQUERY"', join4(parentDir, "jquery.js"), true);
|
|
4353
4391
|
}
|
|
4354
4392
|
if (story.twine1.settings.get("modernizr") === "on") {
|
|
4355
|
-
template = tryReplaceComponent(template, '"MODERNIZR"',
|
|
4393
|
+
template = tryReplaceComponent(template, '"MODERNIZR"', join4(parentDir, "modernizr.js"), true);
|
|
4356
4394
|
}
|
|
4357
4395
|
const displayStart = startName === "Start" ? "" : startName;
|
|
4358
4396
|
template = template.replace('"VERSION"', `Compiled with ${CREATOR_NAME2}, ${VERSION}`);
|
|
@@ -4365,7 +4403,7 @@ function toTwine1HTML(story, format, startName) {
|
|
|
4365
4403
|
} else {
|
|
4366
4404
|
let footer;
|
|
4367
4405
|
try {
|
|
4368
|
-
footer =
|
|
4406
|
+
footer = readFileSync3(join4(formatDir, "footer.html"), "utf-8");
|
|
4369
4407
|
} catch {
|
|
4370
4408
|
footer = "</div>\n</body>\n</html>\n";
|
|
4371
4409
|
}
|
|
@@ -4395,7 +4433,7 @@ function getTwine1PassageChunk(story) {
|
|
|
4395
4433
|
function tryReplaceComponent(template, placeholder, componentPath, required) {
|
|
4396
4434
|
if (!template.includes(placeholder)) return template;
|
|
4397
4435
|
try {
|
|
4398
|
-
let content =
|
|
4436
|
+
let content = readFileSync3(componentPath, "utf-8");
|
|
4399
4437
|
if (content.charCodeAt(0) === 65279) content = content.slice(1);
|
|
4400
4438
|
return template.replace(placeholder, () => content);
|
|
4401
4439
|
} catch (e) {
|
|
@@ -4492,8 +4530,8 @@ function modifyHead(html, modulePaths, headFile, diagnostics) {
|
|
|
4492
4530
|
}
|
|
4493
4531
|
|
|
4494
4532
|
// src/remote-formats.ts
|
|
4495
|
-
import { mkdirSync, readFileSync as
|
|
4496
|
-
import { join as
|
|
4533
|
+
import { mkdirSync, readFileSync as readFileSync4, writeFileSync, existsSync, readdirSync as readdirSync3, statSync as statSync4, rmSync } from "fs";
|
|
4534
|
+
import { join as join5 } from "path";
|
|
4497
4535
|
import { homedir as homedir2 } from "os";
|
|
4498
4536
|
var DEFAULT_SFA_INDICES = [
|
|
4499
4537
|
"https://videlais.github.io/story-formats-archive/official/index.json",
|
|
@@ -4501,8 +4539,8 @@ var DEFAULT_SFA_INDICES = [
|
|
|
4501
4539
|
];
|
|
4502
4540
|
function getCacheDir() {
|
|
4503
4541
|
const xdg = process.env["XDG_CACHE_HOME"];
|
|
4504
|
-
const base = xdg ||
|
|
4505
|
-
return
|
|
4542
|
+
const base = xdg || join5(homedir2(), ".cache");
|
|
4543
|
+
return join5(base, "twee-ts", "storyformats");
|
|
4506
4544
|
}
|
|
4507
4545
|
var indexCache = /* @__PURE__ */ new Map();
|
|
4508
4546
|
function clearIndexCache() {
|
|
@@ -4592,9 +4630,9 @@ async function fetchAndCacheFormat(entry, downloadUrl) {
|
|
|
4592
4630
|
throw new Error(`Failed to parse format JSON from ${downloadUrl}`);
|
|
4593
4631
|
}
|
|
4594
4632
|
const cacheDir = getCacheDir();
|
|
4595
|
-
const formatDir =
|
|
4633
|
+
const formatDir = join5(cacheDir, entry.name, entry.version);
|
|
4596
4634
|
mkdirSync(formatDir, { recursive: true });
|
|
4597
|
-
const formatPath =
|
|
4635
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4598
4636
|
writeFileSync(formatPath, text, "utf-8");
|
|
4599
4637
|
return {
|
|
4600
4638
|
id,
|
|
@@ -4618,9 +4656,9 @@ async function fetchDirectFormat(url) {
|
|
|
4618
4656
|
}
|
|
4619
4657
|
const id = makeFormatId(data.name, data.version);
|
|
4620
4658
|
const cacheDir = getCacheDir();
|
|
4621
|
-
const formatDir =
|
|
4659
|
+
const formatDir = join5(cacheDir, data.name, data.version);
|
|
4622
4660
|
mkdirSync(formatDir, { recursive: true });
|
|
4623
|
-
const formatPath =
|
|
4661
|
+
const formatPath = join5(formatDir, "format.js");
|
|
4624
4662
|
writeFileSync(formatPath, text, "utf-8");
|
|
4625
4663
|
return {
|
|
4626
4664
|
id,
|
|
@@ -4668,10 +4706,10 @@ async function resolveRemoteFormat(name, version, indices, urls) {
|
|
|
4668
4706
|
return void 0;
|
|
4669
4707
|
}
|
|
4670
4708
|
function getCachedFormat(name, version) {
|
|
4671
|
-
const formatPath =
|
|
4709
|
+
const formatPath = join5(getCacheDir(), name, version, "format.js");
|
|
4672
4710
|
try {
|
|
4673
4711
|
if (!existsSync(formatPath)) return void 0;
|
|
4674
|
-
const source =
|
|
4712
|
+
const source = readFileSync4(formatPath, "utf-8");
|
|
4675
4713
|
const id = makeFormatId(name, version);
|
|
4676
4714
|
const data = parseFormatJSON(source, id);
|
|
4677
4715
|
if (!data) return void 0;
|
|
@@ -4702,7 +4740,7 @@ function discoverCachedFormats() {
|
|
|
4702
4740
|
return formats;
|
|
4703
4741
|
}
|
|
4704
4742
|
for (const name of names) {
|
|
4705
|
-
const nameDir =
|
|
4743
|
+
const nameDir = join5(cacheDir, name);
|
|
4706
4744
|
try {
|
|
4707
4745
|
if (!statSync4(nameDir).isDirectory()) continue;
|
|
4708
4746
|
} catch {
|
|
@@ -4738,7 +4776,7 @@ function listCachedFormats() {
|
|
|
4738
4776
|
return entries;
|
|
4739
4777
|
}
|
|
4740
4778
|
for (const name of names) {
|
|
4741
|
-
const nameDir =
|
|
4779
|
+
const nameDir = join5(cacheDir, name);
|
|
4742
4780
|
try {
|
|
4743
4781
|
if (!statSync4(nameDir).isDirectory()) continue;
|
|
4744
4782
|
} catch {
|
|
@@ -4751,7 +4789,7 @@ function listCachedFormats() {
|
|
|
4751
4789
|
continue;
|
|
4752
4790
|
}
|
|
4753
4791
|
for (const version of versions) {
|
|
4754
|
-
const formatPath =
|
|
4792
|
+
const formatPath = join5(nameDir, version, "format.js");
|
|
4755
4793
|
try {
|
|
4756
4794
|
const stat = statSync4(formatPath);
|
|
4757
4795
|
entries.push({
|
|
@@ -4775,7 +4813,7 @@ function clearCachedFormats(name) {
|
|
|
4775
4813
|
rmSync(cacheDir, { recursive: true, force: true });
|
|
4776
4814
|
return count2;
|
|
4777
4815
|
}
|
|
4778
|
-
const nameDir =
|
|
4816
|
+
const nameDir = join5(cacheDir, name);
|
|
4779
4817
|
if (!existsSync(nameDir)) return 0;
|
|
4780
4818
|
let versions;
|
|
4781
4819
|
try {
|
|
@@ -5179,18 +5217,18 @@ function formatLintReport(result) {
|
|
|
5179
5217
|
}
|
|
5180
5218
|
|
|
5181
5219
|
// src/config.ts
|
|
5182
|
-
import { readFileSync as
|
|
5183
|
-
import { join as
|
|
5220
|
+
import { readFileSync as readFileSync5, existsSync as existsSync2 } from "fs";
|
|
5221
|
+
import { join as join6 } from "path";
|
|
5184
5222
|
var CONFIG_FILENAME = "twee-ts.config.json";
|
|
5185
5223
|
var VALID_OUTPUT_MODES = ["html", "twee3", "twee1", "twine2-archive", "twine1-archive", "json"];
|
|
5186
5224
|
var VALID_WORD_COUNT_METHODS = ["tweego", "whitespace"];
|
|
5187
5225
|
function loadConfig(dir) {
|
|
5188
5226
|
const base = dir ?? process.cwd();
|
|
5189
|
-
const configPath =
|
|
5227
|
+
const configPath = join6(base, CONFIG_FILENAME);
|
|
5190
5228
|
if (!existsSync2(configPath)) return null;
|
|
5191
5229
|
let raw;
|
|
5192
5230
|
try {
|
|
5193
|
-
raw =
|
|
5231
|
+
raw = readFileSync5(configPath, "utf-8");
|
|
5194
5232
|
} catch {
|
|
5195
5233
|
return null;
|
|
5196
5234
|
}
|
|
@@ -5210,7 +5248,7 @@ function loadConfig(dir) {
|
|
|
5210
5248
|
function loadConfigFile(filePath) {
|
|
5211
5249
|
let raw;
|
|
5212
5250
|
try {
|
|
5213
|
-
raw =
|
|
5251
|
+
raw = readFileSync5(filePath, "utf-8");
|
|
5214
5252
|
} catch (e) {
|
|
5215
5253
|
throw new Error(`Cannot read config file ${filePath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
5216
5254
|
}
|