From: Dan Allen Date: Mon, 2 Oct 2017 04:01:04 +0000 (-0600) Subject: add format build task X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=659a0d617ea2f3a33168e51cc597434d2595516d;p=eg-antora.git add format build task - add Prettier w/ ESLint integration - add local Gulp plugin to integrate prettier-eslint - add format build task - promote JS file globs to constant --- diff --git a/gulpfile.js b/gulpfile.js index 88ed62a..51082d0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ const gulp = require('gulp') const build = require('./tasks/build') const buildPreview = require('./tasks/build-preview') +const format = require('./tasks/format') const lint = require('./tasks/lint') const pack = require('./tasks/pack') const preview = require('./tasks/preview') @@ -16,8 +17,18 @@ const previewSiteDestDir = path.join(buildDir, 'preview-site') const srcDir = 'src' const destDir = path.join(previewSiteDestDir, '_') +const jsFiles = [ + 'gulpfile.js', + 'tasks/**/*.js', + path.join(srcDir, '{helpers,js}/**/*.js') +] + gulp.task('lint', () => - lint(['gulpfile.js', 'tasks/**/*.js', path.join(srcDir, '{helpers,js}/**/*.js')]) + lint(jsFiles) +) + +gulp.task('format', () => + format(jsFiles) ) gulp.task('build', () => diff --git a/package.json b/package.json index 520d33b..be660cb 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "postcss-calc": "^6.0.0", "postcss-custom-properties": "^6.1.0", "postcss-import": "^11.0.0", + "prettier-eslint": "^8.2.0", "require-from-string": "^2.0.1", "vinyl-fs": "^2.4.4" } diff --git a/tasks/format.js b/tasks/format.js new file mode 100644 index 0000000..f2506d0 --- /dev/null +++ b/tasks/format.js @@ -0,0 +1,10 @@ +'use strict' + +const vfs = require('vinyl-fs') +const prettier = require('./lib/gulp-prettier-eslint') + +module.exports = (files) => + vfs + .src(files) + .pipe(prettier()) + .pipe(vfs.dest(file => file.base)) diff --git a/tasks/lib/gulp-prettier-eslint.js b/tasks/lib/gulp-prettier-eslint.js new file mode 100644 index 0000000..ad90572 --- /dev/null +++ b/tasks/lib/gulp-prettier-eslint.js @@ -0,0 +1,45 @@ +'use strict' + +const { PluginError } = require('gulp-util') +const prettierEslint = require('prettier-eslint') +const through = require('through2') + +module.exports = () => { + const report = { changed: 0, unchanged: 0 } + return through.obj(format).on('end', () => { + if (report.changed > 0) { + const changed = 'formatted ' + .concat(report.changed) + .concat(' file') + .concat(report.changed === 1 ? '' : 's') + const unchanged = 'left ' + .concat(report.unchanged) + .concat(' file') + .concat(report.unchanged === 1 ? '' : 's') + .concat(' unchanged') + console.log(`prettier-eslint: ${changed}; ${unchanged}`) + } + }) + + function format(file, encoding, callback) { + if (file.isNull()) { + return callback(null, file) + } + + if (file.isStream()) { + return callback(new PluginError('gulp-prettier-eslint', 'Streaming not supported')) + } + + const input = file.contents.toString('utf8') + const output = prettierEslint({ text: input }) + + if (input === output) { + report.unchanged += 1 + } else { + report.changed += 1 + file.contents = Buffer.from(output, encoding) + } + + return callback(null, file) + } +} diff --git a/yarn.lock b/yarn.lock index 70dd917..f70f943 100644 --- a/yarn.lock +++ b/yarn.lock @@ -78,7 +78,7 @@ ansi-escapes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92" -ansi-regex@^2.0.0: +ansi-regex@^2.0.0, ansi-regex@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" @@ -90,7 +90,7 @@ ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" -ansi-styles@^3.1.0: +ansi-styles@^3.0.0, ansi-styles@^3.1.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" dependencies: @@ -248,6 +248,13 @@ babel-code-frame@^6.22.0: esutils "^2.0.2" js-tokens "^3.0.2" +babel-runtime@^6.18.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + backo2@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" @@ -702,6 +709,12 @@ commander@~2.8.1: dependencies: graceful-readlink ">= 1.0.0" +common-tags@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.4.0.tgz#1187be4f3d4cf0c0427d43f74eef1f73501614c0" + dependencies: + babel-runtime "^6.18.0" + component-bind@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" @@ -777,6 +790,10 @@ cookie@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" +core-js@^2.4.0: + version "2.5.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b" + core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -1041,6 +1058,10 @@ dev-ip@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/dev-ip/-/dev-ip-1.0.1.tgz#a76a3ed1855be7a012bb8ac16cb80f3c00dc28f0" +dlv@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/dlv/-/dlv-1.1.0.tgz#fee1a7c43f63be75f3f679e85262da5f102764a7" + doctrine@1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" @@ -1263,7 +1284,7 @@ eslint-scope@^3.7.1: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint@^4.0.0, eslint@^4.8.0: +eslint@^4.0.0, eslint@^4.5.0, eslint@^4.8.0: version "4.8.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.8.0.tgz#229ef0e354e0e61d837c7a80fdfba825e199815e" dependencies: @@ -2262,6 +2283,10 @@ indent-string@^2.1.0: dependencies: repeating "^2.0.0" +indent-string@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289" + indexes-of@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/indexes-of/-/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607" @@ -2609,14 +2634,14 @@ js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" -js-yaml@^3.10.0, js-yaml@^3.9.1: +js-yaml@^3.10.0, js-yaml@^3.4.3, js-yaml@^3.9.1: version "3.10.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" dependencies: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^3.4.3, js-yaml@~3.7.0: +js-yaml@~3.7.0: version "3.7.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" dependencies: @@ -2854,6 +2879,10 @@ lodash.memoize@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" +lodash.merge@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5" + lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" @@ -2879,6 +2908,10 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" +lodash.unescape@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" + lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" @@ -2902,6 +2935,17 @@ logalot@^2.0.0: figures "^1.3.5" squeak "^1.0.0" +loglevel-colored-level-prefix@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/loglevel-colored-level-prefix/-/loglevel-colored-level-prefix-1.0.0.tgz#6a40218fdc7ae15fc76c3d0f3e676c465388603e" + dependencies: + chalk "^1.1.3" + loglevel "^1.4.1" + +loglevel@^1.4.1: + version "1.5.0" + resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.5.0.tgz#3863984a2c326b986fbb965f378758a6dc8a4324" + longest@^1.0.0, longest@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" @@ -3830,10 +3874,37 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier-eslint@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/prettier-eslint/-/prettier-eslint-8.2.0.tgz#90adb1f7513be86238a3f32afcea8d1cb4b79055" + dependencies: + common-tags "^1.4.0" + dlv "^1.1.0" + eslint "^4.5.0" + indent-string "^3.2.0" + lodash.merge "^4.6.0" + loglevel-colored-level-prefix "^1.0.0" + prettier "^1.7.0" + pretty-format "^20.0.3" + require-relative "^0.8.7" + typescript "^2.4.2" + typescript-eslint-parser "^7.0.0" + +prettier@^1.7.0: + version "1.7.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.3.tgz#8e6974725273914b1c47439959dd3d3ba53664b6" + pretty-bytes@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9" +pretty-format@^20.0.3: + version "20.0.3" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-20.0.3.tgz#020e350a560a1fe1a98dc3beb6ccffb386de8b14" + dependencies: + ansi-regex "^2.1.1" + ansi-styles "^3.0.0" + pretty-hrtime@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1" @@ -4023,6 +4094,10 @@ reduce-function-call@^1.0.1: dependencies: balanced-match "^0.4.2" +regenerator-runtime@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" + regex-cache@^0.4.2: version "0.4.4" resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" @@ -4098,6 +4173,10 @@ require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" +require-relative@^0.8.7: + version "0.8.7" + resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de" + require-uncached@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" @@ -4756,6 +4835,17 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" +typescript-eslint-parser@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-7.0.0.tgz#be57d8768e37707af825e339ea2af18d7393cabb" + dependencies: + lodash.unescape "4.0.1" + semver "5.3.0" + +typescript@^2.4.2: + version "2.5.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d" + ua-parser-js@0.7.12: version "0.7.12" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"