|
1 | 1 | /** |
2 | 2 | * External dependencies |
3 | 3 | */ |
4 | | -import { basename, join, dirname } from 'node:path'; |
| 4 | +import { basename, join } from 'node:path'; |
5 | 5 | import { fileURLToPath } from 'node:url'; |
6 | 6 | import type { Plugin } from '@terrazzo/parser'; |
7 | 7 |
|
@@ -155,9 +155,13 @@ function getModeOverrides( |
155 | 155 | * For each mode found in tokens (via $extensions.mode), generates a separate |
156 | 156 | * JSON file per source file containing tokens that have values for that mode. |
157 | 157 | * |
| 158 | + * @param options Plugin options. |
| 159 | + * @param options.filePath Output path relative to outDir (default: 'modes'). |
158 | 160 | * @return A Terrazzo plugin that generates mode-specific DTCG override files. |
159 | 161 | */ |
160 | | -export default function pluginModeOverrides(): Plugin { |
| 162 | +export default function pluginModeOverrides( { |
| 163 | + filePath = 'modes', |
| 164 | +} = {} ): Plugin { |
161 | 165 | return { |
162 | 166 | name: '@wordpress/terrazzo-plugin-mode-overrides', |
163 | 167 | async build( { outputFile, sources } ) { |
@@ -189,13 +193,20 @@ export default function pluginModeOverrides(): Plugin { |
189 | 193 | } |
190 | 194 |
|
191 | 195 | // Output as {basename}.{mode}.json (e.g., dimension.compact.json) |
192 | | - const filePath = fileURLToPath( filename ); |
193 | | - const outFile = join( |
194 | | - dirname( filePath ), |
195 | | - 'modes', |
196 | | - `${ basename( filePath, '.json' ) }.${ mode }.json` |
| 196 | + const jsonFileName = `${ basename( |
| 197 | + fileURLToPath( filename ), |
| 198 | + '.json' |
| 199 | + ) }.${ mode }.json`; |
| 200 | + |
| 201 | + const outputFilePath = join( |
| 202 | + filePath, |
| 203 | + jsonFileName |
| 204 | + ).replace( /\\/g, '/' ); |
| 205 | + |
| 206 | + outputFile( |
| 207 | + outputFilePath, |
| 208 | + JSON.stringify( output, null, '\t' ) |
197 | 209 | ); |
198 | | - outputFile( outFile, JSON.stringify( output, null, '\t' ) ); |
199 | 210 | } |
200 | 211 | } |
201 | 212 | }, |
|
0 commit comments