2016-08-04 2 views
4

プライベートサーバでコードチェインにPERFORCEを使用しているため、プロダクションビルド後(つまり、index.htmlが読み込み専用の場合)、私のgulpタスクは以下のエラーで失敗します。jsとcssをgulpに注入する際に、index.htmlへの書き込み権限を与えるにはどうすればよいですか?

[INFO] [11:30:19] Error: EPERM: operation not permitted, open 'C:\MyProjectDir\index.html' 

ファイルをチェックアウトするか、読み取り専用プロパティ(ウィンドウボックスを使用)のチェックを外すと、gulpタスクは正常に終了します。この手作業による介入を避けるために、gulpタスクによって許可を変更する方法はありますか?

PS:私が使用しているのchmod(777)

ガルプファイル(注入が行われる端部)管理者モード

enter image description here

+1

はどのようにWindows' ''上のchmod(777) '何ができますか? – xAqweRx

+0

@xAqweRx:nodejsモジュールであり、どこにも使用できないと言われていますが、どこにでも使用できます。https://www.npmjs.com/package/chmod – abi1964

+0

申し訳ありませんが、誤解されています。 'chmod'について。ちょっと考えました - あなたは ''行政 'の権力で' cmd'を始めようとしましたか? – xAqweRx

答えて

4

一つの選択肢で

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)); 
}); 
... 

実行CMD gulp-execを使用して、読み取り専用フラグをattrib -rで削除してから、で再設定しますデータを注入した後(必要な場合)。続き

は一例です:

gulp.task('remove-readonly-attributes', function() { 
    require("child_process").exec("attrib -r <dir-name>\*.* /s"); 
}); 
+0

例のコマンドを提供してください – abi1964

+0

@Larkeithがgulp-execを使って何を使っているかの例をここで見つけることができます:http://stackoverflow.com/questions/29483772/remove-windows-file-readonly-attribute- in-gulp-file。 –

関連する問題