@@ -15,6 +15,7 @@ import chalk from 'chalk'
15
15
import { execSync } from 'child_process'
16
16
import { configurePayloadConfig } from 'create-payload-app/lib/configure-payload-config.js'
17
17
import { copyRecursiveSync } from 'create-payload-app/utils/copy-recursive-sync.js'
18
+ import minimist from 'minimist'
18
19
import * as fs from 'node:fs/promises'
19
20
import { fileURLToPath } from 'node:url'
20
21
import path from 'path'
@@ -40,6 +41,11 @@ type TemplateVariations = {
40
41
* @default false
41
42
*/
42
43
skipReadme ?: boolean
44
+ skipConfig ?: boolean
45
+ /**
46
+ * @default false
47
+ */
48
+ skipDockerCompose ?: boolean
43
49
configureConfig ?: boolean
44
50
generateLockfile ?: boolean
45
51
}
@@ -50,12 +56,13 @@ main().catch((error) => {
50
56
} )
51
57
52
58
async function main ( ) {
59
+ const args = minimist ( process . argv . slice ( 2 ) )
60
+ const template = args [ 'template' ] // template directory name
53
61
const templatesDir = path . resolve ( dirname , '../templates' )
54
62
55
- // WARNING: This will need to be updated when this merges into main
56
63
const templateRepoUrlBase = `https://github.com/payloadcms/payload/tree/main/templates`
57
64
58
- const variations : TemplateVariations [ ] = [
65
+ let variations : TemplateVariations [ ] = [
59
66
{
60
67
name : 'payload-vercel-postgres-template' ,
61
68
dirname : 'with-vercel-postgres' ,
@@ -132,20 +139,22 @@ async function main() {
132
139
generateLockfile : true ,
133
140
storage : 'localDisk' ,
134
141
sharp : true ,
142
+ skipConfig : true , // Do not copy the payload.config.ts file from the base template
135
143
// The blank template is used as a base for create-payload-app functionality,
136
144
// so we do not configure the payload.config.ts file, which leaves the placeholder comments.
137
145
configureConfig : false ,
138
146
} ,
139
- {
140
- name : 'payload-cloud-mongodb-template' ,
141
- dirname : 'with-payload-cloud' ,
142
- db : 'mongodb' ,
143
- generateLockfile : true ,
144
- storage : 'payloadCloud' ,
145
- sharp : true ,
146
- } ,
147
147
]
148
148
149
+ // If template is set, only generate that template
150
+ if ( template ) {
151
+ const variation = variations . find ( ( v ) => v . dirname === template )
152
+ if ( ! variation ) {
153
+ throw new Error ( `Variation not found: ${ template } ` )
154
+ }
155
+ variations = [ variation ]
156
+ }
157
+
149
158
for ( const {
150
159
name,
151
160
base,
@@ -158,6 +167,8 @@ async function main() {
158
167
sharp,
159
168
configureConfig,
160
169
skipReadme = false ,
170
+ skipConfig = false ,
171
+ skipDockerCompose = false ,
161
172
} of variations ) {
162
173
header ( `Generating ${ name } ...` )
163
174
const destDir = path . join ( templatesDir , dirname )
@@ -167,21 +178,24 @@ async function main() {
167
178
'.next' ,
168
179
'.env$' ,
169
180
'pnpm-lock.yaml' ,
170
- ...( skipReadme ? [ 'README.md' ] : [ '' ] ) ,
181
+ ...( skipReadme ? [ 'README.md' ] : [ ] ) ,
182
+ ...( skipDockerCompose ? [ 'docker-compose.yml' ] : [ ] ) ,
183
+ ...( skipConfig ? [ 'payload.config.ts' ] : [ ] ) ,
171
184
] )
172
185
173
186
log ( `Copied to ${ destDir } ` )
174
187
175
188
if ( configureConfig !== false ) {
176
189
log ( 'Configuring payload.config.ts' )
177
- await configurePayloadConfig ( {
190
+ const configureArgs = {
178
191
dbType : db ,
179
192
packageJsonName : name ,
180
193
projectDirOrConfigPath : { projectDir : destDir } ,
181
194
storageAdapter : storage ,
182
195
sharp,
183
196
envNames,
184
- } )
197
+ }
198
+ await configurePayloadConfig ( configureArgs )
185
199
186
200
log ( 'Configuring .env.example' )
187
201
// Replace DATABASE_URI with the correct env name if set
0 commit comments