@@ -7,15 +7,15 @@ import { kebabCase } from './helpers/text'
77import type { ComponentData , DirectiveData } from './types'
88import { generateComposableDataFromTypes , generateDirectiveDataFromTypes } from './types'
99import Piscina from 'piscina'
10- import { addDescriptions , addDirectiveDescriptions , addPropData , reportMissingDescriptions , stringifyProps } from './utils'
10+ import { addDescriptions , addDirectiveDescriptions , addPropData , reportMissingDescriptions , sortByKey , stringifyProps } from './utils'
1111import * as os from 'os'
1212import { mkdirp } from 'mkdirp'
1313import { createVeturApi } from './vetur'
1414import { rimraf } from 'rimraf'
1515import { createWebTypesApi } from './web-types'
1616import inspector from 'inspector'
1717import yargs from 'yargs'
18- import { parseSassVariables } from './helpers/sass'
18+ import { parseGlobalSassVariables , parseSassVariables } from './helpers/sass'
1919
2020const yar = yargs ( process . argv . slice ( 2 ) )
2121 . option ( 'components' , {
@@ -40,6 +40,10 @@ const componentsInfo: Record<string, { from: string }> = {
4040type Truthy < T > = Exclude < T , null | undefined | 0 | '' | false > ;
4141const BooleanFilter = < T > ( x : T ) : x is Truthy < T > => Boolean ( x )
4242
43+ function clamp ( v : number , min : number , max : number ) {
44+ return Math . max ( min , Math . floor ( Math . min ( max , v ) ) )
45+ }
46+
4347const run = async ( ) => {
4448 const argv = await yar . argv
4549
@@ -49,7 +53,9 @@ const run = async () => {
4953 const pool = new Piscina ( {
5054 filename : path . resolve ( './src/worker.ts' ) ,
5155 niceIncrement : 10 ,
52- maxThreads : inspector . url ( ) ? 1 : Math . max ( 1 , Math . floor ( Math . min ( os . cpus ( ) . length / 2 , os . freemem ( ) / ( 1.1 * 1024 ** 3 ) ) ) ) ,
56+ maxThreads : inspector . url ( )
57+ ? 1
58+ : clamp ( os . freemem ( ) / ( 1.1 * 1024 ** 3 ) , 1 , os . cpus ( ) . length / 2 ) ,
5359 } )
5460
5561 const template = await fs . readFile ( './templates/component.d.ts' , 'utf-8' )
@@ -76,7 +82,7 @@ const run = async () => {
7682 const componentProps = stringifyProps ( componentInstance . props )
7783 const sources = addPropData ( componentName , data , componentProps )
7884 await addDescriptions ( componentName , data , locales , sources )
79- const sass = parseSassVariables ( componentName )
85+ const sass = sortByKey ( parseSassVariables ( componentName ) )
8086
8187 const component = {
8288 displayName : componentName ,
@@ -91,6 +97,15 @@ const run = async () => {
9197 } )
9298 ) ) . filter ( BooleanFilter )
9399
100+ // globalSass
101+ const globalSass = {
102+ fileName : 'globals' ,
103+ displayName : 'globals' ,
104+ pathName : 'globals' ,
105+ sass : sortByKey ( parseGlobalSassVariables ( ) ) ,
106+ }
107+ await fs . writeFile ( path . resolve ( outPath , `globals.json` ) , JSON . stringify ( globalSass , null , 2 ) )
108+
94109 // Composables
95110 if ( ! argv . skipComposables ) {
96111 const composables = await Promise . all ( ( await generateComposableDataFromTypes ( ) ) . map ( async composable => {
0 commit comments