Skip to content

Commit 39ee75f

Browse files
authored
Dummy pr 3 (#122)
* remove unused files * - Simplify PR preview comment logic - Remove OpenHands resolver workflow * Update deploy workflows - Add path to upload artifact in deploy-apps.yml - Set preview to false in deploy to GitHub Pages - Enable keep_files and disable Jekyll in deploy-pr-previews.yml - Modify PR preview deletion to use shell script * Delete index.html * Update deploy-pr-previews.yml * Update build-all.js
1 parent 17fcc45 commit 39ee75f

File tree

1 file changed

+57
-35
lines changed

1 file changed

+57
-35
lines changed

scripts/build-all.js

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (!fs.existsSync(absoluteDestDir)) {
1616
const rootDir = path.resolve(__dirname, '..');
1717
const entries = fs.readdirSync(rootDir, { withFileTypes: true });
1818

19-
// Filter for directories that contain package.json
19+
// Filter for app directories (either have package.json or index.html)
2020
const appDirs = entries
2121
.filter(entry => entry.isDirectory())
2222
.map(dir => dir.name)
@@ -25,55 +25,77 @@ const appDirs = entries
2525
if (['node_modules', '.git', '.github', 'scripts', destDir].includes(dir)) {
2626
return false;
2727
}
28-
// Check for package.json
29-
return fs.existsSync(path.join(rootDir, dir, 'package.json'));
28+
const dirPath = path.join(rootDir, dir);
29+
// Check for either package.json or index.html
30+
return fs.existsSync(path.join(dirPath, 'package.json')) ||
31+
fs.existsSync(path.join(dirPath, 'index.html'));
3032
});
3133

3234
console.log(`Found ${appDirs.length} apps to build`);
3335

34-
// Build each app
36+
// Process each app
3537
appDirs.forEach(appDir => {
3638
const appPath = path.join(rootDir, appDir);
37-
console.log(`\nBuilding ${appDir}...`);
39+
console.log(`\nProcessing ${appDir}...`);
3840

41+
const hasPackageJson = fs.existsSync(path.join(appPath, 'package.json'));
42+
const appDestDir = path.join(absoluteDestDir, appDir);
43+
3944
try {
40-
// Install dependencies
41-
console.log('Installing dependencies...');
42-
execSync('npm install', {
43-
cwd: appPath,
44-
stdio: 'inherit'
45-
});
45+
if (hasPackageJson) {
46+
// Build Node.js app
47+
console.log('Building Node.js app...');
48+
console.log('Installing dependencies...');
49+
execSync('npm install', {
50+
cwd: appPath,
51+
stdio: 'inherit'
52+
});
53+
54+
console.log('Running build...');
55+
execSync('npm run build', {
56+
cwd: appPath,
57+
stdio: 'inherit'
58+
});
4659

47-
// Run build
48-
console.log('Running build...');
49-
execSync('npm run build', {
50-
cwd: appPath,
51-
stdio: 'inherit'
52-
});
60+
// Determine build output directory (build or dist)
61+
let buildDir = fs.existsSync(path.join(appPath, 'build'))
62+
? 'build'
63+
: fs.existsSync(path.join(appPath, 'dist'))
64+
? 'dist'
65+
: null;
5366

54-
// Determine build output directory (build or dist)
55-
let buildDir = fs.existsSync(path.join(appPath, 'build'))
56-
? 'build'
57-
: fs.existsSync(path.join(appPath, 'dist'))
58-
? 'dist'
59-
: null;
67+
if (buildDir) {
68+
// Create app directory in destination
69+
if (!fs.existsSync(appDestDir)) {
70+
fs.mkdirSync(appDestDir, { recursive: true });
71+
}
6072

61-
if (buildDir) {
62-
// Create app directory in destination
63-
const appDestDir = path.join(absoluteDestDir, appDir);
73+
// Copy build files
74+
console.log(`Copying ${buildDir} to ${destDir}/${appDir}`);
75+
const buildPath = path.join(appPath, buildDir);
76+
fs.cpSync(buildPath, appDestDir, { recursive: true });
77+
} else {
78+
console.warn(`No build output found for ${appDir}`);
79+
}
80+
} else {
81+
// Static site with index.html
82+
console.log('Static site detected, copying files...');
6483
if (!fs.existsSync(appDestDir)) {
6584
fs.mkdirSync(appDestDir, { recursive: true });
6685
}
67-
68-
// Copy build files
69-
console.log(`Copying ${buildDir} to ${destDir}/${appDir}`);
70-
const buildPath = path.join(appPath, buildDir);
71-
fs.cpSync(buildPath, appDestDir, { recursive: true });
72-
} else {
73-
console.warn(`No build output found for ${appDir}`);
86+
fs.cpSync(appPath, appDestDir, {
87+
recursive: true,
88+
filter: (src) => {
89+
const relativePath = path.relative(appPath, src);
90+
// Skip node_modules and hidden files/directories
91+
return !relativePath.startsWith('node_modules') &&
92+
!relativePath.startsWith('.');
93+
}
94+
});
95+
console.log(`Copied static files to ${destDir}/${appDir}`);
7496
}
7597
} catch (error) {
76-
console.error(`Error building ${appDir}:`, error.message);
98+
console.error(`Error processing ${appDir}:`, error.message);
7799
}
78100
});
79101

@@ -109,4 +131,4 @@ const indexContent = `
109131

110132
fs.writeFileSync(path.join(absoluteDestDir, 'index.html'), indexContent);
111133

112-
console.log('\nBuild complete! Output is in:', destDir);
134+
console.log('\nBuild complete! Output is in:', destDir);

0 commit comments

Comments
 (0)