forked from mgechev/angular-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement css linting with postcss (stylelint, doiuse, colorguard)
- Loading branch information
Showing
10 changed files
with
127 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "stylelint-config-standard", | ||
"rules": { | ||
"block-no-empty": null, | ||
"at-rule-empty-line-before": null, | ||
"rule-non-nested-empty-line-before": null | ||
} | ||
} |
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,4 +1,5 @@ | ||
export interface InjectableDependency { | ||
src: string; | ||
inject: string | boolean; | ||
vendor?: boolean; | ||
} |
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,15 @@ | ||
declare module 'colorguard' { | ||
|
||
interface IOptions { | ||
ignore?: string[]; | ||
threshold?: number; | ||
whitelist?: string[]; | ||
} | ||
|
||
interface IColorguard { | ||
(opts?: IOptions): NodeJS.ReadWriteStream; | ||
} | ||
|
||
const colorguard: IColorguard; | ||
export = colorguard; | ||
} |
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,16 @@ | ||
declare module 'doiuse' { | ||
|
||
interface IOptions { | ||
browsers?: string[]; | ||
ignore?: string[]; | ||
ignoreFiles?: string[]; | ||
onFeatureUsage?: Function; | ||
} | ||
|
||
interface IDoiuse { | ||
(opts?: IOptions): NodeJS.ReadWriteStream; | ||
} | ||
|
||
const doiuse: IDoiuse; | ||
export = doiuse; | ||
} |
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,20 @@ | ||
declare module 'postcss-reporter' { | ||
|
||
interface IOptions { | ||
clearMessages?: boolean; | ||
formatter?: Function; | ||
plugins?: string[]; | ||
throwError?: boolean; | ||
sortByPosition?: boolean; | ||
positionless?: string; | ||
noIcon?: boolean; | ||
noPlugin?: boolean; | ||
} | ||
|
||
interface IPostcssReporter { | ||
(opts?: IOptions): NodeJS.ReadWriteStream; | ||
} | ||
|
||
const postcssReporter: IPostcssReporter; | ||
export = postcssReporter; | ||
} |
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,16 @@ | ||
declare module 'stylelint' { | ||
|
||
interface IOptions { | ||
config?: Object; | ||
configFile?: string; | ||
configBasedir?: string; | ||
configOverrides?: Object; | ||
} | ||
|
||
interface IStylelint { | ||
(opts?: IOptions): NodeJS.ReadWriteStream; | ||
} | ||
|
||
const stylelint: IStylelint; | ||
export = stylelint; | ||
} |
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,43 @@ | ||
import * as gulp from 'gulp'; | ||
import * as gulpLoadPlugins from 'gulp-load-plugins'; | ||
import * as merge from 'merge-stream'; | ||
import * as reporter from 'postcss-reporter'; | ||
import * as stylelint from 'stylelint'; | ||
import * as doiuse from 'doiuse'; | ||
import * as colorguard from 'colorguard'; | ||
import {join} from 'path'; | ||
import {APP_SRC, APP_ASSETS, BROWSER_LIST, ENV} from '../../config'; | ||
const plugins = <any>gulpLoadPlugins(); | ||
|
||
const isProd = ENV === 'prod'; | ||
|
||
const processors = [ | ||
doiuse({ | ||
browsers: BROWSER_LIST, | ||
}), | ||
colorguard(), | ||
stylelint(), | ||
reporter({clearMessages: true}) | ||
]; | ||
|
||
function lintComponentCss() { | ||
return gulp.src([ | ||
join(APP_SRC, '**', '*.css'), | ||
'!' + join(APP_SRC, 'assets', '**', '*.css') | ||
]) | ||
.pipe(isProd ? plugins.cached('css-lint') : plugins.util.noop()) | ||
.pipe(plugins.postcss(processors)); | ||
} | ||
|
||
function lintExternalCss() { | ||
return gulp.src(getExternalCss().map(r => r.src)) | ||
.pipe(isProd ? plugins.cached('css-lint') : plugins.util.noop()) | ||
.pipe(plugins.postcss(processors)); | ||
} | ||
|
||
function getExternalCss() { | ||
return APP_ASSETS.filter(d => /\.css$/.test(d.src) && !d.vendor); | ||
} | ||
|
||
|
||
export = () => merge(lintComponentCss(), lintExternalCss()); |