From f0ac42ef49c2291d7f5f07caaceb261e9ee27064 Mon Sep 17 00:00:00 2001 From: Dan Bucholtz Date: Tue, 27 Sep 2016 15:12:59 -0500 Subject: [PATCH] chore(build): remove console.debug from prod remove console.debug from prod --- scripts/gulp/tasks/release.ts | 28 +++++++++++++++++++++++++--- src/components/menu/menu-gestures.ts | 21 +++++++++------------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/scripts/gulp/tasks/release.ts b/scripts/gulp/tasks/release.ts index 3c7e80d5f6..fafd0a4628 100644 --- a/scripts/gulp/tasks/release.ts +++ b/scripts/gulp/tasks/release.ts @@ -1,6 +1,7 @@ import { spawn, exec } from 'child_process'; -import { writeFileSync } from 'fs'; +import { readFileSync, writeFileSync } from 'fs'; +import * as glob from 'glob'; import { dest, src, task } from 'gulp'; import { rollup } from 'rollup'; import * as commonjs from 'rollup-plugin-commonjs'; @@ -12,13 +13,34 @@ import { compileSass, copyFonts, createTimestamp, setSassIonicVersion, writePoly task('nightly', (done: (err: any) => void) => { - runSequence('release.prepareReleasePackage', 'release.publishNightly', done); + runSequence('release.prepareReleasePackage', 'release.removeDebugStatements', 'release.publishNightly', done); }); task('release', (done: (err: any) => void) => { - runSequence('release.prepareReleasePackage', 'release.copyProdVersion', done); + // don't automatically push the button, require the user to call the publish command separately for now + runSequence('release.prepareReleasePackage', 'release.copyProdVersion', 'release.removeDebugStatements', done); }); +task('release.removeDebugStatements', (done: Function) => { + glob(`${DIST_BUILD_ROOT}/**/*.js`, (err, filePaths) => { + if (err) { + done(err); + } else { + // can make async if it's slow but it's fine for now + for (let filePath of filePaths) { + const fileContent = readFileSync(filePath).toString(); + const consoleFree = replaceAll(fileContent, 'console.debug', '// console.debug'); + const cleanedJs = replaceAll(consoleFree, 'debugger;', '// debugger;'); + writeFileSync(filePath, cleanedJs); + } + } + }); +}); + +function replaceAll(input: string, tokenToReplace: string, replaceWith: string) { + return input.split(tokenToReplace).join(replaceWith); +} + task('release.publishRelease', (done: Function) => { const npmCmd = spawn('npm', ['publish', DIST_BUILD_ROOT]); npmCmd.stdout.on('data', function (data) { diff --git a/src/components/menu/menu-gestures.ts b/src/components/menu/menu-gestures.ts index f1db9b90d1..fc8611c275 100644 --- a/src/components/menu/menu-gestures.ts +++ b/src/components/menu/menu-gestures.ts @@ -68,17 +68,15 @@ export class MenuContentGesture extends SlideEdgeGesture { let shouldCompleteLeft = (velocity <= 0) && (velocity < -0.2 || slide.delta < -z); - console.debug( - 'menu gesture, onSlide', this.menu.side, - 'distance', slide.distance, - 'delta', slide.delta, - 'velocity', velocity, - 'min', slide.min, - 'max', slide.max, - 'shouldCompleteLeft', shouldCompleteLeft, - 'shouldCompleteRight', shouldCompleteRight, - 'currentStepValue', currentStepValue); - + console.debug('menu gesture, onSlide', this.menu.side); + console.debug('distance', slide.distance); + console.debug('delta', slide.delta); + console.debug('velocity', velocity); + console.debug('min', slide.min); + console.debug('max', slide.max); + console.debug('shouldCompleteLeft', shouldCompleteLeft); + console.debug('shouldCompleteRight', shouldCompleteRight); + console.debug('currentStepValue', currentStepValue); this.menu.swipeEnd(shouldCompleteLeft, shouldCompleteRight, currentStepValue); } @@ -104,4 +102,3 @@ export class MenuContentGesture extends SlideEdgeGesture { }; } } -