create-payload-app
Advanced tools
Comparing version 3.0.0-beta.36 to 3.0.0-beta.37
@@ -9,3 +9,3 @@ import * as p from '@clack/prompts'; | ||
import { tryInitRepoAndCommit } from '../utils/git.js'; | ||
import { debug, error, warning } from '../utils/log.js'; | ||
import { debug, error, info, warning } from '../utils/log.js'; | ||
import { configurePayloadConfig } from './configure-payload-config.js'; | ||
@@ -80,2 +80,3 @@ const filename = fileURLToPath(import.meta.url); | ||
if (!cliArgs['--no-deps']) { | ||
info(`Using ${packageManager}.\n`); | ||
spinner.message('Installing dependencies...'); | ||
@@ -82,0 +83,0 @@ const result = await installDeps({ |
@@ -30,3 +30,3 @@ import fse from 'fs-extra'; | ||
'--db': 'mongodb', | ||
'--local-template': 'blank', | ||
'--local-template': 'blank-3.0', | ||
'--no-deps': true | ||
@@ -33,0 +33,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import type { CliArgs, DbType, PackageManager } from '../types.js'; | ||
import type { CliArgs, DbType, NextAppDetails, PackageManager } from '../types.js'; | ||
type InitNextArgs = Pick<CliArgs, '--debug'> & { | ||
@@ -9,3 +9,2 @@ dbType: DbType; | ||
}; | ||
type NextConfigType = 'cjs' | 'esm'; | ||
type InitNextResult = { | ||
@@ -23,11 +22,4 @@ isSrcDir: boolean; | ||
export declare function initNext(args: InitNextArgs): Promise<InitNextResult>; | ||
type NextAppDetails = { | ||
hasTopLevelLayout: boolean; | ||
isSrcDir: boolean; | ||
nextAppDir?: string; | ||
nextConfigPath?: string; | ||
nextConfigType?: NextConfigType; | ||
}; | ||
export declare function getNextAppDetails(projectDir: string): Promise<NextAppDetails>; | ||
export {}; | ||
//# sourceMappingURL=init-next.d.ts.map |
import * as p from '@clack/prompts'; | ||
import { parse, stringify } from 'comment-json'; | ||
import execa from 'execa'; | ||
import fs from 'fs'; | ||
import fse from 'fs-extra'; | ||
import globby from 'globby'; | ||
import { fileURLToPath } from 'node:url'; | ||
import path from 'path'; | ||
import { promisify } from 'util'; | ||
import { copyRecursiveSync } from '../utils/copy-recursive-sync.js'; | ||
import { debug as origDebug, warning } from '../utils/log.js'; | ||
import { moveMessage } from '../utils/messages.js'; | ||
import { installPackages } from './install-packages.js'; | ||
import { wrapNextConfig } from './wrap-next-config.js'; | ||
const readFile = promisify(fs.readFile); | ||
@@ -13,7 +18,2 @@ const writeFile = promisify(fs.writeFile); | ||
const dirname = path.dirname(filename); | ||
import { fileURLToPath } from 'node:url'; | ||
import { copyRecursiveSync } from '../utils/copy-recursive-sync.js'; | ||
import { debug as origDebug, warning } from '../utils/log.js'; | ||
import { moveMessage } from '../utils/messages.js'; | ||
import { wrapNextConfig } from './wrap-next-config.js'; | ||
export async function initNext(args) { | ||
@@ -30,3 +30,3 @@ const { dbType: dbType, packageManager, projectDir } = args; | ||
} | ||
const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails; | ||
const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails; | ||
if (!nextConfigType) { | ||
@@ -168,44 +168,13 @@ return { | ||
'@payloadcms/next', | ||
'@payloadcms/richtext-lexical' | ||
'@payloadcms/richtext-lexical', | ||
'@payloadcms/plugin-cloud' | ||
].map((pkg)=>`${pkg}@beta`); | ||
packagesToInstall.push(`@payloadcms/db-${dbType}@beta`); | ||
let exitCode = 0; | ||
switch(packageManager){ | ||
case 'npm': | ||
{ | ||
({ exitCode } = await execa('npm', [ | ||
'install', | ||
'--save', | ||
...packagesToInstall | ||
], { | ||
cwd: projectDir | ||
})); | ||
break; | ||
} | ||
case 'yarn': | ||
case 'pnpm': | ||
{ | ||
({ exitCode } = await execa(packageManager, [ | ||
'add', | ||
...packagesToInstall | ||
], { | ||
cwd: projectDir | ||
})); | ||
break; | ||
} | ||
case 'bun': | ||
{ | ||
warning('Bun support is untested.'); | ||
({ exitCode } = await execa('bun', [ | ||
'add', | ||
...packagesToInstall | ||
], { | ||
cwd: projectDir | ||
})); | ||
break; | ||
} | ||
} | ||
return { | ||
success: exitCode === 0 | ||
}; | ||
// Match graphql version of @payloadcms/next | ||
packagesToInstall.push('graphql@^16.8.1'); | ||
return await installPackages({ | ||
packageManager, | ||
packagesToInstall, | ||
projectDir | ||
}); | ||
} | ||
@@ -225,2 +194,11 @@ export async function getNextAppDetails(projectDir) { | ||
} | ||
const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json')); | ||
if (packageObj.dependencies?.payload) { | ||
return { | ||
hasTopLevelLayout: false, | ||
isPayloadInstalled: true, | ||
isSrcDir, | ||
nextConfigPath | ||
}; | ||
} | ||
let nextAppDir = (await globby([ | ||
@@ -239,3 +217,6 @@ '**/app' | ||
} | ||
const configType = await getProjectType(projectDir, nextConfigPath); | ||
const configType = getProjectType({ | ||
nextConfigPath, | ||
packageObj | ||
}); | ||
const hasTopLevelLayout = nextAppDir ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx')) : false; | ||
@@ -250,3 +231,4 @@ return { | ||
} | ||
async function getProjectType(projectDir, nextConfigPath) { | ||
function getProjectType(args) { | ||
const { nextConfigPath, packageObj } = args; | ||
if (nextConfigPath.endsWith('.mjs')) { | ||
@@ -258,3 +240,2 @@ return 'esm'; | ||
} | ||
const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json')); | ||
const packageJsonType = packageObj.type; | ||
@@ -261,0 +242,0 @@ if (packageJsonType === 'module') { |
@@ -5,4 +5,2 @@ import * as p from '@clack/prompts'; | ||
import chalk from 'chalk'; | ||
// @ts-expect-error no types | ||
import { detect } from 'detect-package-manager'; | ||
import figures from 'figures'; | ||
@@ -13,2 +11,3 @@ import path from 'path'; | ||
import { generateSecret } from './lib/generate-secret.js'; | ||
import { getPackageManager } from './lib/get-package-manager.js'; | ||
import { getNextAppDetails, initNext } from './lib/init-next.js'; | ||
@@ -19,2 +18,3 @@ import { parseProjectName } from './lib/parse-project-name.js'; | ||
import { getValidTemplates, validateTemplate } from './lib/templates.js'; | ||
import { updatePayloadInProject } from './lib/update-payload-in-project.js'; | ||
import { writeEnvFile } from './lib/write-env-file.js'; | ||
@@ -71,3 +71,21 @@ import { error, info } from './utils/log.js'; | ||
const nextAppDetails = await getNextAppDetails(process.cwd()); | ||
const { hasTopLevelLayout, nextAppDir, nextConfigPath } = nextAppDetails; | ||
const { hasTopLevelLayout, isPayloadInstalled, nextAppDir, nextConfigPath } = nextAppDetails; | ||
// Upgrade Payload in existing project | ||
if (isPayloadInstalled && nextConfigPath) { | ||
p.log.warn(`Payload installation detected in current project.`); | ||
const shouldUpdate = await p.confirm({ | ||
initialValue: false, | ||
message: chalk.bold(`Upgrade Payload in this project?`) | ||
}); | ||
if (!p.isCancel(shouldUpdate) || shouldUpdate) { | ||
const { message, success: updateSuccess } = await updatePayloadInProject(nextAppDetails); | ||
if (updateSuccess) { | ||
info(message); | ||
} else { | ||
error(message); | ||
} | ||
} | ||
p.outro(feedbackOutro()); | ||
process.exit(0); | ||
} | ||
if (nextConfigPath) { | ||
@@ -78,3 +96,6 @@ this.args['--name'] = slugify(path.basename(path.dirname(nextConfigPath))); | ||
const projectDir = nextConfigPath ? path.dirname(nextConfigPath) : path.resolve(process.cwd(), slugify(projectName)); | ||
const packageManager = await getPackageManager(this.args, projectDir); | ||
const packageManager = await getPackageManager({ | ||
cliArgs: this.args, | ||
projectDir | ||
}); | ||
if (nextConfigPath) { | ||
@@ -185,19 +206,3 @@ p.log.step(chalk.bold(`${chalk.bgBlack(` ${figures.triangleUp} Next.js `)} project detected!`)); | ||
} | ||
async function getPackageManager(args, projectDir) { | ||
let packageManager = 'npm'; | ||
if (args['--use-npm']) { | ||
packageManager = 'npm'; | ||
} else if (args['--use-yarn']) { | ||
packageManager = 'yarn'; | ||
} else if (args['--use-pnpm']) { | ||
packageManager = 'pnpm'; | ||
} else { | ||
const detected = await detect({ | ||
cwd: projectDir | ||
}); | ||
packageManager = detected || 'npm'; | ||
} | ||
return packageManager; | ||
} | ||
//# sourceMappingURL=main.js.map |
@@ -55,3 +55,12 @@ import type arg from 'arg'; | ||
export type EditorType = 'lexical' | 'slate'; | ||
export type NextAppDetails = { | ||
hasTopLevelLayout: boolean; | ||
isPayloadInstalled?: boolean; | ||
isSrcDir: boolean; | ||
nextAppDir?: string; | ||
nextConfigPath?: string; | ||
nextConfigType?: NextConfigType; | ||
}; | ||
export type NextConfigType = 'cjs' | 'esm'; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "create-payload-app", | ||
"version": "3.0.0-beta.36", | ||
"version": "3.0.0-beta.37", | ||
"homepage": "https://payloadcms.com", | ||
@@ -35,3 +35,2 @@ "repository": { | ||
"degit": "^2.8.4", | ||
"detect-package-manager": "^3.0.1", | ||
"esprima-next": "^6.0.3", | ||
@@ -38,0 +37,0 @@ "execa": "^5.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
195402
13
109
1835
12
- Removeddetect-package-manager@^3.0.1
- Removeddetect-package-manager@3.0.2(transitive)