@@ -2,7 +2,7 @@ import {readFileSync, writeFileSync} from 'fs';
22import { pathToFileURL } from 'url' ;
33import { relative , join , dirname } from 'path' ;
44import { compileString } from 'sass' ;
5- import { highlightCodeBlock } from '../highlight-files/highlight-code-block' ;
5+ import { highlightCodeBlock } from '../highlight-files/highlight-code-block.mjs ' ;
66
77/** Information extracted for a single token from the theme. */
88interface ExtractedToken {
@@ -43,40 +43,39 @@ interface ThemeData {
4343}
4444
4545// Script that extracts the tokens from a specific Bazel target.
46- if ( require . main === module ) {
47- const [ packagePath , outputPath , ...inputFiles ] = process . argv . slice ( 2 ) ;
48- const themeFiles = inputFiles
49- // Filter out only the files within the package
50- // since the path also includes dependencies.
51- . filter ( file => file . startsWith ( packagePath ) )
52- . map ( file => {
53- // Assumption: all theme files start with an underscore since they're
54- // partials and they end with `-theme`.
55- // Assumption: the name under which the theme mixin will be available is the
56- // same as the file name without the underscore and `-theme.scss`.
57- const match = file . match ( / _ ( .* ) - t h e m e \. s c s s $ / ) ;
58- return match ? { mixinPrefix : match [ 1 ] , filePath : file } : null ;
59- } )
60- . filter ( file => ! ! file ) ;
61-
62- if ( themeFiles . length === 0 ) {
63- throw new Error ( `Could not find theme files in ${ packagePath } ` ) ;
64- }
6546
66- const themes : ThemeData [ ] = [ ] ;
47+ const [ packagePath , outputPath , ...inputFiles ] = process . argv . slice ( 2 ) ;
48+ const themeFiles = inputFiles
49+ // Filter out only the files within the package
50+ // since the path also includes dependencies.
51+ . filter ( file => file . startsWith ( packagePath ) )
52+ . map ( file => {
53+ // Assumption: all theme files start with an underscore since they're
54+ // partials and they end with `-theme`.
55+ // Assumption: the name under which the theme mixin will be available is the
56+ // same as the file name without the underscore and `-theme.scss`.
57+ const match = file . match ( / _ ( .* ) - t h e m e \. s c s s $ / ) ;
58+ return match ? { mixinPrefix : match [ 1 ] , filePath : file } : null ;
59+ } )
60+ . filter ( file => ! ! file ) ;
61+
62+ if ( themeFiles . length === 0 ) {
63+ throw new Error ( `Could not find theme files in ${ packagePath } ` ) ;
64+ }
65+
66+ const themes : ThemeData [ ] = [ ] ;
6767
68- themeFiles . forEach ( theme => {
69- themes . push ( {
70- name : theme . mixinPrefix ,
71- // This can be derived from the `name` already, but we want the source
72- // of truth to be in this repo, instead of whatever page consumes the data.
73- overridesMixin : `${ theme . mixinPrefix } -overrides` ,
74- tokens : extractTokens ( theme . filePath ) ,
75- } ) ;
68+ themeFiles . forEach ( theme => {
69+ themes . push ( {
70+ name : theme . mixinPrefix ,
71+ // This can be derived from the `name` already, but we want the source
72+ // of truth to be in this repo, instead of whatever page consumes the data.
73+ overridesMixin : `${ theme . mixinPrefix } -overrides` ,
74+ tokens : extractTokens ( theme . filePath ) ,
7675 } ) ;
76+ } ) ;
7777
78- writeFileSync ( outputPath , JSON . stringify ( { example : getUsageExample ( themes ) , themes} ) ) ;
79- }
78+ writeFileSync ( outputPath , JSON . stringify ( { example : getUsageExample ( themes ) , themes} ) ) ;
8079
8180/**
8281 * Extracts the tokens from a theme file.
0 commit comments