Skip to content

Commit 693a366

Browse files
committed
Update buildBlazingUtils.mjs
1 parent 2a1baf2 commit 693a366

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

scripts/buildBlazingUtils.mjs

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -124,51 +124,62 @@ const buildTemplateString = async () => {
124124
outdir: path.resolve(resolveDir, 'blazing-utils'),
125125
})
126126
// */
127+
/**
128+
* @type {import('esbuild').BuildOptions['stdin']}
129+
**/
130+
const stdin = {
131+
contents: `
132+
import {studioTheme as defaultStudioTheme} from './node_modules/@sanity/ui/src/theme/studioTheme/theme.ts'
133+
import {themeFromHues} from 'utils/themeFromHues'
134+
import {
135+
multiply as _multiply,
136+
parseColor,
137+
rgbToHex,
138+
screen as _screen,
139+
rgba,
140+
} from './node_modules/@sanity/ui/src/theme/lib/color-fns/index.ts'
141+
import {createColorTheme} from './node_modules/@sanity/ui/src/theme/lib/theme/color/factory.ts'
142+
143+
function multiply(bg: string, fg: string): string {
144+
const b = parseColor(bg)
145+
const s = parseColor(fg)
146+
const hex = rgbToHex(_multiply(b, s))
147+
148+
return hex
149+
}
150+
151+
function screen(bg: string, fg: string): string {
152+
const b = parseColor(bg)
153+
const s = parseColor(fg)
154+
const hex = rgbToHex(_screen(b, s))
155+
156+
return hex
157+
}
158+
159+
export const studioTheme = themeFromHues({
160+
hues: process.env.__HUES__,
161+
studioTheme: defaultStudioTheme,
162+
multiply,
163+
screen,
164+
rgba,
165+
createColorTheme,
166+
})
167+
`,
168+
resolveDir,
169+
loader: 'ts',
170+
}
127171

128-
return esbuild.build({
172+
await esbuild.build({
129173
...browserDefaults,
174+
minify: false,
130175
outfile: path.resolve(resolveDir, 'blazing-utils/themeFromHues.mjs'),
131-
stdin: {
132-
contents: `
133-
import {studioTheme as defaultStudioTheme} from './node_modules/@sanity/ui/src/theme/studioTheme/theme.ts'
134-
import {themeFromHues} from 'utils/themeFromHues'
135-
import {
136-
multiply as _multiply,
137-
parseColor,
138-
rgbToHex,
139-
screen as _screen,
140-
rgba,
141-
} from './node_modules/@sanity/ui/src/theme/lib/color-fns/index.ts'
142-
import {createColorTheme} from './node_modules/@sanity/ui/src/theme/lib/theme/color/factory.ts'
143-
144-
function multiply(bg: string, fg: string): string {
145-
const b = parseColor(bg)
146-
const s = parseColor(fg)
147-
const hex = rgbToHex(_multiply(b, s))
148-
149-
return hex
150-
}
151-
152-
function screen(bg: string, fg: string): string {
153-
const b = parseColor(bg)
154-
const s = parseColor(fg)
155-
const hex = rgbToHex(_screen(b, s))
156-
157-
return hex
158-
}
159-
160-
export const studioTheme = themeFromHues({
161-
hues: process.env.__HUES__,
162-
studioTheme: defaultStudioTheme,
163-
multiply,
164-
screen,
165-
rgba,
166-
createColorTheme,
167-
})
168-
`,
169-
resolveDir,
170-
loader: 'ts',
171-
},
176+
stdin,
177+
})
178+
await esbuild.build({
179+
...browserDefaults,
180+
minify: true,
181+
outfile: path.resolve(resolveDir, 'blazing-utils/themeFromHues.min.mjs'),
182+
stdin,
172183
})
173184
}
174185

@@ -177,9 +188,9 @@ const buildThemeFromHuesTemplate = async () => {
177188
path.resolve(resolveDir, 'blazing-utils/themeFromHues.mjs'),
178189
'utf8'
179190
)
180-
const minifiedPrebuiltFromEsbuild = await esbuild.transform(
181-
prebuiltFromEsbuild,
182-
{ minify: true }
191+
const minifiedPrebuiltFromEsbuild = await fs.readFile(
192+
path.resolve(resolveDir, 'blazing-utils/themeFromHues.min.mjs'),
193+
'utf8'
183194
)
184195

185196
return esbuild.build({

0 commit comments

Comments
 (0)