Skip to content

Commit

Permalink
fix(classes): add script to update plugin version for jest
Browse files Browse the repository at this point in the history
FIX #528
  • Loading branch information
nartc committed Mar 10, 2023
1 parent a2dea1d commit 018c666
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
23 changes: 6 additions & 17 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "cleanup",
"section": "Cleanup"
},
{
"type": "docs",
"section": "Documentations"
}
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "cleanup", "section": "Cleanup" },
{ "type": "docs", "section": "Documentations" }
]
},
"infile": "CHANGELOG.md"
Expand All @@ -43,7 +31,8 @@
"before:bump": "npm run package",
"after:bump": [
"git checkout -- package.json",
"node tools/scripts/update-peer-deps.mjs"
"node tools/scripts/update-peer-deps.mjs",
"node tools/scripts/update-plugin-version.mjs"
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"dotenv-cli": "7.0.0",
"eslint": "8.35.0",
"eslint-config-prettier": "8.7.0",
"fs-extra": "^11.1.0",
"jest": "29.5.0",
"jest-environment-jsdom": "29.5.0",
"nx": "15.8.5",
Expand Down
10 changes: 10 additions & 0 deletions packages/classes/transformer-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ import type {
import { ModelVisitor } from './lib/model-visitor';
import type { AutomapperTransformerPluginOptions } from './lib/options';
import { isFilenameMatched } from './lib/utils';
import { version as pluginVersion } from './lib/version';

const defaultOptions: AutomapperTransformerPluginOptions = {
modelFileNameSuffix: ['.entity.ts', '.model.ts', '.dto.ts', '.vm.ts'],
};

/**
* Remember to increase the version whenever transformer's content is changed. This is to inform Jest to not reuse
* the previous cache which contains old transformer's content
*/
export const version = pluginVersion;

// Used for constructing cache key
export const name = 'automapper-transformer-plugin';

export default function automapperTransformerPlugin(
program: Program,
options: AutomapperTransformerPluginOptions = {}
Expand Down
2 changes: 2 additions & 0 deletions packages/classes/transformer-plugin/src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* generated */
export const version = '{{REPLACED}}';
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tools/scripts/update-plugin-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import version from '../../version.json' assert { type: 'json' };
import fs from 'fs-extra';
import path from 'path';

const { ensureDirSync, writeFileSync, readFileSync } = fs;

function updateFile(f, content) {
ensureDirSync(path.dirname(f));
if (typeof content === 'string') {
writeFileSync(f, content);
} else {
writeFileSync(f, content(readFileSync(f).toString()));
}
}

const pluginVersion = Number(version.version.split('.').join(''));

['index.js', 'index.cjs', 'src/lib/version.d.ts'].forEach((file) => {
const path = `dist/packages/classes/transformer-plugin/${file}`;
updateFile(path, (content) => {
return content.replace(/('|\")\{\{REPLACED\}\}('|\")/, pluginVersion);
});
});

0 comments on commit 018c666

Please sign in to comment.