Skip to content

Commit d7de835

Browse files
committed
Grab the pyscript namespace from the referenced release, and put it somewhere the docs can find it.
1 parent d0df6fb commit d7de835

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

version-update.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,60 @@ const patch = directory => {
2424
};
2525

2626
patch(join(__dirname, 'docs'));
27+
28+
// Download and extract PyScript source code for the current version.
29+
const { execSync } = require('child_process');
30+
const { mkdtempSync, rmSync, cpSync } = require('fs');
31+
const { tmpdir } = require('os');
32+
33+
const downloadFileSync = (url, destination) => {
34+
// Use curl which is available on Mac and Linux.
35+
try {
36+
execSync(`curl -L -o "${destination}" "${url}"`, {
37+
stdio: 'ignore'
38+
});
39+
} catch (error) {
40+
throw new Error(`Download failed: ${error.message}`);
41+
}
42+
};
43+
44+
const updatePyScriptSource = () => {
45+
const url = `https://github.com/pyscript/pyscript/archive/refs/tags/${version}.zip`;
46+
const tempDir = mkdtempSync(join(tmpdir(), 'pyscript-'));
47+
const zipPath = join(tempDir, `pyscript-${version}.zip`);
48+
const targetDir = join(__dirname, 'pyscript');
49+
50+
try {
51+
console.log(`Downloading PyScript ${version}...`);
52+
downloadFileSync(url, zipPath);
53+
54+
console.log('Extracting archive...');
55+
execSync(`unzip -q "${zipPath}" -d "${tempDir}"`);
56+
57+
const sourceDir = join(
58+
tempDir,
59+
`pyscript-${version}`,
60+
'core',
61+
'src',
62+
'stdlib',
63+
'pyscript'
64+
);
65+
66+
if (!statSync(sourceDir, { throwIfNoEntry: false })?.isDirectory()) {
67+
throw new Error(`Expected directory not found: ${sourceDir}`);
68+
}
69+
70+
console.log('Copying PyScript stdlib files...');
71+
cpSync(sourceDir, targetDir, { recursive: true, force: true });
72+
73+
console.log('PyScript source updated successfully.');
74+
} catch (error) {
75+
console.error('Error updating PyScript source:', error.message);
76+
process.exit(1);
77+
} finally {
78+
console.log('Cleaning up temporary files...');
79+
rmSync(tempDir, { recursive: true, force: true });
80+
}
81+
};
82+
83+
updatePyScriptSource();

0 commit comments

Comments
 (0)