Files
payloadcms/test/generateTypes.js
James Mikrut c11bcd1416 feat: swc register (#1779)
* feat: implements esbuild and removes babel

* chore: implements esbuild-register

* chore: tests passing

* chore: implements @swc/jest for tests

* feat: implements swc

* chore: removes build and relies on swc/register only

* chore: converts some exports

* chore: flattens ts configs

* chore: allows tsx in swc

* chore: converts more exports into js

* chore: restores payload module.exports

* chore: removes unused dependency
2023-01-04 10:11:26 -05:00

37 lines
1004 B
JavaScript

const path = require('path');
const fs = require('fs');
const { generateTypes } = require('../dist/bin/generateTypes');
const [testConfigDir] = process.argv.slice(2);
let testDir;
if (testConfigDir) {
testDir = path.resolve(__dirname, testConfigDir);
setPaths(testDir);
generateTypes();
} else {
// Generate types for entire directory
testDir = __dirname;
fs.readdirSync(__dirname, { withFileTypes: true })
.filter((f) => f.isDirectory())
.forEach((dir) => {
const suiteDir = path.resolve(testDir, dir.name);
const configFound = setPaths(suiteDir);
if (configFound) generateTypes();
});
}
// Set config path and TS output path using test dir
function setPaths(dir) {
const configPath = path.resolve(dir, 'config.ts');
const outputPath = path.resolve(dir, 'payload-types.ts');
if (fs.existsSync(configPath)) {
process.env.PAYLOAD_CONFIG_PATH = configPath;
process.env.PAYLOAD_TS_OUTPUT_PATH = outputPath;
return true;
}
return false;
}