From 0a910dee36cfba09dc6531d03330d52a65f236ed Mon Sep 17 00:00:00 2001 From: Mark Lawlor Date: Thu, 5 May 2022 12:26:42 +1000 Subject: [PATCH] fix: add output option to postcss plugin --- src/postcss/index.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/postcss/index.ts b/src/postcss/index.ts index 8abffa4..013aab0 100644 --- a/src/postcss/index.ts +++ b/src/postcss/index.ts @@ -1,5 +1,5 @@ +import { writeFileSync } from "node:fs"; import { Plugin, PluginCreator } from "postcss"; -import { TailwindConfig } from "tailwindcss/tailwind-config"; import { normaliseSelector } from "../shared/selector"; import { toReactNative } from "./to-react-native"; import { MediaRecord, StyleRecord, Style, StyleError } from "../types/common"; @@ -12,7 +12,9 @@ declare module "postcss" { } } -export interface PostcssPluginOptions extends Partial { +export interface PostcssPluginOptions { + important?: boolean | string; + output?: string; done?: (options: { styles: StyleRecord; media: MediaRecord; @@ -21,9 +23,8 @@ export interface PostcssPluginOptions extends Partial { } export const plugin: PluginCreator = ({ - done = () => { - return; - }, + done, + output, important, } = {}): Plugin => { const styles: StyleRecord = {}; @@ -82,7 +83,17 @@ export const plugin: PluginCreator = ({ } }); - done({ styles, media, errors }); + if (done) done({ styles, media, errors }); + if (output) { + writeFileSync( + output, + `module.exports = { + platform: 'native', + styles: ${JSON.stringify(styles)}, + media: ${JSON.stringify(media)} +}` + ); + } }, }; };