Skip to content

Commit cf8404f

Browse files
committed
chore: update build script
1 parent a6f759b commit cf8404f

File tree

7 files changed

+525
-156
lines changed

7 files changed

+525
-156
lines changed

client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fecommunity/reactpress-client",
3-
"version": "1.0.1-beta.5",
3+
"version": "1.0.1-beta.9",
44
"scripts": {
55
"prebuild": "rimraf .next",
66
"build": "next build",
@@ -15,7 +15,7 @@
1515
"@ant-design/icons": "^4.7.0",
1616
"@ant-design/pro-layout": "7.19.11",
1717
"@monaco-editor/react": "^4.6.0",
18-
"@fecommunity/reactpress-config": "workspace:^1.0.0",
18+
"@fecommunity/reactpress-config": "workspace:*",
1919
"antd": "^5.24.4",
2020
"array-move": "^3.0.1",
2121
"axios": "^0.23.0",

client/public/sitemap.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
3-
<url><loc>http://localhost:3001</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.549Z</lastmod></url>
4-
<url><loc>http://localhost:3001/archives</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.550Z</lastmod></url>
5-
<url><loc>http://localhost:3001/knowledge</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.550Z</lastmod></url>
6-
<url><loc>http://localhost:3001/login</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.550Z</lastmod></url>
7-
<url><loc>http://localhost:3001/nav</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.550Z</lastmod></url>
8-
<url><loc>http://localhost:3001/rss</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T02:57:50.550Z</lastmod></url>
3+
<url><loc>http://localhost:3001</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
4+
<url><loc>http://localhost:3001/archives</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
5+
<url><loc>http://localhost:3001/knowledge</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
6+
<url><loc>http://localhost:3001/login</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
7+
<url><loc>http://localhost:3001/nav</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
8+
<url><loc>http://localhost:3001/rss</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2025-09-20T04:45:06.288Z</lastmod></url>
99
</urlset>

config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fecommunity/reactpress-config",
3-
"version": "1.0.0-beta.15",
3+
"version": "1.0.0-beta.19",
44
"description": "ReactPress Configuration - Environment and i18n configuration for ReactPress",
55
"author": "fecommunity",
66
"main": "./lib/index.js",

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dev:client": "pnpm run --dir ./client dev",
1616
"dev:docs": "pnpm run --dir ./docs dev",
1717
"build": "pnpm build:config && pnpm build:server && pnpm build:client",
18+
"build:packages": "node scripts/build-packages.js",
1819
"build:config": "pnpm run --dir ./config build",
1920
"build:server": "pnpm run --dir ./server build",
2021
"build:client": "pnpm run --dir ./client build",
@@ -35,7 +36,8 @@
3536
"prepare": "husky",
3637
"precommit": "lint-staged",
3738
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
38-
"publish": "node scripts/publish-packages.js"
39+
"publish": "node scripts/publish-packages.js",
40+
"release": "node scripts/build-packages.js --publish"
3941
},
4042
"dependencies": {
4143
"chalk": "^4.1.2",
@@ -72,4 +74,4 @@
7274
]
7375
},
7476
"packageManager": "[email protected]+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"
75-
}
77+
}

