import {createLogger} from "@gongt/ts-stl-library/debug/create-logger"; import {LOG_LEVEL} from "@gongt/ts-stl-library/debug/levels"; import {Application} from "express-serve-static-core"; import {dirname, resolve} from "path"; import {resolve as resolveUrl} from "url"; import {createServeStatic} from "../inject/serve-static"; import {HtmlContainer, IContainerPlugin} from "../middlewares/html-render"; import {IExpressProvide} from "../middlewares/well-known-provider"; const debug = createLogger(LOG_LEVEL.DEBUG, 'npm-plug'); export class npmPackagePlugin implements IContainerPlugin<{}>, IExpressProvide { private root: string; private publicUrl: string; constructor(packageJsonFile = process.cwd() + '/package.json', publicUrl: string) { this.root = resolve(dirname(packageJsonFile), 'node_modules'); this.publicUrl = resolveUrl(publicUrl, 'node_modules'); } __express_provide(app: Application) { debug('serve-static[jspm]:\n\t\tpath=%s\n\t\tlocal=%s', this.publicUrl, this.root); app.use(this.publicUrl, createServeStatic(this.root)); } __modify_html(html: HtmlContainer): void { } }