underpost 3.1.1 → 3.1.3

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.
@@ -230,16 +230,28 @@ const defaultSitemapXsl = `<?xml version="1.0" encoding="UTF-8"?>
230
230
  * @function buildClient
231
231
  * @memberof clientBuild
232
232
  * @param {Object} options - Options for the build process.
233
+ * @param {string} options.deployId - The deployment ID for which to build the client.
233
234
  * @param {Array} options.liveClientBuildPaths - List of paths to build incrementally.
234
235
  * @param {Array} options.instances - List of instances to build.
235
236
  * @param {boolean} options.buildZip - Whether to create zip files of the builds.
237
+ * @param {boolean} options.fullBuild - Whether to perform a full build.
238
+ * @param {boolean} options.iconsBuild - Whether to build icons.
236
239
  * @returns {Promise<void>} - Promise that resolves when the build is complete.
237
240
  * @throws {Error} - If the build fails.
238
241
  * @memberof clientBuild
239
242
  */
240
- const buildClient = async (options = { liveClientBuildPaths: [], instances: [], buildZip: false }) => {
243
+ const buildClient = async (
244
+ options = {
245
+ deployId: '',
246
+ liveClientBuildPaths: [],
247
+ instances: [],
248
+ buildZip: false,
249
+ fullBuild: false,
250
+ iconsBuild: false,
251
+ },
252
+ ) => {
241
253
  const logger = loggerFactory(import.meta);
242
- const deployId = process.env.DEPLOY_ID;
254
+ const deployId = options.deployId || process.env.DEPLOY_ID;
243
255
  const confClient = readConfJson(deployId, 'client');
244
256
  const confServer = readConfJson(deployId, 'server', { loadReplicas: true });
245
257
  const confSSR = readConfJson(deployId, 'ssr');
@@ -373,17 +385,14 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
373
385
  client,
374
386
  directory,
375
387
  disabledRebuild,
376
- minifyBuild,
377
388
  db,
378
389
  redirect,
379
390
  apis,
380
- iconsBuild,
381
- docsBuild,
382
391
  apiBaseProxyPath,
383
392
  apiBaseHost,
384
393
  ttiLoadTimeLimit,
385
394
  singleReplica,
386
- offlineBuild,
395
+ docs,
387
396
  } = confServer[host][path];
388
397
  if (singleReplica) continue;
389
398
  if (!confClient[client]) confClient[client] = {};
@@ -397,9 +406,10 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
397
406
  const rootClientPath = directory ? directory : `${publicPath}/${host}${path}`;
398
407
  const port = newInstance(currentPort);
399
408
  const publicClientId = publicRef ? publicRef : client;
400
- const fullBuildEnabled = !confServer[host][path].liteBuild && !enableLiveRebuild;
409
+ const fullBuildEnabled = options.fullBuild && !enableLiveRebuild;
401
410
  // const baseHost = process.env.NODE_ENV === 'production' ? `https://${host}` : `http://localhost:${port}`;
402
411
  const baseHost = process.env.NODE_ENV === 'production' ? `https://${host}` : ``;
412
+ const minifyBuild = process.env.NODE_ENV === 'production';
403
413
  // ''; // process.env.NODE_ENV === 'production' ? `https://${host}` : ``;
404
414
  currentPort++;
405
415
 
@@ -421,7 +431,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
421
431
  rootClientPath,
422
432
  acmeChallengeFullPath,
423
433
  publicClientId,
424
- iconsBuild,
434
+ iconsBuild: options.iconsBuild,
425
435
  metadata,
426
436
  publicCopyNonExistingFiles,
427
437
  });
@@ -445,11 +455,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
445
455
  'components',
446
456
  baseHost,
447
457
  );
448
- fs.writeFileSync(
449
- jsPublicPath,
450
- minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
451
- 'utf8',
452
- );
458
+ fs.writeFileSync(jsPublicPath, minifyBuild ? UglifyJS.minify(jsSrc).code : jsSrc, 'utf8');
453
459
  }
454
460
  }
455
461
 
@@ -471,11 +477,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
471
477
  'services',
472
478
  baseHost,
473
479
  );
474
- fs.writeFileSync(
475
- jsPublicPath,
476
- minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
477
- 'utf8',
478
- );
480
+ fs.writeFileSync(jsPublicPath, minifyBuild ? UglifyJS.minify(jsSrc).code : jsSrc, 'utf8');
479
481
  }
480
482
  }
481
483
 
@@ -493,11 +495,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
493
495
  'services',
494
496
  baseHost,
495
497
  );
496
- fs.writeFileSync(
497
- jsPublicPath,
498
- minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
499
- 'utf8',
500
- );
498
+ fs.writeFileSync(jsPublicPath, minifyBuild ? UglifyJS.minify(jsSrc).code : jsSrc, 'utf8');
501
499
  }
