diff --git a/config/rollup.js b/config/rollup.js index 23cc6f0..98343a2 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -116,9 +116,6 @@ const bundle = { commonjs({ namedExports, }), - polyfills({ - buffer: false, - }), eslint({ configFile: join('.', 'config', 'eslint.json'), exclude: [ diff --git a/docs/api/cautious-journey.md b/docs/api/cautious-journey.md index bb746a1..cf006b2 100644 --- a/docs/api/cautious-journey.md +++ b/docs/api/cautious-journey.md @@ -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) | | diff --git a/docs/api/cautious-journey.resolveinput.flags.md b/docs/api/cautious-journey.resolveinput.flags.md new file mode 100644 index 0000000..68cea35 --- /dev/null +++ b/docs/api/cautious-journey.resolveinput.flags.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [flags](./cautious-journey.resolveinput.flags.md) + +## ResolveInput.flags property + +Signature: + +```typescript +flags: Array; +``` diff --git a/docs/api/cautious-journey.resolveinput.labels.md b/docs/api/cautious-journey.resolveinput.labels.md new file mode 100644 index 0000000..2ba2f0f --- /dev/null +++ b/docs/api/cautious-journey.resolveinput.labels.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [labels](./cautious-journey.resolveinput.labels.md) + +## ResolveInput.labels property + +Signature: + +```typescript +labels: Array; +``` diff --git a/docs/api/cautious-journey.resolveinput.md b/docs/api/cautious-journey.resolveinput.md new file mode 100644 index 0000000..389e549 --- /dev/null +++ b/docs/api/cautious-journey.resolveinput.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) + +## ResolveInput interface + +Collected inputs for a resolver run. + +Signature: + +```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)> | | + diff --git a/docs/api/cautious-journey.resolveinput.states.md b/docs/api/cautious-journey.resolveinput.states.md new file mode 100644 index 0000000..01a8757 --- /dev/null +++ b/docs/api/cautious-journey.resolveinput.states.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [states](./cautious-journey.resolveinput.states.md) + +## ResolveInput.states property + +Signature: + +```typescript +states: Array; +``` diff --git a/docs/api/cautious-journey.resolvelabels.md b/docs/api/cautious-journey.resolvelabels.md index 6545150..4057f7d 100644 --- a/docs/api/cautious-journey.resolvelabels.md +++ b/docs/api/cautious-journey.resolvelabels.md @@ -14,9 +14,9 @@ export declare function resolveLabels(options: ResolveInput): ResolveResult; | Parameter | Type | Description | | --- | --- | --- | -| options | ResolveInput | | +| options | [ResolveInput](./cautious-journey.resolveinput.md) | | Returns: -ResolveResult +[ResolveResult](./cautious-journey.resolveresult.md) diff --git a/docs/api/cautious-journey.resolveresult.changes.md b/docs/api/cautious-journey.resolveresult.changes.md new file mode 100644 index 0000000..72f02ea --- /dev/null +++ b/docs/api/cautious-journey.resolveresult.changes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [changes](./cautious-journey.resolveresult.changes.md) + +## ResolveResult.changes property + +Signature: + +```typescript +changes: Array; +``` diff --git a/docs/api/cautious-journey.resolveresult.errors.md b/docs/api/cautious-journey.resolveresult.errors.md new file mode 100644 index 0000000..fabbbd2 --- /dev/null +++ b/docs/api/cautious-journey.resolveresult.errors.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [errors](./cautious-journey.resolveresult.errors.md) + +## ResolveResult.errors property + +Signature: + +```typescript +errors: Array; +``` diff --git a/docs/api/cautious-journey.resolveresult.labels.md b/docs/api/cautious-journey.resolveresult.labels.md new file mode 100644 index 0000000..af63047 --- /dev/null +++ b/docs/api/cautious-journey.resolveresult.labels.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) > [labels](./cautious-journey.resolveresult.labels.md) + +## ResolveResult.labels property + +Signature: + +```typescript +labels: Array; +``` diff --git a/docs/api/cautious-journey.resolveresult.md b/docs/api/cautious-journey.resolveresult.md new file mode 100644 index 0000000..9dbbe78 --- /dev/null +++ b/docs/api/cautious-journey.resolveresult.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveResult](./cautious-journey.resolveresult.md) + +## ResolveResult interface + +Collected results from a resolver run. + +Signature: + +```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> | | + diff --git a/docs/api/cautious-journey.statechange.matches.md b/docs/api/cautious-journey.statechange.matches.md new file mode 100644 index 0000000..0382b4a --- /dev/null +++ b/docs/api/cautious-journey.statechange.matches.md @@ -0,0 +1,13 @@ + + +[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. + +Signature: + +```typescript +matches: Array; +``` diff --git a/docs/api/cautious-journey.statechange.md b/docs/api/cautious-journey.statechange.md new file mode 100644 index 0000000..982bbd8 --- /dev/null +++ b/docs/api/cautious-journey.statechange.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateChange](./cautious-journey.statechange.md) + +## StateChange interface + +The transition between two state values. + +Signature: + +```typescript +export interface StateChange extends LabelSet +``` +Extends: LabelSet + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [matches](./cautious-journey.statechange.matches.md) | Array<LabelRef> | Required labels for this state change to occur. | + diff --git a/docs/api/cautious-journey.statelabel.md b/docs/api/cautious-journey.statelabel.md index 8dbab12..e5c6196 100644 --- a/docs/api/cautious-journey.statelabel.md +++ b/docs/api/cautious-journey.statelabel.md @@ -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. | diff --git a/docs/api/cautious-journey.statevalue.becomes.md b/docs/api/cautious-journey.statevalue.becomes.md new file mode 100644 index 0000000..8d5918c --- /dev/null +++ b/docs/api/cautious-journey.statevalue.becomes.md @@ -0,0 +1,13 @@ + + +[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. + +Signature: + +```typescript +becomes: Array; +``` diff --git a/docs/api/cautious-journey.statevalue.md b/docs/api/cautious-journey.statevalue.md new file mode 100644 index 0000000..1775ee1 --- /dev/null +++ b/docs/api/cautious-journey.statevalue.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [StateValue](./cautious-journey.statevalue.md) + +## StateValue interface + +One of many values for a particular state. + +Signature: + +```typescript +export interface StateValue extends BaseLabel +``` +Extends: 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. | + diff --git a/docs/api/cautious-journey.syncissues.md b/docs/api/cautious-journey.syncissues.md index 6e02748..06fd074 100644 --- a/docs/api/cautious-journey.syncissues.md +++ b/docs/api/cautious-journey.syncissues.md @@ -14,7 +14,7 @@ export declare function syncIssues(options: SyncOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | -| options | SyncOptions | | +| options | [SyncOptions](./cautious-journey.syncoptions.md) | | Returns: diff --git a/docs/api/cautious-journey.synclabels.md b/docs/api/cautious-journey.synclabels.md index 5c608d3..58488c6 100644 --- a/docs/api/cautious-journey.synclabels.md +++ b/docs/api/cautious-journey.synclabels.md @@ -14,7 +14,7 @@ export declare function syncLabels(options: SyncOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | -| options | SyncOptions | | +| options | [SyncOptions](./cautious-journey.syncoptions.md) | | Returns: diff --git a/docs/api/cautious-journey.syncoptions.config.md b/docs/api/cautious-journey.syncoptions.config.md new file mode 100644 index 0000000..cda8792 --- /dev/null +++ b/docs/api/cautious-journey.syncoptions.config.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [config](./cautious-journey.syncoptions.config.md) + +## SyncOptions.config property + +Signature: + +```typescript +config: ConfigData; +``` diff --git a/docs/api/cautious-journey.syncoptions.md b/docs/api/cautious-journey.syncoptions.md new file mode 100644 index 0000000..83ea213 --- /dev/null +++ b/docs/api/cautious-journey.syncoptions.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) + +## SyncOptions interface + +Signature: + +```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) | | + diff --git a/docs/api/cautious-journey.syncoptions.project.md b/docs/api/cautious-journey.syncoptions.project.md new file mode 100644 index 0000000..5ceea83 --- /dev/null +++ b/docs/api/cautious-journey.syncoptions.project.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [project](./cautious-journey.syncoptions.project.md) + +## SyncOptions.project property + +Signature: + +```typescript +project: string; +``` diff --git a/docs/api/cautious-journey.syncoptions.remote.md b/docs/api/cautious-journey.syncoptions.remote.md new file mode 100644 index 0000000..910d6f2 --- /dev/null +++ b/docs/api/cautious-journey.syncoptions.remote.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [SyncOptions](./cautious-journey.syncoptions.md) > [remote](./cautious-journey.syncoptions.remote.md) + +## SyncOptions.remote property + +Signature: + +```typescript +remote: Remote; +``` diff --git a/package.json b/package.json index f3920f9..319cfcb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/config/args.ts b/src/config/args.ts new file mode 100644 index 0000000..2d1d9a4 --- /dev/null +++ b/src/config/args.ts @@ -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} [options]`) + .command({ + command: 'sync-issues', + describe: '', + handler: handleMode, + }) + .command({ + command: 'sync-labels', + describe: '', + handler: handleMode, + }); + + return parser; +} diff --git a/src/config.ts b/src/config/index.ts similarity index 86% rename from src/config.ts rename to src/config/index.ts index 0d0a414..43526d9 100644 --- a/src/config.ts +++ b/src/config/index.ts @@ -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. diff --git a/src/index.ts b/src/index.ts index 32386ee..93346ab 100644 --- a/src/index.ts +++ b/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); +}); diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..8671b18 --- /dev/null +++ b/src/main.ts @@ -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): Promise { + // 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; +} diff --git a/src/resolve.ts b/src/resolve.ts index 5131f2e..6120dd5 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -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 = []; + const errors: Array = []; 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), }; } diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..03518c3 --- /dev/null +++ b/src/version.ts @@ -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 }}', + }, +}; diff --git a/yarn.lock b/yarn.lock index db24ee0..aa5191c 100644 --- a/yarn.lock +++ b/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==