Skip to content

Commit

Permalink
feat(config): add project comment, state divider to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube authored and bzlibby committed Aug 20, 2020
1 parent 3a3facb commit 2feb5a3
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 205 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/api/cautious-journey.statelabel.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions docs/api/cautious-journey.syncoptions.colors.md

This file was deleted.

5 changes: 1 addition & 4 deletions docs/api/cautious-journey.syncoptions.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/api/cautious-journey.syncoptions.project.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions docs/api/cautious-journey.syncoptions.states.md

This file was deleted.

80 changes: 49 additions & 31 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,51 @@ import { FlagLabel, StateLabel } from '../labels';
import { RemoteOptions } from '../remote';
import * as SCHEMA_DATA from './schema.yml';

/**
* Config data for the app, loaded from CLI or DOM.
*/
export interface ConfigData {
logger: {
level: LogLevel;
name: string;
};
projects: Array<{
/**
* Color palette for labels without their own.
*/
colors: Array<string>;
export interface LoggerConfig {
level: LogLevel;
name: string;
}

export interface ProjectConfig {
/**
* Color palette for labels without their own.
*/
colors: Array<string>;

/**
* Individual flag labels.
*/
flags: Array<FlagLabel>;
/**
* Leave a comment along with any update, explaining the changes that were made.
*
* @default `true`
*/
comment: boolean;

/**
* Project name or path.
*/
name: string;
/**
* Individual flag labels.
*/
flags: Array<FlagLabel>;

/**
* Remote APIs.
*/
remote: RemoteOptions;
/**
* Project name or path.
*/
name: string;

/**
* Grouped state labels.
*/
states: Array<StateLabel>;
}>;
/**
* Remote APIs.
*/
remote: RemoteOptions;

/**
* Grouped state labels.
*/
states: Array<StateLabel>;
}

/**
* Config data for the app, loaded from CLI or DOM.
*/
export interface ConfigData {
logger: LoggerConfig;
projects: Array<ProjectConfig>;
}

/**
Expand All @@ -54,6 +65,7 @@ export function initConfig(): ConfigData {
},
projects: [{
colors: [],
comment: true,
flags: [],
name: '',
remote: {
Expand Down Expand Up @@ -82,5 +94,11 @@ export function validateConfig(it: unknown): it is ConfigData {
const ajv = new Ajv(SCHEMA_OPTIONS);
ajv.addSchema(SCHEMA_DATA, 'cautious-journey');

return ajv.validate('cautious-journey#/definitions/config', it) === true;
if (ajv.validate('cautious-journey#/definitions/config', it) === true) {
return true;
} else {
/* eslint-disable-next-line */
console.error('invalid config', ajv.errors, it);
return false;
}
}
92 changes: 65 additions & 27 deletions src/config/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ $id: cautious-journey
definitions:
label-ref:
type: object
required:
- name
properties:
name:
type: string

change-set:
type: object
required:
- adds
- removes
properties:
adds:
type: array
Expand All @@ -23,6 +28,9 @@ definitions:

base-label:
type: object
required:
- name
- requires
properties:
color:
type: string
Expand Down Expand Up @@ -59,7 +67,13 @@ definitions:
- $ref: "#/definitions/change-set"
- $ref: "#/definitions/base-label"
- type: object
required:
- divider
- values
properties:
divider:
type: string
default: "/"
values:
type: array
items:
Expand All @@ -71,45 +85,69 @@ definitions:
- $ref: "#/definitions/change-set"
- $ref: "#/definitions/base-label"
- type: object
required:
- becomes
properties:
becomes:
type: array
items:
$ref: "#/definitions/state-change"
default: []

project:
type: object
required:
- colors
- comment
- flags
- name
- remote
- states
properties:
colors:
type: array
items:
type: string
comment:
type: boolean
default: true
flags:
type: array
items:
$ref: "#/definitions/flag-label"
default: []
name:
type: string
remote:
type: object
states:
type: array
items:
$ref: "#/definitions/state-label"
default: []

logger:
type: object
required:
- level
- name
properties:
level:
type: string
name:
type: string

config:
type: object
required:
- logger
- projects
properties:
logger:
type: object
properties:
level:
type: string
name:
type: string
$ref: "#/definitions/logger"
projects:
type: array
items:
type: object
properties:
colors:
type: array
items:
type: string
flags:
type: array
items:
$ref: "#/definitions/flag-label"
default: []
name:
type: string
remote:
type: object
states:
type: array
items:
$ref: "#/definitions/state-label"
default: []

$ref: "#/definitions/project"

type: object
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const STATUS_ERROR = 1;
*/
main(process.argv).then((status) => process.exit(status)).catch((err: Error) => {
// eslint-disable-next-line no-console
console.error('uncaught error during main:', err);
console.error('uncaught error during main:', err.message);
process.exit(STATUS_ERROR);
});

8 changes: 5 additions & 3 deletions src/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export interface StateValue extends BaseLabel {
* Grouped labels: the equivalent of a radio group.
*/
export interface StateLabel extends BaseLabel {
divider: string;

/**
* Values for this state.
*/
Expand All @@ -97,12 +99,12 @@ export function getLabelNames(flags: Array<FlagLabel>, states: Array<StateLabel>
return new Set(labels);
}

export function splitValueName(name: string): Array<string> {
return name.split('/');
export function splitValueName(state: StateLabel, name: string): Array<string> {
return name.split(state.divider);
}

export function getValueName(state: StateLabel, value: StateValue): string {
return `${state.name}/${value.name}`;
return `${state.name}${state.divider}${value.name}`;
}

/**
Expand Down

0 comments on commit 2feb5a3

Please sign in to comment.