scripts/build-packages.js

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
const fs = require('fs');
5+
const path = require('path');
6+
const chalk = require('chalk');
7+
8+
// Package build order (dependencies first)
9+
const packages = [
10+
{
11+
name: '@fecommunity/reactpress-config',
12+
path: 'config',
13+
description: 'Configuration management package'
14+
},
15+
{
16+
name: '@fecommunity/reactpress-server',
17+
path: 'server',
18+
description: 'Backend API server package'
19+
},
20+
{
21+
name: '@fecommunity/reactpress-client',
22+
path: 'client',
23+
description: 'Frontend application package'
24+
}
25+
];
26+
27+
// Get current versions
28+
function getCurrentVersion(packagePath) {
29+
try {
30+
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
31+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
32+
return pkg.version;
33+
} catch (error) {
34+
return 'unknown';
35+
}
36+
}
37+
38+
// Fix workspace dependencies for build
39+
function fixWorkspaceDependenciesForBuild(packagePath) {
40+
console.log(chalk.blue(`🔧 Fixing workspace dependencies for build: ${packagePath}...`));
41+
42+
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
43+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
44+
45+
// Fix dependencies
46+
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
47+
48+
depTypes.forEach(depType => {
49+
if (pkg[depType]) {
50+
Object.keys(pkg[depType]).forEach(depName => {
51+
// Check if it's a workspace dependency
52+
if (pkg[depType][depName] === 'workspace:*' || pkg[depType][depName].startsWith('workspace:')) {
53+
// For build purposes, we'll use the file: protocol to reference local packages
54+
const depPackage = packages.find(p => p.name === depName);
55+
if (depPackage) {
56+
console.log(chalk.gray(` Replacing ${depName} workspace dependency with file reference`));
57+
pkg[depType][depName] = `file:../${depPackage.path}`;
58+
}
59+
}
60+
});
61+
}
62+
});
63+
64+
// Write the updated package.json
65+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
66+
console.log(chalk.green(`✅ Workspace dependencies fixed for build: ${packagePath}`));
67+
}
68+
69+
// Restore workspace dependencies after build
70+
function restoreWorkspaceDependenciesAfterBuild(packagePath) {
71+
console.log(chalk.blue(`🔄 Restoring workspace dependencies after build: ${packagePath}...`));
72+
73+
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
74+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
75+
76+
// Restore dependencies
77+
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
78+
79+
depTypes.forEach(depType => {
80+
if (pkg[depType]) {
81+
Object.keys(pkg[depType]).forEach(depName => {
82+
// Check if this is one of our internal packages referenced with file:
83+
const depPackage = packages.find(p => p.name === depName);
84+
if (depPackage && pkg[depType][depName].startsWith('file:')) {
85+
console.log(chalk.gray(` Restoring ${depName} to workspace dependency`));
86+
pkg[depType][depName] = 'workspace:*';
87+
}
88+
});
89+
}
90+
});
91+
92+
// Write the updated package.json
93+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
94+
console.log(chalk.green(`✅ Workspace dependencies restored after build: ${packagePath}`));
95+
}
96+
97+
// Build package
98+
function buildPackage(pkg) {
99+
console.log(chalk.blue(`\n🔨 Building ${pkg.name} (${pkg.description})...`));
100+
101+
try {
102+
// Fix workspace dependencies for build
103+
fixWorkspaceDependenciesForBuild(pkg.path);
104+
105+
try {
106+
if (pkg.path === 'config') {
107+
execSync('pnpm run build', { cwd: path.join(process.cwd(), pkg.path), stdio: 'inherit' });
108+
} else if (pkg.path === 'server') {
109+
execSync('pnpm run prebuild && pnpm run build', { cwd: path.join(process.cwd(), pkg.path), stdio: 'inherit' });
110+
} else if (pkg.path === 'client') {
111+
execSync('pnpm run prebuild && pnpm run build', { cwd: path.join(process.cwd(), pkg.path), stdio: 'inherit' });
112+
}
113+
console.log(chalk.green(`✅ ${pkg.name} built successfully`));
114+
} finally {
115+
// Always restore workspace dependencies
116+
restoreWorkspaceDependenciesAfterBuild(pkg.path);
117+
}
118+
} catch (error) {
119+
console.log(chalk.red(`❌ Failed to build ${pkg.name}`));
120+
throw error;
121+
}
122+
}
123+
124+
// Main function
125+
async function main() {
126+
console.log(chalk.blue('🏗️ ReactPress Package Builder\n'));
127+
128+
// Show current versions
129+
console.log(chalk.cyan('📋 Current package versions:'));
130+
packages.forEach(pkg => {
131+
const version = getCurrentVersion(pkg.path);
132+
console.log(chalk.gray(` ${pkg.name}: ${version}`));
133+
});
134+
console.log();
135+
136+
try {
137+
// Build packages in order
138+
for (const pkg of packages) {
139+
if (fs.existsSync(path.join(process.cwd(), pkg.path))) {
140+
await buildPackage(pkg);
141+
} else {
142+
console.log(chalk.yellow(`⚠️ Package ${pkg.name} directory not found, skipping...`));
143+
}
144+
}
145+
146+
console.log(chalk.green('\n🎉 All packages built successfully!'));
147+
} catch (error) {
148+
console.error(chalk.red('❌ Build failed:'), error);
149+
process.exit(1);
150+
}
151+
}
152+
153+
// Check if called with --publish flag
154+
if (process.argv.includes('--publish')) {
155+
// When called with --publish, we only show the header and versions but don't build
156+
// The publish script will handle building as needed
157+
console.log(chalk.blue('🏗️ ReactPress Package Builder\n'));
158+
159+
// Show current versions
160+
console.log(chalk.cyan('📋 Current package versions:'));
161+
packages.forEach(pkg => {
162+
const version = getCurrentVersion(pkg.path);
163+
console.log(chalk.gray(` ${pkg.name}: ${version}`));
164+
});
165+
console.log();
166+
167+
// Don't build packages here, just start the publish process
168+
console.log(chalk.blue('\n🚀 Starting publish process...'));
169+
// Execute publish script
170+
const { spawn } = require('child_process');
171+
const publishProcess = spawn('node', ['scripts/publish-packages.js', '--release'], { stdio: 'inherit' });
172+
173+
publishProcess.on('close', (code) => {
174+
if (code === 0) {
175+
console.log(chalk.green('\n✅ Build and publish completed successfully!'));
176+
} else {
177+
console.log(chalk.red('\n❌ Publish process failed!'));
178+
process.exit(code);
179+
}
180+
});
181+
} else {
182+
main();
183+
}

0 commit comments

Comments
 (0)