1. gulp-chmod
Change permissions of Vinyl files
gulp-chmod
Package: gulp-chmod
Created by: sindresorhus
Last modified: Tue, 31 Oct 2023 20:47:49 GMT
Version: 4.0.0
License: MIT
Downloads: 97,517
Repository: https://github.com/sindresorhus/gulp-chmod

Install

npm install gulp-chmod
yarn add gulp-chmod

gulp-chmod

Change permissions of Vinyl files

Install

 npm install --save-dev gulp-chmod

Usage

 import gulp from 'gulp';
import chmod from 'gulp-chmod';

export default () => (
	gulp.src('src/app.js')
		.pipe(chmod(0o755))
		.pipe(gulp.dest('dist'))
);

or

 import gulp from 'gulp';
import chmod from 'gulp-chmod';

export default () => (
	gulp.src('src/app.js')
		.pipe(chmod({
			owner: {
				read: true,
				write: true,
				execute: true
			},
			group: {
				execute: true
			},
			others: {
				execute: true
			}
		}))
		.pipe(gulp.dest('dist'))
);

API

chmod(fileMode, directoryMode?)

fileMode

Type: number | object

Can either be a chmod octal number or an object with the individual permissions specified.

Values depends on the current file, but these are the possible keys:

 {
	owner: {
		read: true,
		write: true,
		execute: true
	},
	group: {
		read: true,
		write: true,
		execute: true
	},
	others: {
		read: true,
		write: true,
		execute: true
	}
}

When read, write, and execute are the same, you can simplify the object:

 {
	read: true
}

Pass undefined to not set permissions on files. Useful if you only want to set permissions on directories.

directoryMode

Type: true | number | object

Same as fileMode, but applies to directories.

Specify true to use the same value as fileMode.

Tip

Combine it with gulp-filter to only change permissions on a subset of the files.

 import gulp from 'gulp';
import chmod from 'gulp-chmod';
import gulpFilter from 'gulp-filter';

const filter = gulpFilter('src/cli.js', {restore: true});

export default = () => (
	gulp.src('src/*.js')
		// Filter a subset of the files
		.pipe(filter)
		// Make them executable
		.pipe(chmod(0o755))
		// Bring back the previously filtered out files
		.pipe(filter.restore)
		.pipe(gulp.dest('dist'))
);

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code