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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/iov-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
dist/
12 changes: 12 additions & 0 deletions packages/iov-cli/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 110,
"trailingComma": "all",
"overrides": [
{
"files": "*.spec.ts",
"options": {
"printWidth": 5000
}
}
]
}
30 changes: 30 additions & 0 deletions packages/iov-cli/jasmine-testrunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node

// setup Jasmine
const Jasmine = require('jasmine');
const jasmine = new Jasmine();
jasmine.loadConfig({
spec_dir: 'build',
spec_files: ['**/*.spec.js'],
helpers: [],
random: false,
seed: null,
stopSpecOnExpectationFailure: false
});
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 15*1000;

// setup console reporter
const JasmineConsoleReporter = require('jasmine-console-reporter');
const reporter = new JasmineConsoleReporter({
colors: 1, // (0|false)|(1|true)|2
cleanStack: 1, // (0|false)|(1|true)|2|3
verbosity: 4, // (0|false)|1|2|(3|true)|4
listStyle: 'indent', // "flat"|"indent"
activity: true,
emoji: true,
});

// initialize and execute
jasmine.env.clearReporters();
jasmine.addReporter(reporter);
jasmine.execute();
26 changes: 26 additions & 0 deletions packages/iov-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@iov/cli",
"version": "0.0.0",
"description": "Cli for using web4",
"author": "Ethan <ethanfrey@users.noreply.github.com>",
"license": "AGPL-3.0",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/iov-one/web4/tree/master/packages/iov-api"
},
"scripts": {
"cli": "ts-node --type-check -r ./src/index.ts",
"lint": "tslint -t verbose --project .",
"format": "prettier --write --loglevel warn './src/**/*.ts'",
"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?

"build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build"
},
"dependencies": {
"ts-node": "^7.0.0"
}
}
6 changes: 6 additions & 0 deletions packages/iov-cli/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const a = 100;

export const bigger = (x: number) => x * 5;

// tslint:disable:no-console
console.log(`loaded up api ${a}`);
15 changes: 15 additions & 0 deletions packages/iov-cli/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// just to see if we can force the import with this
export interface Foo {
name: string;
}

declare module NodeJS {
interface Global {
a: number;
bigger: (x: number) => number;
}
}

declare const a: number;
declare const bigger: (x: number) => number;

26 changes: 26 additions & 0 deletions packages/iov-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -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.


// import * as code from './api';
// import {Foo} from './globals';

declare module NodeJS {
interface Global {
value: number;
fx: (x: number) => number;
}
}

declare const value: number;
declare const fx: (x: number) => number;

const a = 100;
const bigger = (x: number) => x * 5;
global.value = a;
global.fx = bigger;

// tslint:disable:no-console
console.log(`set global ${global.value}`);
console.log('Type fx(value)');

10 changes: 10 additions & 0 deletions packages/iov-cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"rootDir": "src"
},
"includes": [
"src/*.ts"
]
}
3 changes: 3 additions & 0 deletions packages/iov-cli/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tslint.json"
}
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

version "7.0.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-7.0.0.tgz#a94a13c75e5e1aa6b82814b84c68deb339ba7bff"
dependencies:
arrify "^1.0.0"
buffer-from "^1.1.0"
diff "^3.1.0"
make-error "^1.1.1"
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map-support "^0.5.6"
yn "^2.0.0"

tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
Expand Down