GithubHelp home page GithubHelp logo

gulp-chown's Introduction

gulp-chown

Change owner of Vinyl files

Install

npm install --save-dev gulp-chown

Usage

import gulp from 'gulp';
import chown from 'gulp-chown';

export default () => (
	gulp.src('src/app.js')
		.pipe(chown('sindresorhus'))
		.pipe(gulp.dest('dist'))
);

or

import gulp from 'gulp';
import chown from 'gulp-chown';

export default () => (
	gulp.src('src/app.js')
		.pipe(chown(501))
		.pipe(gulp.dest('dist'))
);

API

chown(userId, groupId)

The arguments must be of the same type.

userId

Required
Type: string | number

The user name or user id to change ownership to.

groupId

Type: string | number

The group name or group id to change ownership to.

Tip

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

import gulp from 'gulp';
import chown from 'gulp-chown';
import gFilter from 'gulp-filter';

const filter = gFilter('src/vendor-*.js');

export default () => (
	gulp.src('src/*.js')
		// Filter a subset of the files
		.pipe(filter)
		// Change ownership of them
		.pipe(chown('sindresorhus'))
		// Bring back the previously filtered out files
		.pipe(filter.restore())
		.pipe(gulp.dest('dist'))
);

Related

gulp-chown's People

Contributors

kevva avatar lisandromc avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gulp-chown's Issues

Chown not actually altering files

I'm fairly new to Node.js and Gulp so I surely must have misunderstood the whole thing, but please bear with me.

I applied the very example in the readme but files don't get chown'ed (I'm running gulp as root of course).

The problem seems to be that the finish function doesn't have any side effects, since the file stat data is changed in memory but never persisted:

function finish() {
    file.stat.uid = finalUid != null ? finalUid : file.stat.uid;
    file.stat.gid = finalGid != null ? finalGid : file.stat.gid;
    cb(null, file);
}

my dirty fix was adding this code:

@@ -1,5 +1,6 @@
 'use strict';
 var gutil = require('gulp-util');
+var fs = require('fs');
 var through = require('through2');
 var uidNumber = require('uid-number');
 var defaultMode = 511 & (~process.umask()); // 511 = 0777
@@ -23,6 +24,17 @@ module.exports = function (user, group) {
        function finish() {
            file.stat.uid = finalUid != null ? finalUid : file.stat.uid;
            file.stat.gid = finalGid != null ? finalGid : file.stat.gid;
+           if (finalUid && finalGid) {
+               fs.chown(file.path, finalUid, finalGid, function (err) {
+                   if (err) {
+                       cb(new gutil.PluginError('gulp-chown', err, {fileName: file.path}));
+                       return;
+                   }
+                   cb(null, file);
+               });
+               return;
+           }
+
            cb(null, file);
        }

but it doesn't feel right...

Typo on NPM page

On the npm page, in the API section, you say "userId" twice instead of saying "userId" for the first one and "groupId" for the second.

Does not work with gulp.dest

While the plug-in does change the file.stat.uid that information is not used by gulp.dest so does not seem to have any effect on the file ownership on writing. At a minimum the example should be changed to reflect this although I am not sure how the plug-in would be used without gulp.dest support.

Cache `uidNumber` call

It spawns a child process which is slow. The result should be cached for the lifetime of the process in case a user uses it multiple times.

uidNumber(user, group, function (err, uid, gid) {

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.