-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module): adds export for
createProviderToken
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
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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(); |
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
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(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./", | ||
"baseUrl": "./", | ||
"declaration": false | ||
} | ||
} |