Skip to content

Commit 0f053ec

Browse files
committed
Improve remote
1 parent 7c5c0d4 commit 0f053ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+133809
-15371
lines changed

.eslintignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
bin
22
coverage
33
dist
4-
example/*.ts
54
examples
6-
**/generated/*
7-
**/expected/*
8-
**/specs/*
5+
test/fixtures

.eslintrc.cjs

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ module.exports = {
44
parserOptions: {
55
project: ["./tsconfig.json"],
66
},
7-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
7+
extends: ["plugin:prettier/recommended", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
88
plugins: ["@typescript-eslint"],
9+
overrides: [
10+
{
11+
files: ["**/*.test.*"],
12+
rules: {
13+
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
14+
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
15+
},
16+
},
17+
],
918
};

.github/workflows/ci.yml

+30-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
pull_request:
88

9+
concurrency:
10+
group: ci-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
lint:
1115
runs-on: ubuntu-22.04
@@ -18,11 +22,22 @@ jobs:
1822
- run: pnpm i
1923
- run: npm run lint
2024
test:
25+
runs-on: ubuntu-22.04
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: pnpm/action-setup@v2
29+
with:
30+
version: 7
31+
- uses: actions/setup-node@v3
32+
with:
33+
node-version: 18
34+
- run: pnpm i
35+
- run: npm run test:coverage
36+
test-node-versions:
37+
runs-on: ubuntu-22.04
2138
strategy:
2239
matrix:
23-
node-version: [16.x, 18.x]
24-
os: [macos-12, ubuntu-22.04, windows-2022]
25-
runs-on: ${{ matrix.os }}
40+
node-version: [16.x, 19.x]
2641
steps:
2742
- uses: actions/checkout@v3
2843
- uses: pnpm/action-setup@v2
@@ -33,8 +48,15 @@ jobs:
3348
node-version: ${{ matrix.node-version }}
3449
- run: pnpm i
3550
- run: npm test
36-
if: matrix.os != 'macos-12' || matrix.node-version != '18.x'
37-
- run: npm run test:coverage
38-
if: matrix.os == 'macos-12' && matrix.node-version == '18.x'
39-
- uses: codecov/codecov-action@v3
40-
if: matrix.os == 'macos-12' && matrix.node-version == '18.x'
51+
test-macos:
52+
runs-on: macos-12
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: pnpm/action-setup@v2
56+
with:
57+
version: 7
58+
- uses: actions/setup-node@v3
59+
with:
60+
version: 18
61+
- run: pnpm i
62+
- run: npm test

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
2-
test/fixtures/*.yaml
32
coverage/
43
dist
54
node_modules
5+
test/fixtures/**/*

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
examples/**/*.ts
2+
test/fixtures/**/*
23
*.md
34
*.yaml
45
*.yml

bin/cli.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { URL } from "node:url";
55
import glob from "fast-glob";
66
import parser from "yargs-parser";
77
import openapiTS from "../dist/index.js";
8-
9-
const GREEN = "\u001b[32m";
10-
const BOLD = "\u001b[1m";
11-
const RESET = "\u001b[0m";
8+
import { c, error } from "../dist/utils.js";
129

1310
const HELP = `Usage
1411
$ openapi-typescript [input] [options]
@@ -38,11 +35,6 @@ const HTTP_RE = /^https?:\/\//;
3835

3936
const timeStart = process.hrtime();
4037

41-
function errorAndExit(errorMessage) {
42-
process.exitCode = 1; // needed for async functions
43-
throw new Error(errorMessage);
44-
}
45-
4638
const [, , ...args] = process.argv;
4739
if (args.includes("-ap")) errorAndExit(`The -ap alias has been deprecated. Use "--additional-properties" instead.`);
4840
if (args.includes("-it")) errorAndExit(`The -it alias has been deprecated. Use "--immutable-types" instead.`);
@@ -123,7 +115,7 @@ async function generateSchema(pathToSpec) {
123115

124116
const timeEnd = process.hrtime(timeStart);
125117
const time = timeEnd[0] + Math.round(timeEnd[1] / 1e6);
126-
console.log(`🚀 ${GREEN}${pathToSpec} -> ${BOLD}${outputFilePath}${RESET}${GREEN} [${time}ms]${RESET}`);
118+
console.log(`🚀 ${c.green(`${pathToSpec} ${c.bold(outputFilePath)}`)} ${c.dim(`[${time}ms]`)}`);
127119
} else {
128120
process.stdout.write(result);
129121
// if stdout, (still) don’t log anything to console!
@@ -147,9 +139,7 @@ async function main() {
147139
let outputFile = new URL(flags.output, CWD);
148140
let outputDir = new URL(".", outputFile);
149141

150-
if (output === OUTPUT_FILE) {
151-
console.info(`✨ ${BOLD}openapi-typescript ${packageJSON.version}${RESET}`); // only log if we’re NOT writing to stdout
152-
}
142+
if (output === OUTPUT_FILE) console.info(`✨ ${c.bold(`openapi-typescript ${packageJSON.version}`)}`); // only log if we’re NOT writing to stdout
153143

154144
const pathToSpec = flags._[0];
155145

@@ -173,12 +163,14 @@ async function main() {
173163

174164
// error: no matches for glob
175165
if (inputSpecPaths.length === 0) {
176-
errorAndExit(`✘ Could not find any specs matching "${pathToSpec}". Please check that the path is correct.`);
166+
error(`Could not find any specs matching "${pathToSpec}". Please check that the path is correct.`);
167+
process.exit(1);
177168
}
178169

179170
// error: tried to glob output to single file
180171
if (isGlob && output === OUTPUT_FILE && fs.existsSync(outputDir) && fs.lstatSync(outputDir).isFile()) {
181-
errorAndExit(`✘ Expected directory for --output if using glob patterns. Received "${flags.output}".`);
172+
error(`Expected directory for --output if using glob patterns. Received "${flags.output}".`);
173+
process.exit(1);
182174
}
183175

184176
// generate schema(s) in parallel

0 commit comments

Comments
 (0)