starting watch command
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
*.md
|
||||
*.mustache
|
||||
apis/baseapi.ts
|
||||
apis/exception.ts
|
||||
auth/*
|
||||
http/*
|
||||
middleware.ts
|
||||
servers.ts
|
||||
util.ts
|
||||
configuration.ts
|
||||
rxjsStub.ts
|
||||
.gitignore
|
||||
apis/*.ts
|
||||
!apis/*.client.ts
|
||||
models/*.ts
|
||||
!models/*.model.ts
|
||||
!index.ts
|
||||
!**/index.ts
|
||||
types/ObjectParamAPI.ts
|
||||
types/ObservableAPI.ts
|
||||
types/PromiseAPI.ts
|
||||
git_push.sh
|
||||
package.json
|
||||
tsconfig.json
|
||||
@@ -276,13 +276,14 @@ export class DefaultApiClient {
|
||||
|
||||
/**
|
||||
* Get a batch set of entities given an array of entityRefs.
|
||||
* @param filter Filter for just the entities defined by this filter.
|
||||
* @param getEntitiesByRefsRequest
|
||||
*/
|
||||
public async getEntitiesByRefs(
|
||||
// @ts-ignore
|
||||
request: {
|
||||
body: GetEntitiesByRefsRequest;
|
||||
query?: {
|
||||
query: {
|
||||
filter?: Array<string>;
|
||||
};
|
||||
},
|
||||
@@ -290,9 +291,11 @@ export class DefaultApiClient {
|
||||
): Promise<TypedResponse<EntitiesBatchResponse>> {
|
||||
const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);
|
||||
|
||||
const uriTemplate = `/entities/by-refs/{?filter*}`;
|
||||
const uriTemplate = `/entities/by-refs{?filter*}`;
|
||||
|
||||
const uri = parser.parse(uriTemplate).expand({ ...request.query });
|
||||
const uri = parser.parse(uriTemplate).expand({
|
||||
...request.query,
|
||||
});
|
||||
|
||||
return await this.fetchApi.fetch(`${baseUrl}${uri}`, {
|
||||
headers: {
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
"@stoplight/types": "^14.0.0",
|
||||
"@useoptic/openapi-utilities": "^0.55.0",
|
||||
"chalk": "^4.0.0",
|
||||
"chokidar": "^3.6.0",
|
||||
"codeowners-utils": "^1.0.2",
|
||||
"command-exists": "^1.2.9",
|
||||
"commander": "^12.0.0",
|
||||
|
||||
@@ -58,6 +58,8 @@ function registerPackageCommand(program: Command) {
|
||||
.description(
|
||||
'Additional properties that can be passed to @openapitools/openapi-generator-cli',
|
||||
)
|
||||
.option('--watch')
|
||||
.description('Watch the OpenAPI spec for changes and regenerate on save.')
|
||||
.action(
|
||||
lazy(() =>
|
||||
import('./package/schema/openapi/generate').then(m => m.command),
|
||||
|
||||
@@ -30,6 +30,7 @@ import { getPathToCurrentOpenApiSpec } from '../../../../../lib/openapi/helpers'
|
||||
async function generate(
|
||||
outputDirectory: string,
|
||||
clientAdditionalProperties?: string,
|
||||
abortSignal?: AbortController,
|
||||
) {
|
||||
const resolvedOpenapiPath = await getPathToCurrentOpenApiSpec();
|
||||
const resolvedOutputDirectory = cliPaths.resolveTargetRoot(
|
||||
@@ -69,6 +70,7 @@ async function generate(
|
||||
additionalProperties,
|
||||
],
|
||||
{
|
||||
signal: abortSignal?.signal,
|
||||
maxBuffer: Number.MAX_VALUE,
|
||||
cwd: resolvePackagePath('@backstage/repo-tools'),
|
||||
env: {
|
||||
@@ -83,7 +85,9 @@ async function generate(
|
||||
|
||||
const prettier = cliPaths.resolveTargetRoot('node_modules/.bin/prettier');
|
||||
if (prettier) {
|
||||
await exec(`${prettier} --write ${resolvedOutputDirectory}`);
|
||||
await exec(`${prettier} --write ${resolvedOutputDirectory}`, [], {
|
||||
signal: abortSignal?.signal,
|
||||
});
|
||||
}
|
||||
|
||||
fs.removeSync(resolve(resolvedOutputDirectory, '.openapi-generator-ignore'));
|
||||
@@ -97,14 +101,18 @@ async function generate(
|
||||
export async function command(
|
||||
outputPackage: string,
|
||||
clientAdditionalProperties?: string,
|
||||
abortSignal?: AbortController,
|
||||
): Promise<void> {
|
||||
try {
|
||||
await generate(outputPackage, clientAdditionalProperties);
|
||||
await generate(outputPackage, clientAdditionalProperties, abortSignal);
|
||||
console.log(
|
||||
chalk.green(`Generated client in ${outputPackage}/${OUTPUT_PATH}`),
|
||||
);
|
||||
} catch (err) {
|
||||
console.log();
|
||||
if (err.name === 'AbortError') {
|
||||
console.debug('Server generation aborted.');
|
||||
return;
|
||||
}
|
||||
console.log(chalk.red(`Client generation failed:`));
|
||||
console.log(err);
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import chalk from 'chalk';
|
||||
import { OptionValues } from 'commander';
|
||||
import { command as generateClient } from './client';
|
||||
import { command as generateServer } from './server';
|
||||
import chokidar from 'chokidar';
|
||||
import { getPathToCurrentOpenApiSpec } from '../../../../../lib/openapi/helpers';
|
||||
|
||||
export async function command(opts: OptionValues) {
|
||||
if (!opts.clientPackage && !opts.server) {
|
||||
@@ -25,10 +27,37 @@ export async function command(opts: OptionValues) {
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (opts.clientPackage) {
|
||||
await generateClient(opts.clientPackage, opts.clientAdditionalProperties);
|
||||
}
|
||||
if (opts.server) {
|
||||
await generateServer();
|
||||
|
||||
const sharedCommand = async (abortSignal?: AbortController) => {
|
||||
if (opts.clientPackage) {
|
||||
await generateClient(
|
||||
opts.clientPackage,
|
||||
opts.clientAdditionalProperties,
|
||||
abortSignal,
|
||||
);
|
||||
}
|
||||
if (opts.server) {
|
||||
await generateServer(abortSignal);
|
||||
}
|
||||
};
|
||||
|
||||
if (opts.watch) {
|
||||
try {
|
||||
const resolvedOpenapiPath = await getPathToCurrentOpenApiSpec();
|
||||
let abortController = new AbortController();
|
||||
chokidar.watch(resolvedOpenapiPath).on('change', async () => {
|
||||
console.log('detected changes');
|
||||
abortController.abort();
|
||||
await sharedCommand(abortController);
|
||||
abortController = new AbortController();
|
||||
});
|
||||
await sharedCommand();
|
||||
await new Promise(() => {});
|
||||
} catch (err) {
|
||||
console.error(chalk.red('Error: ', err));
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
await sharedCommand();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import { getPathToCurrentOpenApiSpec } from '../../../../../lib/openapi/helpers'
|
||||
|
||||
const exec = promisify(execCb);
|
||||
|
||||
async function generate() {
|
||||
async function generate(abortSignal?: AbortController) {
|
||||
const openapiPath = await getPathToCurrentOpenApiSpec();
|
||||
const yaml = YAML.load(await fs.readFile(openapiPath, 'utf8'));
|
||||
|
||||
@@ -50,19 +50,26 @@ export const createOpenApiRouter = async (
|
||||
`,
|
||||
);
|
||||
|
||||
await exec(`yarn backstage-cli package lint --fix ${tsPath}`);
|
||||
await exec(`yarn backstage-cli package lint --fix ${tsPath}`, {
|
||||
signal: abortSignal?.signal,
|
||||
});
|
||||
if (await cliPaths.resolveTargetRoot('node_modules/.bin/prettier')) {
|
||||
await exec(`yarn prettier --write ${tsPath}`, {
|
||||
cwd: cliPaths.targetRoot,
|
||||
signal: abortSignal?.signal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function command(): Promise<void> {
|
||||
export async function command(abortSignal?: AbortController): Promise<void> {
|
||||
try {
|
||||
await generate();
|
||||
console.log(chalk.green('Generated all files.'));
|
||||
await generate(abortSignal);
|
||||
console.log(chalk.green('Generated server files.'));
|
||||
} catch (err) {
|
||||
if (err.name === 'AbortError') {
|
||||
console.debug('Server generation aborted.');
|
||||
return;
|
||||
}
|
||||
console.log(chalk.red(`OpenAPI server stub generation failed.`));
|
||||
console.log(err.message);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user