Skip to content

Commit cc6500c

Browse files
committed
feat(build): move from tsc and rollup to tsup
1 parent 2d40bdf commit cc6500c

11 files changed

+217
-147
lines changed

.gitignore

+1-9
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,11 @@ typings/
8989
# dotenv environment variables file
9090
.env*
9191

92-
lib
9392
.cache
9493

9594
# End of https://www.gitignore.io/api/node,macos,vscode
9695

9796
# Cache for parcel serverl in example
9897
.cache
9998

100-
package-lock.json
101-
102-
# examples artefacts
103-
examples/*.ts
104-
examples/model/*
105-
106-
!docs/src/lib
107-
!samples/svelte-query/src/lib
99+
package-lock.json

.npmignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*
2-
!lib/**/*
2+
!dist/**/*
33
!README.md
44
!package.json

package.json

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
"version": "5.0.0-alpha.6",
55
"license": "MIT",
66
"files": [
7-
"lib"
7+
"dist"
88
],
99
"bin": {
10-
"orval": "lib/bin/orval.js"
10+
"orval": "dist/bin/orval.js"
1111
},
12-
"main": "lib/index.js",
13-
"typings": "lib/index.d.ts",
12+
"main": "dist/index.js",
1413
"keywords": [
1514
"rest",
1615
"client",
@@ -35,13 +34,11 @@
3534
"url": "https://github.com/anymaniax/orval"
3635
},
3736
"scripts": {
38-
"rollup": "rollup -c rollup.config.js",
39-
"prebuild": "rimraf ./lib && mkdir lib",
40-
"build": "tsc && yarn rollup",
37+
"build": "tsup ./src/bin/orval.ts ./src/index.ts --minify --clean",
4138
"lint": "eslint src/**/*.ts",
4239
"format": "prettier --write 'src/**/*.{js,ts}'",
4340
"release": "dotenv release-it",
44-
"generate-api": "node ./lib/bin/orval.js --config ./samples/react-app-with-react-query/orval.config.js",
41+
"generate-api": "node ./dist/bin/orval.js --config ./samples/react-app-with-react-query/orval.config.js",
4542
"prepare": "husky install",
4643
"commitlint": "commitlint"
4744
},
@@ -74,8 +71,7 @@
7471
"prettier": "^2.2.1",
7572
"release-it": "^14.6.0",
7673
"rimraf": "^3.0.2",
77-
"rollup": "^2.45.1",
78-
"rollup-plugin-typescript2": "^0.30.0",
74+
"tsup": "^4.8.21",
7975
"typescript": "^4.2.4"
8076
},
8177
"dependencies": {

rollup.config.js

-15
This file was deleted.

src/bin/orval.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import program from 'commander';
2+
import pkg from '../../package.json';
23
import { generateConfig, generateSpec } from '../generate';
34
import { isString } from '../utils/is';
45
import { startMessage } from '../utils/messages/logs';
5-
import { getPackage } from '../utils/packages';
66

7-
const { name, version, description } = getPackage();
7+
startMessage({
8+
name: pkg.name,
9+
version: pkg.version,
10+
description: pkg.description,
11+
});
812

9-
startMessage({ name, version, description });
10-
11-
program.version(version);
13+
program.version(pkg.version);
1214

1315
program
1416
.command('default [open-api-file]', { isDefault: true, hidden: true })

src/generate.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { pathExists } from 'fs-extra';
2-
import { dirname, join } from 'upath';
2+
import { dirname, resolve } from 'upath';
33
import { importSpecs } from './core/importers/specs';
44
import { writeSpecs } from './core/writers/specs';
55
import { ExternalConfigFile, Options } from './types';
66
import { catchError } from './utils/errors';
7+
import { dynamicImport } from './utils/imports';
78

89
export const generateSpec = async (
910
workspace: string,
@@ -22,13 +23,13 @@ export const generateConfig = async (
2223
path: string = './orval.config.js',
2324
projectName?: string,
2425
) => {
25-
const fullPath = join(process.cwd(), path);
26+
const fullPath = resolve(process.cwd(), path);
2627

2728
if (!(await pathExists(fullPath))) {
2829
catchError('orval config not found');
2930
}
3031

31-
const config: ExternalConfigFile = require(fullPath);
32+
const config = await dynamicImport<ExternalConfigFile>(fullPath);
3233

3334
const workspace = dirname(fullPath);
3435

src/utils/imports.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
import { join } from 'upath';
1+
import { resolve } from 'upath';
22
import { isObject, isString } from './is';
33

44
export const dynamicImport = async <T>(
55
toImport: T | string,
66
from = process.cwd(),
77
): Promise<T> => {
8-
if (isString(toImport)) {
9-
const data = await import(join(from, toImport));
8+
if (!toImport) {
9+
return toImport as T;
10+
}
11+
12+
const path = resolve(from, toImport);
1013

11-
if (isObject(data)) {
12-
return (data as any).default as T;
14+
try {
15+
if (isString(toImport)) {
16+
const data = await import(path);
17+
if (isObject(data) && data.default) {
18+
return (data as any).default as T;
19+
}
20+
21+
return data;
1322
}
1423

15-
return data;
24+
return Promise.resolve<T>(toImport);
25+
} catch (error) {
26+
throw `Oups... 🍻. Path: ${path} => ${error}`;
1627
}
17-
18-
return Promise.resolve<T>(toImport);
1928
};

src/utils/messages/inline.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { InfoObject } from 'openapi3-ts';
2-
3-
const pkg = require('../../../package.json');
2+
import pkg from '../../../package.json';
43

54
export const getFilesHeader = ({ title, description, version }: InfoObject) =>
65
`/*\n * Generated by ${pkg.name} v${

src/utils/packages.ts

-19
This file was deleted.

tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"exclude": ["node_modules", "lib", "__tests__", "**/*.test*", "**/*.spec*"],
2+
"exclude": ["node_modules", "dist", "__tests__", "**/*.test*", "**/*.spec*"],
33
"include": ["src/**/*"],
44
"compilerOptions": {
55
"skipLibCheck": true,
@@ -8,8 +8,6 @@
88
"lib": ["es2015", "dom", "es2016.array.include", "es2017.object"],
99
"declaration": true,
1010
"declarationMap": true,
11-
"rootDir": "./src",
12-
"outDir": "./lib",
1311
"downlevelIteration": true,
1412
"strict": true,
1513
"noUnusedLocals": true,

0 commit comments

Comments
 (0)