Skip to content

Commit 7749939

Browse files
committed
updates for single source of truth
1 parent d151457 commit 7749939

File tree

3 files changed

+52
-32
lines changed

3 files changed

+52
-32
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
"devDependencies": {
3535
"@types/node": "^20.0.0",
3636
"copyfiles": "^2.4.1",
37+
"glob": "11.0.3",
38+
"pg-proto-parser": "^1.28.2",
3739
"rimraf": "^5.0.0",
3840
"ts-node": "^10.9.1",
39-
"typescript": "^5.3.3",
40-
"pg-proto-parser": "^1.28.2"
41+
"typescript": "^5.3.3"
4142
}
42-
}
43+
}

scripts/copy-templates.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const fs = require('fs');
44
const path = require('path');
5+
const glob = require('glob');
56

67
const HEADER = `/**
78
* DO NOT MODIFY MANUALLY — this is generated from the templates dir
@@ -19,29 +20,39 @@ const MAKEFILE_HEADER = `# DO NOT MODIFY MANUALLY — this is generated from the
1920
2021
`;
2122

22-
// Version-specific configurations
23-
const VERSION_CONFIGS = {
24-
'13': {
25-
tag: '13-2.2.0',
26-
hasEmscriptenPatch: true
27-
},
28-
'14': {
29-
tag: '14-3.0.0',
30-
hasEmscriptenPatch: false
31-
},
32-
'15': {
33-
tag: '15-4.2.4',
34-
hasEmscriptenPatch: false
35-
},
36-
'16': {
37-
tag: '16-5.2.0',
38-
hasEmscriptenPatch: false
39-
},
40-
'17': {
41-
tag: '17-6.1.0',
42-
hasEmscriptenPatch: false
43-
}
44-
};
23+
// Load version configurations from package.json files
24+
function loadVersionConfigs() {
25+
const configs = {};
26+
const packageFiles = glob.sync('versions/*/package.json');
27+
28+
console.log(`Found ${packageFiles.length} package.json files\n`);
29+
30+
packageFiles.forEach(packageFile => {
31+
try {
32+
const packageData = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
33+
const version = packageData['x-publish']?.pgVersion;
34+
const libpgQueryTag = packageData['x-publish']?.libpgQueryTag;
35+
36+
if (version && libpgQueryTag) {
37+
configs[version] = {
38+
tag: libpgQueryTag,
39+
hasEmscriptenPatch: version === '13' // Only version 13 needs the patch
40+
};
41+
console.log(` Version ${version}: tag ${libpgQueryTag}`);
42+
} else {
43+
console.warn(` Warning: Missing x-publish data in ${packageFile}`);
44+
}
45+
} catch (error) {
46+
console.error(` Error reading ${packageFile}: ${error.message}`);
47+
}
48+
});
49+
50+
console.log(''); // Empty line for readability
51+
return configs;
52+
}
53+
54+
// Load configurations
55+
const VERSION_CONFIGS = loadVersionConfigs();
4556

4657
// Files to copy from templates
4758
const TEMPLATE_FILES = [

templates/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ The following placeholders are used in template files:
3333

3434
## Version-Specific Configurations
3535

36-
The `scripts/copy-templates.js` script contains version-specific configurations:
36+
The `scripts/copy-templates.js` script automatically reads version-specific configurations from each version's `package.json` file. It looks for the `x-publish` section:
37+
38+
```json
39+
"x-publish": {
40+
"publishName": "libpg-query",
41+
"pgVersion": "15",
42+
"distTag": "pg15",
43+
"libpgQueryTag": "15-4.2.4"
44+
}
45+
```
3746

38-
- **Version 13**: Uses tag `13-2.2.0` and requires emscripten patch
39-
- **Version 14**: Uses tag `14-3.0.0`
40-
- **Version 15**: Uses tag `15-4.2.4`
41-
- **Version 16**: Uses tag `16-5.2.0`
42-
- **Version 17**: Uses tag `17-6.1.0`
47+
The script uses:
48+
- `pgVersion` to identify the PostgreSQL version
49+
- `libpgQueryTag` for the {{VERSION_TAG}} placeholder replacement
50+
- Version 13 automatically gets the emscripten patch applied
4351

4452
## Important Notes
4553

0 commit comments

Comments
 (0)