├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── index.js ├── package.json ├── test.js └── test └── fixtures ├── .editorconfig ├── empty ├── file-after.coffee ├── file-after.cshtml ├── file-after.html ├── file-after.jade ├── file-after.js ├── file-after.src ├── file-before.coffee ├── file-before.cshtml ├── file-before.html ├── file-before.jade ├── file-before.js ├── file-before.src ├── not-file-after.coffee ├── not-file-after.cshtml ├── not-file-after.html ├── not-file-after.jade ├── not-file-after.js ├── not-file-after.src ├── not-file-before.coffee ├── not-file-before.cshtml ├── not-file-before.html ├── not-file-before.jade ├── not-file-before.js ├── not-file-before.src ├── not-spaces-after.src ├── not-spaces-before.src ├── spaces-after.src └── spaces-before.src /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | indent_style = space 9 | indent_size = 2 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ 3 | 4 | # Ignore package-lock.json and yarn.lock 5 | package-lock.json 6 | yarn.lock 7 | 8 | # Ignore logs 9 | *.log 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - stable 4 | - '8' 5 | - '6.9.5' 6 | sudo: false 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Cristian Trifan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-remove-code 2 | 3 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 4 | [![npm version](https://badge.fury.io/js/gulp-remove-code.svg)](https://badge.fury.io/js/gulp-remove-code) 5 | [![Build Status](https://travis-ci.org/crissdev/gulp-remove-code.svg?branch=master)](https://travis-ci.org/crissdev/gulp-remove-code) 6 | [![Build status](https://ci.appveyor.com/api/projects/status/kxeyejflng4v6yjn/branch/master?svg=true&passingText=master%20-%20OK)](https://ci.appveyor.com/project/crissdev/gulp-remove-code/branch/master) 7 | [![Dependency Status](https://david-dm.org/crissdev/gulp-remove-code.svg)](https://david-dm.org/crissdev/gulp-remove-code) 8 | 9 | > A [Gulp](https://github.com/gulpjs/gulp) plugin to remove sections of code from files based on conditions 10 | 11 | 12 | ## Install 13 | 14 | ```sh 15 | npm install gulp-remove-code --save-dev 16 | ``` 17 | 18 | ## Usage 19 | 20 | ```js 21 | const removeCode = require('gulp-remove-code'); 22 | 23 | gulp.src('./src/*.js') 24 | .pipe(removeCode({ noDevFeatures: true })) 25 | .pipe(gulp.dest('./dist/')) 26 | 27 | gulp.src('./src/*.js') 28 | .pipe(removeCode({ noDevFeatures: true, commentStart: '/*', commentEnd: '*/' })) 29 | .pipe(gulp.dest('./dist/')) 30 | 31 | gulp.src('./src/*.coffee') 32 | .pipe(removeCode({ noDevFeatures: true })) 33 | .pipe(gulp.dest('./dist/')) 34 | ``` 35 | 36 | ## Examples 37 | 38 | ### Remove code from HTML files 39 | 40 | ```html 41 |
42 | 43 |
Running in sandbox environment
44 | 45 | 46 | Removing code is easy. 47 |
48 | ``` 49 | 50 | ```js 51 | const removeCode = require('gulp-remove-code'); 52 | 53 | gulp.src('./src/file.html') 54 | .pipe(removeCode({ production: true })) 55 | .pipe(gulp.dest('./dist')) 56 | ``` 57 | 58 | The plugin will remove the code inside the comments, as well as the comments. 59 | 60 | 61 | ### Remove code JavaScript files 62 | 63 | ```js 64 | let value = JSON.stringify({key: 'value'}); 65 | 66 | //removeIf(production) 67 | value = JSON.stringify({key: 'value', production: true}, null, 2); 68 | //endRemoveIf(production) 69 | 70 | //removeIf(!development) 71 | value = JSON.stringify({key: 'value', development: false}, null, 2); 72 | //endRemoveIf(!development) 73 | 74 | ``` 75 | 76 | ```js 77 | const removeCode = require('gulp-remove-code'); 78 | 79 | gulp.src('./src/file.js') 80 | .pipe(removeCode({ production: true })) 81 | .pipe(gulp.dest('./dist')) 82 | ``` 83 | 84 | The plugin will remove the code inside the comments, as well as the comments. 85 | 86 | 87 | ### Advanced usage 88 | 89 | Starting with version 2 of this plugin, conditions can also be expressed using the `!` specifier. 90 | 91 | 92 | ```js 93 | // Remove code using *!* (negated) conditions 94 | 95 | //----------- gulpfile.js ----------- 96 | // 97 | const removeCode = require('gulp-remove-code'); 98 | 99 | gulp.src('./src/file.js') 100 | .pipe(removeCode({ production: false })) 101 | .pipe(gulp.dest('./dist')) 102 | 103 | 104 | //----------- app-file.js ----------- 105 | // 106 | //removeIf(!production) 107 | value = JSON.stringify({key: 'value', production: false}, null, 2); 108 | //endRemoveIf(!production) 109 | 110 | ``` 111 | 112 | 113 | 114 | ## API 115 | 116 | ### removeCode([options]) 117 | 118 | ### options 119 | 120 | Type: `Object` 121 | 122 | A key value pair map to specify what code should be removed. The truthy values will remove the code. 123 | 124 | 125 | #### options.commentStart 126 | 127 | Type: `String` 128 | 129 | Default: `Detected from file extension. Use // as fallback.` 130 | 131 | Configure how the start comment is defined. 132 | 133 | 134 | #### options.commentEnd 135 | 136 | Type: `String` 137 | 138 | Default: `Detected from file extension. Use empty as fallback.` 139 | 140 | Configure how the end comment is defined. 141 | 142 | 143 | ## License 144 | 145 | MIT © [Cristian Trifan](https://crissdev.com) 146 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | environment: 4 | matrix: 5 | - nodejs_version: 6.9.5 6 | - nodejs_version: LTS 7 | - nodejs_version: Current 8 | 9 | platform: 10 | - x64 11 | - x86 12 | 13 | install: 14 | - ps: Install-Product node $env:nodejs_version $env:platform 15 | - npm install 16 | 17 | cache: '%AppData%/npm-cache' 18 | 19 | build: off 20 | 21 | test_script: 22 | - node --version 23 | - npm --version 24 | - npm test 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const entries = require('object.entries') 4 | const escapeStringRegexp = require('escape-string-regexp') 5 | const through = require('through2') 6 | const BufferStreams = require('bufferstreams') 7 | const getFileExt = require('path').extname 8 | const PluginError = require('plugin-error') 9 | 10 | const PLUGIN_NAME = 'gulp-remove-code' 11 | const regexCache = new Map() 12 | const extensions = new Map([ 13 | ['.coffee', [['#', ''], ['###', '###']]], 14 | ['.css', [['/*', '*/']]], 15 | ['.html', [['']]], 16 | ['.cshtml', [['@*', '*@'], ['']]], 17 | ['.jade', [['//-', '']]], 18 | ['.js', [['//', ''], ['/*', '*/']]], 19 | ['.ts', [['//', ''], ['/*', '*/']]], 20 | ['.jsx', [['//', ''], ['/*', '*/']]], 21 | ['.tsx', [['//', ''], ['/*', '*/']]] 22 | ]) 23 | 24 | function applyReplacements (buffer, {commentTypes, conditions}) { 25 | let contents = buffer.toString() 26 | 27 | if (buffer.length > 0) { 28 | for (const [key, value] of conditions) { 29 | for (const [commentStart, commentEnd] of commentTypes) { 30 | const regex = getRemovalTagsRegExp(commentStart, commentEnd, key) 31 | 32 | contents = contents.replace(regex, function (ignore, original, capture) { 33 | const not = (capture === '!') 34 | return (value ^ not) ? '' : original 35 | }) 36 | } 37 | } 38 | } 39 | 40 | return Buffer.from(contents) 41 | } 42 | 43 | /** 44 | * @param {string} commentStart 45 | * @param {string} commentEnd 46 | * @param {string} key 47 | * @returns {RegExp} 48 | */ 49 | function getRemovalTagsRegExp (commentStart, commentEnd, key) { 50 | const cacheKey = `${commentStart}${commentEnd}${key}` 51 | 52 | if (regexCache.has(cacheKey)) { 53 | return regexCache.get(cacheKey) 54 | } 55 | 56 | const escapedCommentStart = escapeStringRegexp(commentStart) 57 | const escapedKey = escapeStringRegexp(key) 58 | const escapedCommentEnd = escapeStringRegexp(commentEnd) 59 | const pattern = [ 60 | '(', 61 | escapedCommentStart, 62 | '\\s*removeIf\\((!?)', 63 | escapedKey, 64 | '\\)\\s*', 65 | escapedCommentEnd, 66 | '\\s*' + 67 | '(\\n|\\r|.)*?', 68 | escapedCommentStart, 69 | '\\s*endRemoveIf\\((!?)', 70 | escapedKey, 71 | '\\)\\s*', 72 | escapedCommentEnd, 73 | ')' 74 | ].join('') 75 | const re = new RegExp(pattern, 'gi') 76 | 77 | regexCache.set(cacheKey, re) 78 | 79 | return re 80 | } 81 | 82 | // -------------------------------------------------------------------------------------------------- 83 | 84 | module.exports = function (options) { 85 | options = Object.assign({}, options) 86 | options.conditions = [] 87 | 88 | for (const condition of entries(options)) { 89 | if (condition[0] !== 'commentStart' && condition[0] !== 'commentEnd') { 90 | options.conditions.push(condition) 91 | } 92 | } 93 | 94 | return through.obj(function (file, enc, callback) { 95 | const stream = this 96 | 97 | options = prepareOptions(file, options) 98 | 99 | file.contents = getFileContents(file, options, stream) 100 | 101 | stream.push(file) 102 | callback() 103 | }) 104 | } 105 | 106 | function getFileContents (file, options, stream) { 107 | if (file.isNull()) { 108 | return file.contents 109 | } 110 | 111 | if (file.isBuffer()) { 112 | return getBufferContents(file, options, stream) 113 | } 114 | 115 | if (file.isStream()) { 116 | return getStreamContents(file, options, stream) 117 | } 118 | } 119 | 120 | function getBufferContents (file, options, stream) { 121 | const parsed = removeCode(file, file.contents, options) 122 | 123 | if (parsed instanceof PluginError) { 124 | stream.emit('error', parsed) 125 | return Buffer.from('') 126 | } 127 | 128 | return parsed 129 | } 130 | 131 | function getStreamContents (file, options, stream) { 132 | const streamer = new BufferStreams(function (err, buf, callback) { 133 | if (err) { 134 | stream.emit('error', getError(err)) 135 | return callback() 136 | } 137 | 138 | const parsed = removeCode(file, buf, options) 139 | 140 | if (parsed instanceof PluginError) { 141 | stream.emit('error', parsed) 142 | return callback() 143 | } 144 | 145 | callback(null, parsed) 146 | }) 147 | 148 | return file.contents.pipe(streamer) 149 | } 150 | 151 | function removeCode (file, buf, options) { 152 | try { 153 | const result = applyReplacements(buf, options) 154 | return Buffer.from(result) 155 | } catch (error) { 156 | return getError(error) 157 | } 158 | } 159 | 160 | function prepareOptions (file, options) { 161 | if (!file.isNull()) { 162 | if (!options.commentStart) { 163 | // Detect comment tokens 164 | const fileExt = getFileExt(file.path) 165 | options.commentTypes = extensions.has(fileExt) ? extensions.get(fileExt) : [['//', '']] 166 | } else { 167 | options.commentTypes = [[options.commentStart, options.commentEnd || '']] 168 | } 169 | } 170 | 171 | return options 172 | } 173 | 174 | function getError (error) { 175 | return new PluginError(PLUGIN_NAME, error, {showStack: true}) 176 | } 177 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-remove-code", 3 | "version": "3.0.4", 4 | "description": "Remove sections of code from files based on conditions", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "npm run lint && mocha test.js", 8 | "lint": "eslint --max-warnings 0 index.js test.js", 9 | "lint-watch": "esw -w index.js test.js", 10 | "lint-fix": "eslint --fix index.js test.js" 11 | }, 12 | "files": [ 13 | "index.js" 14 | ], 15 | "engines": { 16 | "node": ">=6.9.5" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/crissdev/gulp-remove-code.git" 21 | }, 22 | "keywords": [ 23 | "gulpplugin", 24 | "gulp-plugin", 25 | "gulp", 26 | "remove", 27 | "remove code", 28 | "code", 29 | "strip", 30 | "strip code", 31 | "stream" 32 | ], 33 | "author": "crissdev (https://crissdev.com)", 34 | "license": "MIT", 35 | "bugs": { 36 | "url": "https://github.com/crissdev/gulp-remove-code/issues" 37 | }, 38 | "homepage": "https://github.com/crissdev/gulp-remove-code", 39 | "dependencies": { 40 | "bufferstreams": "^2.0.1", 41 | "escape-string-regexp": "^1.0.5", 42 | "object.entries": "^1.0.4", 43 | "plugin-error": "^1.0.1", 44 | "through2": "^2.0.3" 45 | }, 46 | "devDependencies": { 47 | "concat-stream": "^1.6.2", 48 | "eslint": "^5.3.0", 49 | "eslint-config-standard": "^11.0.0", 50 | "eslint-plugin-import": "^2.14.0", 51 | "eslint-plugin-node": "^7.0.1", 52 | "eslint-plugin-promise": "^3.8.0", 53 | "eslint-plugin-standard": "^3.1.0", 54 | "eslint-watch": "^4.0.2", 55 | "mocha": "^5.2.0", 56 | "vinyl": "^2.2.0" 57 | }, 58 | "eslintConfig": { 59 | "extends": [ 60 | "standard" 61 | ], 62 | "rules": { 63 | "no-var": "error", 64 | "prefer-const": "error", 65 | "max-len": [ 66 | "error", 67 | 120 68 | ] 69 | }, 70 | "env": { 71 | "mocha": true 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const removeCode = require('./index.js') 4 | const File = require('vinyl') 5 | const concat = require('concat-stream') 6 | const fs = require('fs') 7 | const assert = require('assert') 8 | 9 | describe('gulp-remove-code', function () { 10 | let emptyFile 11 | let nullFile 12 | let coffeeFile 13 | let htmlFile 14 | let cshtmlFile 15 | let jadeFile 16 | let jsFile 17 | let srcFile 18 | let spacesFile 19 | 20 | let notCoffeeFile 21 | let notHtmlFile 22 | let notCshtmlFile 23 | let notJadeFile 24 | let notJsFile 25 | let notSrcFile 26 | let notSpacesFile 27 | 28 | function readFixtureAsText (name) { 29 | return fs.readFileSync('test/fixtures/' + name).toString() 30 | } 31 | 32 | describe('in buffer mode', function () { 33 | beforeEach(function () { 34 | emptyFile = new File({ 35 | path: 'test/fixtures/empty', 36 | contents: Buffer.from('') 37 | }) 38 | nullFile = new File({ 39 | contents: null 40 | }) 41 | 42 | htmlFile = new File({ 43 | path: 'test/fixtures/file-before.html', 44 | contents: fs.readFileSync('test/fixtures/file-before.html') 45 | }) 46 | cshtmlFile = new File({ 47 | path: 'test/fixtures/file-before.cshtml', 48 | contents: fs.readFileSync('test/fixtures/file-before.cshtml') 49 | }) 50 | coffeeFile = new File({ 51 | path: 'test/fixtures/file-before.coffee', 52 | contents: fs.readFileSync('test/fixtures/file-before.coffee') 53 | }) 54 | jadeFile = new File({ 55 | path: 'test/fixtures/file-before.jade', 56 | contents: fs.readFileSync('test/fixtures/file-before.jade') 57 | }) 58 | jsFile = new File({ 59 | path: 'test/fixtures/file-before.js', 60 | contents: fs.readFileSync('test/fixtures/file-before.js') 61 | }) 62 | srcFile = new File({ 63 | path: 'text/fixtures/file-before.src', 64 | contents: fs.readFileSync('test/fixtures/file-before.src') 65 | }) 66 | spacesFile = new File({ 67 | path: 'text/fixtures/spaces-before.src', 68 | contents: fs.readFileSync('test/fixtures/spaces-before.src') 69 | }) 70 | 71 | notHtmlFile = new File({ 72 | path: 'test/fixtures/not-file-before.html', 73 | contents: fs.readFileSync('test/fixtures/not-file-before.html') 74 | }) 75 | notCshtmlFile = new File({ 76 | path: 'test/fixtures/not-file-before.cshtml', 77 | contents: fs.readFileSync('test/fixtures/not-file-before.cshtml') 78 | }) 79 | notCoffeeFile = new File({ 80 | path: 'test/fixtures/not-file-before.coffee', 81 | contents: fs.readFileSync('test/fixtures/not-file-before.coffee') 82 | }) 83 | notJadeFile = new File({ 84 | path: 'test/fixtures/not-file-before.jade', 85 | contents: fs.readFileSync('test/fixtures/not-file-before.jade') 86 | }) 87 | notJsFile = new File({ 88 | path: 'test/fixtures/not-file-before.js', 89 | contents: fs.readFileSync('test/fixtures/not-file-before.js') 90 | }) 91 | notSrcFile = new File({ 92 | path: 'text/fixtures/not-file-before.src', 93 | contents: fs.readFileSync('test/fixtures/not-file-before.src') 94 | }) 95 | notSpacesFile = new File({ 96 | path: 'text/fixtures/not-spaces-before.src', 97 | contents: fs.readFileSync('test/fixtures/not-spaces-before.src') 98 | }) 99 | }) 100 | 101 | it('should do nothing when contents is null', function (done) { 102 | const stream = removeCode() 103 | 104 | stream.once('data', function (file) { 105 | assert.strictEqual(file.isNull(), true) 106 | done() 107 | }) 108 | 109 | stream.write(nullFile) 110 | stream.end() 111 | }) 112 | 113 | it('should do nothing when contents is empty', function (done) { 114 | const stream = removeCode() 115 | 116 | stream.once('data', function (file) { 117 | assert.strictEqual(file.contents.toString(), '') 118 | done() 119 | }) 120 | 121 | stream.write(emptyFile) 122 | stream.end() 123 | }) 124 | 125 | it('should remove code from html file when condition is true', function (done) { 126 | const stream = removeCode({'no-message': true}) 127 | 128 | stream.once('data', function (file) { 129 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.html')) 130 | done() 131 | }) 132 | 133 | stream.write(htmlFile) 134 | stream.end() 135 | }) 136 | 137 | it('should not remove code from html file when condition is false', function (done) { 138 | const stream = removeCode({'no-message': false}) 139 | const originalContents = htmlFile.contents.toString() 140 | 141 | stream.once('data', function (file) { 142 | assert.strictEqual(file.contents.toString(), originalContents) 143 | done() 144 | }) 145 | 146 | stream.write(htmlFile) 147 | stream.end() 148 | }) 149 | 150 | it('should remove code from cshtml file when condition is true', function (done) { 151 | const stream = removeCode({'no-message': true, 'no-html': true}) 152 | 153 | stream.once('data', function (file) { 154 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.cshtml')) 155 | done() 156 | }) 157 | 158 | stream.write(cshtmlFile) 159 | stream.end() 160 | }) 161 | 162 | it('should not remove code from cshtml file when condition is false', function (done) { 163 | const stream = removeCode({'no-message': false, 'no-html': false}) 164 | const originalContents = cshtmlFile.contents.toString() 165 | 166 | stream.once('data', function (file) { 167 | assert.strictEqual(file.contents.toString(), originalContents) 168 | done() 169 | }) 170 | 171 | stream.write(cshtmlFile) 172 | stream.end() 173 | }) 174 | 175 | it('should remove code from coffee file when condition is true', function (done) { 176 | const stream = removeCode({'production': true}) 177 | 178 | stream.once('data', function (file) { 179 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.coffee')) 180 | done() 181 | }) 182 | 183 | stream.write(coffeeFile) 184 | stream.end() 185 | }) 186 | 187 | it('should not remove code from coffee file when condition is false', function (done) { 188 | const stream = removeCode({'production': false}) 189 | const originalContents = coffeeFile.contents.toString() 190 | 191 | stream.once('data', function (file) { 192 | assert.strictEqual(file.contents.toString(), originalContents) 193 | done() 194 | }) 195 | 196 | stream.write(coffeeFile) 197 | stream.end() 198 | }) 199 | 200 | it('should remove code from jade file when condition is true', function (done) { 201 | const stream = removeCode({development: true}) 202 | 203 | stream.once('data', function (file) { 204 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.jade')) 205 | done() 206 | }) 207 | 208 | stream.write(jadeFile) 209 | stream.end() 210 | }) 211 | 212 | it('should not remove code from jade file when condition is false', function (done) { 213 | const stream = removeCode({development: false}) 214 | const originalContents = jadeFile.contents.toString() 215 | 216 | stream.once('data', function (file) { 217 | assert.strictEqual(file.contents.toString(), originalContents) 218 | done() 219 | }) 220 | 221 | stream.write(jadeFile) 222 | stream.end() 223 | }) 224 | 225 | it('should remove code from js file when condition is true', function (done) { 226 | const stream = removeCode({production: true, demo: true}) 227 | 228 | stream.once('data', function (file) { 229 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.js')) 230 | done() 231 | }) 232 | 233 | stream.write(jsFile) 234 | stream.end() 235 | }) 236 | 237 | it('should not remove code from js file when condition is false', function (done) { 238 | const stream = removeCode({production: false, demo: false}) 239 | const originalContents = jsFile.contents.toString() 240 | 241 | stream.once('data', function (file) { 242 | assert.strictEqual(file.contents.toString(), originalContents) 243 | done() 244 | }) 245 | 246 | stream.write(jsFile) 247 | stream.end() 248 | }) 249 | 250 | it('should remove code from custom file when condition is true', function (done) { 251 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 252 | 253 | stream.once('data', function (file) { 254 | assert.strictEqual(file.contents.toString(), readFixtureAsText('file-after.src')) 255 | done() 256 | }) 257 | 258 | stream.write(srcFile) 259 | stream.end() 260 | }) 261 | 262 | it('should not remove code from custom file when condition is false', function (done) { 263 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 264 | const originalContents = srcFile.contents.toString() 265 | 266 | stream.once('data', function (file) { 267 | assert.strictEqual(file.contents.toString(), originalContents) 268 | done() 269 | }) 270 | 271 | stream.write(srcFile) 272 | stream.end() 273 | }) 274 | 275 | it('should allow space between commentStart/commendEnd and removal start/end tag', function (done) { 276 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 277 | 278 | stream.once('data', function (file) { 279 | assert.strictEqual(file.contents.toString(), readFixtureAsText('spaces-after.src')) 280 | done() 281 | }) 282 | 283 | stream.write(spacesFile) 284 | stream.end() 285 | }) 286 | 287 | it('should not modify the options object', function (done) { 288 | const options = {} 289 | const stream = removeCode(options) 290 | 291 | stream.once('data', function () { 292 | assert.strictEqual(Object.keys(options).length, 0, 'Plugin must copy the received options') 293 | done() 294 | }) 295 | 296 | stream.write(htmlFile) 297 | stream.end() 298 | }) 299 | 300 | /* not */ 301 | 302 | it('should remove code from html file when not condition is true', function (done) { 303 | const stream = removeCode({'no-message': false}) 304 | 305 | stream.once('data', function (file) { 306 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.html')) 307 | done() 308 | }) 309 | 310 | stream.write(notHtmlFile) 311 | stream.end() 312 | }) 313 | 314 | it('should not remove code from html file when not condition is false', function (done) { 315 | const stream = removeCode({'no-message': true}) 316 | const originalContents = notHtmlFile.contents.toString() 317 | 318 | stream.once('data', function (file) { 319 | assert.strictEqual(file.contents.toString(), originalContents) 320 | done() 321 | }) 322 | 323 | stream.write(notHtmlFile) 324 | stream.end() 325 | }) 326 | 327 | it('should remove code from cshtml file when not condition is true', function (done) { 328 | const stream = removeCode({'no-message': false, 'no-html': false}) 329 | 330 | stream.once('data', function (file) { 331 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.cshtml')) 332 | done() 333 | }) 334 | 335 | stream.write(notCshtmlFile) 336 | stream.end() 337 | }) 338 | 339 | it('should not remove code from cshtml file when not condition is false', function (done) { 340 | const stream = removeCode({'no-message': true, 'no-html': true}) 341 | const originalContents = notCshtmlFile.contents.toString() 342 | 343 | stream.once('data', function (file) { 344 | assert.strictEqual(file.contents.toString(), originalContents) 345 | done() 346 | }) 347 | 348 | stream.write(notCshtmlFile) 349 | stream.end() 350 | }) 351 | 352 | it('should remove code from coffee file when not condition is true', function (done) { 353 | const stream = removeCode({'production': false}) 354 | 355 | stream.once('data', function (file) { 356 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.coffee')) 357 | done() 358 | }) 359 | 360 | stream.write(notCoffeeFile) 361 | stream.end() 362 | }) 363 | 364 | it('should not remove code from coffee file when not condition is false', function (done) { 365 | const stream = removeCode({'production': true}) 366 | const originalContents = notCoffeeFile.contents.toString() 367 | 368 | stream.once('data', function (file) { 369 | assert.strictEqual(file.contents.toString(), originalContents) 370 | done() 371 | }) 372 | 373 | stream.write(notCoffeeFile) 374 | stream.end() 375 | }) 376 | 377 | it('should remove code from jade file when not condition is true', function (done) { 378 | const stream = removeCode({development: false}) 379 | 380 | stream.once('data', function (file) { 381 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.jade')) 382 | done() 383 | }) 384 | 385 | stream.write(notJadeFile) 386 | stream.end() 387 | }) 388 | 389 | it('should not remove code from jade file when not condition is false', function (done) { 390 | const stream = removeCode({development: true}) 391 | const originalContents = notJadeFile.contents.toString() 392 | 393 | stream.once('data', function (file) { 394 | assert.strictEqual(file.contents.toString(), originalContents) 395 | done() 396 | }) 397 | 398 | stream.write(notJadeFile) 399 | stream.end() 400 | }) 401 | 402 | it('should remove code from js file when not condition is true', function (done) { 403 | const stream = removeCode({production: false, demo: false}) 404 | 405 | stream.once('data', function (file) { 406 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.js')) 407 | done() 408 | }) 409 | 410 | stream.write(notJsFile) 411 | stream.end() 412 | }) 413 | 414 | it('should not remove code from js file when not condition is false', function (done) { 415 | const stream = removeCode({production: true, demo: true}) 416 | const originalContents = notJsFile.contents.toString() 417 | 418 | stream.once('data', function (file) { 419 | assert.strictEqual(file.contents.toString(), originalContents) 420 | done() 421 | }) 422 | 423 | stream.write(notJsFile) 424 | stream.end() 425 | }) 426 | 427 | it('should remove code from custom file when not condition is true', function (done) { 428 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 429 | 430 | stream.once('data', function (file) { 431 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-file-after.src')) 432 | done() 433 | }) 434 | 435 | stream.write(notSrcFile) 436 | stream.end() 437 | }) 438 | 439 | it('should not remove code from custom file when not condition is false', function (done) { 440 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 441 | const originalContents = notSrcFile.contents.toString() 442 | 443 | stream.once('data', function (file) { 444 | assert.strictEqual(file.contents.toString(), originalContents) 445 | done() 446 | }) 447 | 448 | stream.write(notSrcFile) 449 | stream.end() 450 | }) 451 | 452 | it('should allow space between commentStart/commendEnd and removal start/end tag', function (done) { 453 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 454 | 455 | stream.once('data', function (file) { 456 | assert.strictEqual(file.contents.toString(), readFixtureAsText('not-spaces-after.src')) 457 | done() 458 | }) 459 | 460 | stream.write(notSpacesFile) 461 | stream.end() 462 | }) 463 | }) 464 | 465 | describe('in stream mode', function () { 466 | beforeEach(function () { 467 | emptyFile = new File({ 468 | path: 'test/empty', 469 | contents: fs.createReadStream('test/fixtures/empty') 470 | }) 471 | nullFile = new File({ 472 | path: 'test/fixtures/file-before.html', 473 | contents: null 474 | }) 475 | 476 | htmlFile = new File({ 477 | path: 'test/fixtures/file-before.html', 478 | contents: fs.createReadStream('test/fixtures/file-before.html') 479 | }) 480 | cshtmlFile = new File({ 481 | path: 'test/fixtures/file-before.cshtml', 482 | contents: fs.createReadStream('test/fixtures/file-before.cshtml') 483 | }) 484 | coffeeFile = new File({ 485 | path: 'test/fixtures/file-before.coffee', 486 | contents: fs.createReadStream('test/fixtures/file-before.coffee') 487 | }) 488 | jadeFile = new File({ 489 | path: 'test/fixtures/file-before.jade', 490 | contents: fs.createReadStream('test/fixtures/file-before.jade') 491 | }) 492 | jsFile = new File({ 493 | path: 'test/fixtures/file-before.js', 494 | contents: fs.createReadStream('test/fixtures/file-before.js') 495 | }) 496 | srcFile = new File({ 497 | path: 'test/fixtures/file-before.src', 498 | contents: fs.createReadStream('test/fixtures/file-before.src') 499 | }) 500 | spacesFile = new File({ 501 | path: 'test/fixtures/spaces-before.src', 502 | contents: fs.createReadStream('test/fixtures/spaces-before.src') 503 | }) 504 | 505 | notHtmlFile = new File({ 506 | path: 'test/fixtures/not-file-before.html', 507 | contents: fs.createReadStream('test/fixtures/not-file-before.html') 508 | }) 509 | notCshtmlFile = new File({ 510 | path: 'test/fixtures/not-file-before.cshtml', 511 | contents: fs.createReadStream('test/fixtures/not-file-before.cshtml') 512 | }) 513 | notCoffeeFile = new File({ 514 | path: 'test/fixtures/not-file-before.coffee', 515 | contents: fs.createReadStream('test/fixtures/not-file-before.coffee') 516 | }) 517 | notJadeFile = new File({ 518 | path: 'test/fixtures/not-file-before.jade', 519 | contents: fs.createReadStream('test/fixtures/not-file-before.jade') 520 | }) 521 | notJsFile = new File({ 522 | path: 'test/fixtures/not-file-before.js', 523 | contents: fs.createReadStream('test/fixtures/not-file-before.js') 524 | }) 525 | notSrcFile = new File({ 526 | path: 'test/fixtures/not-file-before.src', 527 | contents: fs.createReadStream('test/fixtures/not-file-before.src') 528 | }) 529 | notSpacesFile = new File({ 530 | path: 'test/fixtures/not-spaces-before.src', 531 | contents: fs.createReadStream('test/fixtures/not-spaces-before.src') 532 | }) 533 | }) 534 | 535 | it('should do nothing when contents is empty', function (done) { 536 | const stream = removeCode() 537 | 538 | stream.once('data', function (file) { 539 | file.contents.pipe(concat(function (data) { 540 | assert.strictEqual(data.toString(), '') 541 | done() 542 | })) 543 | }) 544 | 545 | stream.write(emptyFile) 546 | stream.end() 547 | }) 548 | 549 | it('should remove code from html file when condition is true', function (done) { 550 | const stream = removeCode({'no-message': true}) 551 | 552 | stream.once('data', function (file) { 553 | file.contents.pipe(concat(function (data) { 554 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.html')) 555 | done() 556 | })) 557 | }) 558 | 559 | stream.write(htmlFile) 560 | stream.end() 561 | }) 562 | 563 | it('should not remove code from html file when condition is false', function (done) { 564 | const stream = removeCode({'no-message': false}) 565 | const originalContents = readFixtureAsText('file-before.html') 566 | 567 | stream.once('data', function (file) { 568 | file.contents.pipe(concat(function (data) { 569 | assert.strictEqual(data.toString(), originalContents) 570 | done() 571 | })) 572 | }) 573 | 574 | stream.write(htmlFile) 575 | stream.end() 576 | }) 577 | 578 | it('should remove code from cshtml file when condition is true', function (done) { 579 | const stream = removeCode({'no-message': true, 'no-html': true}) 580 | 581 | stream.once('data', function (file) { 582 | file.contents.pipe(concat(function (data) { 583 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.cshtml')) 584 | done() 585 | })) 586 | }) 587 | 588 | stream.write(cshtmlFile) 589 | stream.end() 590 | }) 591 | 592 | it('should not remove code from cshtml file when condition is false', function (done) { 593 | const stream = removeCode({'no-message': false}) 594 | const originalContents = readFixtureAsText('file-before.cshtml') 595 | 596 | stream.once('data', function (file) { 597 | file.contents.pipe(concat(function (data) { 598 | assert.strictEqual(data.toString(), originalContents) 599 | done() 600 | })) 601 | }) 602 | 603 | stream.write(cshtmlFile) 604 | stream.end() 605 | }) 606 | 607 | it('should remove code from coffee file when condition is true', function (done) { 608 | const stream = removeCode({'production': true}) 609 | 610 | stream.once('data', function (file) { 611 | file.contents.pipe(concat(function (data) { 612 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.coffee')) 613 | done() 614 | })) 615 | }) 616 | 617 | stream.write(coffeeFile) 618 | stream.end() 619 | }) 620 | 621 | it('should not remove code from coffee file when condition is false', function (done) { 622 | const stream = removeCode({'production': false}) 623 | const originalContents = readFixtureAsText('file-before.coffee') 624 | 625 | stream.once('data', function (file) { 626 | file.contents.pipe(concat(function (data) { 627 | assert.strictEqual(data.toString(), originalContents) 628 | done() 629 | })) 630 | }) 631 | 632 | stream.write(coffeeFile) 633 | stream.end() 634 | }) 635 | 636 | it('should remove code from jade file when condition is true', function (done) { 637 | const stream = removeCode({development: true}) 638 | 639 | stream.once('data', function (file) { 640 | file.contents.pipe(concat(function (data) { 641 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.jade')) 642 | done() 643 | })) 644 | }) 645 | 646 | stream.write(jadeFile) 647 | stream.end() 648 | }) 649 | 650 | it('should not remove code from jade file when condition is false', function (done) { 651 | const stream = removeCode({development: false}) 652 | const originalContents = readFixtureAsText('file-before.jade') 653 | 654 | stream.once('data', function (file) { 655 | file.contents.pipe(concat(function (data) { 656 | assert.strictEqual(data.toString(), originalContents) 657 | done() 658 | })) 659 | }) 660 | 661 | stream.write(jadeFile) 662 | stream.end() 663 | }) 664 | 665 | it('should remove code from js file when condition is true', function (done) { 666 | const stream = removeCode({production: true, demo: true}) 667 | 668 | stream.once('data', function (file) { 669 | file.contents.pipe(concat(function (data) { 670 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.js')) 671 | done() 672 | })) 673 | }) 674 | 675 | stream.write(jsFile) 676 | stream.end() 677 | }) 678 | 679 | it('should not remove code from js file when condition is false', function (done) { 680 | const stream = removeCode({production: false, demo: false}) 681 | const originalContents = readFixtureAsText('file-before.js') 682 | 683 | stream.once('data', function (file) { 684 | file.contents.pipe(concat(function (data) { 685 | assert.strictEqual(data.toString(), originalContents) 686 | done() 687 | })) 688 | }) 689 | 690 | stream.write(jsFile) 691 | stream.end() 692 | }) 693 | 694 | it('should remove code from custom file when condition is true', function (done) { 695 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 696 | 697 | stream.once('data', function (file) { 698 | file.contents.pipe(concat(function (data) { 699 | assert.strictEqual(data.toString(), readFixtureAsText('file-after.src')) 700 | done() 701 | })) 702 | }) 703 | 704 | stream.write(srcFile) 705 | stream.end() 706 | }) 707 | 708 | it('should not remove code from custom file when condition is false', function (done) { 709 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 710 | const originalContents = readFixtureAsText('file-before.src') 711 | 712 | stream.once('data', function (file) { 713 | file.contents.pipe(concat(function (data) { 714 | assert.strictEqual(data.toString(), originalContents) 715 | done() 716 | })) 717 | }) 718 | 719 | stream.write(srcFile) 720 | stream.end() 721 | }) 722 | 723 | it('should allow space between commentStart/commendEnd and removal start/end tag', function (done) { 724 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 725 | 726 | stream.once('data', function (file) { 727 | file.contents.pipe(concat(function (data) { 728 | assert.strictEqual(data.toString(), readFixtureAsText('spaces-after.src')) 729 | done() 730 | })) 731 | }) 732 | 733 | stream.write(spacesFile) 734 | stream.end() 735 | }) 736 | 737 | it('should not modify the options object', function (done) { 738 | const options = {} 739 | const stream = removeCode(options) 740 | 741 | stream.once('data', function (file) { 742 | file.contents.pipe(concat(function () { 743 | assert.strictEqual(Object.keys(options).length, 0, 'Plugin must copy the received options') 744 | done() 745 | })) 746 | }) 747 | 748 | stream.write(htmlFile) 749 | stream.end() 750 | }) 751 | 752 | /* not */ 753 | 754 | it('should remove code from html file when not condition is true', function (done) { 755 | const stream = removeCode({'no-message': false}) 756 | 757 | stream.once('data', function (file) { 758 | file.contents.pipe(concat(function (data) { 759 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.html')) 760 | done() 761 | })) 762 | }) 763 | 764 | stream.write(notHtmlFile) 765 | stream.end() 766 | }) 767 | 768 | it('should not remove code from html file when not condition is false', function (done) { 769 | const stream = removeCode({'no-message': true}) 770 | const originalContents = readFixtureAsText('not-file-before.html') 771 | 772 | stream.once('data', function (file) { 773 | file.contents.pipe(concat(function (data) { 774 | assert.strictEqual(data.toString(), originalContents) 775 | done() 776 | })) 777 | }) 778 | 779 | stream.write(notHtmlFile) 780 | stream.end() 781 | }) 782 | 783 | it('should remove code from cshtml file when not condition is true', function (done) { 784 | const stream = removeCode({'no-message': false, 'no-html': false}) 785 | 786 | stream.once('data', function (file) { 787 | file.contents.pipe(concat(function (data) { 788 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.cshtml')) 789 | done() 790 | })) 791 | }) 792 | 793 | stream.write(notCshtmlFile) 794 | stream.end() 795 | }) 796 | 797 | it('should not remove code from cshtml file when not condition is false', function (done) { 798 | const stream = removeCode({'no-message': true, 'no-html': true}) 799 | const originalContents = readFixtureAsText('not-file-before.cshtml') 800 | 801 | stream.once('data', function (file) { 802 | file.contents.pipe(concat(function (data) { 803 | assert.strictEqual(data.toString(), originalContents) 804 | done() 805 | })) 806 | }) 807 | 808 | stream.write(notCshtmlFile) 809 | stream.end() 810 | }) 811 | 812 | it('should remove code from coffee file when not condition is true', function (done) { 813 | const stream = removeCode({'production': false}) 814 | 815 | stream.once('data', function (file) { 816 | file.contents.pipe(concat(function (data) { 817 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.coffee')) 818 | done() 819 | })) 820 | }) 821 | 822 | stream.write(notCoffeeFile) 823 | stream.end() 824 | }) 825 | 826 | it('should not remove code from coffee file when not condition is false', function (done) { 827 | const stream = removeCode({'production': true}) 828 | const originalContents = readFixtureAsText('not-file-before.coffee') 829 | 830 | stream.once('data', function (file) { 831 | file.contents.pipe(concat(function (data) { 832 | assert.strictEqual(data.toString(), originalContents) 833 | done() 834 | })) 835 | }) 836 | 837 | stream.write(notCoffeeFile) 838 | stream.end() 839 | }) 840 | 841 | it('should remove code from jade file when not condition is true', function (done) { 842 | const stream = removeCode({development: false}) 843 | 844 | stream.once('data', function (file) { 845 | file.contents.pipe(concat(function (data) { 846 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.jade')) 847 | done() 848 | })) 849 | }) 850 | 851 | stream.write(notJadeFile) 852 | stream.end() 853 | }) 854 | 855 | it('should not remove code from jade file when not condition is false', function (done) { 856 | const stream = removeCode({development: true}) 857 | const originalContents = readFixtureAsText('not-file-before.jade') 858 | 859 | stream.once('data', function (file) { 860 | file.contents.pipe(concat(function (data) { 861 | assert.strictEqual(data.toString(), originalContents) 862 | done() 863 | })) 864 | }) 865 | 866 | stream.write(notJadeFile) 867 | stream.end() 868 | }) 869 | 870 | it('should remove code from js file when not condition is true', function (done) { 871 | const stream = removeCode({production: false, demo: false}) 872 | 873 | stream.once('data', function (file) { 874 | file.contents.pipe(concat(function (data) { 875 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.js')) 876 | done() 877 | })) 878 | }) 879 | 880 | stream.write(notJsFile) 881 | stream.end() 882 | }) 883 | 884 | it('should not remove code from js file when not condition is false', function (done) { 885 | const stream = removeCode({production: true, demo: true}) 886 | const originalContents = readFixtureAsText('not-file-before.js') 887 | 888 | stream.once('data', function (file) { 889 | file.contents.pipe(concat(function (data) { 890 | assert.strictEqual(data.toString(), originalContents) 891 | done() 892 | })) 893 | }) 894 | 895 | stream.write(notJsFile) 896 | stream.end() 897 | }) 898 | 899 | it('should remove code from custom file when not condition is true', function (done) { 900 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 901 | 902 | stream.once('data', function (file) { 903 | file.contents.pipe(concat(function (data) { 904 | assert.strictEqual(data.toString(), readFixtureAsText('not-file-after.src')) 905 | done() 906 | })) 907 | }) 908 | 909 | stream.write(notSrcFile) 910 | stream.end() 911 | }) 912 | 913 | it('should not remove code from custom file when not condition is false', function (done) { 914 | const stream = removeCode({development: true, commentStart: '/#', commentEnd: '#/'}) 915 | const originalContents = readFixtureAsText('not-file-before.src') 916 | 917 | stream.once('data', function (file) { 918 | file.contents.pipe(concat(function (data) { 919 | assert.strictEqual(data.toString(), originalContents) 920 | done() 921 | })) 922 | }) 923 | 924 | stream.write(notSrcFile) 925 | stream.end() 926 | }) 927 | 928 | it('should allow space between commentStart/commendEnd and removal start/end tag', function (done) { 929 | const stream = removeCode({development: false, commentStart: '/#', commentEnd: '#/'}) 930 | 931 | stream.once('data', function (file) { 932 | file.contents.pipe(concat(function (data) { 933 | assert.strictEqual(data.toString(), readFixtureAsText('not-spaces-after.src')) 934 | done() 935 | })) 936 | }) 937 | 938 | stream.write(notSpacesFile) 939 | stream.end() 940 | }) 941 | }) 942 | }) 943 | -------------------------------------------------------------------------------- /test/fixtures/.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = lf 3 | insert_final_newline = false 4 | trim_trailing_whitespace = true 5 | indent_size = 2 6 | -------------------------------------------------------------------------------- /test/fixtures/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crissdev/gulp-remove-code/84ff95919be9d9262987f7922b7398030486f25c/test/fixtures/empty -------------------------------------------------------------------------------- /test/fixtures/file-after.coffee: -------------------------------------------------------------------------------- 1 | end = "production" 2 | -------------------------------------------------------------------------------- /test/fixtures/file-after.cshtml: -------------------------------------------------------------------------------- 1 |
[...]
2 |
-------------------------------------------------------------------------------- /test/fixtures/file-after.html: -------------------------------------------------------------------------------- 1 |
[...]
-------------------------------------------------------------------------------- /test/fixtures/file-after.jade: -------------------------------------------------------------------------------- 1 | div 2 | span Hello! -------------------------------------------------------------------------------- /test/fixtures/file-after.js: -------------------------------------------------------------------------------- 1 | var appVersion = '1.0.0'; 2 | var appType = 'demo'; 3 | -------------------------------------------------------------------------------- /test/fixtures/file-after.src: -------------------------------------------------------------------------------- 1 | 2 | value = 10 3 | -------------------------------------------------------------------------------- /test/fixtures/file-before.coffee: -------------------------------------------------------------------------------- 1 | end = "production" 2 | #removeIf(production) 3 | env = "development" 4 | #endRemoveIf(production) -------------------------------------------------------------------------------- /test/fixtures/file-before.cshtml: -------------------------------------------------------------------------------- 1 |
@*removeIf(no-message)*@Hello!@*endRemoveIf(no-message)*@[...]
2 |
HTML comment
-------------------------------------------------------------------------------- /test/fixtures/file-before.html: -------------------------------------------------------------------------------- 1 |
Hello![...]
-------------------------------------------------------------------------------- /test/fixtures/file-before.jade: -------------------------------------------------------------------------------- 1 | div 2 | //-removeIf(development) 3 | div Running in Sandbox environment 4 | //-endRemoveIf(development) 5 | span Hello! -------------------------------------------------------------------------------- /test/fixtures/file-before.js: -------------------------------------------------------------------------------- 1 | var appVersion = '1.0.0'; 2 | //removeIf(production) 3 | appVersion=(+new Date().getTime()).toString(); 4 | //endRemoveIf(production) 5 | var appType = 'demo'; 6 | //removeIf(demo) 7 | appType = 'full'; 8 | //endRemoveIf(demo) -------------------------------------------------------------------------------- /test/fixtures/file-before.src: -------------------------------------------------------------------------------- 1 | /#removeIf(development)#/ 2 | value = 11 3 | /#endRemoveIf(development)#/ 4 | value = 10 5 | -------------------------------------------------------------------------------- /test/fixtures/not-file-after.coffee: -------------------------------------------------------------------------------- 1 | end = "production" 2 | -------------------------------------------------------------------------------- /test/fixtures/not-file-after.cshtml: -------------------------------------------------------------------------------- 1 |
[...]
2 |
-------------------------------------------------------------------------------- /test/fixtures/not-file-after.html: -------------------------------------------------------------------------------- 1 |
[...]
-------------------------------------------------------------------------------- /test/fixtures/not-file-after.jade: -------------------------------------------------------------------------------- 1 | div 2 | span Hello! -------------------------------------------------------------------------------- /test/fixtures/not-file-after.js: -------------------------------------------------------------------------------- 1 | var appVersion = '1.0.0'; 2 | var appType = 'demo'; 3 | -------------------------------------------------------------------------------- /test/fixtures/not-file-after.src: -------------------------------------------------------------------------------- 1 | 2 | value = 10 3 | -------------------------------------------------------------------------------- /test/fixtures/not-file-before.coffee: -------------------------------------------------------------------------------- 1 | end = "production" 2 | #removeIf(!production) 3 | env = "development" 4 | #endRemoveIf(!production) -------------------------------------------------------------------------------- /test/fixtures/not-file-before.cshtml: -------------------------------------------------------------------------------- 1 |
@*removeIf(!no-message)*@Hello!@*endRemoveIf(!no-message)*@[...]
2 |
HTML comment
-------------------------------------------------------------------------------- /test/fixtures/not-file-before.html: -------------------------------------------------------------------------------- 1 |
Hello![...]
-------------------------------------------------------------------------------- /test/fixtures/not-file-before.jade: -------------------------------------------------------------------------------- 1 | div 2 | //-removeIf(!development) 3 | div Running in Sandbox environment 4 | //-endRemoveIf(!development) 5 | span Hello! -------------------------------------------------------------------------------- /test/fixtures/not-file-before.js: -------------------------------------------------------------------------------- 1 | var appVersion = '1.0.0'; 2 | //removeIf(!production) 3 | appVersion=(+new Date().getTime()).toString(); 4 | //endRemoveIf(!production) 5 | var appType = 'demo'; 6 | //removeIf(!demo) 7 | appType = 'full'; 8 | //endRemoveIf(!demo) -------------------------------------------------------------------------------- /test/fixtures/not-file-before.src: -------------------------------------------------------------------------------- 1 | /#removeIf(!development)#/ 2 | value = 11 3 | /#endRemoveIf(!development)#/ 4 | value = 10 5 | -------------------------------------------------------------------------------- /test/fixtures/not-spaces-after.src: -------------------------------------------------------------------------------- 1 | 2 | value = 'b' 3 | -------------------------------------------------------------------------------- /test/fixtures/not-spaces-before.src: -------------------------------------------------------------------------------- 1 | /# removeIf(!development) #/ 2 | value = 'a' 3 | /# endRemoveIf(!development) #/ 4 | value = 'b' 5 | -------------------------------------------------------------------------------- /test/fixtures/spaces-after.src: -------------------------------------------------------------------------------- 1 | 2 | value = 'b' 3 | -------------------------------------------------------------------------------- /test/fixtures/spaces-before.src: -------------------------------------------------------------------------------- 1 | /# removeIf(development) #/ 2 | value = 'a' 3 | /# endRemoveIf(development) #/ 4 | value = 'b' 5 | --------------------------------------------------------------------------------