Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -10,2 +10,4 @@ #!/usr/bin/env node | ||
const fs = require('fs'); | ||
const Babel = require('@babel/standalone'); | ||
const { minify } = require('terser'); | ||
@@ -16,7 +18,7 @@ const { writeFile, stat, mkdir } = fs.promises; | ||
const abs_path = require.resolve(filepath); | ||
return fs.promises.readFile(abs_path); | ||
return fs.promises.readFile(abs_path, 'utf8'); | ||
} | ||
const options = lily(process.argv.slice(2), { boolean: ['debug', 'raw'] }); | ||
const options = lily(process.argv.slice(2), { boolean: ['debug', 'raw', 'c'] }); | ||
const executable = path.basename(process.argv[1]); | ||
@@ -27,3 +29,3 @@ | ||
} else if (options._.length !== 1) { | ||
console.error(`usage: ${executable} -v | -o <output directory> <input.gs>`); | ||
console.error(`usage: ${executable} -v | [-c] [-t <html template>] -o <output directory> <input.gs>`); | ||
} else { | ||
@@ -44,4 +46,21 @@ fs.promises.readFile(options._[0]).then(async buffer => { | ||
const output_code = await wrap_code(code); | ||
writeFile(path.join(options.o, 'index.js'), output_code); | ||
writeFile(path.join(options.o, 'index.html'), await get_terminal()); | ||
const minified = await minify(output_code, { | ||
sourceMap: { | ||
filename: "index.module.js", | ||
url: "index.module.js.map" | ||
} | ||
}); | ||
writeFile(path.join(options.o, 'index.module.js.map'), minified.map); | ||
var module_code = options.c ? minified.code : output_code; | ||
writeFile(path.join(options.o, 'index.module.js'), module_code); | ||
const output_es5_code = Babel.transform(output_code, { presets: ['env'], targets: {ie: 11} }).code; | ||
const index = options.c ? (await minify(output_es5_code)).code : output_es5_code; | ||
writeFile(path.join(options.o, 'index.js'), index); | ||
let template; | ||
if (options.t) { | ||
template = await fs.promises.readFile(options.t, 'utf8'); | ||
} else { | ||
template = await get_terminal(); | ||
} | ||
writeFile(path.join(options.o, 'index.html'), template); | ||
} else { | ||
@@ -106,8 +125,9 @@ console.log(code); | ||
async function get_terminal(mapping) { | ||
const html = (await readFile('../src/terminal.html')).toString(); | ||
const css = (await readFile('../src/terminal.css')).toString(); | ||
const html = await readFile('../src/terminal.html'); | ||
const css = await readFile('../src/terminal.css'); | ||
return template(html, Object.assign({ | ||
STYLE: css, | ||
HTML: '<div id="term"></div>', | ||
FILE: 'index.js', | ||
MODULE: 'index.module.js', | ||
ES5: 'index.js', | ||
VER: json.version | ||
@@ -114,0 +134,0 @@ }, mapping)); |
@@ -8,3 +8,3 @@ /* ______ _ | ||
* Storytelling Text Based Game Engine | ||
* Copyrigth (C) 2021 Jakub T. Jankiewicz <https://jcubic.pl/me> | ||
* Copyrigth (C) 2021-2022 Jakub T. Jankiewicz <https://jcubic.pl/me> | ||
* | ||
@@ -11,0 +11,0 @@ * Released under GNU GPL v3 or later |
{ | ||
"name": "gaiman", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Gaiman Text based advanture games engine and programming language", | ||
@@ -35,5 +35,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.18.5", | ||
"@babel/standalone": "^7.18.5", | ||
"@jcubic/lily": "^0.3.0", | ||
"escodegen": "^2.0.0" | ||
"escodegen": "^2.0.0", | ||
"terser": "^5.14.2" | ||
} | ||
} |
# Gaiman Engine and Programming Language | ||
![Gaiman: Text based advanture games engine and programming language](assets/banner.svg) | ||
![Gaiman: Text based adventure games engine and programming language](https://raw.githubusercontent.com/jcubic/gaiman/master/assets/banner.svg) | ||
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.2-blue.svg)](https://www.npmjs.com/package/gaiman) | ||
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.3-blue.svg)](https://www.npmjs.com/package/gaiman) | ||
[![Build and test](https://github.com/jcubic/gaiman/actions/workflows/build.yaml/badge.svg)](https://github.com/jcubic/gaiman/actions/workflows/build.yaml) | ||
@@ -12,9 +12,11 @@ [![Coverage Status](https://coveralls.io/repos/github/jcubic/gaiman/badge.svg?branch=master)](https://coveralls.io/github/jcubic/gaiman?branch=master) | ||
Main part of Gaiman is a minimalist programming language and main purpose is to help create | ||
Main part of Gaiman is a minimalist, Ruby inspired, programming language. The main purpose of it is to help creating | ||
[Text Adventure Games](https://en.wikipedia.org/wiki/Interactive_fiction). But it can also be used | ||
to create any interactive CLI applications (Web Based Terminal applications). | ||
It support browser based CLI applications and in the future also native command line. | ||
It supports browser based CLI applications and in the future also native command line. | ||
## Installation | ||
First, you need to install [NodeJS](https://nodejs.org/en/). After you're done, you should open terminal and use npm command (that is included with Node). | ||
``` | ||
@@ -39,6 +41,6 @@ npm install -g gaiman@beta | ||
This is Hello world Gaiman DSL example: | ||
```ruby | ||
echo get "https://gaiman.js.org/gaiman.txt" | ||
echo* "Hi, What is your name?", 50 # Typing animation with 50ms delay | ||
@@ -52,2 +54,14 @@ let name = ask "name? " | ||
```ruby | ||
if cookie.visited then | ||
if cookie.user then | ||
let user = cookie.user | ||
echo "Hello $user, welcome back" | ||
else | ||
ask_details("Welcome back stranger") | ||
end | ||
else | ||
cookie.visited = true | ||
ask_details("Welcome stranger") | ||
end | ||
def ask_details(msg) | ||
@@ -85,19 +99,7 @@ echo msg | ||
end | ||
if cookie.visited then | ||
if cookie.user then | ||
let user = cookie.user | ||
echo "Hello $user, welcome back" | ||
else | ||
ask_details("Welcome back strager") | ||
end | ||
else | ||
cookie.visited = true | ||
ask_details("Welcome stranger") | ||
end | ||
``` | ||
More examples in [examples directory](https://github.com/jcubic/gaiman/tree/master/examples) | ||
See [Reference Manual](https://github.com/jcubic/gaiman/wiki/Reference-Manual) | ||
See [Reference Manual](https://github.com/jcubic/gaiman/wiki/Reference-Manual) for details about the features | ||
@@ -108,2 +110,6 @@ ## Live Demo | ||
Live Edit of Gaiman Code: | ||
![Gaiman programming language Playground Demo Session](https://github.com/jcubic/gaiman/blob/master/assets/edit.gif?raw=true) | ||
Live edit of style | ||
![Gaiman programming language Playground Demo Session](https://github.com/jcubic/gaiman/blob/master/assets/simple.gif?raw=true) | ||
@@ -135,2 +141,2 @@ | ||
Released under GNU GPL v3 or later<br/> | ||
Copyright (c) 2021 [Jakub T. Jankiewicz](https://jcubic.pl/me) | ||
Copyright (c) 2021-2022 [Jakub T. Jankiewicz](https://jcubic.pl/me) |
@@ -34,5 +34,7 @@ // Gaiman Codemirror mode based on Ruby and Lua mode | ||
"ask", "def", "echo", "else", "end", "false", "for", "get", "if", "in", | ||
"let", "not", "or", "post", "return", "sleep", "then", "true", "while", | ||
"throw", "lambda", "do", "continue", "break", "store", "config", "parse", | ||
"type", "ask*", "echo*", "input*", "update", "clear", "mask", "import" | ||
"let", "not", "or", "and", "post", "return", "sleep", "then", "true", | ||
"while", "throw", "lambda", "do", "continue", "break", "store", "config", | ||
"parse", "type", "ask*", "echo*", "input*", "update", "clear", "mask", | ||
"import", "prompt", "rpc", "from", "async", "exec", "exec*", "new", | ||
"animate", "enter" | ||
], keywords = wordRE(keywordList); | ||
@@ -39,0 +41,0 @@ |
@@ -98,2 +98,6 @@ /* ______ _ | ||
}, | ||
set_cookie(name, value) { | ||
document.cookie = `${name}=${value}`; | ||
cookie[name] = value; | ||
}, | ||
post(url, data = {}) { | ||
@@ -105,20 +109,41 @@ return $.post(url, data); | ||
}, | ||
get(url) { | ||
get(url, data) { | ||
if (data) { | ||
return $.get(url, data); | ||
} | ||
return $.get(url); | ||
}, | ||
get_extra(url) { | ||
get_extra(url, data) { | ||
if (data) { | ||
return $.get(url, data, $.noop, "text"); | ||
} | ||
return $.get(url, $.noop, "text"); | ||
}, | ||
set_cookie(name, value) { | ||
document.cookie = `${name}=${value}`; | ||
cookie[name] = value; | ||
load(url) { | ||
return $.getScript(url); | ||
}, | ||
['async'](fn) { | ||
setTimeout(fn, 0); | ||
}, | ||
async rpc(url) { | ||
// TODO: add Open-RPC | ||
return new Proxy({}, { | ||
get(target, name) { | ||
if (name in target) { | ||
return target[name]; | ||
} | ||
if (name === 'then') { | ||
return undefined; | ||
} | ||
return (...args) => { | ||
return $.rpc(url, name, args); | ||
}; | ||
}, | ||
set() { | ||
throw new Error("You can't set properties on rpc object"); | ||
} | ||
}); | ||
} | ||
}; | ||
if (!('Map' in this)) { | ||
$.getScript('https://cdn.jsdelivr.net/gh/jcubic/static/js/map.min.js').then(() => { | ||
window.Map = ES6_Map; | ||
}); | ||
} | ||
function to_string(object) { | ||
@@ -161,5 +186,14 @@ if (object instanceof Array) { | ||
} | ||
var playground = window.parent?.__GAIMAN_PLAYGROUND__; | ||
if (playground) { | ||
options.enabled = false; | ||
} | ||
this._term = root.terminal($.noop, $.extend({ | ||
greetings: false, | ||
exit: false, | ||
keydown: () => { | ||
if (this._animation) { | ||
return false; | ||
} | ||
}, | ||
exceptionHandler(e) { | ||
@@ -226,4 +260,7 @@ if (is_iframe) { | ||
} | ||
echo(arg) { | ||
this._term.echo(to_string(arg), { newline: this._config.newline }); | ||
echo(arg = "") { | ||
if (typeof arg !== 'function') { | ||
arg = to_string(arg); | ||
} | ||
this._term.echo(arg, { newline: this._config.newline }); | ||
} | ||
@@ -233,2 +270,8 @@ echo_extra(string, delay) { | ||
} | ||
enter(string) { | ||
return this._term.enter(string); | ||
} | ||
enter_extra(string, delay) { | ||
return this._term.enter(string, { typing: true, delay }); | ||
} | ||
ask(message, validator = () => true) { | ||
@@ -290,2 +333,13 @@ return new Promise(resolve => { | ||
} | ||
exec(command) { | ||
return this._term.exec(command); | ||
} | ||
exec_extra(command, delay) { | ||
return this._term.exec(command, { typing: true, delay }); | ||
} | ||
async animate(fn) { | ||
this._animation = true; | ||
await fn(); | ||
this._animation = false; | ||
} | ||
clear() { | ||
@@ -515,3 +569,16 @@ this._term.clear(); | ||
let $_SQRT2 = Math.SQRT2; | ||
let $_to_base64 = btoa; | ||
let $_from_base64 = atob; | ||
let $_sprintf = sprintf; | ||
let $_cols = function() { | ||
return gaiman._term.cols(); | ||
}; | ||
let $_rows = function() { | ||
return gaiman._term.rows(); | ||
}; | ||
let $_delay = function(time) { | ||
return new Promise(resolve => setTimeout(resolve, time)); | ||
}; | ||
// Fisher-Yates (aka Knuth) Shuffle | ||
@@ -552,2 +619,3 @@ // ref: https://stackoverflow.com/a/2450976/387194 | ||
}); | ||
throw e; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
932632
22394
137
6
+ Added@babel/cli@^7.17.10
+ Added@babel/core@^7.18.5
+ Added@babel/standalone@^7.18.5
+ Addedterser@^5.14.2
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/cli@7.26.4(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.3(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.3(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/parser@7.26.3(transitive)
+ Added@babel/standalone@7.26.4(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.26.4(transitive)
+ Added@babel/types@7.26.3(transitive)
+ Added@jridgewell/gen-mapping@0.3.8(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/source-map@0.3.6(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbrowserslist@4.24.3(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedcaniuse-lite@1.0.30001690(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedcommander@2.20.36.2.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedelectron-to-chromium@1.5.76(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfs-readdir-recursive@1.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.1.0(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedmake-dir@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.19(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedsemver@5.7.26.3.1(transitive)
+ Addedslash@2.0.0(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedterser@5.37.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyallist@3.1.1(transitive)