502
500
  }
503
501
  }
@@ -517,11 +515,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
517
515
  if (!(enableLiveRebuild && !options.liveClientBuildPaths.find((p) => p.srcBuildPath === jsSrcPath))) {
518
516
  const jsSrc = viewFormatted(await srcFormatted(fs.readFileSync(jsSrcPath, 'utf8')), dists, path, baseHost);
519
517
 
520
- fs.writeFileSync(
521
- jsPublicPath,
522
- minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
523
- 'utf8',
524
- );
518
+ fs.writeFileSync(jsPublicPath, minifyBuild ? UglifyJS.minify(jsSrc).code : jsSrc, 'utf8');
525
519
  }
526
520
 
527
521
  if (
@@ -548,11 +542,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
548
542
  baseHost,
549
543
  );
550
544
 
551
- fs.writeFileSync(
552
- `${buildPath}${buildId}.js`,
553
- minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
554
- 'utf8',
555
- );
545
+ fs.writeFileSync(`${buildPath}${buildId}.js`, minifyBuild ? UglifyJS.minify(jsSrc).code : jsSrc, 'utf8');
556
546
  const title = metadata.title ? metadata.title : title;
557
547
 
558
548
  const canonicalURL = `https://${host}${path}${
@@ -689,7 +679,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [],
689
679
 
690
680
  fs.writeFileSync(
691
681
  `${buildPath}index.html`,
692
- minifyBuild || process.env.NODE_ENV === 'production'
682
+ minifyBuild
693
683
  ? await minify(htmlSrc, {
694
684
  minifyCSS: true,
695
685
  minifyJS: true,
@@ -739,7 +729,7 @@ Sitemap: ${sitemapBaseUrl}/sitemap.xml`,
739
729
  );
740
730
  }
741
731
 
