mango-cms 0.3.35 → 0.3.36

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/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from 'commander';
4
- import { execSync, spawn } from 'child_process';
4
+ import { execSync, spawn, spawnSync } from 'child_process';
5
5
  import path from 'path';
6
6
  import { fileURLToPath } from 'url';
7
7
  import inquirer from 'inquirer';
@@ -14,6 +14,22 @@ import os from 'os';
14
14
  const __filename = fileURLToPath(import.meta.url);
15
15
  const __dirname = path.dirname(__filename);
16
16
 
17
+ // When `mango` is invoked from a global install (npm i -g mango-cms) inside a
18
+ // project that has its own mango-cms in node_modules, defer to the project-local
19
+ // CLI so the version pinned in package.json always wins. This is what lets users
20
+ // type plain `mango dev` / `mango deploy` instead of prefixing with `yarn`/`npx`.
21
+ const localCli = path.join(process.cwd(), 'node_modules', 'mango-cms', 'cli.js');
22
+ if (fs.existsSync(localCli)) {
23
+ let isSelf = false;
24
+ try {
25
+ isSelf = fs.realpathSync(localCli) === fs.realpathSync(__filename);
26
+ } catch (e) { /* fall through and run this copy */ }
27
+ if (!isSelf) {
28
+ const result = spawnSync(process.execPath, [localCli, ...process.argv.slice(2)], { stdio: 'inherit' });
29
+ process.exit(result.status ?? 0);
30
+ }
31
+ }
32
+
17
33
  const program = new Command();
18
34
 
19
35
  // Helper function to download and extract versioned src zip file
@@ -522,15 +538,16 @@ async function detectWebServer() {
522
538
  }
523
539
 
524
540
  // Helper function to generate nginx config
