Skip to content Skip to sidebar Skip to footer

Run Gulp Task After Npm Package Install Without Any Command

I've developed a small angular package that is hosted on npmjs. when I try to install my package I want to change my 'selector' name so that I have written one gulp task like below

Solution 1:

Finally, I found out a solution to achieve my requirements.

I have created a tagchange.js file and placed the below content.

var fs = require('fs');
var glob = require('glob');

var files = glob.sync('./@syncfusion/*');
 
 for (var i = 0; i < files.length; i++) {
 var sourceFile = fs.readFileSync(files[i],'utf8');
 sourceFile = sourceFile.replace(`selector: '[ejs-button]'`,`selector: '[Kumar-button]'`);
 fs.writeFileSync(files[i], sourceFile, 'utf8');
 }

And I have called this in my package package.json file like below:

"dependencies": {
    "postinstall": "*"
  },
  "scripts": {
    "postinstall": "node ./tagchange.js",
    "packagr": "ng-packagr -p ng-package.json && gulp npmrc-changelog-schematics-injection && gulp path-change"
  }

It is working fine

Solution 2:

gulp.task('tag-change', function () {
 // var files = fs.readFileSync('./node_modules/@syncfusion/ej2-angular-buttons/@syncfusion/ej2-angular-buttons.es5.js', 'utf8');var files = glob.sync('./dist/@syncfusion/*');
 
 for (var i = 0; i < files.length; i++) {
 var sourceFile = fs.readFileSync(files[i],'utf8');
 sourceFile = sourceFile.replace(`selector: '[ejs-button]'`,`selector: '[KD-button]'`);
 fs.writeFileSync(files[i], sourceFile, 'utf8');
 }
});

Post a Comment for "Run Gulp Task After Npm Package Install Without Any Command"