742
- if (fullBuildEnabled && !enableLiveRebuild && docsBuild) {
732
+ if (fullBuildEnabled && docs) {
743
733
  await buildDocs({
744
734
  host,
745
735
  path,
@@ -749,13 +739,14 @@ Sitemap: ${sitemapBaseUrl}/sitemap.xml`,
749
739
  publicClientId,
750
740
  rootClientPath,
751
741
  packageData,
742
+ docs,
752
743
  });
753
744
  }
754
745
 
755
746
  if (client) {
756
747
  let PRE_CACHED_RESOURCES = [];
757
748
 
758
- if (views && offlineBuild && fs.existsSync(`${rootClientPath}/sw.js`)) {
749
+ if (views && fs.existsSync(`${rootClientPath}/sw.js`)) {
759
750
  PRE_CACHED_RESOURCES = await fs.readdir(rootClientPath, { recursive: true });
760
751
  PRE_CACHED_RESOURCES = views
761
752
  .map((view) => `${path === '/' ? '' : path}${view.path}`)
@@ -774,7 +765,7 @@ Sitemap: ${sitemapBaseUrl}/sitemap.xml`,
774
765
  const htmlSrc = Render({
775
766
  title: page.title,
776
767
  ssrPath,
777
- ssrHeadComponents: '',
768
+ ssrHeadComponents: '<base target="_top">',
778
769
  ssrBodyComponents: SsrComponent(),
779
770
  renderPayload: {
780
771
  apiBaseProxyPath,
@@ -802,7 +793,7 @@ Sitemap: ${sitemapBaseUrl}/sitemap.xml`,
802
793
 
803
794
  fs.writeFileSync(
804
795
  buildHtmlPath,
805
- minifyBuild || process.env.NODE_ENV === 'production'
796
+ minifyBuild
806
797
  ? await minify(htmlSrc, {
807
798
  minifyCSS: true,
808
799
  minifyJS: true,
@@ -1275,18 +1275,6 @@ const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
1275
1275
  if (Underpost.env.get('await-deploy')) return await awaitDeployMonitor();
1276
1276
  };
1277
1277
 
1278
- /**
1279
- * @method getCronBackUpFolder
1280
- * @description Gets the cron back up folder.
1281
- * @param {string} host - The host.
1282
- * @param {string} path - The path.
1283
- * @returns {string} - The cron back up folder.
1284
- * @memberof ServerConfBuilder
1285
- */
1286
- const getCronBackUpFolder = (host = '', path = '') => {
1287
- return `${host}${path.replace(/\\/g, '/').replace(`/`, '-')}`;
1288
- };
1289
-
1290
1278
  /**
1291
1279
  * @method mergeFile
1292
1280
  * @description Merges the file.
@@ -1499,8 +1487,25 @@ const buildCliDoc = (program, oldVersion, newVersion) => {
1499
1487
  md = md.replaceAll(oldVersion, newVersion);
1500
1488
  fs.writeFileSync(`./src/client/public/nexodev/docs/references/Command Line Interface.md`, md, 'utf8');
1501
1489
  fs.writeFileSync(`./CLI-HELP.md`, md, 'utf8');
1502
- const readme = fs.readFileSync(`./README.md`, 'utf8');
1503
- fs.writeFileSync('./README.md', readme.replaceAll(oldVersion, newVersion), 'utf8');
1490
+
1491
+ // Update README.md: replace version and CLI index section between comment tags
1492
+ let readme = fs.readFileSync(`./README.md`, 'utf8');
1493
+ readme = readme.replaceAll(oldVersion, newVersion);
1494
+ const cliStartTag = '<!-- cli-index-start -->';
1495
+ const cliEndTag = '<!-- cli-index-end -->';
1496
+ const startIdx = readme.indexOf(cliStartTag);
1497
+ const endIdx = readme.indexOf(cliEndTag);
1498
+ if (startIdx !== -1 && endIdx !== -1) {
1499
+ readme =
1500
+ readme.substring(0, startIdx) +
1501
+ cliStartTag +
1502
+ '\n' +
1503
+ baseOptions +
1504
+ '\n' +
1505
+ cliEndTag +
1506
+ readme.substring(endIdx + cliEndTag.length);
1507
+ }
1508
+ fs.writeFileSync('./README.md', readme, 'utf8');
1504
1509
  };
1505
1510
 
1506
1511
  /**
@@ -1743,7 +1748,6 @@ export {
1743
1748
  getDataDeploy,
1744
1749
  validateTemplatePath,
1745
1750
  buildReplicaId,
1746
- getCronBackUpFolder,
1747
1751
  mergeFile,
1748
1752
  getPathsSSR,
1749
1753
  buildKindPorts,
@@ -147,18 +147,25 @@ class UnderpostStartUp {
147
147
  * @param {string} deployId - The ID of the deployment.
148
148
  * @param {string} env - The environment of the deployment.
149
149
  * @param {Object} options - Options for the build.
150
+ * @param {boolean} options.skipPullBase - Whether to skip pulling the base code and use the current workspace code directly.
150
151
  * @param {boolean} options.underpostQuicklyInstall - Whether to use underpost quickly install.
151
152
  * @memberof UnderpostStartUp
152
153
  */
153
- async build(deployId = 'dd-default', env = 'development', options = { underpostQuicklyInstall: false }) {
154
+ async build(
155
+ deployId = 'dd-default',
156
+ env = 'development',
157
+ options = { underpostQuicklyInstall: false, skipPullBase: false },
158
+ ) {
154
159
  const buildBasePath = `/home/dd`;
155
160
  const repoName = `engine-${deployId.split('-')[1]}`;
156
- shellExec(`cd ${buildBasePath} && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}`);
157
- shellExec(`mkdir -p ${buildBasePath}/engine`);
158
- shellExec(`cd ${buildBasePath} && sudo cp -a ./${repoName}/. ./engine`);
159
- shellExec(`cd ${buildBasePath} && sudo rm -rf ./${repoName}`);
160
- shellExec(`cd ${buildBasePath}/engine && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}-private`);
161
- shellExec(`cd ${buildBasePath}/engine && sudo mv ./${repoName}-private ./engine-private`);
161
+ if (!options.skipPullBase) {
162
+ shellExec(`cd ${buildBasePath} && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}`);
163
+ shellExec(`mkdir -p ${buildBasePath}/engine`);
164
+ shellExec(`cd ${buildBasePath} && sudo cp -a ./${repoName}/. ./engine`);
165
+ shellExec(`cd ${buildBasePath} && sudo rm -rf ./${repoName}`);
166
+ shellExec(`cd ${buildBasePath}/engine && underpost clone ${process.env.GITHUB_USERNAME}/${repoName}-private`);
167
+ shellExec(`cd ${buildBasePath}/engine && sudo mv ./${repoName}-private ./engine-private`);
168
+ }
162
169
  shellCd(`${buildBasePath}/engine`);
163
170
  shellExec(options?.underpostQuicklyInstall ? `underpost install` : `npm install`);
164
171
  shellExec(`node bin env ${deployId} ${env}`);
@@ -167,7 +174,7 @@ class UnderpostStartUp {
167
174
  for (const itcScript of itcScripts)
168
175
  if (itcScript.match(deployId)) shellExec(`node ./engine-private/itc-scripts/${itcScript}`);
169
176
  }
170
- await Underpost.repo.client(deployId);
177
+ shellExec(`node bin client ${deployId}`);
171
178
  },
172
179
  /**
173
180
  * Runs a deployment.