feat: add main function, arg parsing for CLI
This commit is contained in:
parent
0d341587e2
commit
1f641fc7ad
|
@ -116,9 +116,6 @@ const bundle = {
|
|||
commonjs({
|
||||
namedExports,
|
||||
}),
|
||||
polyfills({
|
||||
buffer: false,
|
||||
}),
|
||||
eslint({
|
||||
configFile: join('.', 'config', 'eslint.json'),
|
||||
exclude: [
|
||||
|
|
|
@ -26,5 +26,10 @@
|
|||
| [FlagLabel](./cautious-journey.flaglabel.md) | Individual labels: the equivalent of a checkbox. |
|
||||
| [Remote](./cautious-journey.remote.md) | Basic functions which every remote API must provide. |
|
||||
| [RemoteOptions](./cautious-journey.remoteoptions.md) | |
|
||||
| [ResolveInput](./cautious-journey.resolveinput.md) | Collected inputs for a resolver run. |
|
||||
| [ResolveResult](./cautious-journey.resolveresult.md) | Collected results from a resolver run. |
|
||||
| [StateChange](./cautious-journey.statechange.md) | The transition between two state values. |
|
||||
| [StateLabel](./cautious-journey.statelabel.md) | Grouped labels: the equivalent of a radio group. |
|
||||
| [StateValue](./cautious-journey.statevalue.md) | One of many values for a particular state. |
|
||||
| [SyncOptions](./cautious-journey.syncoptions.md) | |
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [flags](./cautious-journey.resolveinput.flags.md)
|
||||
|
||||
## ResolveInput.flags property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
flags: Array<FlagLabel>;
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [labels](./cautious-journey.resolveinput.labels.md)
|
||||
|
||||
## ResolveInput.labels property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
labels: Array<string>;
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md)
|
||||
|
||||
## ResolveInput interface
|
||||
|
||||
Collected inputs for a resolver run.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface ResolveInput
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [flags](./cautious-journey.resolveinput.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->> | |
|
||||
| [labels](./cautious-journey.resolveinput.labels.md) | Array<string> | |
|
||||
| [states](./cautious-journey.resolveinput.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)<!-- -->> | |
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [states](./cautious-journey.resolveinput.states.md)
|
||||
|
||||
## ResolveInput.states property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
states: Array<StateLabel>;
|
||||
```
|
|
@ -14,9 +14,9 @@ export declare function resolveLabels(options: ResolveInput): ResolveResult;
|
|||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | ResolveInput | |
|
||||
| options | [ResolveInput](./cautious-journey.resolveinput.md) | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
ResolveResult
|
||||
[ResolveResult](./cautious-journey.resolveresult.md)
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [changes](./cautious-journey.resolveresult.changes.md)
|
||||
|
||||
## ResolveResult.changes property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
changes: Array<ChangeRecord>;
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [errors](./cautious-journey.resolveresult.errors.md)
|
||||
|
||||
## ResolveResult.errors property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
errors: Array<unknown>;
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [labels](./cautious-journey.resolveresult.labels.md)
|
||||
|
||||
## ResolveResult.labels property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
labels: Array<string>;
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md)
|
||||
|
||||
## ResolveResult interface
|
||||
|
||||
Collected results from a resolver run.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface ResolveResult
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [changes](./cautious-journey.resolveresult.changes.md) | Array<ChangeRecord> | |
|
||||
| [errors](./cautious-journey.resolveresult.errors.md) | Array<unknown> | |
|
||||
| [labels](./cautious-journey.resolveresult.labels.md) | Array<string> | |
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateChange](./cautious-journey.statechange.md) > [matches](./cautious-journey.statechange.matches.md)
|
||||
|
||||
## StateChange.matches property
|
||||
|
||||
Required labels for this state change to occur.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
matches: Array<LabelRef>;
|
||||
```
|
|
@ -0,0 +1,21 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateChange](./cautious-journey.statechange.md)
|
||||
|
||||
## StateChange interface
|
||||
|
||||
The transition between two state values.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface StateChange extends LabelSet
|
||||
```
|
||||
<b>Extends:</b> LabelSet
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [matches](./cautious-journey.statechange.matches.md) | Array<LabelRef> | Required labels for this state change to occur. |
|
||||
|
|
@ -17,5 +17,5 @@ export interface StateLabel extends BaseLabel, LabelSet
|
|||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [values](./cautious-journey.statelabel.values.md) | Array<StateValue> | Values for this state. |
|
||||
| [values](./cautious-journey.statelabel.values.md) | Array<[StateValue](./cautious-journey.statevalue.md)<!-- -->> | Values for this state. |
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateValue](./cautious-journey.statevalue.md) > [becomes](./cautious-journey.statevalue.becomes.md)
|
||||
|
||||
## StateValue.becomes property
|
||||
|
||||
State changes that could occur to this value.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
becomes: Array<StateChange>;
|
||||
```
|
|
@ -0,0 +1,21 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateValue](./cautious-journey.statevalue.md)
|
||||
|
||||
## StateValue interface
|
||||
|
||||
One of many values for a particular state.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface StateValue extends BaseLabel
|
||||
```
|
||||
<b>Extends:</b> BaseLabel
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [becomes](./cautious-journey.statevalue.becomes.md) | Array<[StateChange](./cautious-journey.statechange.md)<!-- -->> | State changes that could occur to this value. |
|
||||
|
|
@ -14,7 +14,7 @@ export declare function syncIssues(options: SyncOptions): Promise<unknown>;
|
|||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | SyncOptions | |
|
||||
| options | [SyncOptions](./cautious-journey.syncoptions.md) | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ export declare function syncLabels(options: SyncOptions): Promise<unknown>;
|
|||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| options | SyncOptions | |
|
||||
| options | [SyncOptions](./cautious-journey.syncoptions.md) | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [config](./cautious-journey.syncoptions.config.md)
|
||||
|
||||
## SyncOptions.config property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
config: ConfigData;
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md)
|
||||
|
||||
## SyncOptions interface
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface SyncOptions
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [config](./cautious-journey.syncoptions.config.md) | ConfigData | |
|
||||
| [project](./cautious-journey.syncoptions.project.md) | string | |
|
||||
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [project](./cautious-journey.syncoptions.project.md)
|
||||
|
||||
## SyncOptions.project property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
project: string;
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [remote](./cautious-journey.syncoptions.remote.md)
|
||||
|
||||
## SyncOptions.remote property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
remote: Remote;
|
||||
```
|
|
@ -27,7 +27,7 @@
|
|||
"@types/react-dom": "^16.9.8",
|
||||
"@types/sinon-chai": "3.2.4",
|
||||
"@types/source-map-support": "0.5.2",
|
||||
"@types/yargs-parser": "^15.0.0",
|
||||
"@types/yargs": "^15.0.5",
|
||||
"@typescript-eslint/eslint-plugin": "3.8.0",
|
||||
"@typescript-eslint/eslint-plugin-tslint": "3.8.0",
|
||||
"@typescript-eslint/parser": "3.8.0",
|
||||
|
@ -81,7 +81,7 @@
|
|||
"tslint-microsoft-contrib": "6.2.0",
|
||||
"tslint-sonarts": "1.9.0",
|
||||
"typescript": "3.9.7",
|
||||
"yargs-parser": "^18.1.3"
|
||||
"yargs": "^15.4.1"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import { usage } from 'yargs';
|
||||
|
||||
import { VERSION_INFO } from '../version';
|
||||
|
||||
export function createParser() {
|
||||
let mode = '';
|
||||
|
||||
function handleMode(argi: string) {
|
||||
mode = argi;
|
||||
}
|
||||
|
||||
/* eslint-disable-next-line sonarjs/prefer-immediate-return */
|
||||
const parser = usage(`Usage: ${VERSION_INFO.package.name} <mode> [options]`)
|
||||
.command({
|
||||
command: 'sync-issues',
|
||||
describe: '',
|
||||
handler: handleMode,
|
||||
})
|
||||
.command({
|
||||
command: 'sync-labels',
|
||||
describe: '',
|
||||
handler: handleMode,
|
||||
});
|
||||
|
||||
return parser;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { FlagLabel, StateLabel } from './labels';
|
||||
import { RemoteOptions } from './remote';
|
||||
import { FlagLabel, StateLabel } from '../labels';
|
||||
import { RemoteOptions } from '../remote';
|
||||
|
||||
/**
|
||||
* Config data for the app, loaded from CLI or DOM.
|
19
src/index.ts
19
src/index.ts
|
@ -1,6 +1,19 @@
|
|||
export { FlagLabel, StateLabel } from './labels';
|
||||
import { main } from './main';
|
||||
|
||||
export { FlagLabel, StateChange, StateLabel, StateValue } from './labels';
|
||||
export { Remote, RemoteOptions } from './remote';
|
||||
export { GithubRemote } from './remote/github';
|
||||
export { GitlabRemote } from './remote/gitlab';
|
||||
export { resolveLabels } from './resolve';
|
||||
export { syncIssues, syncLabels } from './sync';
|
||||
export { ResolveInput, ResolveResult, resolveLabels } from './resolve';
|
||||
export { syncIssues, syncLabels, SyncOptions } from './sync';
|
||||
|
||||
const STATUS_ERROR = 1;
|
||||
|
||||
/**
|
||||
* This is the main entry-point to the program and the only file not included in the main bundle.
|
||||
*/
|
||||
main(process.argv).then((status) => process.exit(status)).catch((err: Error) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('uncaught error during main:', err);
|
||||
process.exit(STATUS_ERROR);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import { createParser } from './config/args';
|
||||
|
||||
export { FlagLabel, StateLabel } from './labels';
|
||||
export { Remote, RemoteOptions } from './remote';
|
||||
export { GithubRemote } from './remote/github';
|
||||
export { GitlabRemote } from './remote/gitlab';
|
||||
export { resolveLabels } from './resolve';
|
||||
export { syncIssues, syncLabels } from './sync';
|
||||
|
||||
export async function main(argv: Array<string>): Promise<number> {
|
||||
// get arguments
|
||||
const parser = createParser();
|
||||
const args = parser.parse(argv.slice(0));
|
||||
|
||||
/* eslint-disable-next-line no-console */
|
||||
console.log('args:', args);
|
||||
|
||||
// load config
|
||||
// create logger
|
||||
// create remote
|
||||
|
||||
// mode switch
|
||||
// - sync labels
|
||||
// - sync issues
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -7,6 +7,7 @@ export enum ChangeEffect {
|
|||
EXISTING = 'existing',
|
||||
CREATED = 'created',
|
||||
REMOVED = 'removed',
|
||||
REQUIRED = 'required',
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,8 @@ export interface ResolveResult {
|
|||
|
||||
export function resolveLabels(options: ResolveInput): ResolveResult {
|
||||
const activeLabels = new Set(options.labels);
|
||||
const changes: Array<ChangeRecord> = [];
|
||||
const errors: Array<unknown> = [];
|
||||
|
||||
const sortedFlags = options.flags.sort((a, b) => a.priority - b.priority);
|
||||
for (const flag of sortedFlags) {
|
||||
|
@ -61,8 +64,8 @@ export function resolveLabels(options: ResolveInput): ResolveResult {
|
|||
}
|
||||
|
||||
return {
|
||||
changes: [],
|
||||
errors: [],
|
||||
changes,
|
||||
errors,
|
||||
labels: Array.from(activeLabels),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
export const VERSION_INFO = {
|
||||
build: {
|
||||
job: '{{ BUILD_JOB }}',
|
||||
node: '{{ NODE_VERSION }}',
|
||||
runner: '{{ BUILD_RUNNER }}',
|
||||
},
|
||||
git: {
|
||||
branch: '{{ GIT_BRANCH }}',
|
||||
commit: '{{ GIT_COMMIT }}',
|
||||
},
|
||||
package: {
|
||||
name: '{{ PACKAGE_NAME }}',
|
||||
version: '{{ PACKAGE_VERSION }}',
|
||||
},
|
||||
};
|
11
yarn.lock
11
yarn.lock
|
@ -498,11 +498,18 @@
|
|||
"@types/node" "*"
|
||||
source-map "^0.6.0"
|
||||
|
||||
"@types/yargs-parser@^15.0.0":
|
||||
"@types/yargs-parser@*":
|
||||
version "15.0.0"
|
||||
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/yargs-parser/-/yargs-parser-15.0.0.tgz#cb3f9f741869e20cce330ffbeb9271590483882d"
|
||||
integrity sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==
|
||||
|
||||
"@types/yargs@^15.0.5":
|
||||
version "15.0.5"
|
||||
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/yargs/-/yargs-15.0.5.tgz#947e9a6561483bdee9adffc983e91a6902af8b79"
|
||||
integrity sha512-Dk/IDOPtOgubt/IaevIUbTgV7doaKkoorvOyYM2CMwuDyP89bekI7H4xLIwunNYiK9jhCkmc6pUrJk3cj2AB9w==
|
||||
dependencies:
|
||||
"@types/yargs-parser" "*"
|
||||
|
||||
"@typescript-eslint/eslint-plugin-tslint@3.8.0":
|
||||
version "3.8.0"
|
||||
resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-3.8.0.tgz#9b0f1d0f26408c2ab170f878eb51d1a096d9b82c"
|
||||
|
@ -5327,7 +5334,7 @@ yargs@^14.2.3:
|
|||
y18n "^4.0.0"
|
||||
yargs-parser "^15.0.1"
|
||||
|
||||
yargs@^15.0.0, yargs@^15.0.2, yargs@^15.3.1:
|
||||
yargs@^15.0.0, yargs@^15.0.2, yargs@^15.3.1, yargs@^15.4.1:
|
||||
version "15.4.1"
|
||||
resolved "https://artifacts.apextoaster.com/repository/group-npm/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
|
||||
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
|
||||
|
|
Loading…
Reference in New Issue