@textadventures/squiffy-cli 6.0.0-alpha.19

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2024 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
+
@@ -0,0 +1,5 @@
1
+ export declare const externalFiles: (inputFilename: string) => {
2
+ getMatchingFilenames: (pattern: string) => Promise<string[]>;
3
+ getContent: (filename: string) => Promise<string>;
4
+ getLocalFilename(filename: string): string;
5
+ };
@@ -0,0 +1,21 @@
1
+ import { glob } from "glob";
2
+ import path from "path";
3
+ import fs from "fs/promises";
4
+ export const externalFiles = (inputFilename) => {
5
+ const includedFiles = [path.resolve(inputFilename)];
6
+ const basePath = path.resolve(path.dirname(inputFilename));
7
+ return {
8
+ getMatchingFilenames: async (pattern) => {
9
+ const filenames = path.join(basePath, pattern);
10
+ const result = await glob(filenames);
11
+ return result.filter((filename) => !includedFiles.includes(filename));
12
+ },
13
+ getContent: async (filename) => {
14
+ includedFiles.push(filename);
15
+ return (await fs.readFile(filename)).toString();
16
+ },
17
+ getLocalFilename(filename) {
18
+ return path.relative(basePath, filename);
19
+ }
20
+ };
21
+ };
@@ -0,0 +1,2 @@
1
+ export declare const writeScriptFile: (inputFilename: string, outputPath: string, outputFilename: string) => Promise<false | undefined>;
2
+ export declare const createPackageFiles: (inputFilename: string, outputPath: string, createZip: boolean) => Promise<boolean>;
@@ -0,0 +1,46 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { compile } from "squiffy-compiler";
4
+ import { externalFiles } from "./external-files.js";
5
+ import { createPackage } from "@textadventures/squiffy-packager";
6
+ async function getCompileResult(inputFilename) {
7
+ const inputFile = fs.readFileSync(inputFilename);
8
+ const inputText = inputFile.toString();
9
+ return await compile({
10
+ scriptBaseFilename: path.basename(inputFilename),
11
+ script: inputText,
12
+ onWarning: console.warn,
13
+ externalFiles: externalFiles(inputFilename),
14
+ globalJs: true,
15
+ });
16
+ }
17
+ export const writeScriptFile = async (inputFilename, outputPath, outputFilename) => {
18
+ console.log("Loading " + inputFilename);
19
+ const result = await getCompileResult(inputFilename);
20
+ if (!result.success) {
21
+ console.log("Failed.");
22
+ return false;
23
+ }
24
+ console.log(`Writing ${outputFilename}`);
25
+ fs.writeFileSync(path.join(outputPath, outputFilename), await result.getJs());
26
+ };
27
+ export const createPackageFiles = async (inputFilename, outputPath, createZip) => {
28
+ console.log("Loading " + inputFilename);
29
+ const result = await getCompileResult(inputFilename);
30
+ if (!result.success) {
31
+ console.log("Failed.");
32
+ return false;
33
+ }
34
+ const pkg = await createPackage(result, createZip);
35
+ const files = pkg.files;
36
+ for (const file of Object.keys(files)) {
37
+ console.log(`Writing ${file}`);
38
+ fs.writeFileSync(path.join(outputPath, file), files[file]);
39
+ }
40
+ if (createZip && pkg.zip) {
41
+ console.log("Writing output.zip");
42
+ fs.writeFileSync(path.join(outputPath, "output.zip"), pkg.zip);
43
+ }
44
+ console.log("Done.");
45
+ return true;
46
+ };
@@ -0,0 +1 @@
1
+ export declare const serve: (directory: string, port: number) => void;
package/dist/server.js ADDED
@@ -0,0 +1,15 @@
1
+ import finalhandler from "finalhandler";
2
+ import * as http from "http";
3
+ import serveStatic from "serve-static";
4
+ function startServer(dir, port) {
5
+ const serve = serveStatic(dir, { index: ["index.html"] });
6
+ const server = http.createServer(function (req, res) {
7
+ const done = finalhandler(req, res);
8
+ serve(req, res, done);
9
+ });
10
+ server.listen(port);
11
+ }
12
+ export const serve = (directory, port) => {
13
+ startServer(directory, port);
14
+ console.log("Started http://localhost:" + port + "/");
15
+ };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+ import { serve } from "./server.js";
5
+ import { createPackageFiles, writeScriptFile } from "./file-packager.js";
6
+ import pkg from "../package.json" with { type: "json" };
7
+ import path from "path";
8
+ const version = pkg.version;
9
+ const argv = yargs(hideBin(process.argv))
10
+ .usage("Usage: npx @textadventures/squiffy-cli filename.squiffy [options]")
11
+ .demand(1)
12
+ .alias("s", "serve")
13
+ .alias("p", "port")
14
+ .describe("s", "Start HTTP server after compiling")
15
+ .describe("p", "Port for HTTP server (only with --serve)")
16
+ .describe("scriptonly", "Only generate JavaScript file (and optionally specify a name)")
17
+ .describe("zip", "Create zip file")
18
+ .version(version)
19
+ .parseSync();
20
+ console.log("Squiffy " + version);
21
+ const options = {
22
+ serve: argv.s,
23
+ scriptOnly: argv.scriptonly,
24
+ zip: argv.zip
25
+ };
26
+ const inputFilename = argv._[0];
27
+ const outputPath = path.resolve(path.dirname(inputFilename));
28
+ if (options.scriptOnly) {
29
+ const outputFilename = typeof options.scriptOnly === "string" ? options.scriptOnly : "story.js";
30
+ await writeScriptFile(inputFilename, outputPath, outputFilename);
31
+ }
32
+ else {
33
+ const result = await createPackageFiles(inputFilename, outputPath, !!options.zip);
34
+ if (result && options.serve) {
35
+ const port = argv.p || 8282;
36
+ serve(outputPath, port);
37
+ }
38
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@textadventures/squiffy-cli",
3
+ "version": "6.0.0-alpha.19",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "main": "dist/squiffy.js",
8
+ "scripts": {
9
+ "build": "tsc"
10
+ },
11
+ "author": "Alex Warren",
12
+ "contributors": [
13
+ "CrisisSDK",
14
+ "mrangel",
15
+ "Luis Felipe Morales"
16
+ ],
17
+ "license": "MIT",
18
+ "description": "",
19
+ "bin": {
20
+ "squiffy-packager": "dist/squiffy.js"
21
+ },
22
+ "dependencies": {
23
+ "@textadventures/squiffy-packager": "^6.0.0-alpha.19",
24
+ "finalhandler": "^2.1.0",
25
+ "glob": "^11.0.3",
26
+ "serve-static": "^2.2.0",
27
+ "squiffy-compiler": "^6.0.0-alpha.19",
28
+ "squiffy-runtime": "^6.0.0-alpha.19",
29
+ "yargs": "^18.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/finalhandler": "^1.2.4",
33
+ "@types/node": "^24.2.1",
34
+ "@types/serve-static": "^1.15.8",
35
+ "@types/yargs": "^17.0.33",
36
+ "tsx": "^4.20.4",
37
+ "typescript": "^5.9.2"
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "type": "module",
43
+ "gitHead": "18189480e046a310c261608d7dbebe95987ba3bf"
44
+ }