@textadventures/squiffy-cli 7.0.0-beta.3 → 7.0.0-beta.5

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/assets.d.ts CHANGED
@@ -5,4 +5,9 @@ import type { CompileSuccess } from "squiffy-compiler";
5
5
  * Returns a map of path (relative to the story folder, with "/" separators) to bytes.
6
6
  */
7
7
  export declare const findAssets: (inputFilename: string, storyText: string) => Record<string, Uint8Array>;
8
+ /**
9
+ * Reads the story's own stylesheets and scripts (@import of .css and .js files), which the compiler
10
+ * names relative to the story folder, so they can go in the zip or be included in a single HTML file.
11
+ */
12
+ export declare const findImportedFiles: (inputFilename: string, result: CompileSuccess) => Record<string, Uint8Array>;
8
13
  export declare const getStoryText: (result: CompileSuccess) => string;
package/dist/assets.js CHANGED
@@ -30,23 +30,40 @@ export const findAssets = (inputFilename, storyText) => {
30
30
  }
31
31
  if (reference in result)
32
32
  continue;
33
- const filename = path.resolve(basePath, reference);
34
- const relative = path.relative(basePath, filename);
35
- if (!relative || relative.startsWith("..") || path.isAbsolute(relative))
36
- continue;
37
- let stat;
38
- try {
39
- stat = fs.statSync(filename);
40
- }
41
- catch {
42
- continue;
43
- }
44
- if (!stat.isFile())
45
- continue;
46
- result[relative.split(path.sep).join("/")] = fs.readFileSync(filename);
33
+ readFileInFolder(basePath, reference, result);
47
34
  }
48
35
  return result;
49
36
  };
37
+ // Adds a file to result, by its path relative to basePath, if it's a file in that folder (or below it)
38
+ const readFileInFolder = (basePath, reference, result) => {
39
+ const filename = path.resolve(basePath, reference);
40
+ const relative = path.relative(basePath, filename);
41
+ if (!relative || relative.startsWith("..") || path.isAbsolute(relative))
42
+ return;
43
+ let stat;
44
+ try {
45
+ stat = fs.statSync(filename);
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ if (!stat.isFile())
51
+ return;
52
+ result[relative.split(path.sep).join("/")] = fs.readFileSync(filename);
53
+ };
54
+ /**
55
+ * Reads the story's own stylesheets and scripts (@import of .css and .js files), which the compiler
56
+ * names relative to the story folder, so they can go in the zip or be included in a single HTML file.
57
+ */
58
+ export const findImportedFiles = (inputFilename, result) => {
59
+ const basePath = path.resolve(path.dirname(inputFilename));
60
+ const { externalStylesheets, externalScripts } = result.getUiInfo();
61
+ const files = {};
62
+ for (const reference of [...externalStylesheets, ...externalScripts]) {
63
+ readFileInFolder(basePath, reference, files);
64
+ }
65
+ return files;
66
+ };
50
67
  // All the text and script in a compiled story, which is where we look for asset references.
51
68
  export const getStoryText = (result) => {
52
69
  const texts = [];
@@ -70,4 +70,31 @@ describe("createPackageFiles with assets", () => {
70
70
  const html = await fs.readFile(path.join(STORY_DIR, "index.html"), "utf8");
71
71
  expect(html).toContain('"cat.png":"data:image/png;base64,iVBORw=="');
72
72
  });
73
+ const importingStory = `@title Imports
74
+ @import my_style.css
75
+ @import my_script.js
76
+
77
+ ![A cat](cat.png)`;
78
+ test("includes the story's own stylesheets and scripts in inline HTML", async () => {
79
+ await writeFile("story.squiffy", importingStory);
80
+ await writeFile("cat.png");
81
+ await writeFile("my_style.css", "#squiffy { color: rebeccapurple; }");
82
+ await writeFile("my_script.js", "window.storyScriptRan = true;");
83
+ expect(await createPackageFiles(storyFile, STORY_DIR, { inlineHtml: true })).toBe(true);
84
+ const html = await fs.readFile(path.join(STORY_DIR, "index.html"), "utf8");
85
+ expect(html).toContain("#squiffy { color: rebeccapurple; }");
86
+ expect(html).toContain("window.storyScriptRan = true;");
87
+ expect(html).not.toContain('href="my_style.css"');
88
+ expect(html).not.toContain('src="my_script.js"');
89
+ expect(html).toContain('"cat.png":"data:image/png;base64,iVBORw=="');
90
+ });
91
+ test("adds the story's own stylesheets and scripts to the zip", async () => {
92
+ await writeFile("story.squiffy", importingStory);
93
+ await writeFile("cat.png");
94
+ await writeFile("my_style.css", "#squiffy { color: rebeccapurple; }");
95
+ await writeFile("my_script.js", "window.storyScriptRan = true;");
96
+ expect(await createPackageFiles(storyFile, STORY_DIR, { createZip: true })).toBe(true);
97
+ const zip = unzipSync(new Uint8Array(await fs.readFile(path.join(STORY_DIR, "output.zip"))));
98
+ expect(Object.keys(zip).sort()).toEqual(["cat.png", "index.html", "my_script.js", "my_style.css", "squiffy.runtime.global.js", "story.js", "style.css"]);
99
+ });
73
100
  });
