Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
grunt-dev-prod-switch
Advanced tools
Use to switch between previously defined block comment blocks in project files to change environment from development to production and back.
Use to switch between previously defined comment blocks in project files to change environment from development to production and back.
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-dev-prod-switch --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-dev-prod-switch');
In your project's Gruntfile, add a section named dev_prod_switch
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
...
dev_prod_switch: {
options: {
environment: 'dev',
env_char: '#',
env_block_dev: 'env:dev',
env_block_prod: 'env:prod'
},
all: {
files: {
'app/index.html': 'app/index.html',
'app/js/main.js': 'app/js/main.js'
}
}
}
...
});
Or
grunt.initConfig({
...
dev_prod_switch: {
options: {
// Can be ran as `grunt --env=dev` or ``grunt --env=prod``
environment: grunt.option('env') || 'dev', // 'prod' or 'dev'
env_char: '#',
env_block_dev: 'env:dev',
env_block_prod: 'env:prod'
},
dynamic_mappings: {
files: [{
expand: true,
cwd: './',
src: ['*.html'],
dest: './'
}]
}
}
...
});
In html or ColdFusion type of files place the code depending on environment as follows:
...
<!-- env:dev -->
<h1>For devs eyes only</h1>
<p>This will be visable in 'dev' environment</p>
<!-- env:dev:end -->
<!-- env:prod -->
<h1>For everyone</h1>
<p>This will be visable in 'prod' environment</p>
<!-- env:prod:end -->
...
In C, Java, JavaScript type of files place the code depending on environment as follows:
...
/* env:dev */
function add(a,b) {
console.log('ADD: ' + a + ' + ' + b + ' = ' + (a + b));
return a+b;
}
/* env:dev:end */
/* env:prod */
function add(a,b) {
return a+b;
}
/* env:prod:end */
...
// Options to switch environment (dev/prod)
var env_option = {
env_dev: 'env:dev',
env_prod: 'env:prod',
blocking_char: '#'
};
/**
* dev
*
* Change environment to "development"
* Use: gulp dev
*/
gulp.task('dev', function() {
var files = [
'./app/index.html'
];
files.forEach(function(file) {
var content = fs.readFileSync(file, "utf8")
.replace(new RegExp("<\!-- " + env_option.env_dev + " --" + env_option.blocking_char + ">","gi"), '<!-- ' + env_option.env_dev + ' -->')
.replace(new RegExp("<\!-- " + env_option.env_prod + " -->","gi"), '<!-- ' + env_option.env_prod + ' --' + env_option.blocking_char + '>')
.replace(new RegExp("\/\* " + env_option.env_dev + " \*" + env_option.blocking_char + '/',"gi"), '/* ' + env_option.env_dev + ' */')
.replace(new RegExp("\/\* " + env_option.env_prod + " \*\/","gi"), '/* ' + env_option.env_prod + ' *' + env_option.blocking_char + '/');
fs.writeFileSync(file, content);
});
});
/**
* prod
*
* Change environment to "production"
* Use: gulp prod
*/
gulp.task('prod', [], function() {
var files = [
'./app/index.html'
];
files.forEach(function(file) {
var content = fs.readFileSync(file, "utf8")
.replace(new RegExp("<\!-- " + env_option.env_prod + " --" + env_option.blocking_char + ">","gi"), '<!-- ' + env_option.env_prod + ' -->')
.replace(new RegExp("<\!-- " + env_option.env_dev + " -->","gi"), '<!-- ' + env_option.env_dev + ' --' + env_option.blocking_char + '>')
.replace(new RegExp("\/\* " + env_option.env_prod + " \*" + env_option.blocking_char + '/',"gi"), '/* ' + env_option.env_prod + ' */')
.replace(new RegExp("\/\* " + env_option.env_dev + " \*\/","gi"), '/* ' + env_option.env_dev + ' *' + env_option.blocking_char + '/');
fs.writeFileSync(file, content);
});
});
Type: String
Default value: NONE
A string value that is used to do define the environment.
Type: String
Default value: '#'
Default character to block the comment.
Type: String
Default value: 'env:dev'
Override the default string of the comment.
So the task will be searching for <!-- env:dev -->
comment blocks
Type: String
Default value: 'env:prod'
Override the default string of the comment.
So the task will be searching for <!-- env:prod -->
comment blocks
FAQs
Use to switch between previously defined block comment blocks in project files to change environment from development to production and back.
The npm package grunt-dev-prod-switch receives a total of 66 weekly downloads. As such, grunt-dev-prod-switch popularity was classified as not popular.
We found that grunt-dev-prod-switch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.