forked from allyusd/prisma-schema-transformer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbin.js
executable file
·66 lines (54 loc) · 1.54 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
require('dotenv').config();
const fs = require('fs');
const arg = require('arg');
const {formatSchema} = require('@prisma/sdk');
const pkg = require('./package.json');
const {fixPrismaFile} = require('./dist');
const args = arg({
// Types
'--help': Boolean,
'--version': Boolean,
'--print': Boolean,
'--deny': [String],
// Aliases
'-v': '--version'
});
if (args['--version']) {
console.log(`${pkg.name} ${pkg.version}`);
process.exit(0);
}
if (args['--help']) {
console.log(`Usage
$ prisma-schema-transformer [options] [...args]
Specify a schema:
$ prisma-schema-transformer ./schema.prisma
Instead of saving the result to the filesystem, you can also print it
$ prisma-schema-transformer ./schema.prisma --print
Exclude some models from the output
$ prisma-schema-transformer ./schema.prisma --deny knex_migrations --deny knex_migration_lock
Options:
--print Do not save
--deny Exlucde model from output
--help Help
--version Version info`);
process.exit(0);
}
if (args._.length !== 1) {
console.log('Invalid argument. Require one positional argument. Run --help for usage.');
process.exit(1);
}
const schemaPath = args._[0];
const isPrint = args['--print'] || false;
const denyList = args['--deny'] || [];
(async function () {
const output = await fixPrismaFile(schemaPath, denyList);
if (isPrint) {
console.log(output);
} else {
fs.writeFileSync(schemaPath, output);
const formatedOutput = await formatSchema({schemaPath});
fs.writeFileSync(schemaPath, formatedOutput);
}
process.exit(0);
})();