Skip to content

Commit

Permalink
feat(build): move from tsc and rollup to tsup
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Apr 13, 2021
1 parent 2d40bdf commit cc6500c
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 147 deletions.
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ typings/
# dotenv environment variables file
.env*

lib
.cache

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

# Cache for parcel serverl in example
.cache

package-lock.json

# examples artefacts
examples/*.ts
examples/model/*

!docs/src/lib
!samples/svelte-query/src/lib
package-lock.json
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*
!lib/**/*
!dist/**/*
!README.md
!package.json
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"version": "5.0.0-alpha.6",
"license": "MIT",
"files": [
"lib"
"dist"
],
"bin": {
"orval": "lib/bin/orval.js"
"orval": "dist/bin/orval.js"
},
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"main": "dist/index.js",
"keywords": [
"rest",
"client",
Expand All @@ -35,13 +34,11 @@
"url": "https://github.com/anymaniax/orval"
},
"scripts": {
"rollup": "rollup -c rollup.config.js",
"prebuild": "rimraf ./lib && mkdir lib",
"build": "tsc && yarn rollup",
"build": "tsup ./src/bin/orval.ts ./src/index.ts --minify --clean",
"lint": "eslint src/**/*.ts",
"format": "prettier --write 'src/**/*.{js,ts}'",
"release": "dotenv release-it",
"generate-api": "node ./lib/bin/orval.js --config ./samples/react-app-with-react-query/orval.config.js",
"generate-api": "node ./dist/bin/orval.js --config ./samples/react-app-with-react-query/orval.config.js",
"prepare": "husky install",
"commitlint": "commitlint"
},
Expand Down Expand Up @@ -74,8 +71,7 @@
"prettier": "^2.2.1",
"release-it": "^14.6.0",
"rimraf": "^3.0.2",
"rollup": "^2.45.1",
"rollup-plugin-typescript2": "^0.30.0",
"tsup": "^4.8.21",
"typescript": "^4.2.4"
},
"dependencies": {
Expand Down
15 changes: 0 additions & 15 deletions rollup.config.js

This file was deleted.

12 changes: 7 additions & 5 deletions src/bin/orval.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import program from 'commander';
import pkg from '../../package.json';
import { generateConfig, generateSpec } from '../generate';
import { isString } from '../utils/is';
import { startMessage } from '../utils/messages/logs';
import { getPackage } from '../utils/packages';

const { name, version, description } = getPackage();
startMessage({
name: pkg.name,
version: pkg.version,
description: pkg.description,
});

startMessage({ name, version, description });

program.version(version);
program.version(pkg.version);

program
.command('default [open-api-file]', { isDefault: true, hidden: true })
Expand Down
7 changes: 4 additions & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { pathExists } from 'fs-extra';
import { dirname, join } from 'upath';
import { dirname, resolve } from 'upath';
import { importSpecs } from './core/importers/specs';
import { writeSpecs } from './core/writers/specs';
import { ExternalConfigFile, Options } from './types';
import { catchError } from './utils/errors';
import { dynamicImport } from './utils/imports';

export const generateSpec = async (
workspace: string,
Expand All @@ -22,13 +23,13 @@ export const generateConfig = async (
path: string = './orval.config.js',
projectName?: string,
) => {
const fullPath = join(process.cwd(), path);
const fullPath = resolve(process.cwd(), path);

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

const config: ExternalConfigFile = require(fullPath);
const config = await dynamicImport<ExternalConfigFile>(fullPath);

const workspace = dirname(fullPath);

Expand Down
25 changes: 17 additions & 8 deletions src/utils/imports.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { join } from 'upath';
import { resolve } from 'upath';
import { isObject, isString } from './is';

export const dynamicImport = async <T>(
toImport: T | string,
from = process.cwd(),
): Promise<T> => {
if (isString(toImport)) {
const data = await import(join(from, toImport));
if (!toImport) {
return toImport as T;
}

const path = resolve(from, toImport);

if (isObject(data)) {
return (data as any).default as T;
try {
if (isString(toImport)) {
const data = await import(path);
if (isObject(data) && data.default) {
return (data as any).default as T;
}

return data;
}

return data;
return Promise.resolve<T>(toImport);
} catch (error) {
throw `Oups... 🍻. Path: ${path} => ${error}`;
}

return Promise.resolve<T>(toImport);
};
3 changes: 1 addition & 2 deletions src/utils/messages/inline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InfoObject } from 'openapi3-ts';

const pkg = require('../../../package.json');
import pkg from '../../../package.json';

export const getFilesHeader = ({ title, description, version }: InfoObject) =>
`/*\n * Generated by ${pkg.name} v${
Expand Down
19 changes: 0 additions & 19 deletions src/utils/packages.ts

This file was deleted.

4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exclude": ["node_modules", "lib", "__tests__", "**/*.test*", "**/*.spec*"],
"exclude": ["node_modules", "dist", "__tests__", "**/*.test*", "**/*.spec*"],
"include": ["src/**/*"],
"compilerOptions": {
"skipLibCheck": true,
Expand All @@ -8,8 +8,6 @@
"lib": ["es2015", "dom", "es2016.array.include", "es2017.object"],
"declaration": true,
"declarationMap": true,
"rootDir": "./src",
"outDir": "./lib",
"downlevelIteration": true,
"strict": true,
"noUnusedLocals": true,
Expand Down
Loading

0 comments on commit cc6500c

Please sign in to comment.