nextjs-cms-kit 0.5.19 → 0.5.21

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.
@@ -18,7 +18,7 @@ export function generateDrizzleSchema(table) {
18
18
  let tableCaseStyleFn;
19
19
  let columnCaseStyleFn;
20
20
  const lzConfig = getCMSConfig();
21
- switch (lzConfig.db.schemaNamingConvention.tableCaseStyle) {
21
+ switch (lzConfig.schemaGeneration.drizzle.naming.tables) {
22
22
  case 'snakeCase':
23
23
  tableCaseStyleFn = toSnakeCase;
24
24
  break;
@@ -30,7 +30,7 @@ export function generateDrizzleSchema(table) {
30
30
  tableCaseStyleFn = toPascalCase;
31
31
  break;
32
32
  }
33
- switch (lzConfig.db.schemaNamingConvention.columnCaseStyle) {
33
+ switch (lzConfig.schemaGeneration.drizzle.naming.columns) {
34
34
  case 'snakeCase':
35
35
  columnCaseStyleFn = toSnakeCase;
36
36
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../src/lib/update-sections.ts"],"names":[],"mappings":"AA6hCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAmBrD"}
1
+ {"version":3,"file":"update-sections.d.ts","sourceRoot":"","sources":["../../src/lib/update-sections.ts"],"names":[],"mappings":"AAgjCA,wBAAsB,cAAc,CAAC,SAAS,UAAQ,iBAmBrD"}
@@ -3,7 +3,9 @@ import { db } from 'nextjs-cms/db/client';
3
3
  import { LZTablesTable } from 'nextjs-cms/db/schema';
4
4
  import { eq, sql } from 'drizzle-orm';
5
5
  import fs from 'fs';
6
+ import path from 'path';
6
7
  import { SectionFactory } from 'nextjs-cms/core/factories';
8
+ import { getCMSConfig } from 'nextjs-cms/core/config';
7
9
  import { CheckboxField, ColorField, DateField, MapField, NumberField, PasswordField, RichTextField, SelectField, SelectMultipleField, TagsField, TextAreaField, TextField, textAreaField, textField, } from 'nextjs-cms/core/fields';
8
10
  import { is } from 'nextjs-cms/core/helpers';
9
11
  import { FileField } from 'nextjs-cms/core/fields';
@@ -498,23 +500,32 @@ async function updateTable(table, s) {
498
500
  s.stop(chalk.italic.hex(`${sqlErrors > 0 ? `#FFA500` : `#fafafa`}`)(`- Table \`${table.name}\` modified successfully ${sqlErrors > 0 ? `with ${sqlErrors} error(s).` : ''}`));
499
501
  }
500
502
  const main = async (s) => {
503
+ const cmsConfig = getCMSConfig();
504
+ const schemaGenerationEnabled = cmsConfig.schemaGeneration.drizzle.enabled;
505
+ const schemaOutDir = cmsConfig.schemaGeneration.drizzle.outDir;
506
+ const schemaFileName = cmsConfig.schemaGeneration.drizzle.fileName;
507
+ const schemaFilePath = path.join(schemaOutDir, schemaFileName);
501
508
  /**
502
509
  * Remove the existing schema file
503
510
  */
504
- console.log(chalk.white(`Removing existing schema file...`));
505
- s.start();
506
- const schemaFilePath = './dynamic-schemas/schema.js';
507
- try {
508
- if (fs.existsSync(schemaFilePath)) {
509
- fs.unlinkSync(schemaFilePath);
511
+ if (schemaGenerationEnabled) {
512
+ console.log(chalk.white(`Removing existing schema file...`));
513
+ s.start();
514
+ try {
515
+ if (fs.existsSync(schemaFilePath)) {
516
+ fs.unlinkSync(schemaFilePath);
517
+ }
518
+ }
519
+ catch (error) {
520
+ console.error('Error removing schema file:', error);
510
521
  }
522
+ s.stop();
523
+ console.log(chalk.white(`Generating Drizzle schema...`));
524
+ s.start();
511
525
  }
512
- catch (error) {
513
- console.error('Error removing schema file:', error);
526
+ else {
527
+ console.log(chalk.yellow(`Schema generation is disabled. Skipping Drizzle schema generation.`));
514
528
  }
515
- s.stop();
516
- console.log(chalk.white(`Generating Drizzle schema...`));
517
- s.start();
518
529
  const drizzleTableSchemas = [];
519
530
  const drizzleColumnTypes = ['mysqlTable'];
520
531
  let sections = [];
@@ -646,20 +657,25 @@ const main = async (s) => {
646
657
  }
647
658
  }
648
659
  /**
649
- * Make sure the dynamic-schemas directory exists
660
+ * Write schema file if schema generation is enabled
650
661
  */
651
- if (!fs.existsSync('./dynamic-schemas')) {
652
- fs.mkdirSync('./dynamic-schemas');
662
+ if (schemaGenerationEnabled) {
663
+ /**
664
+ * Make sure the output directory exists
665
+ */
666
+ if (!fs.existsSync(schemaOutDir)) {
667
+ fs.mkdirSync(schemaOutDir, { recursive: true });
668
+ }
669
+ /**
670
+ * Append the Drizzle column types to the schema file
671
+ */
672
+ fs.appendFileSync(schemaFilePath, 'import {' + drizzleColumnTypes.join(',') + "} from 'drizzle-orm/mysql-core'\n\n");
673
+ /**
674
+ * Append the Drizzle table schemas to the schema file
675
+ */
676
+ fs.appendFileSync(schemaFilePath, drizzleTableSchemas.join('\n'));
677
+ s.stop();
653
678
  }
654
- /**
655
- * Append the Drizzle column types to the schema file
656
- */
657
- fs.appendFileSync(schemaFilePath, 'import {' + drizzleColumnTypes.join(',') + "} from 'drizzle-orm/mysql-core'\n\n");
658
- /**
659
- * Append the Drizzle table schemas to the schema file
660
- */
661
- fs.appendFileSync(schemaFilePath, drizzleTableSchemas.join('\n'));
662
- s.stop();
663
679
  console.log(chalk.white('Finding tables to create, update or remove...'));
664
680
  s.start();
665
681
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nextjs-cms-kit",
3
3
  "private": false,
4
- "version": "0.5.19",
4
+ "version": "0.5.21",
5
5
  "bin": {
6
6
  "nextjs-cms-kit": "./dist/index.js"
7
7
  },
@@ -27,7 +27,7 @@
27
27
  "glob": "^11.0.3",
28
28
  "mysql2": "^3.12.0",
29
29
  "zod": "4.1.12",
30
- "nextjs-cms": "0.5.19"
30
+ "nextjs-cms": "0.5.21"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/bcrypt": "^6.0.0",
@@ -38,9 +38,9 @@
38
38
  "tsup": "^8.3.6",
39
39
  "tsx": "^4.20.6",
40
40
  "typescript": "^5.9.2",
41
+ "@lzcms/prettier-config": "0.1.0",
41
42
  "@lzcms/eslint-config": "0.3.0",
42
- "@lzcms/tsconfig": "0.1.0",
43
- "@lzcms/prettier-config": "0.1.0"
43
+ "@lzcms/tsconfig": "0.1.0"
44
44
  },
45
45
  "prettier": "@lzcms/prettier-config",
46
46
  "scripts": {