-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
d46eb89
commit d60e49a
Showing
9 changed files
with
189 additions
and
151 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
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 +1,35 @@ | ||
export const stylelintConfigFilePattern = '.stylelintrc(.(json|yml|yaml|js))?'; | ||
import { type Tree, joinPathFragments, offsetFromRoot, readJson, writeJson } from '@nx/devkit'; | ||
import type { Config } from 'stylelint'; | ||
import { PROJECT_STYLELINT_CONFIG_SCSS_OVERRIDE, ROOT_STYLELINT_CONFIG, ROOT_STYLELINT_CONFIG_SCSS } from './config'; | ||
|
||
export const STYLELINT_CONFIG_FILE_PATTERN = '.stylelintrc(.(json|yml|yaml|js))?'; | ||
|
||
export const STYLELINT_CONFIG_FILE = '.stylelintrc.json'; | ||
|
||
export const createRootStylelintConfigFile = (tree: Tree, withScssSupport: boolean) => | ||
writeJson<Config>(tree, STYLELINT_CONFIG_FILE, withScssSupport ? ROOT_STYLELINT_CONFIG_SCSS : ROOT_STYLELINT_CONFIG); | ||
|
||
export function createProjectStylelintConfigFile(tree: Tree, projectRoot: string, withScssSupport: boolean) { | ||
const config = { | ||
extends: [joinPathFragments(offsetFromRoot(projectRoot), STYLELINT_CONFIG_FILE)], | ||
ignoreFiles: ['!**/*'], | ||
overrides: [ | ||
{ | ||
files: ['**/*.css'], | ||
rules: {}, | ||
}, | ||
], | ||
}; | ||
|
||
if (withScssSupport) { | ||
config.overrides.push(PROJECT_STYLELINT_CONFIG_SCSS_OVERRIDE); | ||
} | ||
|
||
writeJson<Config>(tree, joinPathFragments(projectRoot, STYLELINT_CONFIG_FILE), config); | ||
} | ||
|
||
export function isCompatibleRootConfig(tree: Tree): boolean { | ||
if (!tree.exists(STYLELINT_CONFIG_FILE)) return false; | ||
const config = readJson<Config>(tree, STYLELINT_CONFIG_FILE); | ||
return config.ignoreFiles === '**/*' || (Array.isArray(config.ignoreFiles) && config.ignoreFiles.includes('**/*')); | ||
} |
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,35 @@ | ||
import type { Config } from 'stylelint'; | ||
|
||
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] | ||
? ElementType | ||
: never; | ||
|
||
type ConfigOverride = ArrayElement<NonNullable<Config['overrides']>>; | ||
|
||
export const ROOT_STYLELINT_CONFIG = { | ||
ignoreFiles: ['**/*'], | ||
overrides: [ | ||
{ | ||
files: ['**/*.css'], | ||
extends: ['stylelint-config-standard'], | ||
rules: {}, | ||
}, | ||
], | ||
rules: {}, | ||
} satisfies Config; | ||
|
||
export const ROOT_STYLELINT_CONFIG_SCSS_OVERRIDE: ConfigOverride = { | ||
files: ['**/*.scss'], | ||
extends: ['stylelint-config-standard-scss'], | ||
rules: {}, | ||
}; | ||
|
||
export const ROOT_STYLELINT_CONFIG_SCSS = { | ||
...ROOT_STYLELINT_CONFIG, | ||
overrides: [...ROOT_STYLELINT_CONFIG.overrides, ROOT_STYLELINT_CONFIG_SCSS_OVERRIDE], | ||
} satisfies Config; | ||
|
||
export const PROJECT_STYLELINT_CONFIG_SCSS_OVERRIDE = { | ||
files: ['**/*.scss'], | ||
rules: {}, | ||
} satisfies ConfigOverride; |
Oops, something went wrong.