Skip to content

Commit

Permalink
refactor(core): correct types for abstract plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Igmat committed Jan 29, 2018
1 parent b2e4a67 commit 0413cbe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions packages/baset-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { isPrimitive, promisify } from 'util';
import { NodeVM } from 'vm2';
import { CompilerFunction, NodeVM } from 'vm2';

const writeFile = promisify(fs.writeFile);
const readFile = promisify(fs.readFile);
Expand All @@ -12,13 +12,17 @@ function defaultJsCompiler(code: string, filename: string) {
return code;
}

export interface IPluginConstructor {
// tslint:disable-next-line:no-any
new(compilers: { [index: string]: (code: string, filename: string) => string }, context: NodeVM, pluginsOptions: any): IPlugin;
}
export interface IPlugin {
read(filePath: string, result: string | Promise<string>): Promise<string> | string;
export abstract class AbstractPlugin {
abstract read: (filePath: string, result: string | Promise<string>) => Promise<string> | string;
constructor(
public compilers: IDictionary<CompilerFunction>,
public context: NodeVM,
// tslint:disable-next-line:no-any
public pluginsOptions: any) { }
}
type IPluginConstructor =
// tslint:disable-next-line:no-any
new (compilers: IDictionary<CompilerFunction>, context: NodeVM, pluginsOptions: any) => AbstractPlugin;

export interface IDictionary<T> {
[index: string]: T;
Expand Down
3 changes: 2 additions & 1 deletion packages/baset-plugin-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"typescript": "^2.6.2"
},
"dependencies": {
"json-beautify": "^1.0.1"
"json-beautify": "^1.0.1",
"baset-core": "^0.5.0"
}
}
7 changes: 3 additions & 4 deletions packages/baset-plugin-export/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { AbstractPlugin } from 'baset-core';
import * as fs from 'fs';
import * as beautify from 'json-beautify';
import * as path from 'path';
import { isPrimitive, promisify } from 'util';
import { NodeVM } from 'vm2';

const writeFile = promisify(fs.writeFile);
const unlink = promisify(fs.unlink);

export default class ExportReader {
constructor(private options: {}) {
}

export default class ExportReader extends AbstractPlugin {
read = async (filePath: string, spec: string | Promise<string>) => {
let result;
const specValue = (typeof spec === 'string')
Expand Down
3 changes: 2 additions & 1 deletion packages/baset-plugin-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dependencies": {
"find-up": "^2.1.0",
"ts-node": "^4.1.0",
"typescript": "^2.6.2"
"typescript": "^2.6.2",
"baset-core": "^0.5.0"
}
}

0 comments on commit 0413cbe

Please sign in to comment.