javascriptgulpgulp-task

Gulp task for add one new line to particular file


How to add one line to required file using gulp task?

This is my file:

export { NumericTextBoxComponent} from './numerictextbox/numerictextbox.component';
export { NumericTextBoxModule } from './numerictextbox/numerictextbox.module';
export { NumericTextBoxAllModule } from './numerictextbox/numerictextbox-all.module';
export * from '@syncfusion/ej2-inputs';

Here I want to add one new line which is:

export { EJsvalidator} from './form-validator/form-validator';

How can i do?

I tried like this :

var footer = require('gulp-footer');
gulp.task('add', function() {
    return gulp.src('./third-party/angular/src/index.ts')
           .pipe(footer("export { EJsvalidator} from './form-validator/form-validator';"))
           .pipe(gulp.dest('./third-party/angular/src/index.ts'));
});

If i execute this task, it shows following error:

PS D:\ej2-input-component> gulp add
[14:29:09] Using gulpfile D:\ej2-input-component\gulpfile.js
[14:29:09] Starting 'add'...
[14:29:09] 'add' errored after 15 ms
[14:29:09] Error: EEXIST: file already exists, mkdir 'D:\ej2-input-component\third-party\angular\src\index.ts'
PS D:\ej2-input-component>


Solution

  • The documentations says gulp.dest('./dist/'), so maybe try gulp.dest('./third-party/angular/src/').

    Also, about your comment :

    one more small pblm , i want to add it into next line but it is adding continues of last line

    Yes, that's the point of gulp-footer, it is made to add lines in the footer, which means at the end of the file :) There are more flexible modules, like gulp-insert-lines.