Optimize setup script to skip if packages already exist

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-24 01:02:24 +00:00
parent 086740d449
commit d16e919faf
2 changed files with 27 additions and 0 deletions

1
package-lock.json generated
View File

@@ -7,6 +7,7 @@
"": {
"name": "spark-template",
"version": "0.0.0",
"hasInstallScript": true,
"dependencies": {
"@github/spark": ">=0.43.1 <1",
"@heroicons/react": "^2.2.0",

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env node
'use strict';
/**
* Setup script for creating the packages folder structure
* This creates placeholder files for all packages referenced in package-glue.ts
@@ -50,6 +52,30 @@ const packages = [
}
];
// Check if all packages already exist (optimization for postinstall)
function allPackagesExist() {
if (!fs.existsSync(packagesDir)) {
return false;
}
for (const pkg of packages) {
const componentsPath = path.join(packagesDir, pkg.id, 'seed', 'components.json');
const metadataPath = path.join(packagesDir, pkg.id, 'seed', 'metadata.json');
if (!fs.existsSync(componentsPath) || !fs.existsSync(metadataPath)) {
return false;
}
}
return true;
}
// Skip if everything is already set up
if (allPackagesExist()) {
console.log('✓ Packages folder already exists with all required packages.');
process.exit(0);
}
console.log('Setting up packages folder...\n');
// Create packages directory if it doesn't exist