Skip to content

Commit

Permalink
feat(adapters.nestjs): add post install script
Browse files Browse the repository at this point in the history
Add post install script to apply the nestjs adapter to @automock/common
  • Loading branch information
omermorad committed Dec 9, 2023
1 parent 12e4ad4 commit e397886
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/adapters/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
}
],
"scripts": {
"postinstall": "node postinstall.js",
"prebuild": "yarn rimraf dist",
"build": "yarn tsc -p tsconfig.build.json",
"test": "yarn jest",
"lint": "yarn eslint '{src,test}/**/*.ts'"
},
"files": [
"postinstall.js",
"dist"
],
"dependencies": {
Expand Down
25 changes: 25 additions & 0 deletions packages/adapters/nestjs/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');

const filePath = path.join(__dirname, '..', 'common', 'typings.d.ts');
const newContent = "\nexport type IdentifierMetadata = import('@automock/adapters.nestjs').IdentifierMetadata;\n";

fs.readFile(filePath, 'utf8', function (err, data) {
console.log('Automock: attempting to override @automock/common typings file')

if (err) {
console.log('Automock: an error occurred while reading @automock/common typings file')
return console.error(err);
}

const updatedData = data + newContent;

fs.writeFile(filePath, updatedData, 'utf8', function (err) {
if (err) {
console.log('Automock: an error occurred while writing to @automock/common typings file')
return console.log(err);
}

console.log('Automock: @automock/common typings file updated with successfully with the proper Automock adapter')
});
});

0 comments on commit e397886

Please sign in to comment.