Skip to content

Commit

Permalink
Merge pull request #1650 from davidpcaldwell/davidpcaldwell/issue/#1642
Browse files Browse the repository at this point in the history
#1642: jsh.script.arguments, jsh.script.loader JSAPI -> Fifty
  • Loading branch information
davidpcaldwell authored Sep 6, 2024
2 parents 662717e + d947eb1 commit 98f513a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 58 deletions.
51 changes: 0 additions & 51 deletions jrunscript/jsh/script/plugin.jsh.api.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<div>
<h1>Exports</h1>
<ul>
<li class="value">
<div class="name">arguments</div>
<span class="type">Array of string</span>
<span>An array containing the arguments passed to the shell.</span>
</li>
<li class="constructor">
<div class="name"><a id="exports.Loader">Loader</a></div>
<span>A constructor that can be used by scripts to create <a href="#types.Loader">Loader</a>s.</span>
Expand All @@ -71,52 +66,6 @@ <h1>Exports</h1>
<span class="type"><a href="#types.Loader">Loader</a></span>
<span>An object that loads code from the files and subdirectories of the given directory.</span>
</div>
<script type="application/x.jsapi#tests">
// test(typeof(module.loader.resource) == "function");
</script>
</li>
<li class="value">
<div class="name">loader</div>
<span class="type"><a href="#types.Loader">Loader</a></span>
<span>
An object that can be used to load code associated with this script. For packaged scripts, this object loads
modules and files packaged with the script using the packaging tool. For unpackaged scripts, this object loads
modules and files relative to the directory from which the script was run (although a script can replace this
property; see <code><a href="#exports.Loader">Loader</a></code>).
</span>
<script type="application/x.jsapi#tests" jsapi:id="loader"><![CDATA[
if ($jsapi.environment.jsh && $jsapi.environment.jsh.built) {
var a = jsh.shell.jsh({
shell: $jsapi.environment.jsh.built.home,
script: $jsapi.environment.jsh.src.getFile("jrunscript/jsh/script/test/loader.jsh.js"),
stdio: {
output: String
},
evaluate: function(result) {
return JSON.parse(result.stdio.output);
}
});
verify(a).submodule.message.is("ititit");
}

if ($jsapi.environment.jsh && $jsapi.environment.jsh.src) {
var started = jsh.httpd.Tomcat.serve({
directory: $jsapi.environment.jsh.src
});

var b = jsh.shell.jsh({
shell: $jsapi.environment.jsh.built.home,
script: "http://127.0.0.1:" + started.port + "/" + "jrunscript/jsh/script/test/loader.jsh.js",
stdio: {
output: String
},
evaluate: function(result) {
return JSON.parse(result.stdio.output);
}
});
verify(b).submodule.message.is("ititit");
}
]]></script>
</li>
<li class="function" jsapi:id="getopts">
<div class="name"><a id="properties.getopts">getopts</a></div>
Expand Down
98 changes: 91 additions & 7 deletions jrunscript/jsh/script/plugin.jsh.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ namespace slime.jsh.script {
url?: slime.web.Url
}

export interface Exports {
/** @deprecated */
pathname: any
getRelativePath: any
}

(
function(
fifty: slime.fifty.test.Kit
Expand Down Expand Up @@ -329,18 +335,96 @@ namespace slime.jsh.script {
)(fifty);

export interface Exports {
arguments: string[]
getopts: Function & { UNEXPECTED_OPTION_PARSER: any, ARRAY: any, OBJECT: any, parser: { Pathname: (s: string) => slime.jrunscript.file.Pathname } }
/** @deprecated */
pathname: any
/** @deprecated */
addClasses: any
getRelativePath: any
}

export interface Exports {
/**
* An array containing the arguments passed to the shell.
*/
arguments: string[]
}

export interface Exports {
/**
* An object that can be used to load code associated with this script. For packaged scripts, this object loads modules and
* files packaged with the script using the packaging tool. For unpackaged scripts, this object loads modules and files
* relative to the directory from which the script was run (although a script can replace this property; see `
* `Loader`).
*/
loader: slime.old.Loader
}

(
function(
fifty: slime.fifty.test.Kit
) {
const { verify } = fifty;
const { $api, jsh } = fifty.global;

var script = fifty.jsh.file.relative("test/loader.jsh.js");
var scriptUrl = "http://raw.githubusercontent.com/davidpcaldwell/slime/local/jrunscript/jsh/script/test/loader.jsh.js";

var getJson: (intention: slime.jrunscript.shell.run.Intention) => { submodule: { message: string } } = $api.fp.pipe(
$api.fp.world.Sensor.mapping({
sensor: jsh.shell.subprocess.question
}),
$api.fp.impure.tap(function(exit) {
if (exit.status) {
jsh.shell.console("Exit status: " + exit.status);
jsh.shell.console("Standard error:");
jsh.shell.console(exit.stdio.error);
throw new Error("Exit status: " + exit.status);
}
}),
$api.fp.property("stdio"),
$api.fp.property("output"),
JSON.parse
);

fifty.tests.exports.loader = fifty.test.Parent();

fifty.tests.exports.loader.shape = function() {
verify(test.subject).evaluate.property("loader").evaluate.property("get").is.type("function");
}

fifty.tests.exports.loader.jsapi = function() {
var local = test.shells.unbuilt().invoke({
script: script.pathname,
stdio: {
output: "string"
}
});

var json = getJson(local);

verify(json).submodule.message.is("ititit");

var remote = test.shells.unbuilt().invoke({
script: scriptUrl,
stdio: {
output: "string"
}
});

var json = getJson(remote);

verify(json).submodule.message.is("ititit");
}
}
//@ts-ignore
)(fifty);

export interface Exports {
Loader?: any
}

export interface Exports {
getopts: Function & { UNEXPECTED_OPTION_PARSER: any, ARRAY: any, OBJECT: any, parser: { Pathname: (s: string) => slime.jrunscript.file.Pathname } }
Application: slime.jsh.script.old.application.Constructor & {
run: any
}
loader: slime.old.Loader
Loader?: any
world: {
file: slime.jrunscript.file.world.Location
}
Expand Down

0 comments on commit 98f513a

Please sign in to comment.