ts-generator
Advanced tools
Comparing version 0.0.3 to 0.0.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = require("path"); | ||
const tsGen_1 = require("../tsGen"); | ||
const tsGenerator_1 = require("../tsGenerator"); | ||
const deps_1 = require("../deps"); | ||
@@ -13,5 +13,5 @@ const parseConfigFile_1 = require("../parseConfigFile"); | ||
const cfg = await parseConfigFile_1.parseConfigFile(deps, { configPath, cwd }); | ||
const plugins = cfg.plugins.map(pluginCfg => loadPlugin_1.loadPlugin(deps, { cwd: cfg.cwd, rawConfig: pluginCfg })); | ||
await tsGen_1.tsGen(cfg, plugins, deps); | ||
const plugins = cfg.plugins.map(pluginCfg => loadPlugin_1.loadPlugin(deps, { cwd: cfg.cwd, rawConfig: pluginCfg, logger: deps.logger.childLogger(pluginCfg.generator) })); | ||
await tsGenerator_1.tsGenerator(cfg, plugins, deps); | ||
} | ||
exports.cli = cli; |
@@ -13,5 +13,5 @@ "use strict"; | ||
resolve: require.resolve.bind(require), | ||
logger: new logger_1.ConsoleLogger(false), | ||
logger: new logger_1.ConsoleLogger("ts-gen", "normal"), | ||
}; | ||
} | ||
exports.createDeps = createDeps; |
declare type TLoggerFunction = (...args: any[]) => void; | ||
declare type TLoggerLvl = "normal" | "verbose"; | ||
export interface TLogger { | ||
info: TLoggerFunction; | ||
verbose: TLoggerFunction; | ||
error: TLoggerFunction; | ||
warn: TLoggerFunction; | ||
accent(s: string): string; | ||
childLogger(name: string): TLogger; | ||
} | ||
export declare class ConsoleLogger implements TLogger { | ||
private isSilent; | ||
constructor(isSilent: boolean); | ||
private name; | ||
private lvl; | ||
constructor(name: string, lvl: TLoggerLvl); | ||
private prefix; | ||
info(...args: any[]): void; | ||
verbose(...args: any[]): void; | ||
error(...args: any[]): void; | ||
warn(...args: any[]): void; | ||
accent(s: string): string; | ||
childLogger(name: string): TLogger; | ||
} | ||
export declare class NoLogger implements TLogger { | ||
info(): void; | ||
verbose(): void; | ||
error(): void; | ||
warn(): void; | ||
accent(s: string): string; | ||
childLogger(): TLogger; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* tslint:disable:no-console */ | ||
const chalk_1 = require("chalk"); | ||
const { gray, green, yellow, red } = chalk_1.default; | ||
class ConsoleLogger { | ||
constructor(isSilent) { | ||
this.isSilent = isSilent; | ||
constructor(name, lvl) { | ||
this.name = name; | ||
this.lvl = lvl; | ||
} | ||
prefix() { | ||
return `${gray(this.name)}:`; | ||
} | ||
info(...args) { | ||
if (!this.isSilent) { | ||
console.info(...args); | ||
console.info(this.prefix(), ...args); | ||
} | ||
verbose(...args) { | ||
if (this.lvl === "verbose") { | ||
console.info(this.prefix(), ...args); | ||
} | ||
} | ||
error(...args) { | ||
console.info(...args); | ||
console.error(this.prefix(), ...args.map(m => red(m))); | ||
} | ||
warn(...args) { | ||
console.info(...args); | ||
console.info(this.prefix(), ...args.map(m => yellow(m))); | ||
} | ||
accent(s) { | ||
return green(s); | ||
} | ||
childLogger(name) { | ||
return new ConsoleLogger(name, this.lvl); | ||
} | ||
} | ||
@@ -22,5 +38,12 @@ exports.ConsoleLogger = ConsoleLogger; | ||
info() { } | ||
verbose() { } | ||
error() { } | ||
warn() { } | ||
accent(s) { | ||
return s; | ||
} | ||
childLogger() { | ||
return new NoLogger(); | ||
} | ||
} | ||
exports.NoLogger = NoLogger; |
@@ -0,13 +1,16 @@ | ||
import { Options as PrettierOptions } from "prettier"; | ||
import { TDeps } from "./deps"; | ||
import { Options as PrettierOptions } from "prettier"; | ||
import { Dictionary } from "./stl"; | ||
export declare type TPluginCfg<T = Dictionary<any>> = { | ||
import { Omit } from "./stl"; | ||
export declare type TRawPluginCfg<T = Dictionary<any>> = { | ||
files: string; | ||
generator: string; | ||
} & T; | ||
export interface TTsGenCfg { | ||
export declare type TPluginCfg<T = Dictionary<any>> = Omit<TRawPluginCfg<T>, "generator">; | ||
export interface TRawCfg { | ||
cwd: string; | ||
plugins: TPluginCfg[]; | ||
plugins: TRawPluginCfg[]; | ||
prettier?: PrettierOptions; | ||
} | ||
export declare type TCfg = Omit<TRawCfg, "plugins">; | ||
interface TArgs { | ||
@@ -17,3 +20,3 @@ cwd: string; | ||
} | ||
export declare function parseConfigFile({ fs, prettier, logger }: TDeps, { cwd, configPath }: TArgs): Promise<TTsGenCfg>; | ||
export declare function parseConfigFile({ fs, prettier, logger }: TDeps, { cwd, configPath }: TArgs): Promise<TRawCfg>; | ||
export {}; |
import { TDeps } from "../deps"; | ||
import { TContext, TsGeneratorPlugin } from "./types"; | ||
import { Dictionary } from "../stl"; | ||
export declare function loadPlugin(deps: TDeps, ctx: TContext): TsGeneratorPlugin; | ||
export declare function getFirstKey<T>(object: Dictionary<T>): T; |
@@ -6,5 +6,17 @@ "use strict"; | ||
const pluginPath = resolvePlugin_1.resolvePlugin(deps, ctx.rawConfig.generator, ctx.cwd); | ||
const PluginCtr = require(pluginPath).default; | ||
const PluginModule = require(pluginPath); | ||
const moduleExportsCount = Object.keys(PluginModule).length; | ||
if (moduleExportsCount !== 1) { | ||
throw new Error(`Loading plugin ${ctx.rawConfig.generator} failed. Plugin module has to export exactly one entity. Found ${moduleExportsCount} instead`); | ||
} | ||
const PluginCtr = getFirstKey(PluginModule); | ||
return new PluginCtr(ctx); | ||
} | ||
exports.loadPlugin = loadPlugin; | ||
function getFirstKey(object) { | ||
for (const k of Object.keys(object)) { | ||
return object[k]; | ||
} | ||
throw new Error("Any key missing!"); | ||
} | ||
exports.getFirstKey = getFirstKey; |
import { TPluginCfg } from "../parseConfigFile"; | ||
import { Dictionary } from "../stl"; | ||
export declare type TPluginState = "uninitialized" | "initialized"; | ||
import { TLogger } from "../logger"; | ||
export declare type TOutput = void | TFileDesc | TFileDesc[]; | ||
export declare abstract class TsGeneratorPlugin { | ||
readonly ctx: TContext; | ||
state: TPluginState; | ||
abstract readonly name: string; | ||
readonly logger: TLogger; | ||
constructor(ctx: TContext); | ||
@@ -17,2 +17,3 @@ beforeRun(): TOutput | Promise<TOutput>; | ||
rawConfig: TPluginCfg<T>; | ||
logger?: TLogger; | ||
} | ||
@@ -19,0 +20,0 @@ export interface TFileDesc { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logger_1 = require("../logger"); | ||
class TsGeneratorPlugin { | ||
constructor(ctx) { | ||
this.ctx = ctx; | ||
this.state = "uninitialized"; | ||
this.logger = ctx.logger || new logger_1.NoLogger(); | ||
} | ||
@@ -8,0 +9,0 @@ beforeRun() { } |
export * from "./utils"; | ||
export * from "./plugins/types"; | ||
export { tsGen } from "./tsGen"; | ||
export { tsGenerator } from "./tsGenerator"; |
@@ -8,3 +8,3 @@ "use strict"; | ||
__export(require("./plugins/types")); | ||
var tsGen_1 = require("./tsGen"); | ||
exports.tsGen = tsGen_1.tsGen; | ||
var tsGenerator_1 = require("./tsGenerator"); | ||
exports.tsGenerator = tsGenerator_1.tsGenerator; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"bin": "dist/cli/run.js", | ||
@@ -20,3 +20,3 @@ "main": "./dist/publicApi.js", | ||
"build": "rm -rf ./dist && tsc -p tsconfig.prod.json --outDir ./dist", | ||
"prepublish": "yarn test && yarn build", | ||
"prepublishOnly": "yarn test && yarn build", | ||
"format": "prettier --list-different '**/*.{ts,json,md, gql}'", | ||
@@ -60,2 +60,3 @@ "format:fix": "prettier --write '**/*.{ts,json,md,gql}'", | ||
"@types/prettier": "^1.13.2", | ||
"chalk": "^2.4.1", | ||
"glob": "^7.1.2", | ||
@@ -62,0 +63,0 @@ "mkdirp": "^0.5.1", |
@@ -7,3 +7,3 @@ # ts-generator | ||
[![Coverage Status](https://coveralls.io/repos/github/krzkaczor/ts-gen/badge.svg?branch=master)](https://coveralls.io/github/krzkaczor/ts-gen?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/krzkaczor/ts-generator/badge.svg?branch=master)](https://coveralls.io/github/krzkaczor/ts-gen?branch=master) | ||
@@ -10,0 +10,0 @@ ## Features: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18340
32
401
6
+ Addedchalk@^2.4.1
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)