Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo cli #177

Closed
wants to merge 4 commits into from
Closed

Demo cli #177

wants to merge 4 commits into from

Conversation

ethanfrey
Copy link
Contributor

Experiment how to get a nice cli that can import all the typescript code, along with some initialization stuff (not as easy with ts-node as node).

I got some globals set from an import, try yarn cli then type fx(value) for an exported number and exported function. However, it seems to break as soon as I import anything from that file...

Working out how to handle #111

@ethanfrey ethanfrey added the wip work in progress label Jul 18, 2018
Copy link
Contributor

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool start!

I was trying a different path before (run ts-node --eval "my code" or ts-node --print "my code") but this always ends execution instead of starting a repl.

@@ -5751,6 +5751,19 @@ ts-node@^6.0.3:
source-map-support "^0.5.6"
yn "^2.0.0"

ts-node@^7.0.0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have "ts-node": "^6.0.3", in the main package.json. I Think we should upgrade that instead of adding a new one

"test-node": "./jasmine-testrunner.js",
"test": "yarn build-or-skip && yarn test-node",
"prebuild": "yarn format && yarn lint",
"build": "tsc",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing to be built in this package, right?

@@ -0,0 +1,26 @@
// I tried to add these but they just broke tsc
// so it seems we can add globals defined in the same module,
// but if we import anything it breaks???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you cannot change global in a typesafe way, because it is of type NodeJS.Global. I was able to hack in some values but could not read them from the repl anymore because it type checked global before accessing the existing values.

I think the way to go is rather patch https://github.com/TypeStrong/ts-node/blob/master/src/bin.ts to let it consume some inital commands. That would bring them into the proper scope directly.

@ethanfrey
Copy link
Contributor Author

After thinking about this, maybe just running normal ts-node and then force the user to do something like

import * from '@iov/cli';

on the first line of the repl to load in all the features.

I had no intention of merging this, feel free to push other experiments on this branch to try them out

@webmaster128 webmaster128 mentioned this pull request Jul 19, 2018
@ethanfrey ethanfrey closed this Jul 19, 2018
@webmaster128 webmaster128 deleted the demo-cli branch July 20, 2018 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wip work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants