From 5c2adf2c503820c21b2d1890133fc13efbb197b4 Mon Sep 17 00:00:00 2001 From: solufa Date: Thu, 30 Jul 2020 09:35:25 +0900 Subject: [PATCH] feat: update aspida --- .github/workflows/nodejs.yml | 13 +++++++-- .gitignore | 3 ++ __tests__/index.spec.ts | 20 ++++++-------- package.json | 2 +- src/buildTemplate.ts | 17 ++---------- src/buildV3.ts | 7 +---- src/cli.ts | 15 ++++++++++ src/cli/build.ts | 53 ------------------------------------ src/cli/command.ts | 9 ------ src/cli/index.ts | 31 --------------------- src/getConfig.ts | 10 ++++--- src/index.ts | 31 ++++++++++++++++++--- src/writeRouteFile.ts | 30 +++++++++++--------- tsconfig.json | 2 +- yarn.lock | 18 ++++++------ 15 files changed, 101 insertions(+), 160 deletions(-) create mode 100644 src/cli.ts delete mode 100644 src/cli/build.ts delete mode 100644 src/cli/command.ts delete mode 100644 src/cli/index.ts diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 6d7c42b5..438e4856 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -4,13 +4,18 @@ on: push jobs: test: - runs-on: ubuntu-latest + name: "Test on Node:${{ matrix.node-version }} OS:${{ matrix.os }}" + runs-on: ${{ matrix.os }} + strategy: + matrix: + node-version: [12, 14] + os: [windows-latest, ubuntu-latest] steps: - uses: actions/checkout@v2 - - name: Use Node.js + - name: setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: - node-version: "12.x" + node-version: ${{ matrix.node-version }} - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" @@ -23,9 +28,11 @@ jobs: ${{ runner.os }}-yarn- - run: yarn --frozen-lockfile - run: yarn lint + if: matrix.os != 'windows-latest' - run: yarn typecheck - run: yarn test --coverage - run: npx codecov + if: github.ref == 'refs/heads/master' && matrix.os == 'ubuntu-latest' && matrix.node-version == 14 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index f06235c4..ec52b072 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ node_modules dist +test2 +reference +aspida.taichi.config.js diff --git a/__tests__/index.spec.ts b/__tests__/index.spec.ts index 3a4684cf..a5b59995 100644 --- a/__tests__/index.spec.ts +++ b/__tests__/index.spec.ts @@ -1,25 +1,23 @@ import fs from 'fs' -import getConfig from '../src/getConfig' -import buildFromScript from '../src' +import { ConfigFile } from '../src/getConfig' +import build from '../src' describe('cli test', () => { beforeAll(() => fs.mkdirSync('_samples')) - afterAll(fn => fs.rmdir('_samples', { recursive: true }, fn)) + afterAll(() => fs.promises.rmdir('_samples', { recursive: true })) test('main', () => { - const configs = getConfig('aspida.config.js') + const configs: ConfigFile[] = require('../aspida.config.js') return Promise.all( configs.map(async config => { - const outputDir = `_${config.output}` - await buildFromScript({ + await build({ ...config, - input: config.input, - output: outputDir - }) + input: `_${config.input}` + })[0] - expect(fs.readFileSync(`${outputDir}/$api.ts`, 'utf8')).toBe( - fs.readFileSync(`${config.output}/$api.ts`, 'utf8') + expect(fs.readFileSync(`_${config.input}/$api.ts`, 'utf8')).toBe( + fs.readFileSync(`${config.input}/$api.ts`, 'utf8').replace(/\r/g, '') ) }) ) diff --git a/package.json b/package.json index 47e54a86..7bf277b0 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "swagger" ], "dependencies": { - "aspida": "^0.19.2", + "aspida": "^0.20.2", "swagger-parser": "^10.0.1", "swagger2openapi": "^6.2.1" }, diff --git a/src/buildTemplate.ts b/src/buildTemplate.ts index 04b81d38..12e0769e 100644 --- a/src/buildTemplate.ts +++ b/src/buildTemplate.ts @@ -2,24 +2,11 @@ import { parse } from 'swagger-parser' import { OpenAPI, OpenAPIV3 } from 'openapi-types' import buildV3 from './buildV3' import resolveExternalRefs from './resolveExternalRefs' - -export type Template = { - baseURL: string - types: string | null - files: { - file: string[] - methods: string - }[] -} +import { Config } from './getConfig' const isV3 = (openapi: OpenAPI.Document): openapi is OpenAPIV3.Document => 'openapi' in openapi -export default async ( - input: string | OpenAPI.Document, - isYaml: boolean, - needsMock: boolean, - needsMockType: boolean -): Promise