-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: simplify repo cleaning * build: port execute-rule to ts
- Loading branch information
Showing
11 changed files
with
96 additions
and
75 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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 @@ | ||
export * from "./lib"; |
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 @@ | ||
module.exports = require('./lib'); |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
}; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import execute from '.'; | ||
|
||
test('does nothing without params', async () => { | ||
const exec = execute as any; | ||
expect(await exec()).toBeNull(); | ||
}); | ||
|
||
test('returns plain config', async () => { | ||
const actual = await execute(['name', 'config']); | ||
expect(actual).toEqual(['name', 'config']); | ||
}); | ||
|
||
test('unwraps promised config', async () => { | ||
const actual = await execute(['name', Promise.resolve('config')]); | ||
expect(actual).toEqual(['name', 'config']); | ||
}); | ||
|
||
test('executes config functions', async () => { | ||
const actual = await execute(['name', () => 'config']); | ||
expect(actual).toEqual(['name', 'config']); | ||
}); | ||
|
||
test('executes async config functions', async () => { | ||
const actual = await execute(['name', async () => 'config']); | ||
expect(actual).toEqual(['name', 'config']); | ||
}); |
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,25 @@ | ||
type Rule<T> = readonly [string, Config<T>]; | ||
type Config<T> = T | Promise<T> | ExectableConfig<T>; | ||
type ExectableConfig<T> = (() => T) | (() => Promise<T>); | ||
|
||
type ExecutedRule<T> = readonly [string, T]; | ||
|
||
export default execute; | ||
|
||
export async function execute<T = unknown>(rule: Rule<T>): Promise<ExecutedRule<T> | null> { | ||
if (!Array.isArray(rule)) { | ||
return null; | ||
} | ||
|
||
const [name, config] = rule; | ||
|
||
const fn = executable(config) | ||
? config | ||
: async () => config; | ||
|
||
return [name, await fn()]; | ||
}; | ||
|
||
function executable<T>(config: Config<T>): config is ExectableConfig<T> { | ||
return typeof config === 'function'; | ||
} |
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,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": [ | ||
"dom", | ||
"es2015" | ||
], | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true | ||
}, | ||
"include": [ | ||
"./src" | ||
], | ||
"exclude": [ | ||
"./src/**/*.test.ts" | ||
] | ||
} |
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