0

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>
Kumaresan Sd
  • 1,399
  • 4
  • 16
  • 34
  • Possible duplicate of [How can I use Gulp to add a line of text to a file](https://stackoverflow.com/questions/38374936/how-can-i-use-gulp-to-add-a-line-of-text-to-a-file) – Jeremy Thille Jul 23 '18 at 08:43
  • Hi @JeremyThille, i am new to this .can you please show another one example... – Kumaresan Sd Jul 23 '18 at 08:47
  • Well, I can [google around](https://www.google.com/search?q=how+to+add+a+line+of+text+to+a+file+using+gulp&oq=how+to+add+a+line+of+text+to+a+file+using+gulp&aqs=chrome..69i57.10038j0j7&sourceid=chrome&ie=UTF-8) and it will give me plenty of relevant results about how to do this :) – Jeremy Thille Jul 23 '18 at 08:51
  • still, i did not get a point. – Kumaresan Sd Jul 23 '18 at 08:54
  • 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')); }); – Kumaresan Sd Jul 23 '18 at 08:54
  • And what did it do? Nothing? Did you execute that task? – Jeremy Thille Jul 23 '18 at 08:59
  • yes i executed that task it shows following error: – Kumaresan Sd Jul 23 '18 at 09:00
  • 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> – Kumaresan Sd Jul 23 '18 at 09:00
  • The documentations says `gulp.dest('./dist/')`, so maybe try `gulp.dest('./third-party/angular/src/')` ? – Jeremy Thille Jul 23 '18 at 09:05
  • love you friend, it works thank you – Kumaresan Sd Jul 23 '18 at 09:06
  • post this as your answer i will accept but one more small pblm , i want to add it into next line but it is adding continues of last line – Kumaresan Sd Jul 23 '18 at 09:07
  • Just add a newline \n to the beginning of your footer, like "\n export...…….." – Mark Jul 23 '18 at 13:38

1 Answers1

1

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.

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63