Created
February 16, 2017 23:08
-
-
Save tvand7093/12b506dc40515ab724bdb8f4537c2c6c to your computer and use it in GitHub Desktop.
A patch to run prior to building a typescript project that uses the azure-arm-website node module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
function patchFile() { | |
//get the path to the file to be patched. This is for differnet OS's. | |
const basePath = path.join(__dirname, | |
'node_modules', 'azure-arm-website', 'lib', 'models'); | |
//the actual file we are modifying. | |
const modulefile = path.join(basePath, 'index.d.ts'); | |
// read the file. If error, than module probably doesn't exist. | |
fs.readFile(modulefile, (error, contents) => { | |
if(error) { | |
console.log("Error reading module. Skipping..."); | |
return; | |
} | |
// file exists, so check if it has been patched already or not. | |
if(contents.indexOf('import { BaseResource }') > -1){ | |
console.log("Module already patched. Skipping..."); | |
return; | |
} | |
// buffer is the patch. | |
let buffer = new Buffer("import { BaseResource } from 'ms-rest-azure';\n"); | |
// append the patch to the original file. | |
let patched = Buffer.concat([buffer, contents]); | |
//write the patch file to the original file name. | |
fs.writeFile(modulefile, patched, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("The module was successfully patched."); | |
}); | |
}); | |
} | |
// run the patch operation. | |
patchFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment