mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed eslint warning
- Fixed dev and production builds for faster testing
This commit is contained in:
parent
b7c09f9ac8
commit
fe136fd235
@ -19,7 +19,7 @@ jobs:
|
||||
- node_modules
|
||||
- run:
|
||||
name: build
|
||||
command: yarn run build
|
||||
command: yarn run release
|
||||
- run:
|
||||
name: test
|
||||
command: yarn run test:coverage
|
||||
|
||||
@ -2,6 +2,6 @@ language: node_js
|
||||
node_js:
|
||||
- node
|
||||
script:
|
||||
- npm run build
|
||||
- npm run release
|
||||
- npm run test:coverage
|
||||
- npm run codecov
|
||||
|
||||
@ -43,8 +43,10 @@
|
||||
"src/templates/**/*.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"clean": "rimraf ./dist ./test/result ./coverage ./samples/examples",
|
||||
"build": "rollup --config",
|
||||
"clean": "rimraf ./dist ./test/result ./coverage ./samples/examples ./node_modules/.cache",
|
||||
"build": "rollup --config --environment NODE_ENV:development",
|
||||
"build:watch": "rollup --config --environment NODE_ENV:development --watch",
|
||||
"release": "rollup --config --environment NODE_ENV:production",
|
||||
"run": "node ./test/index.js",
|
||||
"test": "jest",
|
||||
"test:update": "jest --updateSnapshot",
|
||||
@ -54,6 +56,7 @@
|
||||
"eslint:fix": "eslint \"./src/**/*.ts\" \"./bin/index.js\" --fix",
|
||||
"prettier": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --check",
|
||||
"prettier:fix": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --write",
|
||||
"prepublish": "yarn run clean && yarn run release",
|
||||
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const commonjs = require('@rollup/plugin-commonjs');
|
||||
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
||||
const { terser } = require('rollup-plugin-terser');
|
||||
const {nodeResolve} = require('@rollup/plugin-node-resolve');
|
||||
const {terser} = require('rollup-plugin-terser');
|
||||
const typescript = require('rollup-plugin-typescript2');
|
||||
const handlebars = require('handlebars');
|
||||
const path = require('path');
|
||||
@ -11,37 +11,49 @@ const fs = require('fs');
|
||||
const pkg = require('./package.json');
|
||||
const external = Object.keys(pkg.dependencies);
|
||||
|
||||
|
||||
/**
|
||||
* Custom plugin to parse handlebar imports and precompile
|
||||
* the template on the fly. This reduces runtime by about
|
||||
* half on large projects.
|
||||
*/
|
||||
function handlebarsPlugin() {
|
||||
return {
|
||||
resolveId(file, importer) {
|
||||
if (file.endsWith('.hbs')) {
|
||||
return path.resolve(path.dirname(importer), file);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
load(file) {
|
||||
if (file.endsWith('.hbs')) {
|
||||
const template = fs.readFileSync(file, 'utf8').toString().trim();
|
||||
const templateSpec = handlebars.precompile(template, {
|
||||
strict: true,
|
||||
noEscape: true,
|
||||
preventIndent: true,
|
||||
knownHelpersOnly: true,
|
||||
knownHelpers: {
|
||||
equals: true,
|
||||
notEquals: true,
|
||||
},
|
||||
});
|
||||
return `export default ${templateSpec};`;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
const handlebarsPlugin = () => ({
|
||||
resolveId: (file, importer) => {
|
||||
if (path.extname(file) === '.hbs') {
|
||||
return path.resolve(path.dirname(importer), file);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
load: (file) => {
|
||||
if (path.extname(file) === '.hbs') {
|
||||
const template = fs.readFileSync(file, 'utf8').toString().trim();
|
||||
const templateSpec = handlebars.precompile(template, {
|
||||
strict: true,
|
||||
noEscape: true,
|
||||
preventIndent: true,
|
||||
knownHelpersOnly: true,
|
||||
knownHelpers: {
|
||||
equals: true,
|
||||
notEquals: true,
|
||||
},
|
||||
});
|
||||
return `export default ${templateSpec};`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
const getPlugins = () => {
|
||||
const plugins = [
|
||||
handlebarsPlugin(),
|
||||
typescript(),
|
||||
nodeResolve(),
|
||||
commonjs(),
|
||||
]
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return plugins;
|
||||
}
|
||||
return [...plugins, terser()];
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -59,17 +71,5 @@ export default {
|
||||
'handlebars/runtime',
|
||||
...external,
|
||||
],
|
||||
plugins: [
|
||||
handlebarsPlugin(),
|
||||
typescript({
|
||||
clean: true,
|
||||
}),
|
||||
nodeResolve(),
|
||||
commonjs(),
|
||||
terser({
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
plugins: getPlugins(),
|
||||
};
|
||||
|
||||
2
src/typings/hbs.d.ts
vendored
2
src/typings/hbs.d.ts
vendored
@ -10,7 +10,7 @@ declare module '*.hbs' {
|
||||
export default {
|
||||
compiler: [8, '>= 4.3.0'],
|
||||
useData: true,
|
||||
main: function (container, depth0, helpers, partials, data) {
|
||||
main: function () {
|
||||
return '';
|
||||
},
|
||||
};
|
||||
|
||||
@ -21,8 +21,7 @@
|
||||
"strictFunctionTypes": true,
|
||||
"removeComments": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"isolatedModules": true
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
|
||||
"files": [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user