-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from lifeomic/typescript
Convert to typescript
- Loading branch information
Showing
40 changed files
with
929 additions
and
719 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"@lifeomic/standards/javascript" | ||
"@lifeomic/standards" | ||
], | ||
"env": { | ||
"node": true, | ||
|
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 |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
node_modules/ | ||
|
||
yarn-error.log | ||
|
||
test/build | ||
coverage |
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,41 @@ | ||
import type { Config } from '@jest/types'; | ||
import inspector from 'inspector'; | ||
|
||
// If we are debugging then extend the timeout to max value, otherwise use the default. | ||
const testTimeout = inspector.url() ? 1e8 : undefined; | ||
|
||
const config: Config.InitialOptions = { | ||
rootDir: __dirname, | ||
preset: '@lifeomic/jest-config', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'@swc/jest', | ||
{ | ||
jsc: { target: 'es2021' }, | ||
}, | ||
], | ||
}, | ||
collectCoverageFrom: ['src/**/*.ts'], | ||
collectCoverage: false, | ||
coverageThreshold: { | ||
global: { | ||
statements: 100, | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
}, | ||
}, | ||
coveragePathIgnorePatterns: ['<rootDir>/test/', '/node_modules/'], | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
testMatch: [ | ||
'<rootDir>/test/**/*.test.ts', | ||
], | ||
verbose: true, | ||
maxWorkers: 4, | ||
testTimeout, | ||
}; | ||
|
||
export default 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
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,9 @@ | ||
export class ValidationError extends Error { | ||
constructor ( | ||
public stdout: string, | ||
public stderr: string, | ||
) { | ||
super('An error was detected during response validation'); | ||
this.name = 'ValidationError'; | ||
} | ||
} |
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 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,65 @@ | ||
#!/usr/bin/env node | ||
|
||
import glob from 'glob'; | ||
import path from 'path'; | ||
import yargs from 'yargs'; | ||
import { ValidationError } from './ValidationError'; | ||
import { alphaProxy } from './alphaProxy'; | ||
import { Config } from './types'; | ||
import { callAlpha } from './utils'; | ||
|
||
const config: Config = { | ||
transformResponse: [(data) => data], | ||
validateStatus: () => true, | ||
responsePostProcessors: [], | ||
}; | ||
|
||
const run = async () => { | ||
const plugins = await Promise.all(glob.sync(path.join(__dirname, 'plugins/*.[jt]s')) | ||
.map(async (filename) => { | ||
const plugin = await import(filename); | ||
return plugin.default(yargs); | ||
})); | ||
|
||
const args = await yargs.parse(); | ||
|
||
const skipRequest = plugins.some((execute) => execute(config, args)); | ||
|
||
const { | ||
proxied, | ||
proxyPort, | ||
} = config; | ||
|
||
if (proxied) { | ||
alphaProxy(config).on('listening', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
console.log(`Proxy is listening on port ${proxyPort!}; Press any key to quit;`); | ||
}); | ||
|
||
// These are only relevant in a terminal, not in tests | ||
/* istanbul ignore next */ | ||
if (process.stdin.isTTY) { | ||
/* istanbul ignore next */ | ||
process.stdin.setRawMode(true); | ||
} | ||
process.stdin.on('data', () => { | ||
process.exit(0); | ||
}); | ||
} else if (!skipRequest) { | ||
callAlpha(config).then((result) => { | ||
process.stdout.write(result.data); | ||
}).catch((error) => { | ||
if (error instanceof ValidationError) { | ||
process.stdout.write(error.stdout); | ||
process.stderr.write(error.stderr); | ||
} else { | ||
console.error(error.toString()); | ||
} | ||
process.exitCode = 1; | ||
}); | ||
} | ||
}; | ||
|
||
run().catch((error) => { | ||
console.error(error); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.