@openapi-generator-plus/generator-common
Advanced tools
Comparing version 0.15.0 to 0.16.0
@@ -32,3 +32,3 @@ "use strict"; | ||
const sanitizedCombined = combined.replace(/[^a-zA-Z0-9]/g, '_').replace(/_+$/, ''); | ||
return case_transforms_1.camelCase(sanitizedCombined); | ||
return (0, case_transforms_1.camelCase)(sanitizedCombined); | ||
}, | ||
@@ -35,0 +35,0 @@ toSchemaName: (name) => { |
@@ -11,4 +11,4 @@ import { CodegenResult } from '@openapi-generator-plus/testing'; | ||
* @param func a function to handle the generation result | ||
* @param outputPath if specified, generate to the given output path instead of a temp path (must be under cwd) | ||
* @param testName the name of the test | ||
*/ | ||
export declare function testGenerate(result: CodegenResult, func: TestGenerateFunc, outputPath?: string): Promise<void>; | ||
export declare function testGenerate(result: CodegenResult, func: TestGenerateFunc, testName: string): Promise<void>; |
@@ -9,7 +9,8 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const os_1 = __importDefault(require("os")); | ||
const os_1 = require("os"); | ||
const process_1 = require("process"); | ||
const rimraf_1 = __importDefault(require("rimraf")); | ||
function rimrafPromise(path, options) { | ||
return new Promise(function (resolve, reject) { | ||
rimraf_1.default(path, options || {}, function (error) { | ||
(0, rimraf_1.default)(path, options || {}, function (error) { | ||
if (error) { | ||
@@ -28,32 +29,12 @@ reject(error); | ||
* @param func a function to handle the generation result | ||
* @param outputPath if specified, generate to the given output path instead of a temp path (must be under cwd) | ||
* @param testName the name of the test | ||
*/ | ||
async function testGenerate(result, func, outputPath) { | ||
let tmpdir; | ||
let deleteOutput = false; | ||
if (outputPath) { | ||
outputPath = path_1.default.resolve(outputPath); | ||
if (!outputPath.startsWith(process.cwd())) { | ||
throw new Error(`Invalid output path: ${outputPath} not under cwd ${process.cwd()}`); | ||
} | ||
/* Clean the output first */ | ||
await rimrafPromise(outputPath, { disableGlob: true }); | ||
await fs_1.promises.mkdir(outputPath, { recursive: true }); | ||
tmpdir = undefined; | ||
} | ||
else { | ||
tmpdir = await fs_1.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'openapi-generator-plus')); | ||
outputPath = tmpdir; | ||
deleteOutput = true; | ||
} | ||
try { | ||
await result.state.generator.exportTemplates(outputPath, result.doc); | ||
await func(outputPath); | ||
} | ||
finally { | ||
if (tmpdir && deleteOutput) { | ||
await rimrafPromise(tmpdir, { disableGlob: true }); | ||
} | ||
} | ||
async function testGenerate(result, func, testName) { | ||
const outputPath = path_1.default.join((0, os_1.tmpdir)(), 'openapi-generator-plus-generators', path_1.default.basename((0, process_1.cwd)()), testName); | ||
/* Clean the output first */ | ||
await rimrafPromise(outputPath, { disableGlob: true }); | ||
await fs_1.promises.mkdir(outputPath, { recursive: true }); | ||
await result.state.generator.exportTemplates(outputPath, result.doc); | ||
await func(outputPath); | ||
} | ||
exports.testGenerate = testGenerate; |
{ | ||
"name": "@openapi-generator-plus/generator-common", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "Common utilities for openapi-generator-plus generators", | ||
@@ -33,3 +33,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "38b1124afb2161d51174baf23605329ef0ed7db5" | ||
"gitHead": "36347a7a7cc3cd0e63b1828a65e262ba784b53a9" | ||
} |
import { CodegenResult } from '@openapi-generator-plus/testing' | ||
import { promises as fs } from 'fs' | ||
import path from 'path' | ||
import os from 'os' | ||
import { tmpdir } from 'os' | ||
import { cwd } from 'process' | ||
import rimraf from 'rimraf' | ||
@@ -29,32 +30,13 @@ | ||
* @param func a function to handle the generation result | ||
* @param outputPath if specified, generate to the given output path instead of a temp path (must be under cwd) | ||
* @param testName the name of the test | ||
*/ | ||
export async function testGenerate(result: CodegenResult, func: TestGenerateFunc, outputPath?: string): Promise<void> { | ||
let tmpdir: string | undefined | ||
let deleteOutput = false | ||
if (outputPath) { | ||
outputPath = path.resolve(outputPath) | ||
if (!outputPath.startsWith(process.cwd())) { | ||
throw new Error(`Invalid output path: ${outputPath} not under cwd ${process.cwd()}`) | ||
} | ||
export async function testGenerate(result: CodegenResult, func: TestGenerateFunc, testName: string): Promise<void> { | ||
const outputPath = path.join(tmpdir(), 'openapi-generator-plus-generators', path.basename(cwd()), testName) | ||
/* Clean the output first */ | ||
await rimrafPromise(outputPath, { disableGlob: true }) | ||
await fs.mkdir(outputPath, { recursive: true }) | ||
/* Clean the output first */ | ||
await rimrafPromise(outputPath, { disableGlob: true }) | ||
await fs.mkdir(outputPath, { recursive: true }) | ||
tmpdir = undefined | ||
} else { | ||
tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), 'openapi-generator-plus')) | ||
outputPath = tmpdir | ||
deleteOutput = true | ||
} | ||
try { | ||
await result.state.generator.exportTemplates(outputPath, result.doc) | ||
await func(outputPath) | ||
} finally { | ||
if (tmpdir && deleteOutput) { | ||
await rimrafPromise(tmpdir, { disableGlob: true }) | ||
} | ||
} | ||
await result.state.generator.exportTemplates(outputPath, result.doc) | ||
await func(outputPath) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32364
479