diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index af32ca5b..ff1e9f15 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,22 +11,23 @@ jobs: name: Packages runs-on: ubuntu-latest steps: - - uses: actions/setup-node@v3 - with: - node-version: 20.x - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm - run: SKIP_GENAPI=1 npm ci genApi: name: Generate APIs runs-on: ubuntu-latest steps: - - uses: actions/setup-node@v3 - with: - node-version: 20.x - uses: actions/checkout@v4 - - run: SKIP_GENAPI=1 npm ci - - run: npm run postinstall - - uses: actions/upload-artifact@v3 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm + - run: npm ci + - uses: actions/upload-artifact@v4 with: name: apis path: ./src/lib/apis/generated @@ -35,12 +36,13 @@ jobs: runs-on: ubuntu-latest needs: [packages, genApi] steps: - - uses: actions/setup-node@v3 - with: - node-version: 20.x - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm - run: SKIP_GENAPI=1 npm ci - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: apis path: ./src/lib/apis/generated @@ -52,12 +54,13 @@ jobs: runs-on: ubuntu-latest needs: [packages, genApi] steps: - - uses: actions/setup-node@v3 - with: - node-version: 20.x - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm - run: SKIP_GENAPI=1 npm ci - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: apis path: ./src/lib/apis/generated @@ -67,12 +70,13 @@ jobs: runs-on: ubuntu-latest needs: [packages, genApi] steps: - - uses: actions/setup-node@v3 - with: - node-version: 20.x - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: npm - run: SKIP_GENAPI=1 npm ci - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: apis path: ./src/lib/apis/generated diff --git a/package.json b/package.json index 094aacca..753a776e 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,9 @@ "lint": "eslint --fix --ext .ts,.vue src", "lint:nofix": "eslint --ext .ts,.vue src", "type-check": "vue-tsc --noEmit", - "fetch-openapi": "node scripts/fetchOpenapi.js", "gen-api": "node scripts/generateApi.js", - "start-mock": "prism mock -p 4010 -d scripts/traPortfolio.v1.yaml", - "clean": "rimraf scripts/traPorfolio.v1.yaml src/lib/apis/generated", - "postinstall": "npm run fetch-openapi && npm run gen-api" + "start-mock": "prism mock -p 4010 -d https://raw.githubusercontent.com/traPtitech/traPortfolio/main/docs/swagger/traPortfolio.v1.yaml", + "postinstall": "npm run gen-api" }, "dependencies": { "@iconify/iconify": "^3.1.1", diff --git a/scripts/fetchOpenapi.js b/scripts/fetchOpenapi.js deleted file mode 100644 index 3d6ec81e..00000000 --- a/scripts/fetchOpenapi.js +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -/* eslint-disable no-undef */ -const fetch = require('node-fetch') -const fs = require('fs').promises -const path = require('path') - -const URL = - 'https://raw.githubusercontent.com/traPtitech/traPortfolio/main/docs/swagger/traPortfolio.v1.yaml' -const dist = './traPortfolio.v1.yaml' - -if (process.env.SKIP_GENAPI) { - // eslint-disable-next-line no-console - console.log('Skipped fetching openapi.') - return -} - -;(async () => { - const res = await fetch(URL) - const body = await res.text() - await fs.writeFile(path.resolve(__dirname, dist), body) -})() diff --git a/scripts/generateApi.js b/scripts/generateApi.js index bba7a69a..ba233e6b 100644 --- a/scripts/generateApi.js +++ b/scripts/generateApi.js @@ -7,7 +7,7 @@ const { promisify } = require('util') const execPromise = promisify(exec) const addApis = require('./addApis') -const SWAGGER_PATH = 'scripts/traPortfolio.v1.yaml' +const SWAGGER_PATH = 'https://raw.githubusercontent.com/traPtitech/traPortfolio/main/docs/swagger/traPortfolio.v1.yaml' const GENERATED_DIR = 'src/lib/apis/generated' const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx'