Skip to content

Commit

Permalink
Add type renderer (#19)
Browse files Browse the repository at this point in the history
* add type renderer

* render type declarations

* sort exported entity types

* fix build

* implement client-cli

* 2.14.0
  • Loading branch information
kbarbounakis authored Mar 31, 2024
1 parent 658491f commit 0f5c7db
Show file tree
Hide file tree
Showing 17 changed files with 1,701 additions and 772 deletions.
1,559 changes: 789 additions & 770 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "@themost/client",
"version": "2.13.0",
"version": "2.14.0",
"description": "MOST Web Framework Codename Blueshift - Client Common",
"module": "dist/index.esm.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"client-cli": "util/bin/cli.js"
},
"scripts": {
"build": "rimraf dist && rimraf common/dist && rollup -c ./rollup.config.js -m",
"watch": "rimraf dist && rimraf common/dist && rollup -c ./rollup.config.js -m -w",
Expand All @@ -29,12 +32,14 @@
"@themost/query": "^2.11.2",
"@themost/xml": "^2.5.1",
"buffer": "^6.0.3",
"minimist": "^1.2.8",
"superagent": "^8.1.2"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.1",
"@themost/test": "^2.3.4",
"@themost/test": "^2.4.0",
"@types/jasmine": "^3.10.0",
"@types/minimist": "^1.2.5",
"@types/node": "^16.11.4",
"@types/superagent": "^8.1.1",
"@typescript-eslint/eslint-plugin": "^6.13.1",
Expand All @@ -44,6 +49,7 @@
"dotenv": "^16.3.1",
"eslint": "^8.54.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
Expand Down
27 changes: 27 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,32 @@ module.exports = [
plugins: [typescript({
tsconfig: path.resolve(process.cwd(), 'common/tsconfig.lib.json')
})]
},
{
input: path.resolve(process.cwd(), 'util/src/index.ts'),
output: {
dir: 'util/dist',
format: 'cjs',
sourcemap: true
},
external: Object.keys(pkg.dependencies).concat(['@themost/client', '@themost/client/common']),
plugins: [
typescript({
tsconfig: path.resolve(process.cwd(), 'util/tsconfig.lib.json'),
declaration: true,
declarationDir: 'util/dist/'
})]
},
{
input: 'util/src/index.ts',
output: {
file: 'util/dist/index.esm.js',
format: 'esm',
sourcemap: true
},
external: Object.keys(pkg.dependencies).concat(['@themost/client', '@themost/client/common']),
plugins: [typescript({
tsconfig: path.resolve(process.cwd(), 'util/tsconfig.lib.json')
})]
}
];
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"ES2017"
],
"paths": {
"@themost/client/util": [
"./util/src/index"
],
"@themost/client/common": [
"./common/src/index"
],
Expand Down
38 changes: 38 additions & 0 deletions util/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const minimist = require('minimist');
const { TypeRenderer } = require('../dist');
const { writeFileSync } = require('fs');

async function main() {
const args = minimist(process.argv.slice(2), {
alias: {
outFile: 'out-file'
},
});
if (args.help) {
console.log('Usage: client-cli [options]');
console.log('Options:');
console.log(' --host <host> The HTTP address of the host api server to connect to');
console.log(' --out-file <file> The output file to write the rendered types to');
return;
}
if (!args.host) {
console.error('Error: Missing required argument --host');
return process.exit(-1);
}
const typeRenderer = new TypeRenderer(args.host);
const result = await typeRenderer.renderAny();
if (args.outFile) {
writeFileSync(args.outFile, result);
} else {
process.stdout.write(result);
process.stdout.write('\n');
}
}

main().then(() => {
return process.exit(0);
}).catch((err) => {
console.error(err.message);
console.error(err.stack);
return process.exit(-1);
});
9 changes: 9 additions & 0 deletions util/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"module": "dist/index.esm.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jasmine"
}
}
27 changes: 27 additions & 0 deletions util/spec/TypeRenderer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {TypeRenderer} from '@themost/client/util';
import { serveApplication, getApplication } from '@themost/test';

describe("BasicClientDataContext", () => {

beforeAll(async () => {
const app = await getApplication();
await serveApplication(app, 8080)
});

it("should render type", async () => {
const renderer = new TypeRenderer('http://localhost:8080/api/');
let typeDeclaration = await renderer.render('Thing');
expect(typeDeclaration).toBeInstanceOf(String);
typeDeclaration = await renderer.render('Workspace');
expect(typeDeclaration).toBeInstanceOf(String);
});

it("should render any type", async () => {
const renderer = new TypeRenderer('http://localhost:8080/api/');
const typeDeclarations = await renderer.renderAny();
expect(typeDeclarations).toBeInstanceOf(String);
});



});
8 changes: 8 additions & 0 deletions util/spec/helpers/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayPending: true,
displayStacktrace: 'raw'
}
}));
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
5 changes: 5 additions & 0 deletions util/spec/helpers/ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path');
require('ts-node').register({
project: path.resolve(__dirname, '../../tsconfig.spec.json'),
transpileOnly: true
});
8 changes: 8 additions & 0 deletions util/spec/helpers/tsconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const tsConfig = require("../../tsconfig.spec.json");
const tsConfigPaths = require("tsconfig-paths");

const baseUrl = "./";
tsConfigPaths.register({
baseUrl,
paths: tsConfig.compilerOptions.paths,
});
Loading

0 comments on commit 0f5c7db

Please sign in to comment.