-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
176 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const distDir = __dirname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { join } from 'node:path' | ||
import { createSyncFn } from 'synckit' | ||
import { distDir } from '../dirs' | ||
import type { run } from '../worker' | ||
|
||
export const syncAction = createSyncFn(join(distDir, 'worker.js')) as typeof run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import settings from '../settings' | ||
import exploreConfig from 'explore-config' | ||
|
||
export default function resolveContext(context) { | ||
const resolvedSettings = Object.assign(settings, context.settings?.['@master/css']) | ||
const config = resolvedSettings?.config | ||
return { | ||
settings: resolvedSettings, | ||
options: context.options[0] || {}, | ||
config: typeof config === 'object' ? config : exploreConfig(resolvedSettings?.config || '') | ||
config: resolvedSettings?.config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import process from 'node:process' | ||
import exploreConfig from 'explore-config' | ||
import { runAsWorker } from 'synckit' | ||
import MasterCSS, { Config, reorderForReadableClasses } from '@master/css' | ||
import { validate, createValidRules } from '@master/css-validator' | ||
import { Rule } from '@master/css' | ||
|
||
let masterCSS: MasterCSS | ||
let masterConfig: string | Config | ||
|
||
// bypass icon rules in ESLint | ||
process.env.ESLINT ||= 'true' | ||
|
||
function _getMasterCSS(config: string | Config) { | ||
console.log('new master css') | ||
return new MasterCSS(typeof config === 'object' ? config : exploreConfig(config || '')) | ||
} | ||
|
||
export function getMasterCSS(config: string | Config) { | ||
if (!masterCSS || masterConfig !== config) { | ||
masterCSS = _getMasterCSS(config) | ||
masterConfig = config | ||
} | ||
return masterCSS | ||
} | ||
|
||
function actionSort(classNames: string[], config: string | Config) { | ||
return reorderForReadableClasses(classNames, { css: getMasterCSS(config) }) | ||
.filter((eachOrderedClassName: string) => classNames.includes(eachOrderedClassName)) | ||
} | ||
|
||
function actionValidate(className: string, config: string | Config) { | ||
return validate(className, { css: getMasterCSS(config) }) | ||
} | ||
|
||
function actionRuleOfClass(classNames: string[], config: string | Config) { | ||
const ruleOfClass = {} | ||
classNames | ||
.forEach(eachClassName => { | ||
ruleOfClass[eachClassName] = createValidRules(eachClassName, { css: getMasterCSS(config) })[0] | ||
}) | ||
return ruleOfClass | ||
} | ||
|
||
export function run(action: 'sort', classNames: string[], config: string | Config): string[] | ||
export function run(action: 'validate', className: string, config: string | Config): {isMasterCSS: boolean;errors: SyntaxError[]} | ||
export function run(action: 'ruleOfClass', className: string, config: string | Config): Rule | ||
export function run(action: string, ...args: any[]): any { | ||
switch (action) { | ||
case 'sort': | ||
// @ts-expect-error cast | ||
return actionSort(...args) | ||
case 'validate': | ||
// @ts-expect-error cast | ||
return actionValidate(...args) | ||
case 'ruleOfClass': | ||
// @ts-expect-error cast | ||
return actionRuleOfClass(...args) | ||
} | ||
} | ||
|
||
runAsWorker(run as any) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.