Skip to content

Commit

Permalink
fix(build): autogen生成時にbackendを2度buildしているのを修正 (misskey-dev#14309)
Browse files Browse the repository at this point in the history
* fix(build): autogen生成時にbackendを2度buildしているのを修正

* fix

* fix
  • Loading branch information
kakkokari-gtyih authored Jul 27, 2024
1 parent 0d76842 commit 46d96c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build-assets": "node ./scripts/build-assets.mjs",
"build": "pnpm build-pre && pnpm -r build && pnpm build-assets",
"build-storybook": "pnpm --filter frontend build-storybook",
"build-misskey-js-with-types": "pnpm build-pre && pnpm --filter backend... --filter=!misskey-js build && pnpm --filter backend generate-api-json && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && pnpm --filter misskey-js update-autogen-code && pnpm --filter misskey-js build && pnpm --filter misskey-js api",
"build-misskey-js-with-types": "pnpm build-pre && pnpm --filter backend... --filter=!misskey-js build && pnpm --filter backend generate-api-json --no-build && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && pnpm --filter misskey-js update-autogen-code && pnpm --filter misskey-js build && pnpm --filter misskey-js api",
"start": "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js",
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js",
"init": "pnpm migrate",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"test:e2e": "pnpm build && pnpm build:test && pnpm jest:e2e",
"test-and-coverage": "pnpm jest-and-coverage",
"test-and-coverage:e2e": "pnpm build && pnpm build:test && pnpm jest-and-coverage:e2e",
"generate-api-json": "pnpm build && node ./scripts/generate_api_json.js"
"generate-api-json": "node ./scripts/generate_api_json.js"
},
"optionalDependencies": {
"@swc/core-android-arm64": "1.3.11",
Expand Down
35 changes: 29 additions & 6 deletions packages/backend/scripts/generate_api_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { loadConfig } from '../built/config.js'
import { genOpenapiSpec } from '../built/server/api/openapi/gen-spec.js'
import { writeFileSync } from "node:fs";
import { execa } from 'execa';
import { writeFileSync, existsSync } from "node:fs";

const config = loadConfig();
const spec = genOpenapiSpec(config, true);
async function main() {
if (!process.argv.includes('--no-build')) {
await execa('pnpm', ['run', 'build'], {
stdout: process.stdout,
stderr: process.stderr,
});
}

writeFileSync('./built/api.json', JSON.stringify(spec), 'utf-8');
if (!existsSync('./built')) {
throw new Error('`built` directory does not exist.');
}

/** @type {import('../src/config.js')} */
const { loadConfig } = await import('../built/config.js');

/** @type {import('../src/server/api/openapi/gen-spec.js')} */
const { genOpenapiSpec } = await import('../built/server/api/openapi/gen-spec.js');

const config = loadConfig();
const spec = genOpenapiSpec(config, true);

writeFileSync('./built/api.json', JSON.stringify(spec), 'utf-8');
}

main().catch(e => {
console.error(e);
process.exit(1);
});

0 comments on commit 46d96c7

Please sign in to comment.