diff --git a/packages/baset-core/src/index.ts b/packages/baset-core/src/index.ts index f61f11a4..f639e8c7 100644 --- a/packages/baset-core/src/index.ts +++ b/packages/baset-core/src/index.ts @@ -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); @@ -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): Promise | string; +export abstract class AbstractPlugin { + abstract read: (filePath: string, result: string | Promise) => Promise | string; + constructor( + public compilers: IDictionary, + public context: NodeVM, + // tslint:disable-next-line:no-any + public pluginsOptions: any) { } } +type IPluginConstructor = + // tslint:disable-next-line:no-any + new (compilers: IDictionary, context: NodeVM, pluginsOptions: any) => AbstractPlugin; export interface IDictionary { [index: string]: T; diff --git a/packages/baset-plugin-export/package.json b/packages/baset-plugin-export/package.json index c1b819b0..64ca0318 100644 --- a/packages/baset-plugin-export/package.json +++ b/packages/baset-plugin-export/package.json @@ -31,6 +31,7 @@ "typescript": "^2.6.2" }, "dependencies": { - "json-beautify": "^1.0.1" + "json-beautify": "^1.0.1", + "baset-core": "^0.5.0" } } diff --git a/packages/baset-plugin-export/src/index.ts b/packages/baset-plugin-export/src/index.ts index 6ff65e2c..541b3b85 100644 --- a/packages/baset-plugin-export/src/index.ts +++ b/packages/baset-plugin-export/src/index.ts @@ -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) => { let result; const specValue = (typeof spec === 'string') diff --git a/packages/baset-plugin-ts/package.json b/packages/baset-plugin-ts/package.json index 5b020f04..5f1e4f6c 100644 --- a/packages/baset-plugin-ts/package.json +++ b/packages/baset-plugin-ts/package.json @@ -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" } }