title: How can I provide write permission to index.html while injecting js and css in gulp?
body: <p>I use perforce for code checkin in our private server, so after production build (i.e., when index.html is read only) my gulp task fails with below error.</p>
  
  <pre><code>[INFO] [11:30:19] Error: EPERM: operation not permitted, open 'C:\MyProjectDir\index.html'
  </code></pre>
  
  <p>Once I checkout files or uncheck the read only property (using windows box) the gulp task finishes successfully. Is there a way to change it's permission through gulp task to avoid this manual intervention?</p>
  
  <p>PS: I have used chmod(777)</p>
  
  <p>Gulp file (end part where inject takes place)</p>
  
  <pre><code>var gulp = require('gulp'),
      gutil = require('gulp-util'),
      uglify = require('gulp-uglify'),
      minify = require('gulp-minify-css'),
      concatVendor = require('gulp-concat-vendor'),
      concatCss = require('gulp-concat-css'),
      rev = require('gulp-rev'),
      clone = require('gulp-clone'),
      inject = require('gulp-inject'),
      del = require('del'),
      runSequence = require('run-sequence'),
      chmod = require('gulp-chmod'),
      series = require('stream-series'),
      ngAnnotate = require('gulp-ng-annotate'),
      rename = require("gulp-rename");
  ...
  gulp.task('index', ['gulp-js-files', 'gulp-css-files'], function() {
      var target = gulp.src(mainIndexFile);
      return target.pipe(chmod(777)).pipe(inject(series(vendorCss, customCss, vendorJs), { ignorePath: ['MyProjectDir'], addRootSlash: false }))
          .pipe(gulp.dest(mainDestination));
  });
  ...
  </code></pre>
  
  <p>Running cmd in Administrator mode</p>
  
  <p><a href="https://i.stack.imgur.com/mqe4U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqe4U.png" alt="enter image description here"></a></p>