Skip to content

Commit e8ecbfd

Browse files
committed
Merge branch 'release/v0.28.10'
2 parents bc92572 + f931ea6 commit e8ecbfd

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zeed",
33
"type": "module",
4-
"version": "0.28.9",
4+
"version": "0.28.10",
55
"packageManager": "pnpm@10.11.0",
66
"description": "🌱 Simple foundation library",
77
"author": {

src/common/schema/export-swift.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ declare module './schema' {
77
interface TypeProps {
88
swiftName?: string
99
swiftProtocol?: string
10+
swiftDesc?: string
1011
}
1112
}
1213

src/common/schema/parse-args.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ export function helpSchemaArgs<T>(schema: Type<T>): string {
8080
if (schema.type !== 'boolean')
8181
s += `=${schema.type}`
8282
lines.push(s)
83-
if (schema._props?.argDesc)
84-
lines.push(` ${schema._props?.argDesc}`)
83+
const desc = schema._props?.argDesc ?? schema._props?.desc
84+
if (desc)
85+
lines.push(` ${desc}`)
8586
})
8687

8788
return lines.join('\n')

src/common/schema/parse-env.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('env.spec', () => {
3434

3535
it('parse prefix', async () => {
3636
const schema = object({
37-
ServiceName: string().default('generic'),
38-
servicePort: number().default(80),
37+
ServiceName: string().default('generic').props({ desc: 'The name of the service' }),
38+
servicePort: number().default(80).props({ desc: 'The port of the service' }),
3939
ServiceFlag: boolean().default(true),
4040
})
4141

@@ -55,9 +55,14 @@ describe('env.spec', () => {
5555
`)
5656

5757
expect(stringFromSchemaEnv(schema, 'APP_', true)).toMatchInlineSnapshot(`
58-
"# APP_SERVICE_NAME=generic
58+
"# The name of the service
59+
# APP_SERVICE_NAME=generic
60+
61+
# The port of the service
5962
# APP_SERVICE_PORT=80
60-
# APP_SERVICE_FLAG=true"
63+
64+
# APP_SERVICE_FLAG=true
65+
"
6166
`)
6267
})
6368
})

src/common/schema/parse-env.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { valueToBoolean, valueToBooleanNotFalse, valueToInteger } from '../data/
55
import { objectFilter, objectMap } from '../data/object'
66
import { isSchemaObjectFlat } from './utils'
77

8-
// declare module './types' {
9-
// interface TypeProps {
10-
// argShort?: string
11-
// }
12-
// }
8+
declare module './schema' {
9+
interface TypeProps {
10+
envDesc?: string
11+
}
12+
}
1313

1414
// eslint-disable-next-line node/prefer-global/process
1515
export function parseSchemaEnv<T>(schema: Type<T>, env: any = process?.env ?? {}, prefix = ''): T {
@@ -41,7 +41,14 @@ export function stringFromSchemaEnv<T>(schema: Type<T>, prefix = '', commentOut
4141
assert(isSchemaObjectFlat(schema), 'schema should be a flat object')
4242
const lines: string[] = []
4343
objectMap(schema._object!, (key, schema) => {
44+
const desc = schema._props?.envDesc ?? schema._props?.desc
45+
if (desc) {
46+
desc.trim().split('\n').forEach((line: string) => {
47+
lines.push(`# ${line.trim()}`)
48+
})
49+
}
4450
lines.push(`${commentOut ? '# ' : ''}${prefix + fromCamelCase(key, '_').toUpperCase()}=${schema._default ?? ''}`)
51+
lines.push('')
4552
}) as T
4653
return lines.join('\n')
4754
}

src/common/schema/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString
44
import { first } from '../data/utils'
55

66
export interface TypeProps {
7+
desc?: string
78
}
89

910
// export interface TypeAssert {

0 commit comments

Comments
 (0)