diff --git a/build/gulp/plugins/gulp-example-source.ts b/build/gulp/plugins/gulp-example-source.ts index d1ca9e7cca..81f59d82f4 100644 --- a/build/gulp/plugins/gulp-example-source.ts +++ b/build/gulp/plugins/gulp-example-source.ts @@ -45,11 +45,12 @@ export default () => const sourcePath = getRelativePathToSourceFile(file.path) const source = createExampleSourceCode(file) - cb( - null, - new Vinyl({ - path: sourcePath, - contents: Buffer.from(JSON.stringify(source, null, 2)), - }), - ) + const sourceFile = new Vinyl({ + path: sourcePath, + contents: Buffer.from(JSON.stringify(source, null, 2)), + }) + // `gulp-cache` relies on this private entry + sourceFile._cachedKey = file._cachedKey + + cb(null, sourceFile) }) diff --git a/build/gulp/plugins/gulp-react-docgen.ts b/build/gulp/plugins/gulp-react-docgen.ts index b498dcbba7..548107f33f 100644 --- a/build/gulp/plugins/gulp-react-docgen.ts +++ b/build/gulp/plugins/gulp-react-docgen.ts @@ -3,7 +3,7 @@ import * as path from 'path' import * as through2 from 'through2' import * as Vinyl from 'vinyl' -import { getComponentInfo, getBufferChecksum, getInfoChecksum } from './util' +import { getComponentInfo } from './util' const pluginName = 'gulp-react-docgen' @@ -19,20 +19,16 @@ export default () => return } - const infoFilename = file.basename.replace(/\.tsx$/, '.info.json') - const nextChecksum = getBufferChecksum(file.contents) - - if (getInfoChecksum(infoFilename) === nextChecksum) { - cb(null) - return - } - try { - const contents = getComponentInfo(file.path, nextChecksum) + const infoFilename = file.basename.replace(/\.tsx$/, '.info.json') + const contents = getComponentInfo(file.path) + const infoFile = new Vinyl({ path: `./${infoFilename}`, contents: Buffer.from(JSON.stringify(contents, null, 2)), }) + // `gulp-cache` relies on this private entry + infoFile._cachedKey = file._cachedKey cb(null, infoFile) } catch (err) { diff --git a/build/gulp/plugins/util/checksumUtils.ts b/build/gulp/plugins/util/checksumUtils.ts deleted file mode 100644 index 7a6699f954..0000000000 --- a/build/gulp/plugins/util/checksumUtils.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as fs from 'fs' -import * as crypto from 'crypto' - -import config from '../../../../config' - -export const getInfoChecksum = (filename: string): string | null => { - try { - const buffer = fs.readFileSync(config.paths.docsSrc('componentInfo', filename)) - const componentInfo = JSON.parse(buffer.toString()) - - return componentInfo.checksum - } catch (e) {} - - return null -} - -export const getBufferChecksum = (buffer: Buffer): string => - crypto - .createHash('md5') - .update(buffer) - .digest('hex') diff --git a/build/gulp/plugins/util/getComponentInfo.ts b/build/gulp/plugins/util/getComponentInfo.ts index 411cb1dfd1..4437689ec1 100644 --- a/build/gulp/plugins/util/getComponentInfo.ts +++ b/build/gulp/plugins/util/getComponentInfo.ts @@ -12,7 +12,7 @@ interface BehaviorInfo { category: string } -const getComponentInfo = (filepath: string, checksum?: string) => { +const getComponentInfo = (filepath: string) => { const absPath = path.resolve(process.cwd(), filepath) const dir = path.dirname(absPath) @@ -43,9 +43,6 @@ const getComponentInfo = (filepath: string, checksum?: string) => { // remove keys we don't use delete info.methods - // add checksum - info.checksum = checksum - // add exported Component info const Component = require(absPath).default info.constructorName = _.get(Component, 'prototype.constructor.name', null) diff --git a/build/gulp/plugins/util/index.ts b/build/gulp/plugins/util/index.ts index d6a291e7d3..62d923f7a7 100644 --- a/build/gulp/plugins/util/index.ts +++ b/build/gulp/plugins/util/index.ts @@ -1,4 +1,3 @@ -export * from './checksumUtils' export { default as getComponentInfo } from './getComponentInfo' export { default as getRelativePathToSourceFile } from './getRelativePathToSourceFile' export { default as parseDefaultValue } from './parseDefaultValue' diff --git a/build/gulp/tasks/docs.ts b/build/gulp/tasks/docs.ts index c2fc764393..ccba1eaee1 100644 --- a/build/gulp/tasks/docs.ts +++ b/build/gulp/tasks/docs.ts @@ -1,6 +1,7 @@ import * as historyApiFallback from 'connect-history-api-fallback' import * as express from 'express' import { task, src, dest, lastRun, parallel, series, watch } from 'gulp' +import * as cache from 'gulp-cache' import * as remember from 'gulp-remember' import * as fs from 'fs' import * as path from 'path' @@ -33,6 +34,8 @@ const handleWatchUnlink = (group, path) => { // Clean // ---------------------------------------- +task('clean:cache', () => cache.clearAll()) + task('clean:docs:component-menu', cb => { rimraf(paths.docsSrc('componentMenu.json'), cb) }) @@ -83,7 +86,11 @@ const markdownSrc = [ task('build:docs:component-info', () => src(componentsSrc, { since: lastRun('build:docs:component-info') }) - .pipe(gulpReactDocgen()) + .pipe( + cache(gulpReactDocgen(), { + name: 'componentInfo', + }), + ) .pipe(dest(paths.docsSrc('componentInfo'))), ) @@ -109,7 +116,11 @@ task('build:docs:example-menu', () => task('build:docs:example-sources', () => src(examplesSrc, { since: lastRun('build:docs:example-sources') }) - .pipe(gulpExampleSource()) + .pipe( + cache(gulpExampleSource(), { + name: 'exampleSources', + }), + ) .pipe(dest(paths.docsSrc('exampleSources'))), ) diff --git a/package.json b/package.json index f1a6ce1cf4..7d26a58987 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build:docs": "gulp --series dll build:docs", "build:dist": "gulp --series build:dist", "ci": "yarn lint && yarn prettier && yarn test --strict", + "clean:cache": "gulp clean:cache", "predeploy:docs": "cross-env NODE_ENV=production yarn build:docs", "deploy:docs": "gulp deploy:docs", "lint": "tslint -t stylish -p .", @@ -114,6 +115,7 @@ "gh-pages": "^1.0.0", "glob": "^7.1.2", "gulp": "^4.0.0", + "gulp-cache": "^1.0.2", "gulp-debug": "^4.0.0", "gulp-load-plugins": "^1.5.0", "gulp-plumber": "^1.2.0", diff --git a/yarn.lock b/yarn.lock index b9d7546196..9b870e48ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1640,6 +1640,16 @@ cache-base@^1.0.1: union-value "^1.0.0" unset-value "^1.0.0" +cache-swap@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/cache-swap/-/cache-swap-0.3.0.tgz#1c541aa108a50106f630bdd98fe1dec8ba133f51" + integrity sha1-HFQaoQilAQb2ML3Zj+HeyLoTP1E= + dependencies: + graceful-fs "^4.1.2" + mkdirp "^0.5.1" + object-assign "^4.0.1" + rimraf "^2.4.0" + callsites@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" @@ -4312,6 +4322,18 @@ gud@^1.0.0: resolved "https://registry.yarnpkg.com/gud/-/gud-1.0.0.tgz#a489581b17e6a70beca9abe3ae57de7a499852c0" integrity sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw== +gulp-cache@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/gulp-cache/-/gulp-cache-1.0.2.tgz#064ed713de47b0ff26b491abd899590891e426f4" + integrity sha512-SFtWmWYARVzbzb6UiRZhZxpGo9oyXCOuXdTa0ML8CWQdFRTYZCfddn/grXG6SzdiY/D4rOnqpDJ8R2Trv0SQRQ== + dependencies: + babel-runtime "^6.26.0" + cache-swap "^0.3.0" + object.pick "^1.3.0" + plugin-error "^0.1.2" + through2 "^2.0.3" + vinyl "^2.1.0" + gulp-cli@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/gulp-cli/-/gulp-cli-2.0.1.tgz#7847e220cb3662f2be8a6d572bf14e17be5a994b" @@ -9007,7 +9029,7 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: +rimraf@^2.2.8, rimraf@^2.4.0, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" integrity sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==