Socket
Socket
Sign inDemoInstall

nexus-prisma-generate

Package Overview
Dependencies
92
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

1

dist/config.d.ts
export declare function findDatamodelAndComputeSchema(): string;
export declare function findRootDirectory(): string;

@@ -57,2 +57,36 @@ "use strict";

}
function findRootDirectory() {
var cwd = process.cwd();
var tsConfig = findConfigFile(cwd, 'tsconfig.json');
if (tsConfig) {
return path.dirname(tsConfig);
}
var packageJson = findConfigFile(cwd, 'package.json');
if (packageJson) {
return path.dirname(packageJson);
}
return cwd;
}
exports.findRootDirectory = findRootDirectory;
function findConfigFile(searchPath, configName) {
if (configName === void 0) { configName = 'package.json'; }
return forEachAncestorDirectory(searchPath, function (ancestor) {
var fileName = path.join(ancestor, configName);
return fs.existsSync(fileName) ? fileName : undefined;
});
}
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
function forEachAncestorDirectory(directory, callback) {
while (true) {
var result = callback(directory);
if (result !== undefined) {
return result;
}
var parentPath = path.dirname(directory);
if (parentPath === directory) {
return undefined;
}
directory = parentPath;
}
}
//# sourceMappingURL=config.js.map

2

dist/index.d.ts
#!/usr/bin/env node
export {};
export declare function getImportPathRelativeToOutput(importPath: string, outputDir: string): string;

@@ -7,19 +7,32 @@ #!/usr/bin/env node

var path_1 = require("path");
var meow = require("meow");
var source_helper_1 = require("./source-helper");
var config_1 = require("./config");
run();
function run() {
var cli = meow("\n nexus-prisma-generate prisma-client-dir output\n\n > Generate the TypeScript types for nexus-prisma\n\n -----\n \n Inputs should be relative to the root of your project\n\n `prisma-client-dir`: Path to your prisma-client directory (eg: ./generated/nexus-prisma/)\n `output`: Path to where you want to output the typings (eg: ./generated/nexus-prisma.ts)\n");
main(cli);
function main(cli) {
var _a = cli.input, prismaClientDir = _a[0], output = _a[1];
if (!prismaClientDir || !fs_1.existsSync(prismaClientDir)) {
console.log('No valid `prisma-client-dir` was found');
process.exit(1);
}
if (!output || !output.endsWith('.ts')) {
console.log('No valid `output` was found. Must point to a .ts file');
process.exit(1);
}
var rootPath = config_1.findRootDirectory();
var schema = config_1.findDatamodelAndComputeSchema();
var types = source_helper_1.extractTypes(schema);
var typesToRender = render(types);
var outputPath = path_1.join(process.cwd(), './src/generated/nexus-prisma.ts');
var typesToRender = render(types, getImportPathRelativeToOutput(prismaClientDir, output));
// Create the output directories if needed (mkdir -p)
fs_1.mkdirSync(path_1.dirname(output), { recursive: true });
var outputPath = path_1.join(rootPath, output);
fs_1.writeFileSync(outputPath, typesToRender);
console.log('Types generated at src/generated/nexus-prisma.ts');
console.log("Types generated at " + output);
}
// TODO: Dynamically resolve prisma-client import path
function render(types) {
function render(types, prismaClientPath) {
var objectTypes = types.types.filter(function (t) { return t.type.isObject; });
var inputTypes = types.types.filter(function (t) { return t.type.isInput; });
var enumTypes = types.enums;
return "// GENERATED TYPES FOR PRISMA PLUGIN. /!\\ DO NOT EDIT MANUALLY\n\nimport {\n ArgDefinition,\n ContextValue,\n RootValue,\n} from 'nexus/dist/types'\nimport { GraphQLResolveInfo } from 'graphql'\n\nimport * as prisma from './prisma-client'\n\n" + objectTypes.map(renderType).join(os_1.EOL) + "\n\n" + inputTypes.map(renderInputType).join(os_1.EOL) + "\n\n" + renderEnumTypes(enumTypes) + "\n\nexport interface PluginTypes {\n fields: {\n" + objectTypes
return "// GENERATED TYPES FOR PRISMA PLUGIN. /!\\ DO NOT EDIT MANUALLY\n\nimport {\n ArgDefinition,\n ContextValue,\n RootValue,\n} from 'nexus/dist/types'\nimport { GraphQLResolveInfo } from 'graphql'\n\nimport * as prisma from '" + prismaClientPath + "'\n\n" + objectTypes.map(renderType).join(os_1.EOL) + "\n\n" + inputTypes.map(renderInputType).join(os_1.EOL) + "\n\n" + renderEnumTypes(enumTypes) + "\n\nexport interface PluginTypes {\n fields: {\n" + objectTypes
.map(function (type) { return " " + type.name + ": " + getExposableObjectsTypeName(type); })

@@ -125,2 +138,16 @@ .join(os_1.EOL) + "\n }\n fieldsDetails: {\n" + objectTypes

}
function getImportPathRelativeToOutput(importPath, outputDir) {
var relativePath = path_1.relative(path_1.dirname(outputDir), importPath);
if (!relativePath.startsWith('.')) {
relativePath = './' + relativePath;
}
// remove .ts or .js file extension
relativePath = relativePath.replace(/\.(ts|js)$/, '');
// remove /index
relativePath = relativePath.replace(/\/index$/, '');
// replace \ with /
relativePath = relativePath.replace(/\\/g, '/');
return relativePath;
}
exports.getImportPathRelativeToOutput = getImportPathRelativeToOutput;
//# sourceMappingURL=index.js.map
{
"name": "nexus-prisma-generate",
"version": "0.0.3",
"version": "0.0.4",
"typings": "dist/index.d.ts",

@@ -28,13 +28,15 @@ "license": "MIT",

"dependencies": {
"graphql": "14.0.2",
"js-yaml": "^3.12.1",
"prisma-generate-schema": "^1.24.0"
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0",
"js-yaml": "3.12.1",
"meow": "^5.0.0",
"prisma-generate-schema": "1.24.0"
},
"devDependencies": {
"@types/js-yaml": "^3.11.4",
"@types/node": "10.12.18",
"@types/js-yaml": "3.12.0",
"@types/node": "10.12.20",
"@types/meow": "^5.0.0",
"jest": "23.6.0",
"prettier": "1.15.3",
"prettier": "1.16.3",
"ts-jest": "23.10.5",
"typescript": "3.2.2"
"typescript": "3.2.4"
},

@@ -41,0 +43,0 @@ "prettier": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc