Skip to content

Commit

Permalink
feat(module): adds export for createProviderToken
Browse files Browse the repository at this point in the history
The export for the `createProviderToken` can be made use of in tests or manual usages to get the
Ogma provider token (like in factories) so that developers no longer need to know what the
dependency injection token is.
  • Loading branch information
jmcdo29 committed Jul 25, 2020
1 parent c7cd6d7 commit 9b0b43f
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
],
"scripts": {
"preversion": "yarn run format && yarn run lint && yarn build",
"postversion": "yarn build:tools && yarn updatePeerDeps",
"bootstrap": "lerna bootstrap",
"build": "lerna run build --stream",
"build:tools": "tsc -p tools/tsconfig.json",
"benchmark:all": "yarn benchmark:interceptor && yarn benchmark:logger",
"benchmark:interceptor": "rimraf benchmarks/interceptor/dist && tsc -p benchmarks/interceptor/tsconfig.json && node benchmarks/interceptor/dist/main.js",
"benchmark:logger": "rimraf benchmarks/logger/dist && tsc -p benchmarks/logger/tsconfig.json && node benchmarks/logger/dist/index.js",
Expand All @@ -47,7 +49,8 @@
"test:debug": "node --inspect-brk -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:int": "jest --config jest-integration.config.js",
"test:int:debug": "node --inspect-brk -r ts-node/register node_modules/.bin/jest --runInBand --config jest-integration.config.js"
"test:int:debug": "node --inspect-brk -r ts-node/register node_modules/.bin/jest --runInBand --config jest-integration.config.js",
"updatePeerDeps": "node tools/peer-update.js"
},
"devDependencies": {
"@commitlint/cli": "^9.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/nestjs-module/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './interceptor/ogma.interceptor';
export * from './interceptor/providers/abstract-interceptor.service';
export * from './interfaces/ogma-options.interface';
export * from './ogma.module';
export { createProviderToken } from './ogma.provider';
export * from './ogma.service';
53 changes: 53 additions & 0 deletions tools/peer-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const logger_1 = require('@ogma/logger');
const fs_1 = require('fs');
const versionMap = {};
function readDirectory(dir) {
return fs_1.readdirSync(dir);
}
function getPackageJSON(packageName) {
const packageString = fs_1
.readFileSync(`./packages/${packageName}/package.json`)
.toString();
return JSON.parse(packageString);
}
function populateVersionMap(packageObject) {
versionMap[packageObject.name] = packageObject.version;
return packageObject;
}
function hasOgmaPeerDep(packageObject) {
return packageObject.peerDependencies
? Object.keys(packageObject.peerDependencies).some(
(key) => !!versionMap[key],
)
: false;
}
function updatePeerDep(packageObject) {
Object.keys(packageObject.peerDependencies)
.filter((key) => !!versionMap[key])
.forEach(
(key) => (packageObject.peerDependencies[key] = '^' + versionMap[key]),
);
return packageObject;
}
function updatePackageJSON(packageObject) {
fs_1.writeFileSync(
`./packages/${packageObject.name.replace('@ogma/', '')}/package.json`,
Buffer.from(JSON.stringify(packageObject, null, 2) + '\n'),
);
console.log(
`Updated ${logger_1.color.blue('package.json')} for ${logger_1.color.green(
packageObject.name,
)}`,
);
}
function bootstrap() {
readDirectory('./packages')
.map(getPackageJSON)
.map(populateVersionMap)
.filter(hasOgmaPeerDep)
.map(updatePeerDep)
.forEach(updatePackageJSON);
}
bootstrap();
67 changes: 67 additions & 0 deletions tools/peer-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { color } from '@ogma/logger';
import { readdirSync, readFileSync, writeFileSync } from 'fs';

const versionMap: Record<string, string> = {};

interface packageJSON {
version: string;
dependencies: Record<string, string>;
peerDependencies: Record<string, string>;
name: string;
}

function readDirectory(dir: string): string[] {
return readdirSync(dir);
}

function getPackageJSON(packageName: string): packageJSON {
const packageString = readFileSync(
`./packages/${packageName}/package.json`,
).toString();
return JSON.parse(packageString);
}

function populateVersionMap(packageObject: packageJSON): packageJSON {
versionMap[packageObject.name] = packageObject.version;
return packageObject;
}

function hasOgmaPeerDep(packageObject: packageJSON): boolean {
return packageObject.peerDependencies
? Object.keys(packageObject.peerDependencies).some(
(key) => !!versionMap[key],
)
: false;
}

function updatePeerDep(packageObject: packageJSON): packageJSON {
Object.keys(packageObject.peerDependencies)
.filter((key) => !!versionMap[key])
.forEach(
(key) => (packageObject.peerDependencies[key] = '^' + versionMap[key]),
);
return packageObject;
}

function updatePackageJSON(packageObject: packageJSON): void {
writeFileSync(
`./packages/${packageObject.name.replace('@ogma/', '')}/package.json`,
Buffer.from(JSON.stringify(packageObject, null, 2) + '\n'),
);
console.log(
`Updated ${color.blue('package.json')} for ${color.green(
packageObject.name,
)}`,
);
}

function bootstrap() {
readDirectory('./packages')
.map(getPackageJSON)
.map(populateVersionMap)
.filter(hasOgmaPeerDep)
.map(updatePeerDep)
.forEach(updatePackageJSON);
}

bootstrap();
8 changes: 8 additions & 0 deletions tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./",
"baseUrl": "./",
"declaration": false
}
}

0 comments on commit 9b0b43f

Please sign in to comment.