Skip to content

Commit 6fcac52

Browse files
committed
prepare versions for parser
1 parent 289dce3 commit 6fcac52

File tree

5 files changed

+199
-1
lines changed

5 files changed

+199
-1
lines changed

packages/parser/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
versions
4+
*.log
5+
.DS_Store
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "pgsql-parser",
3+
"version": "{{VERSION}}",
4+
"author": "Dan Lynch <[email protected]>",
5+
"description": "The real PostgreSQL query parser",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/launchql/pgsql-parser",
10+
"license": "MIT",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/launchql/pgsql-parser"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/launchql/pgsql-parser/issues"
21+
},
22+
"scripts": {
23+
"copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
24+
"clean": "rimraf dist",
25+
"prepare": "npm run build",
26+
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
27+
"build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
28+
"lint": "eslint . --fix",
29+
"test": "jest",
30+
"test:watch": "jest --watch"
31+
},
32+
"keywords": [
33+
"sql",
34+
"postgres",
35+
"postgresql",
36+
"pg",
37+
"parser",
38+
"query",
39+
"database"
40+
],
41+
"dependencies": {
42+
"@pgsql/types": "{{TYPES_VERSION}}",
43+
"libpg-query": "{{LIBPG_QUERY_VERSION}}",
44+
"pgsql-deparser": "{{PGSQL_PARSER_VERSION}}"
45+
}
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"libpg-query": {
3+
"16": "16.5.5",
4+
"15": "15.4.8",
5+
"14": "14.2.5",
6+
"13": "13.5.7"
7+
},
8+
"pgsql-parser": {
9+
"13": "13.18.0",
10+
"14": "14.0.0",
11+
"15": "15.0.0",
12+
"16": "16.0.0"
13+
},
14+
"@pgsql/types": {
15+
"13": "13.11.1",
16+
"14": "14.1.1",
17+
"15": "15.1.1",
18+
"16": "16.1.1"
19+
}
20+
}

packages/parser/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
2828
"lint": "eslint . --fix",
2929
"test": "jest",
30-
"test:watch": "jest --watch"
30+
"test:watch": "jest --watch",
31+
"prepare-versions": "ts-node scripts/prepare-versions.ts"
3132
},
3233
"keywords": [
3334
"sql",
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
// Read the versions configuration
5+
const configPath = path.join(__dirname, '../config/parser-versions.json');
6+
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
7+
8+
// Read the package.json template
9+
const templatePath = path.join(__dirname, '../config/package.template.json');
10+
const packageTemplate = fs.readFileSync(templatePath, 'utf-8');
11+
12+
// Create versions directory if it doesn't exist
13+
const versionsDir = path.join(__dirname, '../versions');
14+
if (!fs.existsSync(versionsDir)) {
15+
fs.mkdirSync(versionsDir, { recursive: true });
16+
}
17+
18+
// Generate version-specific packages
19+
const pgVersions = Object.keys(config['libpg-query']);
20+
21+
pgVersions.forEach(pgVersion => {
22+
const libpgQueryVersion = config['libpg-query'][pgVersion];
23+
24+
const typesVersion = config['@pgsql/types'][pgVersion];
25+
26+
// For pgsql-parser, we only have versions 13 and 17
27+
let pgsqlParserVersion = config['pgsql-parser'][pgVersion];
28+
if (!pgsqlParserVersion) {
29+
// If specific version doesn't exist, skip this PG version
30+
console.log(`Skipping PG${pgVersion} - no pgsql-parser version available`);
31+
return;
32+
}
33+
34+
// Create version directory
35+
const versionDir = path.join(versionsDir, `${pgVersion}`);
36+
if (!fs.existsSync(versionDir)) {
37+
fs.mkdirSync(versionDir, { recursive: true });
38+
}
39+
40+
// Create src directory
41+
const srcDir = path.join(versionDir, 'src');
42+
if (!fs.existsSync(srcDir)) {
43+
fs.mkdirSync(srcDir, { recursive: true });
44+
}
45+
46+
// Generate package.json
47+
const packageJson = packageTemplate
48+
.replace(/{{VERSION}}/g, `${pgVersion}.0.0`)
49+
.replace(/{{LIBPG_QUERY_VERSION}}/g, libpgQueryVersion)
50+
.replace(/{{PGSQL_PARSER_VERSION}}/g, pgsqlParserVersion)
51+
.replace(/{{TYPES_VERSION}}/g, typesVersion);
52+
53+
fs.writeFileSync(
54+
path.join(versionDir, 'package.json'),
55+
packageJson
56+
);
57+
58+
// Generate index.ts
59+
const indexContent = `export {
60+
parse as parse,
61+
parseSync as parseSync,
62+
loadModule as loadModule
63+
} from 'libpg-query';
64+
65+
export {
66+
deparse,
67+
deparseSync,
68+
} from 'pgsql-deparser';
69+
70+
export * from '@pgsql/types';
71+
`;
72+
73+
fs.writeFileSync(
74+
path.join(srcDir, 'index.ts'),
75+
indexContent
76+
);
77+
78+
fs.writeFileSync(path.join(versionDir, 'tsconfig.json'), JSON.stringify({
79+
"compilerOptions": {
80+
"outDir": "dist",
81+
"rootDir": "src/",
82+
"target": "es2022",
83+
"module": "commonjs",
84+
"esModuleInterop": true,
85+
"forceConsistentCasingInFileNames": true,
86+
"strict": true,
87+
"strictNullChecks": false,
88+
"skipLibCheck": true,
89+
"sourceMap": false,
90+
"declaration": true,
91+
"resolveJsonModule": true,
92+
"moduleResolution": "node"
93+
},
94+
"include": [
95+
"src/**/*.ts"
96+
],
97+
"exclude": [
98+
"dist",
99+
"node_modules",
100+
"**/*.spec.*",
101+
"**/*.test.*"
102+
]
103+
}, null, 2));
104+
105+
106+
fs.writeFileSync(path.join(versionDir, 'tsconfig.esm.json'), JSON.stringify({
107+
"extends": "./tsconfig.json",
108+
"compilerOptions": {
109+
"outDir": "dist/esm",
110+
"module": "es2022",
111+
"rootDir": "src/",
112+
"declaration": false
113+
}
114+
}, null, 2));
115+
116+
117+
// Copy the README.md files
118+
fs.copyFileSync(
119+
path.join(__dirname, '../README.md'),
120+
path.join(versionDir, 'README.md')
121+
);
122+
123+
console.log(`✓ Generated PG${pgVersion} with libpg-query@${libpgQueryVersion} and pgsql-parser@${pgsqlParserVersion}`);
124+
});
125+
126+
console.log('\nVersion preparation complete!');

0 commit comments

Comments
 (0)