@prairielearn/postgres-tools 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/bin/pg-describe.js +1 -1
- package/dist/bin/pg-describe.js.map +1 -1
- package/package.json +8 -8
- package/src/bin/pg-describe.ts +5 -1
package/CHANGELOG.md
CHANGED
package/dist/bin/pg-describe.js
CHANGED
|
@@ -5,7 +5,7 @@ import chalk from 'chalk';
|
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
6
|
import _ from 'lodash';
|
|
7
7
|
import yargs from 'yargs';
|
|
8
|
-
import { describeDatabase, formatDatabaseDescription } from '../describe.js';
|
|
8
|
+
import { describeDatabase, formatDatabaseDescription, } from '../describe.js';
|
|
9
9
|
const args = yargs(process.argv.slice(2))
|
|
10
10
|
.usage('Usage: $0 <database name> [options]')
|
|
11
11
|
.demandCommand(1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-describe.js","sourceRoot":"","sources":["../../src/bin/pg-describe.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"pg-describe.js","sourceRoot":"","sources":["../../src/bin/pg-describe.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,KAAK,MAAM,OAAO,CAA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,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IACxC,MAAM,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAClE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path';\n\nimport async from 'async';\nimport chalk from 'chalk';\nimport fs from 'fs-extra';\nimport _ from 'lodash';\nimport yargs from 'yargs';\n\nimport {\n describeDatabase,\n formatDatabaseDescription,\n type DatabaseDescription,\n} from '../describe.js';\n\nconst args = yargs(process.argv.slice(2))\n .usage('Usage: $0 <database name> [options]')\n .demandCommand(1)\n .option('output', {\n alias: 'o',\n nargs: 1,\n string: true,\n description: 'Specify a directory to output files to',\n })\n .option('ignore-tables', {\n array: true,\n description: 'a list of tables to ignore',\n })\n .option('ignore-enums', {\n array: true,\n description: 'a list of enums to ignore',\n })\n .option('ignore-columns', {\n array: true,\n description: 'a list of columns to ignore, formatted like [table].[column]',\n })\n .help('h')\n .alias('h', 'help')\n .example('$0 postgres', 'Describe the \"postgres\" database')\n .example(\n '$0 userdb -o db_description --ignore-tables a b --ignore-columns a.col1 a.col2',\n 'Describe the \"userdb\" database; ignore specific tables and columns',\n )\n .strict();\n\nconst argv = args.parseSync();\n\nif (argv._.length !== 1) {\n args.showHelp();\n process.exit(1);\n}\n\n// Disable color if we're not attached to a tty\nconst coloredOutput = !argv.output && process.stdout.isTTY;\n\nconst options = {\n ignoreTables: (argv['ignore-tables'] ?? []).map((table) => table.toString()),\n ignoreEnums: (argv['ignore-enums'] ?? []).map((enumName) => enumName.toString()),\n ignoreColumns: (argv['ignore-columns'] ?? []).map((column) => column.toString()),\n};\n\nfunction formatText(text: string, formatter: (text: string) => string) {\n if (!argv.output && coloredOutput) {\n return formatter(text);\n }\n return text;\n}\n\ndescribeDatabase(argv._[0].toString(), options).then(\n async (description) => {\n if (argv.output) {\n await writeDescriptionToDisk(description, argv.output);\n } else {\n printDescription(description);\n }\n process.exit(0);\n },\n (err) => {\n console.error(err);\n process.exit(1);\n },\n);\n\nfunction printDescription(description: DatabaseDescription) {\n const formattedDescription = formatDatabaseDescription(description, { coloredOutput });\n _.forEach(_.sortBy(_.keys(formattedDescription.tables)), (tableName) => {\n process.stdout.write(formatText(`[table] ${tableName}\\n`, chalk.bold));\n process.stdout.write(formattedDescription.tables[tableName]);\n process.stdout.write('\\n\\n');\n });\n\n _.forEach(_.sortBy(_.keys(formattedDescription.enums)), (enumName) => {\n process.stdout.write(formatText(`[enum] ${enumName}\\n`, chalk.bold));\n process.stdout.write(formattedDescription.enums[enumName]);\n process.stdout.write('\\n\\n');\n });\n}\n\nasync function writeDescriptionToDisk(description: DatabaseDescription, dir: string) {\n const formattedDescription = formatDatabaseDescription(description, { coloredOutput: false });\n await fs.emptyDir(dir);\n await fs.mkdir(path.join(dir, 'tables'));\n await fs.mkdir(path.join(dir, 'enums'));\n await async.eachOf(formattedDescription.tables, async (value, key) => {\n await fs.writeFile(path.join(dir, 'tables', `${key}.pg`), value);\n });\n await async.eachOf(formattedDescription.enums, async (value, key) => {\n await fs.writeFile(path.join(dir, 'enums', `${key}.pg`), value);\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prairielearn/postgres-tools",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@prairielearn/tsconfig": "^0.0.0",
|
|
21
|
-
"@types/diff": "^5.2.
|
|
21
|
+
"@types/diff": "^5.2.3",
|
|
22
22
|
"@types/fs-extra": "^11.0.4",
|
|
23
|
-
"@types/lodash": "^4.17.
|
|
24
|
-
"@types/node": "^20.
|
|
23
|
+
"@types/lodash": "^4.17.13",
|
|
24
|
+
"@types/node": "^20.17.5",
|
|
25
25
|
"@types/yargs": "^17.0.33",
|
|
26
|
-
"typescript": "^5.
|
|
26
|
+
"typescript": "^5.6.3",
|
|
27
27
|
"typescript-cp": "^0.1.9"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@prairielearn/postgres": "^2.1.
|
|
31
|
-
"async": "^3.2.
|
|
30
|
+
"@prairielearn/postgres": "^2.1.4",
|
|
31
|
+
"async": "^3.2.6",
|
|
32
32
|
"chalk": "^5.3.0",
|
|
33
|
-
"diff": "^
|
|
33
|
+
"diff": "^7.0.0",
|
|
34
34
|
"fs-extra": "^11.2.0",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"postgres-array": "^3.0.2",
|
package/src/bin/pg-describe.ts
CHANGED
|
@@ -8,7 +8,11 @@ import fs from 'fs-extra';
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
9
|
import yargs from 'yargs';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
describeDatabase,
|
|
13
|
+
formatDatabaseDescription,
|
|
14
|
+
type DatabaseDescription,
|
|
15
|
+
} from '../describe.js';
|
|
12
16
|
|
|
13
17
|
const args = yargs(process.argv.slice(2))
|
|
14
18
|
.usage('Usage: $0 <database name> [options]')
|