Skip to content

Commit

Permalink
chore(cli): Remove redundant loops and checks (redwoodjs#11929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jan 25, 2025
1 parent 6bbb925 commit a8d1c62
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/cli/src/commands/generate/scaffold/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import {
builder as serviceBuilder,
} from '../service/service'

// note a better way to do this is in https://github.com/redwoodjs/redwood/pull/3783/files
const NON_EDITABLE_COLUMNS = ['id', 'createdAt', 'updatedAt']
// Any assets that should not trigger an overwrite error and require a --force
const SKIPPABLE_ASSETS = ['scaffold.css']
const PACKAGE_SET = 'Set'
Expand All @@ -59,12 +57,19 @@ const getIdName = (model) => {
return model.fields.find((field) => field.isId)?.name
}

const filterAutoGeneratedColumnsForScaffold = (column) => {
const isAutoGeneratedColumnForScaffold = (column) => {
const autoGeneratedFunctions = ['now', 'autoincrement']
return !(

const columnDefaultFunction =
typeof column.default === 'object' && 'name' in column.default
? column.default?.name
: ''

return (
column.isId ||
column.isUpdatedAt ||
autoGeneratedFunctions.includes(column?.default?.name)
column.name === 'createdAt' ||
autoGeneratedFunctions.includes(columnDefaultFunction)
)
}

Expand Down Expand Up @@ -400,11 +405,9 @@ const modelRelatedVariables = (model) => {
isRelationalField,
}
})
const editableColumns = columns
.filter((column) => {
return NON_EDITABLE_COLUMNS.indexOf(column.name) === -1
})
.filter(filterAutoGeneratedColumnsForScaffold)
const editableColumns = columns.filter(
(column) => !isAutoGeneratedColumnForScaffold(column),
)
const fieldsToImport = Object.keys(
editableColumns.reduce((accumulator, column) => {
accumulator[column.component] = true
Expand Down

0 comments on commit a8d1c62

Please sign in to comment.