Skip to content

Commit b2e03fd

Browse files
committed
Add parameter for postgres config
1 parent d26b62a commit b2e03fd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type CMTDOptions = {
1717
dropExtensions?: boolean;
1818
camelCase?: boolean;
1919
logger?: Logger;
20+
config?: any;
2021
};
2122

2223
export interface Logger {
@@ -33,6 +34,7 @@ export class CMTD {
3334
private dropExtensions: boolean;
3435
private camelCase: boolean;
3536
private logger: Logger;
37+
private config: any;
3638

3739
constructor (
3840
{
@@ -43,6 +45,7 @@ export class CMTD {
4345
dropExtensions,
4446
camelCase,
4547
logger,
48+
config
4649
}: CMTDOptions
4750
)
4851
{
@@ -53,12 +56,13 @@ export class CMTD {
5356
this.dropExtensions = defaultTo(dropExtensions, false);
5457
this.camelCase = defaultTo(camelCase, false);
5558
this.logger = defaultTo(logger, console);
59+
this.config = defaultTo(config, undefined);
5660
}
5761

5862
private async generateTypes(filePath: string) {
5963
return new Promise<void> (
6064
(resolve, _reject) => {
61-
parser(filePath)
65+
parser(filePath, this.config)
6266
.then(
6367
tokens => {
6468
const fileName = path.isAbsolute(filePath) ? path.relative(this.inputDirectoryName, filePath) : filePath;

src/parser.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ import fs from 'fs-extra';
22
import { cosmiconfigSync } from 'cosmiconfig';
33
import postcss, { AcceptedPlugin, Parser, Root } from 'postcss';
44

5-
// TODO this could proably use some better type definitions, but I can't find them :(
6-
const explorer = cosmiconfigSync('postcss');
7-
const found = explorer.search();
8-
const config = found!.config;
9-
10-
export const importer = require('postcss-import')(config.plugins['postcss-import']) as AcceptedPlugin;
11-
export const localByDefault = require('postcss-modules-local-by-default') as AcceptedPlugin;
12-
export const scope = require('postcss-modules-scope') as AcceptedPlugin;
13-
export const comment = require('postcss-comment') as Parser;
14-
15-
export const defaultPlugins = [ importer, localByDefault, scope ];
16-
175
export type ParserReturn = Set<string>;
186

197
export async function parser(
208
filePath: string,
9+
config: any,
2110
plugins: AcceptedPlugin[] | null = null,
2211
): Promise<ParserReturn> {
12+
// TODO config is 'any' this could probably use some better type definitions, but I can't find them :(
13+
if(config === undefined) {
14+
config = cosmiconfigSync('postcss').search()?.config ?? {};
15+
}
16+
17+
const importer = require('postcss-import')(config.plugins['postcss-import']) as AcceptedPlugin;
18+
const localByDefault = require('postcss-modules-local-by-default') as AcceptedPlugin;
19+
const scope = require('postcss-modules-scope') as AcceptedPlugin;
20+
const comment = require('postcss-comment') as Parser;
21+
22+
const defaultPlugins = [ importer, localByDefault, scope ];
23+
2324
const exportTokens = new Set<string>();
2425

2526
const gatherPlugIn = (root: Root) => {

0 commit comments

Comments
 (0)