deathcap / nodeachrome

run Node.js scripts in Google Chrome (experimental)
MIT License
2 stars 0 forks source link

Pure JavaScript Node.js implementations of common shell CLI utilities #16

Open deathcap opened 8 years ago

deathcap commented 8 years ago

JavaScript implementations of popular CLI command Unix utilities, using Node.js/browserify/web/nodeachrome compatible API. Similar to the Perl-based Unix Reconstruction Project:

http://cpansearch.perl.org/src/CWEST/ppt-0.14/html/index.html "Welcome to the Unix Reconstruction Project. Our goal is quite simply to reimplement the classic Unix command set in pure Perl, and to have as much fun as we can doing so."

but for JavaScript.

These would be real command-line scripts (standalone files, run in their own process, read from process.argv, and they process.exit when done https://github.com/deathcap/nodeachrome/issues/11, for CLI wrapping in general https://github.com/deathcap/nodeachrome/issues/13), not JavaScript functions. These projects provide JavaScript functions:

https://github.com/shelljs/shelljs - but, primarily implemented using sync APIs (open request for async commands https://github.com/shelljs/shelljs/issues/2 but some still use sync APIs underneath) https://github.com/deathcap/shellasync - closer, is useful and compatible and included in nodeachrome, but provides functions not standalone scripts


to do: is there any existing JavaScript-based analogue of the "Unix Reconstruction Project"?

deathcap commented 8 years ago

Found this project:

https://github.com/dthree/cash Cross-platform Linux commands in ES6

works quite well:

tmp $ node ./node_modules/cash/bin/ls.js -l ~/games/voxeljs/nodeachrome/
total 19416
drwxr-xr-x 10 501 20  340 Apr 29 20:55 app
-rw-r--r--  1 501 20 2878 Apr 23 13:59 concept.txt
drwxr-xr-x  8 501 20  272 Apr 26 21:51 host
-rw-r--r--  1 501 20 1075 Apr 23 13:58 LICENSE
-rw-r--r--  1 501 20 6943 Apr 29 20:57 README.md
drwxr-xr-x  9 501 20  306 Apr 29 20:51 sandbox

ought to test it within the nodeachrome environment, see if it works

deathcap commented 8 years ago

Trying to use cash within Nodeachrome:

diff --git a/app/package.json b/app/package.json
index d3a0af0..6dca2c5 100644
--- a/app/package.json
+++ b/app/package.json
@@ -15,6 +15,7 @@
     "acorn": "^3.1.0",
     "asarray": "^0.1.0",
     "browserify": "^13.0.0",
+    "cash": "^0.8.0",
     "npm": "deathcap/npm#static-require",
     "npm-registry-client": "deathcap/npm-registry-client#browserify",
     "shellasync": "^2.1.0"
diff --git a/app/userland/syscall.js b/app/userland/syscall.js
index e6ff7da..b294697 100644
--- a/app/userland/syscall.js
+++ b/app/userland/syscall.js
@@ -33,6 +33,7 @@ window.addEventListener('message', (event) => {
       init: () => require('./bin/init'),
       npm: () => require('./bin/npm'),
       browserify: () => require('./bin/browserify'),
+      ls: () => require('cash/bin/ls'),
     };

     if (commands[process.argv[1]]) {

or with:

Getting maximum call stack exceeded error in require on _process:

bundle-userland.js:21 Uncaught RangeError: Maximum call stack size exceedednewRequire @ bundle-userland.js:21R @ bundle-userland.js:35newRequire @ bundle-userland.js:21R @ bundle-userland.js:35newRequire @ bundle-userland.js:21R @ bundle-userland.js:35newRequire @ bundle-userland.js:21R @ bundle-userland.js:35newRequire @ bundle-userland.js:21R @ bundle-userland.js:35postMessage (async)iframe.addEventListener @ scheduler.js:52

deathcap commented 8 years ago

Another possibility, albeit farfetched: port BSD command-line utilities (most programs in base/head/bin) from C to JS, testing with: https://github.com/deathcap/transpile-c-to-js