1
0
Fork 0

feat: add main function, arg parsing for CLI

This commit is contained in:
ssube 2020-08-11 22:19:01 -05:00
parent 0d341587e2
commit 1f641fc7ad
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
30 changed files with 343 additions and 19 deletions

View File

@ -116,9 +116,6 @@ const bundle = {
commonjs({
namedExports,
}),
polyfills({
buffer: false,
}),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [

View File

@ -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) | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [flags](./cautious-journey.resolveinput.flags.md)
## ResolveInput.flags property
<b>Signature:</b>
```typescript
flags: Array<FlagLabel>;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [labels](./cautious-journey.resolveinput.labels.md)
## ResolveInput.labels property
<b>Signature:</b>
```typescript
labels: Array<string>;
```

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [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&lt;[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->&gt; | |
| [labels](./cautious-journey.resolveinput.labels.md) | Array&lt;string&gt; | |
| [states](./cautious-journey.resolveinput.states.md) | Array&lt;[StateLabel](./cautious-journey.statelabel.md)<!-- -->&gt; | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveInput](./cautious-journey.resolveinput.md) &gt; [states](./cautious-journey.resolveinput.states.md)
## ResolveInput.states property
<b>Signature:</b>
```typescript
states: Array<StateLabel>;
```

View File

@ -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)

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [changes](./cautious-journey.resolveresult.changes.md)
## ResolveResult.changes property
<b>Signature:</b>
```typescript
changes: Array<ChangeRecord>;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [errors](./cautious-journey.resolveresult.errors.md)
## ResolveResult.errors property
<b>Signature:</b>
```typescript
errors: Array<unknown>;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [ResolveResult](./cautious-journey.resolveresult.md) &gt; [labels](./cautious-journey.resolveresult.labels.md)
## ResolveResult.labels property
<b>Signature:</b>
```typescript
labels: Array<string>;
```

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [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&lt;ChangeRecord&gt; | |
| [errors](./cautious-journey.resolveresult.errors.md) | Array&lt;unknown&gt; | |
| [labels](./cautious-journey.resolveresult.labels.md) | Array&lt;string&gt; | |

View File

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateChange](./cautious-journey.statechange.md) &gt; [matches](./cautious-journey.statechange.matches.md)
## StateChange.matches property
Required labels for this state change to occur.
<b>Signature:</b>
```typescript
matches: Array<LabelRef>;
```

View File

@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [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&lt;LabelRef&gt; | Required labels for this state change to occur. |

View File

@ -17,5 +17,5 @@ export interface StateLabel extends BaseLabel, LabelSet
| Property | Type | Description |
| --- | --- | --- |
| [values](./cautious-journey.statelabel.values.md) | Array&lt;StateValue&gt; | Values for this state. |
| [values](./cautious-journey.statelabel.values.md) | Array&lt;[StateValue](./cautious-journey.statevalue.md)<!-- -->&gt; | Values for this state. |

View File

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [StateValue](./cautious-journey.statevalue.md) &gt; [becomes](./cautious-journey.statevalue.becomes.md)
## StateValue.becomes property
State changes that could occur to this value.
<b>Signature:</b>
```typescript
becomes: Array<StateChange>;
```

View File

@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [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&lt;[StateChange](./cautious-journey.statechange.md)<!-- -->&gt; | State changes that could occur to this value. |

View File

@ -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>

View File

@ -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>

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [config](./cautious-journey.syncoptions.config.md)
## SyncOptions.config property
<b>Signature:</b>
```typescript
config: ConfigData;
```

View File

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [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) | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [project](./cautious-journey.syncoptions.project.md)
## SyncOptions.project property
<b>Signature:</b>
```typescript
project: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [remote](./cautious-journey.syncoptions.remote.md)
## SyncOptions.remote property
<b>Signature:</b>
```typescript
remote: Remote;
```

View File

@ -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": {

26
src/config/args.ts Normal file
View File

@ -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;
}

View File

@ -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.

View File

@ -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);
});

27
src/main.ts Normal file
View File

@ -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;
}

View File

@ -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),
};
}

15
src/version.ts Normal file
View File

@ -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 }}',
},
};

View File

@ -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==