@fecommunity/reactpress 2.0.0-beta-4-beta.1 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{scripts → bin}/reactpress.js +0 -0
- package/package.json +38 -34
- package/scripts/build-packages.js +271 -0
- package/scripts/deploy.sh +25 -0
- package/scripts/{reactpress-publish.js → publish-packages.js} +47 -237
- package/scripts/reactpress-server-old.js +130 -0
- package/scripts/reactpress-server.js +666 -0
- package/scripts/reactpress-cli.js +0 -90
- package/scripts/reactpress-deploy.sh +0 -47
- /package/scripts/{reactpress-dev.js → dev.js} +0 -0
|
@@ -10,9 +10,9 @@ const crypto = require('crypto');
|
|
|
10
10
|
// Package build order (dependencies first)
|
|
11
11
|
const packages = [
|
|
12
12
|
{
|
|
13
|
-
name: '@fecommunity/reactpress',
|
|
14
|
-
path: '
|
|
15
|
-
description: '
|
|
13
|
+
name: '@fecommunity/reactpress-config',
|
|
14
|
+
path: 'config',
|
|
15
|
+
description: 'Configuration management package'
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
name: '@fecommunity/reactpress-server',
|
|
@@ -66,31 +66,8 @@ function getPackageHash(packagePath) {
|
|
|
66
66
|
return generateHash(fullPath);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// Check if package has meaningful changes
|
|
70
|
-
function
|
|
71
|
-
try {
|
|
72
|
-
// Create a hash file path to store previous hash in node_modules
|
|
73
|
-
const hashFilePath = path.join(process.cwd(), 'node_modules', '.build-cache', `${packageName.replace('/', '_')}.hash`);
|
|
74
|
-
|
|
75
|
-
// Generate current hash
|
|
76
|
-
const currentHash = getPackageHash(packagePath);
|
|
77
|
-
|
|
78
|
-
// Check if we have a previous hash
|
|
79
|
-
if (fs.existsSync(hashFilePath)) {
|
|
80
|
-
const previousHash = fs.readFileSync(hashFilePath, 'utf8').trim();
|
|
81
|
-
return currentHash !== previousHash;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// If no previous hash, consider it as having changes
|
|
85
|
-
return true;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.log(chalk.yellow(`⚠️ Could not check changes for ${packageName}, assuming changes exist`));
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Check if package has meaningful changes (for publish)
|
|
93
|
-
function hasMeaningfulChangesForPublish(packagePath, packageName) {
|
|
69
|
+
// Check if package has meaningful changes
|
|
70
|
+
function hasMeaningfulChanges(packagePath, packageName) {
|
|
94
71
|
try {
|
|
95
72
|
// Create a hash file path to store previous hash in node_modules
|
|
96
73
|
const hashFilePath = path.join(process.cwd(), 'node_modules', '.publish-cache', `${packageName.replace('/', '_')}.hash`);
|
|
@@ -112,27 +89,8 @@ function hasMeaningfulChangesForPublish(packagePath, packageName) {
|
|
|
112
89
|
}
|
|
113
90
|
}
|
|
114
91
|
|
|
115
|
-
// Save package hash
|
|
116
|
-
function
|
|
117
|
-
try {
|
|
118
|
-
const hashFilePath = path.join(process.cwd(), 'node_modules', '.build-cache', `${packageName.replace('/', '_')}.hash`);
|
|
119
|
-
|
|
120
|
-
// Ensure cache directory exists
|
|
121
|
-
const cacheDir = path.dirname(hashFilePath);
|
|
122
|
-
if (!fs.existsSync(cacheDir)) {
|
|
123
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Generate and save current hash
|
|
127
|
-
const currentHash = getPackageHash(packagePath);
|
|
128
|
-
fs.writeFileSync(hashFilePath, currentHash);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.log(chalk.yellow(`⚠️ Could not save hash for ${packageName}`));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Save package hash (for publish)
|
|
135
|
-
function savePackageHashForPublish(packagePath, packageName) {
|
|
92
|
+
// Save package hash
|
|
93
|
+
function savePackageHash(packagePath, packageName) {
|
|
136
94
|
try {
|
|
137
95
|
const hashFilePath = path.join(process.cwd(), 'node_modules', '.publish-cache', `${packageName.replace('/', '_')}.hash`);
|
|
138
96
|
|
|
@@ -251,67 +209,8 @@ function updateVersion(packagePath, newVersion) {
|
|
|
251
209
|
console.log(chalk.green(`✅ Version updated from ${oldVersion} to ${newVersion}`));
|
|
252
210
|
}
|
|
253
211
|
|
|
254
|
-
// Fix workspace dependencies for build
|
|
255
|
-
function fixWorkspaceDependenciesForBuild(packagePath) {
|
|
256
|
-
console.log(chalk.blue(`🔧 Fixing workspace dependencies for build: ${packagePath}...`));
|
|
257
|
-
|
|
258
|
-
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
|
|
259
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
260
|
-
|
|
261
|
-
// Fix dependencies
|
|
262
|
-
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
|
|
263
|
-
|
|
264
|
-
depTypes.forEach(depType => {
|
|
265
|
-
if (pkg[depType]) {
|
|
266
|
-
Object.keys(pkg[depType]).forEach(depName => {
|
|
267
|
-
// Check if it's a workspace dependency
|
|
268
|
-
if (pkg[depType][depName] === 'workspace:*' || pkg[depType][depName].startsWith('workspace:')) {
|
|
269
|
-
// For build purposes, we'll use the file: protocol to reference local packages
|
|
270
|
-
const depPackage = packages.find(p => p.name === depName);
|
|
271
|
-
if (depPackage) {
|
|
272
|
-
console.log(chalk.gray(` Replacing ${depName} workspace dependency with file reference`));
|
|
273
|
-
pkg[depType][depName] = `file:../${depPackage.path}`;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// Write the updated package.json
|
|
281
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
282
|
-
console.log(chalk.green(`✅ Workspace dependencies fixed for build: ${packagePath}`));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Restore workspace dependencies after build
|
|
286
|
-
function restoreWorkspaceDependenciesAfterBuild(packagePath) {
|
|
287
|
-
console.log(chalk.blue(`🔄 Restoring workspace dependencies after build: ${packagePath}...`));
|
|
288
|
-
|
|
289
|
-
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
|
|
290
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
291
|
-
|
|
292
|
-
// Restore dependencies
|
|
293
|
-
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
|
|
294
|
-
|
|
295
|
-
depTypes.forEach(depType => {
|
|
296
|
-
if (pkg[depType]) {
|
|
297
|
-
Object.keys(pkg[depType]).forEach(depName => {
|
|
298
|
-
// Check if this is one of our internal packages referenced with file:
|
|
299
|
-
const depPackage = packages.find(p => p.name === depName);
|
|
300
|
-
if (depPackage && pkg[depType][depName].startsWith('file:')) {
|
|
301
|
-
console.log(chalk.gray(` Restoring ${depName} to workspace dependency`));
|
|
302
|
-
pkg[depType][depName] = 'workspace:*';
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
// Write the updated package.json
|
|
309
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
310
|
-
console.log(chalk.green(`✅ Workspace dependencies restored after build: ${packagePath}`));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
212
|
// Fix workspace dependencies for publish
|
|
314
|
-
function
|
|
213
|
+
function fixWorkspaceDependencies(packagePath, packageVersions) {
|
|
315
214
|
console.log(chalk.blue(`🔧 Fixing workspace dependencies for publish: ${packagePath}...`));
|
|
316
215
|
|
|
317
216
|
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
|
|
@@ -342,7 +241,7 @@ function fixWorkspaceDependenciesForPublish(packagePath, packageVersions) {
|
|
|
342
241
|
}
|
|
343
242
|
|
|
344
243
|
// Restore workspace dependencies after publish
|
|
345
|
-
function
|
|
244
|
+
function restoreWorkspaceDependencies(packagePath) {
|
|
346
245
|
console.log(chalk.blue(`🔄 Restoring workspace dependencies for ${packagePath}...`));
|
|
347
246
|
|
|
348
247
|
const pkgPath = path.join(process.cwd(), packagePath, 'package.json');
|
|
@@ -370,33 +269,25 @@ function restoreWorkspaceDependenciesAfterPublish(packagePath) {
|
|
|
370
269
|
}
|
|
371
270
|
|
|
372
271
|
// Build package
|
|
373
|
-
function buildPackage(
|
|
374
|
-
console.log(chalk.blue(`\n🔨 Building ${
|
|
272
|
+
function buildPackage(packagePath, packageName) {
|
|
273
|
+
console.log(chalk.blue(`\n🔨 Building ${packageName}...`));
|
|
375
274
|
|
|
376
275
|
try {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
// Templates don't need to be built, just validate package.json
|
|
391
|
-
console.log(chalk.gray(' Templates do not require building, skipping...'));
|
|
392
|
-
}
|
|
393
|
-
console.log(chalk.green(`✅ ${pkg.name} built successfully`));
|
|
394
|
-
} finally {
|
|
395
|
-
// Always restore workspace dependencies
|
|
396
|
-
restoreWorkspaceDependenciesAfterBuild(pkg.path);
|
|
397
|
-
}
|
|
276
|
+
if (packagePath === 'config') {
|
|
277
|
+
execSync('pnpm run build', { cwd: path.join(process.cwd(), packagePath), stdio: 'inherit' });
|
|
278
|
+
} else if (packagePath === 'server') {
|
|
279
|
+
execSync('pnpm run prebuild && pnpm run build', { cwd: path.join(process.cwd(), packagePath), stdio: 'inherit' });
|
|
280
|
+
} else if (packagePath === 'client') {
|
|
281
|
+
execSync('pnpm run prebuild && pnpm run build', { cwd: path.join(process.cwd(), packagePath), stdio: 'inherit' });
|
|
282
|
+
} else if (packagePath === 'toolkit') {
|
|
283
|
+
execSync('pnpm run build', { cwd: path.join(process.cwd(), packagePath), stdio: 'inherit' });
|
|
284
|
+
} else if (packagePath === 'templates/hello-world' || packagePath === 'templates/twentytwentyfive') {
|
|
285
|
+
// Templates don't need to be built, just validate package.json
|
|
286
|
+
console.log(chalk.gray(' Templates do not require building, skipping...'));
|
|
287
|
+
}
|
|
288
|
+
console.log(chalk.green(`✅ ${packageName} built successfully`));
|
|
398
289
|
} catch (error) {
|
|
399
|
-
console.log(chalk.red(`❌ Failed to build ${
|
|
290
|
+
console.log(chalk.red(`❌ Failed to build ${packageName}`));
|
|
400
291
|
throw error;
|
|
401
292
|
}
|
|
402
293
|
}
|
|
@@ -451,57 +342,8 @@ function checkEnvironment() {
|
|
|
451
342
|
return true;
|
|
452
343
|
}
|
|
453
344
|
|
|
454
|
-
//
|
|
455
|
-
async function
|
|
456
|
-
console.log(chalk.blue('🏗️ ReactPress Package Builder\n'));
|
|
457
|
-
|
|
458
|
-
// Show current versions
|
|
459
|
-
console.log(chalk.cyan('📋 Current package versions:'));
|
|
460
|
-
packages.forEach(pkg => {
|
|
461
|
-
const version = getCurrentVersion(pkg.path);
|
|
462
|
-
console.log(chalk.gray(` ${pkg.name}: ${version}`));
|
|
463
|
-
});
|
|
464
|
-
console.log();
|
|
465
|
-
|
|
466
|
-
try {
|
|
467
|
-
// Track which packages actually need to be built
|
|
468
|
-
const packagesToBuild = [];
|
|
469
|
-
|
|
470
|
-
// Check for meaningful changes in each package
|
|
471
|
-
for (const pkg of packages) {
|
|
472
|
-
if (fs.existsSync(path.join(process.cwd(), pkg.path))) {
|
|
473
|
-
if (hasMeaningfulChangesForBuild(pkg.path, pkg.name)) {
|
|
474
|
-
packagesToBuild.push(pkg);
|
|
475
|
-
console.log(chalk.blue(`\n📦 ${pkg.name} has changes, will be built`));
|
|
476
|
-
} else {
|
|
477
|
-
console.log(chalk.gray(`\n⏭️ ${pkg.name} has no meaningful changes, skipping...`));
|
|
478
|
-
}
|
|
479
|
-
} else {
|
|
480
|
-
console.log(chalk.yellow(`⚠️ Package ${pkg.name} directory not found, skipping...`));
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (packagesToBuild.length === 0) {
|
|
485
|
-
console.log(chalk.green('\n✅ No packages have meaningful changes. Nothing to build!'));
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// Build packages that have changes
|
|
490
|
-
for (const pkg of packagesToBuild) {
|
|
491
|
-
await buildPackage(pkg);
|
|
492
|
-
// Save the hash after successful build
|
|
493
|
-
savePackageHashForBuild(pkg.path, pkg.name);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
console.log(chalk.green(`\n🎉 ${packagesToBuild.length} package(s) built successfully!`));
|
|
497
|
-
} catch (error) {
|
|
498
|
-
console.error(chalk.red('❌ Build failed:'), error);
|
|
499
|
-
process.exit(1);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// Publish packages function
|
|
504
|
-
async function publishPackages() {
|
|
345
|
+
// Main function
|
|
346
|
+
async function main() {
|
|
505
347
|
// Check if called with --no-build flag
|
|
506
348
|
const noBuild = process.argv.includes('--no-build');
|
|
507
349
|
|
|
@@ -550,7 +392,7 @@ async function publishPackages() {
|
|
|
550
392
|
// Check for meaningful changes in each package
|
|
551
393
|
for (const pkg of packages) {
|
|
552
394
|
if (fs.existsSync(path.join(process.cwd(), pkg.path))) {
|
|
553
|
-
if (
|
|
395
|
+
if (hasMeaningfulChanges(pkg.path, pkg.name)) {
|
|
554
396
|
packagesToBuild.push(pkg);
|
|
555
397
|
console.log(chalk.blue(`\n📦 ${pkg.name} has changes, will be built`));
|
|
556
398
|
} else {
|
|
@@ -568,9 +410,9 @@ async function publishPackages() {
|
|
|
568
410
|
|
|
569
411
|
// Build packages that have changes
|
|
570
412
|
for (const pkg of packagesToBuild) {
|
|
571
|
-
buildPackage(pkg);
|
|
413
|
+
buildPackage(pkg.path, pkg.name);
|
|
572
414
|
// Save the hash after successful build
|
|
573
|
-
|
|
415
|
+
savePackageHash(pkg.path, pkg.name);
|
|
574
416
|
}
|
|
575
417
|
|
|
576
418
|
console.log(chalk.green(`\n🎉 ${packagesToBuild.length} package(s) built successfully!`));
|
|
@@ -591,7 +433,7 @@ async function publishPackages() {
|
|
|
591
433
|
]);
|
|
592
434
|
|
|
593
435
|
// Check if the selected package has meaningful changes
|
|
594
|
-
if (!
|
|
436
|
+
if (!hasMeaningfulChanges(selectedPackage.path, selectedPackage.name)) {
|
|
595
437
|
console.log(chalk.gray(`\n⏭️ ${selectedPackage.name} has no meaningful changes, skipping...`));
|
|
596
438
|
console.log(chalk.green('✅ Nothing to publish!'));
|
|
597
439
|
return;
|
|
@@ -641,13 +483,13 @@ async function publishPackages() {
|
|
|
641
483
|
packageVersions[selectedPackage.name] = newVersion;
|
|
642
484
|
|
|
643
485
|
// Fix workspace dependencies before publishing
|
|
644
|
-
|
|
486
|
+
fixWorkspaceDependencies(selectedPackage.path, packageVersions);
|
|
645
487
|
|
|
646
488
|
try {
|
|
647
489
|
updateVersion(selectedPackage.path, newVersion);
|
|
648
490
|
// Only build if not disabled
|
|
649
491
|
if (!noBuild) {
|
|
650
|
-
buildPackage(selectedPackage);
|
|
492
|
+
buildPackage(selectedPackage.path, selectedPackage.name);
|
|
651
493
|
}
|
|
652
494
|
|
|
653
495
|
// Determine tag based on version type
|
|
@@ -655,12 +497,12 @@ async function publishPackages() {
|
|
|
655
497
|
publishPackage(selectedPackage.path, selectedPackage.name, tag);
|
|
656
498
|
|
|
657
499
|
// Save the hash after successful publish
|
|
658
|
-
|
|
500
|
+
savePackageHash(selectedPackage.path, selectedPackage.name);
|
|
659
501
|
|
|
660
502
|
console.log(chalk.green(`\n🎉 ${selectedPackage.name} v${newVersion} published successfully!`));
|
|
661
503
|
} finally {
|
|
662
504
|
// Always restore workspace dependencies
|
|
663
|
-
|
|
505
|
+
restoreWorkspaceDependencies(selectedPackage.path);
|
|
664
506
|
}
|
|
665
507
|
|
|
666
508
|
return;
|
|
@@ -708,7 +550,7 @@ async function publishPackages() {
|
|
|
708
550
|
continue;
|
|
709
551
|
}
|
|
710
552
|
|
|
711
|
-
if (
|
|
553
|
+
if (hasMeaningfulChanges(pkg.path, pkg.name)) {
|
|
712
554
|
packagesToPublish.push(pkg);
|
|
713
555
|
console.log(chalk.blue(`\n📦 ${pkg.name} has changes, will be published`));
|
|
714
556
|
} else {
|
|
@@ -744,21 +586,21 @@ async function publishPackages() {
|
|
|
744
586
|
packageVersions[pkg.name] = newVersion;
|
|
745
587
|
|
|
746
588
|
// Fix workspace dependencies before publishing
|
|
747
|
-
|
|
589
|
+
fixWorkspaceDependencies(pkg.path, packageVersions);
|
|
748
590
|
|
|
749
591
|
try {
|
|
750
592
|
updateVersion(pkg.path, newVersion);
|
|
751
593
|
// Only build if not disabled
|
|
752
594
|
if (!noBuild) {
|
|
753
|
-
buildPackage(pkg);
|
|
595
|
+
buildPackage(pkg.path, pkg.name);
|
|
754
596
|
}
|
|
755
597
|
publishPackage(pkg.path, pkg.name, tag);
|
|
756
598
|
|
|
757
599
|
// Save the hash after successful publish
|
|
758
|
-
|
|
600
|
+
savePackageHash(pkg.path, pkg.name);
|
|
759
601
|
} finally {
|
|
760
602
|
// Always restore workspace dependencies
|
|
761
|
-
|
|
603
|
+
restoreWorkspaceDependencies(pkg.path);
|
|
762
604
|
}
|
|
763
605
|
}
|
|
764
606
|
|
|
@@ -847,7 +689,7 @@ async function publishPackages() {
|
|
|
847
689
|
continue;
|
|
848
690
|
}
|
|
849
691
|
|
|
850
|
-
if (
|
|
692
|
+
if (hasMeaningfulChanges(pkg.path, pkg.name)) {
|
|
851
693
|
packagesToPublish.push(pkg);
|
|
852
694
|
console.log(chalk.blue(`\n📦 ${pkg.name} has changes, will be published`));
|
|
853
695
|
} else {
|
|
@@ -869,13 +711,13 @@ async function publishPackages() {
|
|
|
869
711
|
packageVersions[pkg.name] = pkgVersion;
|
|
870
712
|
|
|
871
713
|
// Fix workspace dependencies before publishing
|
|
872
|
-
|
|
714
|
+
fixWorkspaceDependencies(pkg.path, packageVersions);
|
|
873
715
|
|
|
874
716
|
try {
|
|
875
717
|
updateVersion(pkg.path, pkgVersion);
|
|
876
718
|
// Only build if not disabled
|
|
877
719
|
if (!noBuild) {
|
|
878
|
-
buildPackage(pkg);
|
|
720
|
+
buildPackage(pkg.path, pkg.name);
|
|
879
721
|
}
|
|
880
722
|
|
|
881
723
|
// Determine tag based on version type and branch
|
|
@@ -883,10 +725,10 @@ async function publishPackages() {
|
|
|
883
725
|
publishPackage(pkg.path, pkg.name, tag);
|
|
884
726
|
|
|
885
727
|
// Save the hash after successful publish
|
|
886
|
-
|
|
728
|
+
savePackageHash(pkg.path, pkg.name);
|
|
887
729
|
} finally {
|
|
888
730
|
// Always restore workspace dependencies
|
|
889
|
-
|
|
731
|
+
restoreWorkspaceDependencies(pkg.path);
|
|
890
732
|
}
|
|
891
733
|
}
|
|
892
734
|
|
|
@@ -907,39 +749,7 @@ ${Object.entries(packageVersions).map(([name, version]) => `- ${name}@${version}
|
|
|
907
749
|
}
|
|
908
750
|
}
|
|
909
751
|
|
|
910
|
-
// Main function
|
|
911
|
-
async function main() {
|
|
912
|
-
// Check command line arguments
|
|
913
|
-
const args = process.argv.slice(2);
|
|
914
|
-
|
|
915
|
-
if (args.includes('--publish')) {
|
|
916
|
-
// When called with --publish, start the publish process
|
|
917
|
-
console.log(chalk.blue('🏗️ ReactPress Package Builder\n'));
|
|
918
|
-
|
|
919
|
-
// Show current versions
|
|
920
|
-
console.log(chalk.cyan('📋 Current package versions:'));
|
|
921
|
-
packages.forEach(pkg => {
|
|
922
|
-
const version = getCurrentVersion(pkg.path);
|
|
923
|
-
console.log(chalk.gray(` ${pkg.name}: ${version}`));
|
|
924
|
-
});
|
|
925
|
-
console.log();
|
|
926
|
-
|
|
927
|
-
// Start the publish process
|
|
928
|
-
await publishPackages();
|
|
929
|
-
} else if (args.includes('--build')) {
|
|
930
|
-
// When called with --build, just build packages
|
|
931
|
-
await buildPackages();
|
|
932
|
-
} else {
|
|
933
|
-
// Default behavior - show help
|
|
934
|
-
console.log(chalk.blue('🏗️ ReactPress CLI\n'));
|
|
935
|
-
console.log('Usage:');
|
|
936
|
-
console.log(' node scripts/reactpress-cli.js --build Build all packages');
|
|
937
|
-
console.log(' node scripts/reactpress-cli.js --publish Publish packages (interactive)');
|
|
938
|
-
console.log('');
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
|
|
942
752
|
main().catch(error => {
|
|
943
|
-
console.error(chalk.red('❌
|
|
753
|
+
console.error(chalk.red('❌ Publishing failed:'), error);
|
|
944
754
|
process.exit(1);
|
|
945
|
-
});
|
|
755
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const express = require('express');
|
|
4
|
+
const mysql = require('mysql2/promise');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const open = require('open');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const crypto = require('crypto');
|
|
10
|
+
|
|
11
|
+
const PORT = 3003;
|
|
12
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
13
|
+
|
|
14
|
+
// WordPress-style 5-minute installation
|
|
15
|
+
async function install() {
|
|
16
|
+
console.log(chalk.blue('🚀 ReactPress 5-Minute Installation'));
|
|
17
|
+
console.log(chalk.cyan('🌍 Starting installation wizard...'));
|
|
18
|
+
|
|
19
|
+
const app = express();
|
|
20
|
+
app.use(express.json());
|
|
21
|
+
app.get('/', (req, res) => res.send(getHTML()));
|
|
22
|
+
|
|
23
|
+
app.post('/test-db', async (req, res) => {
|
|
24
|
+
const { host, port, user, password, database } = req.body;
|
|
25
|
+
try {
|
|
26
|
+
const conn = await mysql.createConnection({ host, port: parseInt(port), user, password });
|
|
27
|
+
await conn.execute(`CREATE DATABASE IF NOT EXISTS \`${database}\` CHARACTER SET utf8mb4`);
|
|
28
|
+
await conn.end();
|
|
29
|
+
res.json({ success: true, message: 'Database connection successful!' });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
res.json({ success: false, message: error.message });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
app.post('/install', async (req, res) => {
|
|
36
|
+
const { db, site } = req.body;
|
|
37
|
+
const env = `DB_HOST=${db.host}\nDB_PORT=${db.port}\nDB_USER=${db.user}\nDB_PASSWD=${db.password}\nDB_DATABASE=${db.database}\nCLIENT_SITE_URL=${site.clientUrl}\nSERVER_SITE_URL=${site.serverUrl}\nJWT_SECRET=${crypto.randomBytes(32).toString('hex')}\n`;
|
|
38
|
+
fs.writeFileSync(envPath, env);
|
|
39
|
+
res.json({ success: true, message: 'ReactPress installed successfully!' });
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
console.log(chalk.green('\n🎉 Installation completed!'));
|
|
42
|
+
console.log(chalk.cyan('Run: npx reactpress-server start'));
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}, 2000);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const server = app.listen(PORT, () => {
|
|
48
|
+
const url = `http://localhost:${PORT}`;
|
|
49
|
+
console.log(chalk.green(`✅ Installation wizard: ${url}`));
|
|
50
|
+
open(url);
|
|
51
|
+
console.log(chalk.gray('Press Ctrl+C to cancel\n'));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
process.on('SIGINT', () => {
|
|
55
|
+
console.log(chalk.yellow('\n⚠️ Installation cancelled'));
|
|
56
|
+
server.close();
|
|
57
|
+
process.exit(0);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function start() {
|
|
62
|
+
if (!fs.existsSync(envPath)) {
|
|
63
|
+
console.log(chalk.red('❌ No configuration found!'));
|
|
64
|
+
console.log(chalk.yellow('Run: npx reactpress-server install'));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
console.log(chalk.blue('🚀 Starting ReactPress Server...'));
|
|
68
|
+
const { spawn } = require('child_process');
|
|
69
|
+
spawn('npm', ['run', 'start:dev'], { cwd: path.resolve(__dirname, '../server'), stdio: 'inherit' });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!clientUrl || !serverUrl) {
|
|
73
|
+
showNotice('Please fill in all site URLs.', 'error', 'installResult');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const installBtn = document.getElementById('installBtn');
|
|
78
|
+
const originalText = installBtn.innerHTML;
|
|
79
|
+
|
|
80
|
+
installBtn.disabled = true;
|
|
81
|
+
installBtn.innerHTML = '<span class="wp-loader"></span>Installing ReactPress...';
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetch('/install', {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: {
|
|
87
|
+
'Content-Type': 'application/json'
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
db: dbData,
|
|
91
|
+
site: { clientUrl, serverUrl }
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const result = await response.json();
|
|
96
|
+
|
|
97
|
+
if (result.success) {
|
|
98
|
+
showStep(3);
|
|
99
|
+
} else {
|
|
100
|
+
showNotice(result.message, 'error', 'installResult');
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
showNotice('Installation failed. Please try again.', 'error', 'installResult');
|
|
104
|
+
} finally {
|
|
105
|
+
installBtn.disabled = false;
|
|
106
|
+
installBtn.innerHTML = originalText;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Initialize progress bar
|
|
111
|
+
updateProgress();
|
|
112
|
+
|
|
113
|
+
// Auto-focus first input
|
|
114
|
+
document.getElementById('dbHost').focus();
|
|
115
|
+
</script>
|
|
116
|
+
</body>
|
|
117
|
+
</html>`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Main entry point
|
|
121
|
+
const args = process.argv.slice(2);
|
|
122
|
+
if (args.length === 0 || args[0] === 'install') {
|
|
123
|
+
install();
|
|
124
|
+
} else if (args[0] === 'start') {
|
|
125
|
+
start();
|
|
126
|
+
} else {
|
|
127
|
+
console.log(chalk.blue('ReactPress Server CLI'));
|
|
128
|
+
console.log(chalk.gray('npx reactpress-server # Install'));
|
|
129
|
+
console.log(chalk.gray('npx reactpress-server start # Start server'));
|
|
130
|
+
}
|