525
- function generateNginxConfig(settings, buildPath) {
541
+ function generateNginxConfig(settings, buildPath, deployUi = false) {
526
542
  const domain = settings.mangoDomain;
527
543
  const port = settings.port || 3002;
528
544
  const frontPort = settings.frontPort || 3001;
529
545
  const uiDomain = settings.uiDomain;
530
546
  const uiPort = settings.uiPort || 3001;
531
547
 
532
- // Reverse-proxy the Mango UI (Nuxt SSR server) on its own subdomain, when configured.
533
- const uiServerBlock = uiDomain ? `
548
+ // Reverse-proxy the Mango UI (Nuxt SSR server) on its own subdomain,
549
+ // only when the UI is part of this deploy and a uiDomain is configured.
550
+ const uiServerBlock = (deployUi && uiDomain) ? `
534
551
  server {
535
552
  server_name ${uiDomain};
536
553
 
@@ -617,15 +634,16 @@ ${uiServerBlock}`;
617
634
  }
618
635
 
619
636
  // Helper function to generate apache config
620
- function generateApacheConfig(settings, buildPath) {
637
+ function generateApacheConfig(settings, buildPath, deployUi = false) {
621
638
  const domain = settings.mangoDomain;
622
639
  const port = settings.port || 3002;
623
640
  const frontPort = settings.frontPort || 3001;
624
641
  const uiDomain = settings.uiDomain;
625
642
  const uiPort = settings.uiPort || 3001;
626
643
 
627
- // Reverse-proxy the Mango UI (Nuxt SSR server) on its own subdomain, when configured.
628
- const uiVirtualHost = uiDomain ? `
644
+ // Reverse-proxy the Mango UI (Nuxt SSR server) on its own subdomain,
645
+ // only when the UI is part of this deploy and a uiDomain is configured.
646
+ const uiVirtualHost = (deployUi && uiDomain) ? `
629
647
  <VirtualHost *:80>
630
648
  ServerName ${uiDomain}
631
649
 
@@ -697,7 +715,7 @@ ${uiVirtualHost}`;
697
715
  }
698
716
 
699
717
  // Helper function to configure web server
700
- async function configureWebServer(settings, buildPath) {
718
+ async function configureWebServer(settings, buildPath, deployUi = false) {
701
719
  let webServer = await detectWebServer();
702
720
 
703
721
  if (!webServer) {
@@ -713,8 +731,8 @@ async function configureWebServer(settings, buildPath) {
713
731
  }
714
732
 
715
733
  const config = webServer === 'nginx' ?
716
- generateNginxConfig(settings, buildPath) :
717
- generateApacheConfig(settings, buildPath);
734
+ generateNginxConfig(settings, buildPath, deployUi) :
735
+ generateApacheConfig(settings, buildPath, deployUi);
718
736
 
719
737
  const configPath = webServer === 'nginx' ?
720
738
  `/etc/nginx/sites-available/${settings.database.toLowerCase()}` :
@@ -796,7 +814,9 @@ async function managePM2Process(settings) {
796
814
  }
797
815
  }
798
816
 
799
- // Helper function to build and (re)start the Mango UI (Nuxt) under PM2
817
+ // Helper function to build and (re)start the Mango UI (Nuxt) under PM2.
818
+ // Only called when the UI deploy is explicitly enabled (--ui flag or
819
+ // "deployUi": true in settings.json) — the admin UI is opt-in on deploy.
800
820
  async function manageUiPM2Process(settings, mangoCmsRoot, userProjectRoot) {
801
821
  if (!settings.uiDomain) {
802
822
  console.log('No uiDomain configured, skipping Mango UI deploy.');
@@ -843,29 +863,39 @@ async function manageUiPM2Process(settings, mangoCmsRoot, userProjectRoot) {
843
863
  program
844
864
  .command('deploy')
845
865
  .description('Build and deploy Mango CMS using PM2')
846
- .action(async () => {
866
+ .option('--ui', 'also build and deploy the Mango admin UI (off by default; or set "deployUi": true in settings.json)')
867
+ .action(async (options) => {
847
868
  try {
848
869
  const configPath = path.join(process.cwd(), 'mango/config/settings.json');
849
870
  const settings = JSON.parse(fs.readFileSync(configPath, 'utf8'));
850
871
  const mangoCmsRoot = path.resolve(__dirname);
851
872
  const userProjectRoot = process.cwd();
852
873
 
874
+ // The admin UI is opt-in: deployed only with --ui or "deployUi": true.
875
+ const deployUi = Boolean(options.ui || settings.deployUi);
876
+
853
877
  // Run build command
854
878
  console.log('Building Mango CMS...');
855
879
  execSync('npm run mango build', { stdio: 'inherit' });
856
880
 
857
- // Make sure a UI bundle is available for deploy.
858
- await ensureUiExists(mangoCmsRoot);
881
+ // Make sure a UI bundle is available for deploy (only when deploying it).
882
+ if (deployUi) {
883
+ await ensureUiExists(mangoCmsRoot);
884
+ }
859
885
 
860
886
  // Check if PM2 is installed
861
887
  if (await checkPM2()) {
862
888
  await managePM2Process(settings);
863
- await manageUiPM2Process(settings, mangoCmsRoot, userProjectRoot);
889
+ if (deployUi) {
890
+ await manageUiPM2Process(settings, mangoCmsRoot, userProjectRoot);
891
+ } else {
892
+ console.log('Skipping Mango UI deploy (opt in with "mango deploy --ui" or "deployUi": true in settings.json).');
893
+ }
864
894
 
865
895
  // Configure web server
866
896
  const buildPath = path.join(process.cwd(), 'build');
867
897
  try {
868
- await configureWebServer(settings, buildPath);
898
+ await configureWebServer(settings, buildPath, deployUi);
869
899
  } catch (error) {
870
900
  console.warn('Warning: Could not configure web server:', error.message);
871
901
  console.warn('You may need to configure your web server manually.');
@@ -881,8 +911,9 @@ program
881
911
 
882
912
  program
883
913
  .command('launch')
884
- .description('One-shot server deploy: git pull, install, build the site, and deploy backend + UI')
885
- .action(async () => {
914
+ .description('One-shot server deploy: git pull, install, build the site, and deploy the backend (add --ui for the admin UI)')
915
+ .option('--ui', 'also build and deploy the Mango admin UI (off by default; or set "deployUi": true in settings.json)')
916
+ .action(async (options) => {
886
917
  try {
887
918
  const cwd = process.cwd();
888
919
  const useYarn = fs.existsSync(path.join(cwd, 'yarn.lock'));
@@ -909,12 +940,14 @@ program
909
940
  console.log('\n→ Skipping site build (no "build" script found)');
910
941
  }
911
942
 
912
- // 4. Deploy backend + UI + web server config via the freshly installed mango.
913
- // `mango deploy` builds the backend, (re)starts PM2 for {db}-mango, {db}
914
- // and {db}-ui, and writes the nginx/apache blocks for all three domains.
915
- run('Deploying backend + UI', 'npx mango deploy');
943
+ // 4. Deploy backend (+ UI when opted in) + web server config via the
944
+ // freshly installed mango. `mango deploy` builds the backend and
945
+ // (re)starts PM2 for {db}-mango and {db}; with --ui it also builds
946
+ // the admin UI, starts {db}-ui, and writes its web server block.
947
+ const deployCmd = options.ui ? 'npx mango deploy --ui' : 'npx mango deploy';
948
+ run(options.ui ? 'Deploying backend + UI' : 'Deploying backend', deployCmd);
916
949
 
917
- console.log('\n✨ Launch complete! Backend, site, and UI are deployed.');
950
+ console.log(`\n✨ Launch complete! Backend and site are deployed${options.ui ? ', along with the admin UI' : ''}.`);
918
951
  } catch (error) {
919
952
  console.error('\nLaunch failed:', error.message);
920
953
  process.exit(1);
@@ -24,7 +24,7 @@
24
24
  "dayjs": "^1.10.7",
25
25
  "express": "^4.18.1",
26
26
  "google-maps": "^4.3.3",
27
- "mango-cms": "^0.3.31",
27
+ "mango-cms": "^0.3.36",
28
28
  "mapbox-gl": "^2.7.0",
29
29
  "vite": "^6.2.2",
30
30
  "vue": "^3.2.37",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mango-cms",
3
- "version": "0.3.35",
3
+ "version": "0.3.36",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {