-
Notifications
You must be signed in to change notification settings - Fork 142
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
6 changed files
with
11,011 additions
and
13,125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,82 @@ | ||
import path from 'path' | ||
import gulp from 'gulp' | ||
import { globbySync } from 'globby' | ||
import eslint from 'gulp-eslint' | ||
import plumber from 'gulp-plumber' | ||
import gulpIf from 'gulp-if' | ||
import notify from 'gulp-notify' | ||
import logger from 'gulp-logger' | ||
|
||
import { env, themes, projectPath } from './config.mjs' | ||
import configLoader from './config-loader.mjs' | ||
|
||
export default (name, file) => { | ||
import fs from 'fs-extra' | ||
import { globby } from 'globby' | ||
import { ESLint } from 'eslint' | ||
import progress from 'progress' | ||
import log from 'fancy-log' | ||
import colors from 'ansi-colors' | ||
|
||
import configLoader from '../helpers/config-loader.mjs' | ||
import { env, themes, projectPath } from '../helpers/config.mjs' | ||
|
||
export default async (name, file) => { | ||
const theme = themes[name] | ||
const srcBase = path.join(projectPath, theme.dest) | ||
const eslintConfig = configLoader('eslint.json') | ||
const files = globbySync(srcBase + '/**/*.js') | ||
|
||
return gulp.src(file ? file : files.length ? files : '.') | ||
.pipe(gulpIf( | ||
!env.ci, | ||
plumber({ | ||
errorHandler: notify.onError('Error: <%= error.message %>') | ||
const themePath = path.resolve(projectPath, theme.src) + '/' | ||
|
||
configLoader('.browserslistrc') | ||
|
||
const eslint = new ESLint({ | ||
cwd: themePath, | ||
baseConfig: configLoader('.eslintrc.json'), | ||
resolvePluginsRelativeTo: process.cwd(), | ||
useEslintrc: false, | ||
fix: env.fix | ||
}) | ||
|
||
const formatter = await eslint.loadFormatter('stylish') | ||
|
||
const paths = [] | ||
|
||
if (file) { | ||
paths.push(file) | ||
} | ||
else { | ||
paths.push('**/*.js', '!**/node_modules/**') | ||
|
||
if (await fs.pathExists(themePath + '.eslintignore')) { | ||
const ignore = await fs.readFile(themePath + '.eslintignore', 'utf8') | ||
ignore.split('\n').forEach(path => { | ||
if (path) { | ||
paths.push('!' + path) | ||
} | ||
}) | ||
)) | ||
.pipe(eslint(eslintConfig)) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()) | ||
.pipe(logger({ | ||
display : 'name', | ||
beforeEach: 'Theme: ' + name + ' ' + 'File: ', | ||
afterEach : ' - ESLint finished.' | ||
})) | ||
} | ||
} | ||
|
||
const files = await globby(paths, { absolute: true, cwd: themePath }) | ||
|
||
const progressBar = new progress(':percent | ETA: :etas | :current/:total | [:bar]', { | ||
total: files.length, | ||
clear: true | ||
}) | ||
|
||
const resultText = [] | ||
|
||
await Promise.all(files.map(async filePath => { | ||
const code = await fs.readFile(filePath, 'utf8') | ||
const results = await eslint.lintText(code, { filePath }) | ||
|
||
progressBar.tick() | ||
|
||
if (!results[0].messages.length) { | ||
return | ||
} | ||
|
||
if (env.fix) { | ||
await ESLint.outputFixes(results) | ||
} | ||
|
||
resultText.push(formatter.format(results)) | ||
})) | ||
|
||
if (resultText.length) { | ||
log(resultText.join('\n')) | ||
|
||
if (env.ci) { | ||
process.exit(1) | ||
} | ||
} | ||
else { | ||
log(colors.green('ESLint found no problems!')) | ||
} | ||
} |
Oops, something went wrong.