@@ -0,0 +1,2 @@
1
+ export declare const PROBLEMS_FILENAME = "twine-import.txt";
2
+ export declare const convertTwineFile: (inputFilename: string, outputFolder?: string) => boolean;
@@ -0,0 +1,44 @@
1
+ import * as fs from "fs";
2
+ import path from "path";
3
+ import { convertTwine, formatTwineProblems, TwineParseError } from "squiffy-compiler";
4
+ export const PROBLEMS_FILENAME = "twine-import.txt";
5
+ // Converts a Twine story (#378), in Twee or Twine's HTML, into a new folder with a Squiffy story
6
+ // in it: the story file, a squiffy.json, the story's CSS and JavaScript, and twine-import.txt,
7
+ // which lists what couldn't be converted exactly. The folder is next to the Twine file, with the
8
+ // same name, unless another is given. Returns false if the story couldn't be converted.
9
+ export const convertTwineFile = (inputFilename, outputFolder) => {
10
+ console.log("Loading " + inputFilename);
11
+ if (!fs.existsSync(inputFilename)) {
12
+ console.error(`${inputFilename} doesn't exist.`);
13
+ return false;
14
+ }
15
+ const parsed = path.parse(path.resolve(inputFilename));
16
+ const folder = path.resolve(outputFolder ?? path.join(parsed.dir, parsed.name));
17
+ if (fs.existsSync(folder) && (!fs.statSync(folder).isDirectory() || fs.readdirSync(folder).length > 0)) {
18
+ console.error(`${folder} already exists. Choose another folder with --out, or move it out of the way.`);
19
+ return false;
20
+ }
21
+ let result;
22
+ try {
23
+ result = convertTwine(fs.readFileSync(inputFilename, "utf8"));
24
+ }
25
+ catch (e) {
26
+ if (e instanceof TwineParseError) {
27
+ console.error(e.message);
28
+ return false;
29
+ }
30
+ throw e;
31
+ }
32
+ fs.mkdirSync(folder, { recursive: true });
33
+ for (const [name, text] of Object.entries(result.files)) {
34
+ fs.writeFileSync(path.join(folder, name), text);
35
+ }
36
+ fs.writeFileSync(path.join(folder, PROBLEMS_FILENAME), formatTwineProblems(result, parsed.base));
37
+ const relative = path.relative(process.cwd(), folder) || ".";
38
+ console.log(`Converted ${result.passages} passage${result.passages == 1 ? "" : "s"} from ${result.format || "Twine"} into ${path.join(relative, result.main)}.`);
39
+ if (result.problems.length > 0) {
40
+ console.warn(`${result.problems.length} thing${result.problems.length == 1 ? "" : "s"} couldn't be converted exactly. They're listed in ${path.join(relative, PROBLEMS_FILENAME)}.`);
41
+ }
42
+ console.log(`To try it: npx @textadventures/squiffy-cli ${relative} -s`);
43
+ return true;
44
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { describe, test, expect, beforeEach, afterEach, vi } from "vitest";
2
+ import { convertTwineFile } from "./convert-twine.js";
3
+ import fs from "fs/promises";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const TEST_DIR = path.join(__dirname, "..", "test-fixtures-convert-twine");
8
+ const tweeFile = path.join(TEST_DIR, "cave.twee");
9
+ const outputFolder = path.join(TEST_DIR, "cave");
10
+ const twee = `:: StoryTitle
11
+ The Cave
12
+
13
+ :: StoryData
14
+ { "format": "Harlowe", "format-version": "3.3.9", "start": "Start" }
15
+
16
+ :: Start
17
+ (set: $torch to false)You're at the mouth of a cave. [[Go in->Cave]]
18
+
19
+ :: Cave
20
+ (if: $torch)[You can see.](else:)[It's dark.] (click: ?page)[Bats!]
21
+ `;
22
+ beforeEach(async () => {
23
+ await fs.mkdir(TEST_DIR, { recursive: true });
24
+ vi.spyOn(console, "log").mockImplementation(() => { });
25
+ vi.spyOn(console, "warn").mockImplementation(() => { });
26
+ vi.spyOn(console, "error").mockImplementation(() => { });
27
+ });
28
+ afterEach(async () => {
29
+ vi.restoreAllMocks();
30
+ await fs.rm(TEST_DIR, { recursive: true, force: true });
31
+ });
32
+ describe("convertTwineFile", () => {
33
+ test("converts the story into a folder named after the file", async () => {
34
+ await fs.writeFile(tweeFile, twee);
35
+ expect(convertTwineFile(tweeFile)).toBe(true);
36
+ const story = await fs.readFile(path.join(outputFolder, "story.squiffy"), "utf8");
37
+ expect(story).toContain("@title The Cave");
38
+ expect(story).toContain("[[Start]]:\n@set torch = false\nYou're at the mouth of a cave. [[Go in]](Cave)");
39
+ expect(story).toContain("{{#if torch}}You can see.{{else}}It's dark.{{/if}}");
40
+ expect(JSON.parse(await fs.readFile(path.join(outputFolder, "squiffy.json"), "utf8")).main).toBe("story.squiffy");
41
+ expect(await fs.readFile(path.join(outputFolder, "twine-import.txt"), "utf8")).toContain("Clicking anywhere on the page has been converted to Continue links.");
42
+ });
43
+ test("writes to the folder given", async () => {
44
+ await fs.writeFile(tweeFile, twee);
45
+ const other = path.join(TEST_DIR, "other");
46
+ expect(convertTwineFile(tweeFile, other)).toBe(true);
47
+ await expect(fs.access(path.join(other, "story.squiffy"))).resolves.toBeUndefined();
48
+ });
49
+ test("doesn't write into a folder that has files in it", async () => {
50
+ await fs.writeFile(tweeFile, twee);
51
+ await fs.mkdir(outputFolder);
52
+ await fs.writeFile(path.join(outputFolder, "notes.txt"), "mine");
53
+ expect(convertTwineFile(tweeFile)).toBe(false);
54
+ await expect(fs.access(path.join(outputFolder, "story.squiffy"))).rejects.toThrow();
55
+ });
56
+ test("says if the file isn't a Twine story", async () => {
57
+ const htmlFile = path.join(TEST_DIR, "page.html");
58
+ await fs.writeFile(htmlFile, "<html><body>Hello</body></html>");
59
+ expect(convertTwineFile(htmlFile)).toBe(false);
60
+ expect(console.error).toHaveBeenCalledWith("This doesn't look like a Twine story: there's no story data in it.");
61
+ });
62
+ });
@@ -0,0 +1 @@
1
+ export declare const convertV6Story: (inputFilename: string) => Promise<boolean>;
@@ -0,0 +1,74 @@
1
+ import * as fs from "fs";
2
+ import path from "path";
3
+ import { analyse, convertSetters, findV5Syntax, formatProjectFile, PROJECT_FILENAME } from "squiffy-compiler";
4
+ import { listSquiffyFiles } from "squiffy-compiler/node";
5
+ import { externalFiles } from "./external-files.js";
6
+ // Converts a Squiffy 6 story to Squiffy 7's rules for setters (#373): text in @set and link
7
+ // setters is quoted, and @name becomes name, in the main file and every .squiffy file it
8
+ // @imports. Then adds a squiffy.json, which is what turns the new rules on, leaving out any other
9
+ // .squiffy files in the folder so the story is made of the same files as before. Each changed
10
+ // file is kept with a .bak extension. Returns false if the story couldn't be converted.
11
+ export const convertV6Story = async (inputFilename) => {
12
+ const mainFile = path.resolve(inputFilename);
13
+ const root = path.dirname(mainFile);
14
+ console.log("Loading " + mainFile);
15
+ for (let dir = root;; dir = path.dirname(dir)) {
16
+ const projectFile = path.join(dir, PROJECT_FILENAME);
17
+ if (fs.existsSync(projectFile)) {
18
+ console.error(`${projectFile} already exists, so this story already uses Squiffy 7's rules for setters.`);
19
+ return false;
20
+ }
21
+ if (path.dirname(dir) == dir)
22
+ break;
23
+ }
24
+ const script = fs.readFileSync(mainFile).toString();
25
+ if (findV5Syntax(script).length > 0) {
26
+ console.error("This story looks like it uses Squiffy 5 text processor syntax. Run with --convert-v5 first.");
27
+ return false;
28
+ }
29
+ // The story's files: the main file and the .squiffy files it @imports
30
+ const analysis = await analyse({ script, scriptBaseFilename: path.basename(mainFile), externalFiles: externalFiles(mainFile) });
31
+ if (!analysis.success) {
32
+ console.error("The story has errors, so it can't be converted. Fix them, then try again.");
33
+ return false;
34
+ }
35
+ const storyFiles = analysis.files.map((file, i) => i == 0 ? mainFile : path.resolve(root, file.filename ?? ""));
36
+ // Convert everything first, so nothing is written if a .bak is in the way
37
+ const changes = [];
38
+ let problems = 0;
39
+ for (const filename of storyFiles) {
40
+ const result = convertSetters(fs.readFileSync(filename).toString());
41
+ if (result.converted > 0) {
42
+ if (fs.existsSync(filename + ".bak")) {
43
+ console.error(`${filename}.bak already exists. Move or delete it, then try again.`);
44
+ return false;
45
+ }
46
+ changes.push({ filename, script: result.script, converted: result.converted });
47
+ }
48
+ if (result.problems.length > 0) {
49
+ if (problems == 0)
50
+ console.warn("These couldn't be converted automatically, so have been left as they are:");
51
+ for (const problem of result.problems) {
52
+ console.warn(` ${path.relative(root, filename)} line ${problem.line}: ${problem.text}`);
53
+ console.warn(` ${problem.reason}`);
54
+ }
55
+ problems += result.problems.length;
56
+ }
57
+ }
58
+ for (const change of changes) {
59
+ fs.copyFileSync(change.filename, change.filename + ".bak");
60
+ fs.writeFileSync(change.filename, change.script);
61
+ console.log(`Converted ${change.converted} setter${change.converted == 1 ? "" : "s"} in ${path.relative(root, change.filename)}. The original file has been saved as ${path.basename(change.filename)}.bak`);
62
+ }
63
+ if (changes.length == 0) {
64
+ console.log("No setters needed converting.");
65
+ }
66
+ // squiffy.json makes every .squiffy file in the folder part of the story, so leave out the
67
+ // ones that weren't
68
+ const inStory = new Set(storyFiles);
69
+ const exclude = (await listSquiffyFiles(root)).filter(file => !inStory.has(path.resolve(root, file)));
70
+ fs.writeFileSync(path.join(root, PROJECT_FILENAME), formatProjectFile({ main: path.basename(mainFile), exclude }));
71
+ console.log(`Added ${PROJECT_FILENAME}, so the story now uses Squiffy 7's rules for setters.`
72
+ + (exclude.length ? ` It leaves out the other .squiffy files in the folder: ${exclude.join(", ")}.` : ""));
73
+ return true;
74
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,67 @@
1
+ import { describe, test, expect, beforeEach, afterEach, vi } from "vitest";
2
+ import { convertV6Story } from "./convert-v6.js";
3
+ import fs from "fs/promises";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const TEST_DIR = path.join(__dirname, "..", "test-fixtures-convert-v6");
8
+ const file = (name) => path.join(TEST_DIR, name);
9
+ const read = (name) => fs.readFile(file(name), "utf8");
10
+ const exists = (name) => fs.access(file(name)).then(() => true, () => false);
11
+ beforeEach(async () => {
12
+ await fs.mkdir(path.join(TEST_DIR, "parts"), { recursive: true });
13
+ vi.spyOn(console, "log").mockImplementation(() => { });
14
+ vi.spyOn(console, "warn").mockImplementation(() => { });
15
+ vi.spyOn(console, "error").mockImplementation(() => { });
16
+ });
17
+ afterEach(async () => {
18
+ vi.restoreAllMocks();
19
+ await fs.rm(TEST_DIR, { recursive: true, force: true });
20
+ });
21
+ describe("convertV6Story", () => {
22
+ test("converts the main file and its imports, keeps backups, and adds a squiffy.json", async () => {
23
+ const main = "@import parts/shop.squiffy\n\n[[start]]:\n@set weapon = sword\n[[Shop]](shop, gold = @start_gold)";
24
+ const shop = "[[shop]]:\n@set mood = grumpy";
25
+ const unchanged = "[[other]]:\n@set gold = 10";
26
+ await fs.writeFile(file("story.squiffy"), main);
27
+ await fs.writeFile(file("parts/shop.squiffy"), shop);
28
+ await fs.writeFile(file("parts/other.squiffy"), "@import ../unused.squiffy");
29
+ await fs.writeFile(file("unused.squiffy"), unchanged);
30
+ await fs.writeFile(file("story2.squiffy"), "[[x]]:\n@set a = b");
31
+ expect(await convertV6Story(file("story.squiffy"))).toBe(true);
32
+ expect(await read("story.squiffy")).toBe("@import parts/shop.squiffy\n\n[[start]]:\n@set weapon = \"sword\"\n[[Shop]](shop, gold = start_gold)");
33
+ expect(await read("parts/shop.squiffy")).toBe("[[shop]]:\n@set mood = \"grumpy\"");
34
+ expect(await read("story.squiffy.bak")).toBe(main);
35
+ expect(await read("parts/shop.squiffy.bak")).toBe(shop);
36
+ // Files that aren't part of the story are left alone, and left out of it
37
+ expect(await read("story2.squiffy")).toBe("[[x]]:\n@set a = b");
38
+ expect(JSON.parse(await read("squiffy.json"))).toMatchObject({
39
+ main: "story.squiffy",
40
+ exclude: ["parts/other.squiffy", "story2.squiffy", "unused.squiffy"],
41
+ });
42
+ });
43
+ test("adds a squiffy.json even if nothing needs converting", async () => {
44
+ await fs.writeFile(file("story.squiffy"), "[[start]]:\n@set gold = 10");
45
+ expect(await convertV6Story(file("story.squiffy"))).toBe(true);
46
+ expect(await exists("story.squiffy.bak")).toBe(false);
47
+ expect(JSON.parse(await read("squiffy.json")).main).toBe("story.squiffy");
48
+ });
49
+ test("refuses a story that already has a squiffy.json", async () => {
50
+ await fs.writeFile(file("story.squiffy"), "[[start]]:\n@set a = b");
51
+ await fs.writeFile(file("squiffy.json"), "{ \"version\": 1, \"main\": \"story.squiffy\" }");
52
+ expect(await convertV6Story(file("story.squiffy"))).toBe(false);
53
+ expect(await read("story.squiffy")).toBe("[[start]]:\n@set a = b");
54
+ });
55
+ test("refuses a story with Squiffy 5 syntax", async () => {
56
+ await fs.writeFile(file("story.squiffy"), "[[start]]:\n{if x:yes}\n@set a = b");
57
+ expect(await convertV6Story(file("story.squiffy"))).toBe(false);
58
+ expect(await exists("squiffy.json")).toBe(false);
59
+ });
60
+ test("changes nothing if a backup is in the way", async () => {
61
+ await fs.writeFile(file("story.squiffy"), "[[start]]:\n@set a = b");
62
+ await fs.writeFile(file("story.squiffy.bak"), "old");
63
+ expect(await convertV6Story(file("story.squiffy"))).toBe(false);
64
+ expect(await read("story.squiffy")).toBe("[[start]]:\n@set a = b");
65
+ expect(await exists("squiffy.json")).toBe(false);
66
+ });
67
+ });
@@ -1,11 +1,11 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
- import { compile, findV5Syntax, formatDiagnostic } from "squiffy-compiler";
3
+ import { compile, convertSetters, findV5Syntax, formatDiagnostic } from "squiffy-compiler";
4
4
  import { externalFiles } from "./external-files.js";
5
- import { findAssets, getStoryText } from "./assets.js";
5
+ import { findAssets, findImportedFiles, getStoryText } from "./assets.js";
6
6
  import { createPackage } from "@textadventures/squiffy-packager";
7
7
  // A story given as a filename is just that file and its @imports, as with no squiffy.json
8
- const toStory = (input) => typeof input == "string" ? { mainFile: input } : input;
8
+ const toStory = (input) => typeof input == "string" ? { mainFile: input, expressions: false } : input;
9
9
  async function getCompileResult(story) {
10
10
  const inputFilename = story.mainFile;
11
11
  const inputFile = fs.readFileSync(inputFilename);
@@ -13,11 +13,15 @@ async function getCompileResult(story) {
13
13
  if (findV5Syntax(inputText).length > 0) {
14
14
  console.warn("This story looks like it uses Squiffy 5 text processor syntax. Run with --convert-v5 to convert it to Squiffy 6.");
15
15
  }
16
+ else if (!story.expressions && convertSetters(inputText).converted > 0) {
17
+ console.log("This story uses Squiffy 6's rules for @set and link setters. Run with --convert-v6 to convert it to Squiffy 7's.");
18
+ }
16
19
  const result = await compile({
17
20
  scriptBaseFilename: path.basename(inputFilename),
18
21
  script: inputText,
19
22
  externalFiles: externalFiles(inputFilename),
20
23
  storyFiles: story.storyFiles,
24
+ expressions: story.expressions,
21
25
  globalJs: true,
22
26
  });
23
27
  for (const diagnostic of result.diagnostics) {
@@ -55,9 +59,13 @@ export const createPackageFiles = async (input, outputPath, options = {}) => {
55
59
  console.log("Failed.");
56
60
  return false;
57
61
  }
58
- // Asset files (images etc.) referenced by the story. The other package files are written to the
59
- // story's folder, alongside these, so they only need to be passed on for the zip or for inlining.
60
- const assets = options.assets ?? findAssets(inputFilename, getStoryText(result));
62
+ // Asset files (images etc.) referenced by the story, and its own stylesheets and scripts. The other
63
+ // package files are written to the story's folder, alongside these, so they only need to be passed
64
+ // on for the zip or for inlining.
65
+ const assets = options.assets ?? {
66
+ ...findAssets(inputFilename, getStoryText(result)),
67
+ ...findImportedFiles(inputFilename, result),
68
+ };
61
69
  const assetPaths = Object.keys(assets);
62
70
  if (assetPaths.length > 0 && (options.createZip || options.inlineHtml)) {
63
71
  console.log(`Including asset${assetPaths.length == 1 ? "" : "s"}: ${assetPaths.join(", ")}`);
package/dist/squiffy.js CHANGED
@@ -4,6 +4,8 @@ import { hideBin } from "yargs/helpers";
4
4
  import { serve } from "./server.js";
5
5
  import { createPackageFiles, writeScriptFile } from "./file-packager.js";
6
6
  import { convertV5File } from "./convert-v5.js";
7
+ import { convertV6Story } from "./convert-v6.js";
8
+ import { convertTwineFile } from "./convert-twine.js";
7
9
  import { findStory, StoryNotFoundError } from "squiffy-compiler/node";
8
10
  import pkg from "../package.json" with { type: "json" };
9
11
  import path from "path";
@@ -20,6 +22,12 @@ const argv = yargs(hideBin(process.argv))
20
22
  .describe("inline", "Create single HTML file with everything inlined")
21
23
  .describe("convert-v5", "Convert Squiffy 5 text processor syntax to Squiffy 6, keeping a backup of the original file")
22
24
  .boolean("convert-v5")
25
+ .describe("convert-v6", "Convert a Squiffy 6 story's @set and link setters to Squiffy 7's rules and add a squiffy.json, keeping a backup of each file changed")
26
+ .boolean("convert-v6")
27
+ .describe("convert-twine", "Convert a Twine story (a .twee file, or Twine's published or archive .html) to Squiffy, in a new folder next to it")
28
+ .boolean("convert-twine")
29
+ .describe("out", "With --convert-twine, the folder to put the Squiffy story in")
30
+ .string("out")
23
31
  .version(version)
24
32
  .parseSync();
25
33
  console.log("Squiffy " + version);
@@ -50,6 +58,24 @@ if (argv.convertV5) {
50
58
  process.exitCode = 1;
51
59
  }
52
60
  }
61
+ else if (argv.convertV6) {
62
+ if (argv._[0] === undefined) {
63
+ console.error("Give the story's main .squiffy file to convert.");
64
+ process.exitCode = 1;
65
+ }
66
+ else if (!await convertV6Story(input)) {
67
+ process.exitCode = 1;
68
+ }
69
+ }
70
+ else if (argv.convertTwine) {
71
+ if (argv._[0] === undefined) {
72
+ console.error("Give the Twine file to convert: a .twee file, or Twine's published or archive .html.");
73
+ process.exitCode = 1;
74
+ }
75
+ else if (!convertTwineFile(input, argv.out)) {
76
+ process.exitCode = 1;
77
+ }
78
+ }
53
79
  else if (options.scriptOnly) {
54
80
  const story = await findStoryOrExit();
55
81
  const outputFilename = typeof options.scriptOnly === "string" ? options.scriptOnly : "story.js";
@@ -60,7 +86,8 @@ else {
60
86
  const outputPath = path.dirname(story.mainFile);
61
87
  const result = await createPackageFiles(story, outputPath, {
62
88
  createZip: !!options.zip,
63
- inlineHtml: !!options.inline
89
+ inlineHtml: !!options.inline,
90
+ backButton: story.backButton,
64
91
  });
65
92
  if (result && options.serve) {
66
93
  const port = argv.p || 8282;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textadventures/squiffy-cli",
3
- "version": "7.0.0-beta.3",
3
+ "version": "7.0.0-beta.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/textadventures/squiffy.git",
@@ -35,12 +35,12 @@
35
35
  "squiffy-packager": "dist/squiffy.js"
36
36
  },
37
37
  "dependencies": {
38
- "@textadventures/squiffy-packager": "^7.0.0-beta.3",
38
+ "@textadventures/squiffy-packager": "^7.0.0-beta.5",
39
39
  "finalhandler": "^2.1.0",
40
40
  "glob": "^14.0.6",
41
41
  "serve-static": "^2.2.0",
42
- "squiffy-compiler": "^7.0.0-beta.3",
43
- "squiffy-runtime": "^7.0.0-beta.3",
42
+ "squiffy-compiler": "^7.0.0-beta.5",
43
+ "squiffy-runtime": "^7.0.0-beta.5",
44
44
  "yargs": "^18.2.0"
45
45
  },
46
46
  "devDependencies": {
@@ -56,6 +56,5 @@
56
56
  "files": [
57
57
  "dist"
58
58
  ],
59
- "type": "module",
60
- "gitHead": "016f53cc52dc2cf504787ef8329740ca2cf8d481"
59
+ "type": "module"
61
60
  }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014-2026 Alex Warren, textadventures.co.uk and contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-