-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lockfile): consolidate TS and JSON schema type definitions (#…
…777) * feat(api): creation of a new `list` command * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * Update packages/api/src/commands/list.ts Co-authored-by: Kanad Gupta <[email protected]> * fix: pr feedback * feat(api): addition of a new `uninstall` command * feat(api): outputting `language` to the `list` command * docs: cleanup * refactor: don't use enum * refactor: use json schema for types * ci: add bin script for updating files * chore: update schema.json * fix: use prettier to format schema.json * refactor: rename file, clean up package.json scripts * fix: node 20 compat and `ts-node --esm` not working there * fix: bad merge... git can be mad dumb sometimes * Update packages/api/src/lockfileSchema.ts Co-authored-by: Jon Ursenbach <[email protected]> * chore: rename var Co-Authored-By: Jon Ursenbach <[email protected]> * refactor: use existing map Co-Authored-By: Jon Ursenbach <[email protected]> * chore: stricter type Co-Authored-By: Jon Ursenbach <[email protected]> --------- Co-authored-by: Jon Ursenbach <[email protected]> Co-authored-by: Jon Ursenbach <[email protected]>
- Loading branch information
1 parent
e44461a
commit eb76200
Showing
7 changed files
with
141 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Updates packageInfo.ts and schema.json with the latest package info. | ||
* This script is run every time a new release is tagged. | ||
*/ | ||
import fs from 'node:fs'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies, node/no-extraneous-import | ||
import prettier from 'prettier'; | ||
|
||
import pkg from '../package.json' assert { type: 'json' }; | ||
import { lockfileSchema } from '../src/lockfileSchema.js'; | ||
|
||
async function run() { | ||
// use prettier to format schema file | ||
const prettierConfig = await prettier.resolveConfig(process.cwd()); | ||
const formattedSchema = await prettier.format(JSON.stringify(lockfileSchema), { parser: 'json', ...prettierConfig }); | ||
fs.writeFileSync('./schema.json', formattedSchema); | ||
|
||
const packageInfo = ` | ||
// This file is automatically updated by the build script. | ||
export const PACKAGE_NAME = '${pkg.name}'; | ||
export const PACKAGE_VERSION = '${pkg.version}'; | ||
`.trimStart(); | ||
|
||
fs.writeFileSync('./src/packageInfo.ts', packageInfo); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { FromSchema } from '@readme/api-core/lib'; | ||
|
||
import { SupportedLanguages } from './codegen/factory.js'; | ||
|
||
const lockfileApiSchema = { | ||
type: 'object', | ||
required: ['createdAt', 'identifier', 'installerVersion', 'integrity'], | ||
properties: { | ||
createdAt: { | ||
type: 'string', | ||
format: 'date-time', | ||
description: 'The date that this SDK was installed.', | ||
examples: ['2023-10-19T20:35:39.268Z'], | ||
}, | ||
identifier: { | ||
type: 'string', | ||
description: | ||
"A unique identifier of the API. This'll be used to do imports on `@api/<identifier>` and also where the SDK code will be located in `.api/apis/<identifier>`", | ||
examples: ['petstore'], | ||
}, | ||
installerVersion: { | ||
type: 'string', | ||
description: 'The version of `api` that was used to install this SDK.', | ||
examples: ['7.0.0'], | ||
}, | ||
integrity: { | ||
type: 'string', | ||
description: | ||
'An integrity hash that will be used to determine on `npx api update` calls if the API has changed since the SDK was last generated.', | ||
examples: ['sha512-otRF5TLMeDczSJlrmWLNDHLfmXg+C98oa/I/X2WWycwngh+a6WsbnjTbfwKGRU5DFbagOn2qX2SRvtBGOBRVGg=='], | ||
}, | ||
language: { | ||
type: 'string', | ||
description: 'The language that this SDK was generated for.', | ||
default: SupportedLanguages.JS, | ||
enum: Object.values(SupportedLanguages), | ||
}, | ||
private: { | ||
type: 'boolean', | ||
description: 'Was this SDK installed as a private, unpublished, package to the filesystem?', | ||
}, | ||
source: { | ||
type: 'string', | ||
description: 'The original source that was used to generate the SDK with.', | ||
examples: [ | ||
'https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json', | ||
'./petstore.json', | ||
'@developers/v2.0#nysezql0wwo236', | ||
], | ||
}, | ||
updatedAt: { | ||
type: 'string', | ||
format: 'date-time', | ||
description: 'The date that this SDK was last rebuilt or updated.', | ||
examples: ['2023-10-19T20:35:39.268Z'], | ||
}, | ||
}, | ||
additionalProperties: false, | ||
} as const; | ||
|
||
export const lockfileSchema = { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
title: 'api storage lockfile', | ||
description: 'See https://api.readme.dev/docs', | ||
type: 'object', | ||
required: ['apis'], | ||
additionalProperties: false, | ||
properties: { | ||
$schema: { | ||
type: 'string', | ||
}, | ||
apis: { | ||
type: 'array', | ||
description: 'The list of installed APIs', | ||
items: { | ||
$ref: '#/definitions/api', | ||
}, | ||
}, | ||
}, | ||
definitions: { | ||
api: lockfileApiSchema, | ||
}, | ||
} as const; | ||
|
||
export type Lockfile = FromSchema<typeof lockfileSchema>; | ||
export type LockfileAPI = FromSchema<typeof lockfileApiSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters