GithubHelp home page GithubHelp logo

gulp-chmod's Introduction

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

gulp-chmod's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-chmod's Issues

Feature: Create Actual Stats Object when Missing

Hey sindresorhus,

I was about to write a tool with a similar goal in mind. Then I found this after remembering to look for "chmod" (whoops! ๐Ÿ˜Š).

Anyway, the primary difference is that I was intending to create a fs.Stats instance when it was missing. My plan was to use my module stats-ctor for that case.

Of course, there is a trade off in that some other properties of the stat would be defaulted. What do you think? Would that be useful?

How to chmod folders?

#Hi there,

I need to change the permissions of a folder, so others can execute it. How do I do that?

Cheers!
Jens

Folder is not copied if folder mode is present

explanation.tar.gz

gulp-chmod version 2.0.0 from npm.

This gulpfile.js doesn't work for me if I have folders in src :-(.

const gulp = require('gulp');
const chmod = require('gulp-chmod');

gulp.task('default', () =>
gulp.src('src/*')
.pipe(chmod(0o755, 0o755))
.pipe(gulp.dest('dist'))
);

`dirMode` option

From #4

I think this should follow gulp.dest and have a separate option for dirMode as it seems that's needed for some reason: gulpjs/vinyl-fs#35 Could maybe have it as a second argument to chmod.

Remove ACLs from files and directories

I have a few files downloaded from Dropbox that have extended attributes set, also called Access Control Lists in macOS. Is there a way using this plugin to modify or remove extended attributes, or is it limited to user/group/world only?

Here's the options I use to remove ACLs: chmod -RN

Fail to chmod 777 on Windows

Hello !

I am having trouble trying to set chmod to 777 on a tree.
Here is what I do :

pipes.allPermissionsAllowedOnDist = function() {
    return gulp.src(paths.dist + "**/*")
        .pipe(print())
        .pipe(pipes.allPermissionsAllowed());
};

gulp.task("allow-all-test", pipes.allPermissionsAllowedOnDistDev);

For indication what I am currently trying to do is to lock my dist folders (and all the files in it) for avoiding to modify dist files instead of app files by error. This part is working and I set a chmod 555 on all the files.
But when gulp watch is active and try to reload files, I have a permission error as gulp is trying to modify read-and-execute-only files. So I decided to use the above function specifically for gulp watch to allow modifcation when a file is reloaded.
But this part is not working, the print line indicate that tree is correctly browsed but file are still locked after execution.

Any idea ?
Thanks !

the empty directory was lost

when I use chmod(0o755, 0o755) to change the permission of a directory which contain a empty sub-direcotry, and then the sub-dir was lost.

and use chmod(0o755), the sub-dir is ok.

The plugin does not change the attributes

Hi, I use Gulp for development in Visual Studio, which puts the "read-only" attribute on all files in the project.

I need to clear the "read only" attribute when running Gulp.

The plugin was installed correctly, the task is written, but the attribute is not removed.

New octal integer literal

Ok so today I learned that with updating to 2.0.0 I need to use new octal integer literals.

 .pipe(chmod(0o777))

It would be very kind of you to add some warning, when still using the old syntax ... as it would shorten the time to fix update errors considerably!

Thank you!

Why don't you use gulp.dest option?

Hi,

I was using this plugin for copy files with permission until today without a doubt, but I found a gulp.dest {mode: '0644'} option that is doing as same as gulp-chmod.

What the purpose do you suggest to use this plugin for?

owner option needed

Most deb packages needs root:root owner. It'll be cool to have this functionality or have option to set user and group params for files and folders.

Now I use this workaround to set root:root for all my files:
fakeroot gulp

An error is thrown if `file.stat == null`

When using an additional gulp plugin such as gulp-concat, which returns a Buffer with no fs.Stats, then gulp-chmod throws the following error.

TypeError: Cannot set property 'mode' of null
at Transform._transform (/home/vagrant/Code/storm/node_modules/gulp-chmod/index.js:48:19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.