From 288683114d5e1cd2b9c99ad0bec26c1af87a4aab Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Jul 2018 22:57:30 +0200 Subject: [PATCH 1/4] Empty package for iov-cli --- packages/iov-cli/.gitignore | 2 ++ packages/iov-cli/.prettierrc.json | 12 +++++++++++ packages/iov-cli/jasmine-testrunner.js | 30 ++++++++++++++++++++++++++ packages/iov-cli/package.json | 22 +++++++++++++++++++ packages/iov-cli/src/index.ts | 0 packages/iov-cli/tsconfig.json | 11 ++++++++++ packages/iov-cli/tslint.json | 3 +++ 7 files changed, 80 insertions(+) create mode 100644 packages/iov-cli/.gitignore create mode 100644 packages/iov-cli/.prettierrc.json create mode 100755 packages/iov-cli/jasmine-testrunner.js create mode 100644 packages/iov-cli/package.json create mode 100644 packages/iov-cli/src/index.ts create mode 100644 packages/iov-cli/tsconfig.json create mode 100644 packages/iov-cli/tslint.json diff --git a/packages/iov-cli/.gitignore b/packages/iov-cli/.gitignore new file mode 100644 index 000000000..edd9d60a7 --- /dev/null +++ b/packages/iov-cli/.gitignore @@ -0,0 +1,2 @@ +build/ +dist/ diff --git a/packages/iov-cli/.prettierrc.json b/packages/iov-cli/.prettierrc.json new file mode 100644 index 000000000..1f642fb6b --- /dev/null +++ b/packages/iov-cli/.prettierrc.json @@ -0,0 +1,12 @@ +{ + "printWidth": 110, + "trailingComma": "all", + "overrides": [ + { + "files": "*.spec.ts", + "options": { + "printWidth": 5000 + } + } + ] +} diff --git a/packages/iov-cli/jasmine-testrunner.js b/packages/iov-cli/jasmine-testrunner.js new file mode 100755 index 000000000..20d1658bb --- /dev/null +++ b/packages/iov-cli/jasmine-testrunner.js @@ -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(); diff --git a/packages/iov-cli/package.json b/packages/iov-cli/package.json new file mode 100644 index 000000000..58032d727 --- /dev/null +++ b/packages/iov-cli/package.json @@ -0,0 +1,22 @@ +{ + "name": "@iov/cli", + "version": "0.0.0", + "description": "Cli for using web4", + "author": "Ethan ", + "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": { + "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", + "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build" + } +} diff --git a/packages/iov-cli/src/index.ts b/packages/iov-cli/src/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/iov-cli/tsconfig.json b/packages/iov-cli/tsconfig.json new file mode 100644 index 000000000..df66add1d --- /dev/null +++ b/packages/iov-cli/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "build", + "rootDir": "src" + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/iov-cli/tslint.json b/packages/iov-cli/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/iov-cli/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} From 9f66004864d3d9c846c11ba8e15fabefdf4372d0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Jul 2018 23:04:16 +0200 Subject: [PATCH 2/4] add ts-node and yarn cli runs it --- packages/iov-cli/package.json | 4 ++++ packages/iov-cli/tsconfig.json | 6 ------ yarn.lock | 13 +++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/iov-cli/package.json b/packages/iov-cli/package.json index 58032d727..7dfb4db23 100644 --- a/packages/iov-cli/package.json +++ b/packages/iov-cli/package.json @@ -11,6 +11,7 @@ "url": "https://github.com/iov-one/web4/tree/master/packages/iov-api" }, "scripts": { + "cli": "ts-node --type-check", "lint": "tslint -t verbose --project .", "format": "prettier --write --loglevel warn './src/**/*.ts'", "test-node": "./jasmine-testrunner.js", @@ -18,5 +19,8 @@ "prebuild": "yarn format && yarn lint", "build": "tsc", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build" + }, + "dependencies": { + "ts-node": "^7.0.0" } } diff --git a/packages/iov-cli/tsconfig.json b/packages/iov-cli/tsconfig.json index df66add1d..c41a46240 100644 --- a/packages/iov-cli/tsconfig.json +++ b/packages/iov-cli/tsconfig.json @@ -1,10 +1,4 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "outDir": "build", - "rootDir": "src" - }, "include": [ "src/**/*" ] diff --git a/yarn.lock b/yarn.lock index 0bc1f3647..492404c9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5751,6 +5751,19 @@ ts-node@^6.0.3: source-map-support "^0.5.6" yn "^2.0.0" +ts-node@^7.0.0: + 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" From 140a953321bfb934998e422f0bd55613e15f6c63 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Jul 2018 23:30:09 +0200 Subject: [PATCH 3/4] yarn cli sets global.cli (available on repl) to number --- packages/iov-cli/package.json | 2 +- packages/iov-cli/src/index.ts | 21 +++++++++++++++++++++ packages/iov-cli/tsconfig.json | 9 +++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/iov-cli/package.json b/packages/iov-cli/package.json index 7dfb4db23..bf40f306b 100644 --- a/packages/iov-cli/package.json +++ b/packages/iov-cli/package.json @@ -11,7 +11,7 @@ "url": "https://github.com/iov-one/web4/tree/master/packages/iov-api" }, "scripts": { - "cli": "ts-node --type-check", + "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", diff --git a/packages/iov-cli/src/index.ts b/packages/iov-cli/src/index.ts index e69de29bb..77328d448 100644 --- a/packages/iov-cli/src/index.ts +++ b/packages/iov-cli/src/index.ts @@ -0,0 +1,21 @@ +const a = 100; + +const bigger = (x: number) => x * 5; + +// tslint:disable:no-console +console.log(`loaded up ${a}`); + +declare module NodeJS { + interface Global { + cli: number; + } +} + +declare const cli: number; + + +global.cli = a; + +console.log(`set global ${global.cli}`); + + diff --git a/packages/iov-cli/tsconfig.json b/packages/iov-cli/tsconfig.json index c41a46240..e62635888 100644 --- a/packages/iov-cli/tsconfig.json +++ b/packages/iov-cli/tsconfig.json @@ -1,5 +1,10 @@ { - "include": [ - "src/**/*" + "compilerOptions": { + "baseUrl": ".", + "outDir": "build", + "rootDir": "src" + }, + "includes": [ + "src/*.ts" ] } From e194dc0155775004367445f58401533113e35d72 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Jul 2018 23:45:18 +0200 Subject: [PATCH 4/4] Document failed imports when adding to global --- packages/iov-cli/src/api.ts | 6 ++++++ packages/iov-cli/src/globals.d.ts | 15 +++++++++++++++ packages/iov-cli/src/index.ts | 27 ++++++++++++++++----------- 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 packages/iov-cli/src/api.ts create mode 100644 packages/iov-cli/src/globals.d.ts diff --git a/packages/iov-cli/src/api.ts b/packages/iov-cli/src/api.ts new file mode 100644 index 000000000..26d35668f --- /dev/null +++ b/packages/iov-cli/src/api.ts @@ -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}`); diff --git a/packages/iov-cli/src/globals.d.ts b/packages/iov-cli/src/globals.d.ts new file mode 100644 index 000000000..14f90e741 --- /dev/null +++ b/packages/iov-cli/src/globals.d.ts @@ -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; + diff --git a/packages/iov-cli/src/index.ts b/packages/iov-cli/src/index.ts index 77328d448..58ca35824 100644 --- a/packages/iov-cli/src/index.ts +++ b/packages/iov-cli/src/index.ts @@ -1,21 +1,26 @@ -const a = 100; +// 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??? -const bigger = (x: number) => x * 5; - -// tslint:disable:no-console -console.log(`loaded up ${a}`); +// import * as code from './api'; +// import {Foo} from './globals'; declare module NodeJS { interface Global { - cli: number; + value: number; + fx: (x: number) => number; } } -declare const cli: number; - +declare const value: number; +declare const fx: (x: number) => number; -global.cli = a; - -console.log(`set global ${global.cli}`); +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)');