create-payload-app 3.0.0-canary.fb81f02 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +9 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/create-project.d.ts.map +1 -1
- package/dist/lib/create-project.js +10 -7
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/create-project.spec.js +5 -7
- package/dist/lib/create-project.spec.js.map +1 -1
- package/dist/lib/download-template.d.ts +7 -0
- package/dist/lib/download-template.d.ts.map +1 -0
- package/dist/lib/download-template.js +28 -0
- package/dist/lib/download-template.js.map +1 -0
- package/dist/lib/get-package-manager.d.ts.map +1 -1
- package/dist/lib/get-package-manager.js +22 -10
- package/dist/lib/get-package-manager.js.map +1 -1
- package/dist/lib/init-next.d.ts +5 -5
- package/dist/lib/init-next.d.ts.map +1 -1
- package/dist/lib/init-next.js +7 -5
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/install-packages.js +12 -12
- package/dist/lib/install-packages.js.map +1 -1
- package/dist/lib/parse-project-name.d.ts.map +1 -1
- package/dist/lib/parse-project-name.js +9 -3
- package/dist/lib/parse-project-name.js.map +1 -1
- package/dist/lib/parse-template.d.ts.map +1 -1
- package/dist/lib/parse-template.js +3 -1
- package/dist/lib/parse-template.js.map +1 -1
- package/dist/lib/replacements.d.ts.map +1 -1
- package/dist/lib/replacements.js +16 -4
- package/dist/lib/replacements.js.map +1 -1
- package/dist/lib/select-db.d.ts.map +1 -1
- package/dist/lib/select-db.js +13 -4
- package/dist/lib/select-db.js.map +1 -1
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +3 -2
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/update-payload-in-project.d.ts.map +1 -1
- package/dist/lib/update-payload-in-project.js +7 -5
- package/dist/lib/update-payload-in-project.js.map +1 -1
- package/dist/lib/wrap-next-config.d.ts.map +1 -1
- package/dist/lib/wrap-next-config.js +4 -8
- package/dist/lib/wrap-next-config.js.map +1 -1
- package/dist/lib/write-env-file.d.ts +2 -1
- package/dist/lib/write-env-file.d.ts.map +1 -1
- package/dist/lib/write-env-file.js +9 -4
- package/dist/lib/write-env-file.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +21 -13
- package/dist/main.js.map +1 -1
- package/dist/scripts/pack-template-files.js +3 -3
- package/dist/scripts/pack-template-files.js.map +1 -1
- package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +8 -6
- package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +8 -6
- package/dist/template/src/app/(payload)/admin/importMap.js +1 -0
- package/dist/template/src/app/(payload)/api/[...slug]/route.ts +11 -2
- package/dist/template/src/app/(payload)/api/graphql/route.ts +4 -2
- package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +2 -1
- package/dist/template/src/app/(payload)/layout.tsx +19 -4
- package/dist/template/src/payload-types.ts +127 -0
- package/dist/template/src/payload.config.ts +5 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/copy-recursive-sync.d.ts +1 -1
- package/dist/utils/copy-recursive-sync.d.ts.map +1 -1
- package/dist/utils/copy-recursive-sync.js +4 -1
- package/dist/utils/copy-recursive-sync.js.map +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +1 -0
- package/dist/utils/messages.js.map +1 -1
- package/license.md +22 -0
- package/package.json +18 -6
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe,KAAsB,CAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { readFileSync } from 'fs';
|
2
|
+
import { fileURLToPath } from 'node:url';
|
3
|
+
import path from 'path';
|
4
|
+
const filename = fileURLToPath(import.meta.url);
|
5
|
+
const dirname = path.dirname(filename);
|
6
|
+
const packageJson = JSON.parse(readFileSync(path.resolve(dirname, '../../package.json'), 'utf-8'));
|
7
|
+
export const PACKAGE_VERSION = packageJson.version;
|
8
|
+
|
9
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/constants.ts"],"sourcesContent":["import { readFileSync } from 'fs'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nconst packageJson = JSON.parse(readFileSync(path.resolve(dirname, '../../package.json'), 'utf-8'))\nexport const PACKAGE_VERSION = packageJson.version\n"],"names":["readFileSync","fileURLToPath","path","filename","url","dirname","packageJson","JSON","parse","resolve","PACKAGE_VERSION","version"],"mappings":"AAAA,SAASA,YAAY,QAAQ,KAAI;AACjC,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,MAAMG,cAAcC,KAAKC,KAAK,CAACR,aAAaE,KAAKO,OAAO,CAACJ,SAAS,uBAAuB;AACzF,OAAO,MAAMK,kBAAkBJ,YAAYK,OAAO,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../src/lib/create-project.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../src/lib/create-project.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA+CtF,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,eAAe,CAAA;CAC1B,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DhB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhB"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import * as p from '@clack/prompts';
|
2
2
|
import chalk from 'chalk';
|
3
|
-
import degit from 'degit';
|
4
3
|
import execa from 'execa';
|
5
4
|
import fse from 'fs-extra';
|
6
5
|
import { fileURLToPath } from 'node:url';
|
@@ -8,6 +7,7 @@ import path from 'path';
|
|
8
7
|
import { tryInitRepoAndCommit } from '../utils/git.js';
|
9
8
|
import { debug, error, info, warning } from '../utils/log.js';
|
10
9
|
import { configurePayloadConfig } from './configure-payload-config.js';
|
10
|
+
import { downloadTemplate } from './download-template.js';
|
11
11
|
const filename = fileURLToPath(import.meta.url);
|
12
12
|
const dirname = path.dirname(filename);
|
13
13
|
async function createOrFindProjectDir(projectDir) {
|
@@ -26,6 +26,8 @@ async function installDeps(args) {
|
|
26
26
|
installCmd = 'yarn';
|
27
27
|
} else if (packageManager === 'pnpm') {
|
28
28
|
installCmd = 'pnpm install';
|
29
|
+
} else if (packageManager === 'bun') {
|
30
|
+
installCmd = 'bun install';
|
29
31
|
}
|
30
32
|
try {
|
31
33
|
await execa.command(installCmd, {
|
@@ -49,13 +51,14 @@ export async function createProject(args) {
|
|
49
51
|
const localTemplate = path.resolve(dirname, '../../../../templates/', cliArgs['--local-template']);
|
50
52
|
await fse.copy(localTemplate, projectDir);
|
51
53
|
} else if ('url' in template) {
|
52
|
-
let templateUrl = template.url;
|
53
54
|
if (cliArgs['--template-branch']) {
|
54
|
-
|
55
|
-
debug(`Using template url: ${templateUrl}`);
|
55
|
+
template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`;
|
56
56
|
}
|
57
|
-
|
58
|
-
|
57
|
+
await downloadTemplate({
|
58
|
+
debug: cliArgs['--debug'],
|
59
|
+
projectDir,
|
60
|
+
template
|
61
|
+
});
|
59
62
|
}
|
60
63
|
const spinner = p.spinner();
|
61
64
|
spinner.start('Checking latest Payload version...');
|
@@ -71,7 +74,7 @@ export async function createProject(args) {
|
|
71
74
|
}
|
72
75
|
});
|
73
76
|
// Remove yarn.lock file. This is only desired in Payload Cloud.
|
74
|
-
const lockPath = path.resolve(projectDir, '
|
77
|
+
const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml');
|
75
78
|
if (fse.existsSync(lockPath)) {
|
76
79
|
await fse.remove(lockPath);
|
77
80
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport
|
1
|
+
{"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nimport type { CliArgs, DbDetails, PackageManager, ProjectTemplate } from '../types.js'\n\nimport { tryInitRepoAndCommit } from '../utils/git.js'\nimport { debug, error, info, warning } from '../utils/log.js'\nimport { configurePayloadConfig } from './configure-payload-config.js'\nimport { downloadTemplate } from './download-template.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nasync function createOrFindProjectDir(projectDir: string): Promise<void> {\n const pathExists = await fse.pathExists(projectDir)\n if (!pathExists) {\n await fse.mkdir(projectDir)\n }\n}\n\nasync function installDeps(args: {\n cliArgs: CliArgs\n packageManager: PackageManager\n projectDir: string\n}): Promise<boolean> {\n const { cliArgs, packageManager, projectDir } = args\n if (cliArgs['--no-deps']) {\n return true\n }\n let installCmd = 'npm install --legacy-peer-deps'\n\n if (packageManager === 'yarn') {\n installCmd = 'yarn'\n } else if (packageManager === 'pnpm') {\n installCmd = 'pnpm install'\n } else if (packageManager === 'bun') {\n installCmd = 'bun install'\n }\n\n try {\n await execa.command(installCmd, {\n cwd: path.resolve(projectDir),\n })\n return true\n } catch (err: unknown) {\n error(`Error installing dependencies${err instanceof Error ? `: ${err.message}` : ''}.`)\n return false\n }\n}\n\nexport async function createProject(args: {\n cliArgs: CliArgs\n dbDetails?: DbDetails\n packageManager: PackageManager\n projectDir: string\n projectName: string\n template: ProjectTemplate\n}): Promise<void> {\n const { cliArgs, dbDetails, packageManager, projectDir, projectName, template } = args\n\n if (cliArgs['--dry-run']) {\n debug(`Dry run: Creating project in ${chalk.green(projectDir)}`)\n return\n }\n\n await createOrFindProjectDir(projectDir)\n\n if (cliArgs['--local-template']) {\n // Copy template from local path. For development purposes.\n const localTemplate = path.resolve(\n dirname,\n '../../../../templates/',\n cliArgs['--local-template'],\n )\n await fse.copy(localTemplate, projectDir)\n } else if ('url' in template) {\n if (cliArgs['--template-branch']) {\n template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`\n }\n\n await downloadTemplate({\n debug: cliArgs['--debug'],\n projectDir,\n template,\n })\n }\n\n const spinner = p.spinner()\n spinner.start('Checking latest Payload version...')\n\n await updatePackageJSON({ projectDir, projectName })\n spinner.message('Configuring Payload...')\n await configurePayloadConfig({\n dbType: dbDetails?.type,\n projectDirOrConfigPath: { projectDir },\n })\n\n // Remove yarn.lock file. This is only desired in Payload Cloud.\n const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml')\n if (fse.existsSync(lockPath)) {\n await fse.remove(lockPath)\n }\n\n if (!cliArgs['--no-deps']) {\n info(`Using ${packageManager}.\\n`)\n spinner.message('Installing dependencies...')\n const result = await installDeps({ cliArgs, packageManager, projectDir })\n if (result) {\n spinner.stop('Successfully installed Payload and dependencies')\n } else {\n spinner.stop('Error installing dependencies', 1)\n }\n } else {\n spinner.stop('Dependency installation skipped')\n }\n\n if (!cliArgs['--no-git']) {\n tryInitRepoAndCommit({ cwd: projectDir })\n }\n}\n\nexport async function updatePackageJSON(args: {\n projectDir: string\n projectName: string\n}): Promise<void> {\n const { projectDir, projectName } = args\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n packageObj.name = projectName\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to update name in package.json. ${err instanceof Error ? err.message : ''}`)\n }\n}\n"],"names":["p","chalk","execa","fse","fileURLToPath","path","tryInitRepoAndCommit","debug","error","info","warning","configurePayloadConfig","downloadTemplate","filename","url","dirname","createOrFindProjectDir","projectDir","pathExists","mkdir","installDeps","args","cliArgs","packageManager","installCmd","command","cwd","resolve","err","Error","message","createProject","dbDetails","projectName","template","green","localTemplate","copy","split","spinner","start","updatePackageJSON","dbType","type","projectDirOrConfigPath","lockPath","existsSync","remove","result","stop","packageJsonPath","packageObj","readJson","name","writeJson","spaces"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,WAAW,QAAO;AACzB,OAAOC,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAIvB,SAASC,oBAAoB,QAAQ,kBAAiB;AACtD,SAASC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,sBAAsB,QAAQ,gCAA+B;AACtE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,MAAMC,WAAWT,cAAc,YAAYU,GAAG;AAC9C,MAAMC,UAAUV,KAAKU,OAAO,CAACF;AAE7B,eAAeG,uBAAuBC,UAAkB;IACtD,MAAMC,aAAa,MAAMf,IAAIe,UAAU,CAACD;IACxC,IAAI,CAACC,YAAY;QACf,MAAMf,IAAIgB,KAAK,CAACF;IAClB;AACF;AAEA,eAAeG,YAAYC,IAI1B;IACC,MAAM,EAAEC,OA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AG,GAAG,CAAC;IAC7F;AACF"}
|
@@ -10,6 +10,7 @@ import { getValidTemplates } from './templates.js';
|
|
10
10
|
describe('createProject', ()=>{
|
11
11
|
let projectDir;
|
12
12
|
beforeAll(()=>{
|
13
|
+
// eslint-disable-next-line no-console
|
13
14
|
console.log = jest.fn();
|
14
15
|
});
|
15
16
|
beforeEach(()=>{
|
@@ -29,7 +30,7 @@ describe('createProject', ()=>{
|
|
29
30
|
'project-name'
|
30
31
|
],
|
31
32
|
'--db': 'mongodb',
|
32
|
-
'--local-template': 'blank
|
33
|
+
'--local-template': 'blank',
|
33
34
|
'--no-deps': true
|
34
35
|
};
|
35
36
|
const packageManager = 'yarn';
|
@@ -51,17 +52,17 @@ describe('createProject', ()=>{
|
|
51
52
|
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
52
53
|
const packageJson = fse.readJsonSync(packageJsonPath);
|
53
54
|
// Check package name and description
|
54
|
-
expect(packageJson.name).
|
55
|
+
expect(packageJson.name).toStrictEqual(projectName);
|
55
56
|
});
|
56
57
|
describe('creates project from template', ()=>{
|
57
58
|
const templates = getValidTemplates();
|
58
59
|
it.each([
|
59
60
|
[
|
60
|
-
'blank
|
61
|
+
'blank',
|
61
62
|
'mongodb'
|
62
63
|
],
|
63
64
|
[
|
64
|
-
'blank
|
65
|
+
'blank',
|
65
66
|
'postgres'
|
66
67
|
]
|
67
68
|
])('update config and deps: %s, %s', async (templateName, db)=>{
|
@@ -94,9 +95,6 @@ describe('createProject', ()=>{
|
|
94
95
|
absolute: true,
|
95
96
|
cwd: projectDir
|
96
97
|
}))?.[0];
|
97
|
-
if (!payloadConfigPath) {
|
98
|
-
throw new Error(`Could not find payload.config.ts inside ${projectDir}`);
|
99
|
-
}
|
100
98
|
const content = fse.readFileSync(payloadConfigPath, 'utf-8');
|
101
99
|
// Check payload.config.ts
|
102
100
|
expect(content).not.toContain('// database-adapter-import');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import { jest } from '@jest/globals'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport * as os from 'node:os'\nimport path from 'path'\n\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\n\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n const tempDirectory = fs.realpathSync(os.tmpdir())\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank
|
1
|
+
{"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import { jest } from '@jest/globals'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport * as os from 'node:os'\nimport path from 'path'\n\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\n\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n // eslint-disable-next-line no-console\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n const tempDirectory = fs.realpathSync(os.tmpdir())\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank',\n '--no-deps': true,\n } as CliArgs\n const packageManager = 'yarn'\n\n it('creates plugin template', async () => {\n const projectName = 'plugin'\n const template: ProjectTemplate = {\n name: 'plugin',\n type: 'plugin',\n description: 'Template for creating a Payload plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template',\n }\n await createProject({\n cliArgs: args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Check package name and description\n expect(packageJson.name).toStrictEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank', 'mongodb'],\n ['blank', 'postgres'],\n\n // TODO: Re-enable these once 3.0 is stable and templates updated\n // ['website', 'mongodb'],\n // ['website', 'postgres'],\n // ['ecommerce', 'mongodb'],\n // ['ecommerce', 'postgres'],\n ])('update config and deps: %s, %s', async (templateName, db) => {\n const projectName = 'starter-project'\n\n const template = templates.find((t) => t.name === templateName)\n\n const cliArgs = {\n ...args,\n '--db': db,\n '--local-template': templateName,\n } as CliArgs\n\n await createProject({\n cliArgs,\n dbDetails: {\n type: db as DbType,\n dbUri: `${db}://localhost:27017/create-project-test`,\n },\n packageManager,\n projectDir,\n projectName,\n template: template as ProjectTemplate,\n })\n\n const dbReplacement = dbReplacements[db as DbType]\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Verify git was initialized\n expect(fse.existsSync(path.resolve(projectDir, '.git'))).toBe(true)\n\n // Should only have one db adapter\n expect(\n Object.keys(packageJson.dependencies).filter((n) => n.startsWith('@payloadcms/db-')),\n ).toHaveLength(1)\n\n const payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: projectDir,\n })\n )?.[0]\n\n const content = fse.readFileSync(payloadConfigPath, 'utf-8')\n\n // Check payload.config.ts\n expect(content).not.toContain('// database-adapter-import')\n expect(content).toContain(dbReplacement.importReplacement)\n\n expect(content).not.toContain('// database-adapter-config-start')\n expect(content).not.toContain('// database-adapter-config-end')\n expect(content).toContain(dbReplacement.configReplacement().join('\\n'))\n })\n })\n })\n})\n"],"names":["jest","fs","fse","globby","os","path","createProject","dbReplacements","getValidTemplates","describe","projectDir","beforeAll","console","log","fn","beforeEach","tempDirectory","realpathSync","tmpdir","Math","random","toString","substring","afterEach","existsSync","rmSync","recursive","args","_","packageManager","it","projectName","template","name","type","description","url","cliArgs","packageJsonPath","resolve","packageJson","readJsonSync","expect","toStrictEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","toBe","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,SAASA,IAAI,QAAQ,gBAAe;AACpC,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,YAAYC,QAAQ,UAAS;AAC7B,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,cAAc,QAAQ,oBAAmB;AAClD,SAASC,iBAAiB,QAAQ,iBAAgB;AAElDC,SAAS,iBAAiB;IACxB,IAAIC;IACJC,UAAU;QACR,sCAAsC;QACtCC,QAAQC,GAAG,GAAGb,KAAKc,EAAE;IACvB;IAEAC,WAAW;QACT,MAAMC,gBAAgBf,GAAGgB,YAAY,CAACb,GAAGc,MAAM;QAC/CR,aAAa,CAAC,EAAEM,cAAc,CAAC,EAAEG,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,CAAC;IAC5E;IAEAC,UAAU;QACR,IAAIrB,IAAIsB,UAAU,CAACd,aAAa;YAC9BR,IAAIuB,MAAM,CAACf,YAAY;gBAAEgB,WAAW;YAAK;QAC3C;IACF;IAEAjB,SAAS,kBAAkB;QACzB,MAAMkB,OAAO;YACXC,GAAG;gBAAC;aAAe;YACnB,QAAQ;YACR,oBAAoB;YACpB,aAAa;QACf;QACA,MAAMC,iBAAiB;QAEvBC,GAAG,2BAA2B;YAC5B,MAAMC,cAAc;YACpB,MAAMC,WAA4B;gBAChCC,MAAM;gBAC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C,KAAKrD;gBACP,EAAC,GACA,CAAC,EAAE;gBAEN,MAAMsD,UAAU9D,IAAI+D,YAAY,CAACJ,mBAAmB;gBAEpD,0BAA0B;gBAC1BnB,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASG,SAAS,CAACf,cAAcgB,iBAAiB;gBAEzD1B,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASG,SAAS,CAACf,cAAciB,iBAAiB,GAAGC,IAAI,CAAC;YACnE;QACF;IACF;AACF"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { ProjectTemplate } from '../types.js';
|
2
|
+
export declare function downloadTemplate({ debug, projectDir, template, }: {
|
3
|
+
debug?: boolean;
|
4
|
+
projectDir: string;
|
5
|
+
template: ProjectTemplate;
|
6
|
+
}): Promise<void>;
|
7
|
+
//# sourceMappingURL=download-template.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"download-template.d.ts","sourceRoot":"","sources":["../../src/lib/download-template.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,eAAe,CAAA;CAC1B,iBAmBA"}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Readable } from 'node:stream';
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
3
|
+
import { x } from 'tar';
|
4
|
+
import { debug as debugLog } from '../utils/log.js';
|
5
|
+
export async function downloadTemplate({ debug, projectDir, template }) {
|
6
|
+
const branchOrTag = template.url.split('#')?.[1] || 'beta';
|
7
|
+
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`;
|
8
|
+
const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`;
|
9
|
+
if (debug) {
|
10
|
+
debugLog(`Using template url: ${template.url}`);
|
11
|
+
debugLog(`Codeload url: ${url}`);
|
12
|
+
debugLog(`Filter: ${filter}`);
|
13
|
+
}
|
14
|
+
await pipeline(await downloadTarStream(url), x({
|
15
|
+
cwd: projectDir,
|
16
|
+
filter: (p)=>p.includes(filter),
|
17
|
+
strip: 2 + template.name.split('/').length
|
18
|
+
}));
|
19
|
+
}
|
20
|
+
async function downloadTarStream(url) {
|
21
|
+
const res = await fetch(url);
|
22
|
+
if (!res.body) {
|
23
|
+
throw new Error(`Failed to download: ${url}`);
|
24
|
+
}
|
25
|
+
return Readable.from(res.body);
|
26
|
+
}
|
27
|
+
|
28
|
+
//# sourceMappingURL=download-template.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/download-template.ts"],"sourcesContent":["import { Readable } from 'node:stream'\nimport { pipeline } from 'node:stream/promises'\nimport { x } from 'tar'\n\nimport type { ProjectTemplate } from '../types.js'\n\nimport { debug as debugLog } from '../utils/log.js'\n\nexport async function downloadTemplate({\n debug,\n projectDir,\n template,\n}: {\n debug?: boolean\n projectDir: string\n template: ProjectTemplate\n}) {\n const branchOrTag = template.url.split('#')?.[1] || 'beta'\n const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`\n const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`\n\n if (debug) {\n debugLog(`Using template url: ${template.url}`)\n debugLog(`Codeload url: ${url}`)\n debugLog(`Filter: ${filter}`)\n }\n\n await pipeline(\n await downloadTarStream(url),\n x({\n cwd: projectDir,\n filter: (p) => p.includes(filter),\n strip: 2 + template.name.split('/').length,\n }),\n )\n}\n\nasync function downloadTarStream(url: string) {\n const res = await fetch(url)\n\n if (!res.body) {\n throw new Error(`Failed to download: ${url}`)\n }\n\n return Readable.from(res.body as unknown as NodeJS.ReadableStream)\n}\n"],"names":["Readable","pipeline","x","debug","debugLog","downloadTemplate","projectDir","template","branchOrTag","url","split","filter","replace","name","downloadTarStream","cwd","p","includes","strip","length","res","fetch","body","Error","from"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,CAAC,QAAQ,MAAK;AAIvB,SAASC,SAASC,QAAQ,QAAQ,kBAAiB;AAEnD,OAAO,eAAeC,iBAAiB,EACrCF,KAAK,EACLG,UAAU,EACVC,QAAQ,EAKT;IACC,MAAMC,cAAcD,SAASE,GAAG,CAACC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI;IACpD,MAAMD,MAAM,CAAC,sDAAsD,EAAED,YAAY,CAAC;IAClF,MAAMG,SAAS,CAAC,QAAQ,EAAEH,YAAYI,OAAO,CAAC,MAAM,IAAI,WAAW,EAAEL,SAASM,IAAI,CAAC,CAAC,CAAC;IAErF,IAAIV,OAAO;QACTC,SAAS,CAAC,oBAAoB,EAAEG,SAASE,GAAG,CAAC,CAAC;QAC9CL,SAAS,CAAC,cAAc,EAAEK,IAAI,CAAC;QAC/BL,SAAS,CAAC,QAAQ,EAAEO,OAAO,CAAC;IAC9B;IAEA,MAAMV,SACJ,MAAMa,kBAAkBL,MACxBP,EAAE;QACAa,KAAKT;QACLK,QAAQ,CAACK,IAAMA,EAAEC,QAAQ,CAACN;QAC1BO,OAAO,IAAIX,SAASM,IAAI,CAACH,KAAK,CAAC,KAAKS,MAAM;IAC5C;AAEJ;AAEA,eAAeL,kBAAkBL,GAAW;IAC1C,MAAMW,MAAM,MAAMC,MAAMZ;IAExB,IAAI,CAACW,IAAIE,IAAI,EAAE;QACb,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAEd,IAAI,CAAC;IAC9C;IAEA,OAAOT,SAASwB,IAAI,CAACJ,IAAIE,IAAI;AAC/B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-package-manager.d.ts","sourceRoot":"","sources":["../../src/lib/get-package-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE1D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,cAAc,CAAC,
|
1
|
+
{"version":3,"file":"get-package-manager.d.ts","sourceRoot":"","sources":["../../src/lib/get-package-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE1D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,cAAc,CAAC,CA0B1B"}
|
@@ -11,24 +11,36 @@ export async function getPackageManager(args) {
|
|
11
11
|
detected = 'yarn';
|
12
12
|
} else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {
|
13
13
|
detected = 'npm';
|
14
|
+
} else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) {
|
15
|
+
detected = 'bun';
|
16
|
+
} else if (await commandExists('pnpm')) {
|
17
|
+
// Prefer pnpm if it's installed
|
18
|
+
detected = 'pnpm';
|
14
19
|
} else {
|
15
|
-
// Otherwise check
|
16
|
-
|
17
|
-
detected = 'pnpm';
|
18
|
-
} else if (await commandExists('yarn')) {
|
19
|
-
detected = 'yarn';
|
20
|
-
} else {
|
21
|
-
detected = 'npm';
|
22
|
-
}
|
20
|
+
// Otherwise check the execution environment
|
21
|
+
detected = getEnvironmentPackageManager();
|
23
22
|
}
|
24
23
|
return detected;
|
25
|
-
} catch (
|
24
|
+
} catch (ignore) {
|
26
25
|
return 'npm';
|
27
26
|
}
|
28
27
|
}
|
28
|
+
function getEnvironmentPackageManager() {
|
29
|
+
const userAgent = process.env.npm_config_user_agent || '';
|
30
|
+
if (userAgent.startsWith('yarn')) {
|
31
|
+
return 'yarn';
|
32
|
+
}
|
33
|
+
if (userAgent.startsWith('pnpm')) {
|
34
|
+
return 'pnpm';
|
35
|
+
}
|
36
|
+
if (userAgent.startsWith('bun')) {
|
37
|
+
return 'bun';
|
38
|
+
}
|
39
|
+
return 'npm';
|
40
|
+
}
|
29
41
|
async function commandExists(command) {
|
30
42
|
try {
|
31
|
-
await execa.command(`command -v ${command}`);
|
43
|
+
await execa.command(process.platform === 'win32' ? `where ${command}` : `command -v ${command}`);
|
32
44
|
return true;
|
33
45
|
} catch {
|
34
46
|
return false;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/get-package-manager.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\n\nimport type { CliArgs, PackageManager } from '../types.js'\n\nexport async function getPackageManager(args: {\n cliArgs?: CliArgs\n projectDir: string\n}): Promise<PackageManager> {\n const { cliArgs, projectDir } = args\n\n try {\n // Check for flag or lockfile\n let detected: PackageManager = 'npm'\n if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`)) {\n detected = 'pnpm'\n } else if (cliArgs?.['--use-yarn'] || fse.existsSync(`${projectDir}/yarn.lock`)) {\n detected = 'yarn'\n } else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {\n detected = 'npm'\n } else {\n
|
1
|
+
{"version":3,"sources":["../../src/lib/get-package-manager.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\n\nimport type { CliArgs, PackageManager } from '../types.js'\n\nexport async function getPackageManager(args: {\n cliArgs?: CliArgs\n projectDir: string\n}): Promise<PackageManager> {\n const { cliArgs, projectDir } = args\n\n try {\n // Check for flag or lockfile\n let detected: PackageManager = 'npm'\n if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`)) {\n detected = 'pnpm'\n } else if (cliArgs?.['--use-yarn'] || fse.existsSync(`${projectDir}/yarn.lock`)) {\n detected = 'yarn'\n } else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {\n detected = 'npm'\n } else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) {\n detected = 'bun'\n } else if (await commandExists('pnpm')) {\n // Prefer pnpm if it's installed\n detected = 'pnpm'\n } else {\n // Otherwise check the execution environment\n detected = getEnvironmentPackageManager()\n }\n\n return detected\n } catch (ignore) {\n return 'npm'\n }\n}\n\nfunction getEnvironmentPackageManager(): PackageManager {\n const userAgent = process.env.npm_config_user_agent || ''\n\n if (userAgent.startsWith('yarn')) {\n return 'yarn'\n }\n\n if (userAgent.startsWith('pnpm')) {\n return 'pnpm'\n }\n\n if (userAgent.startsWith('bun')) {\n return 'bun'\n }\n\n return 'npm'\n}\n\nasync function commandExists(command: string): Promise<boolean> {\n try {\n await execa.command(process.platform === 'win32' ? `where ${command}` : `command -v ${command}`)\n return true\n } catch {\n return false\n }\n}\n"],"names":["execa","fse","getPackageManager","args","cliArgs","projectDir","detected","existsSync","commandExists","getEnvironmentPackageManager","ignore","userAgent","process","env","npm_config_user_agent","startsWith","command","platform"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAI1B,OAAO,eAAeC,kBAAkBC,IAGvC;IACC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGF;IAEhC,IAAI;QACF,6BAA6B;QAC7B,IAAIG,WAA2B;QAC/B,IAAIF,SAAS,CAAC,aAAa,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,eAAe,CAAC,GAAG;YAC7EC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,aAAa,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,UAAU,CAAC,GAAG;YAC/EC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,YAAY,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,kBAAkB,CAAC,GAAG;YACtFC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,YAAY,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,UAAU,CAAC,GAAG;YAC9EC,WAAW;QACb,OAAO,IAAI,MAAME,cAAc,SAAS;YACtC,gCAAgC;YAChCF,WAAW;QACb,OAAO;YACL,4CAA4C;YAC5CA,WAAWG;QACb;QAEA,OAAOH;IACT,EAAE,OAAOI,QAAQ;QACf,OAAO;IACT;AACF;AAEA,SAASD;IACP,MAAME,YAAYC,QAAQC,GAAG,CAACC,qBAAqB,IAAI;IAEvD,IAAIH,UAAUI,UAAU,CAAC,SAAS;QAChC,OAAO;IACT;IAEA,IAAIJ,UAAUI,UAAU,CAAC,SAAS;QAChC,OAAO;IACT;IAEA,IAAIJ,UAAUI,UAAU,CAAC,QAAQ;QAC/B,OAAO;IACT;IAEA,OAAO;AACT;AAEA,eAAeP,cAAcQ,OAAe;IAC1C,IAAI;QACF,MAAMhB,MAAMgB,OAAO,CAACJ,QAAQK,QAAQ,KAAK,UAAU,CAAC,MAAM,EAAED,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAEA,QAAQ,CAAC;QAC/F,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
package/dist/lib/init-next.d.ts
CHANGED
@@ -7,15 +7,15 @@ type InitNextArgs = {
|
|
7
7
|
useDistFiles?: boolean;
|
8
8
|
} & Pick<CliArgs, '--debug'>;
|
9
9
|
type InitNextResult = {
|
10
|
-
isSrcDir: boolean;
|
11
|
-
nextAppDir: string;
|
12
|
-
payloadConfigPath: string;
|
13
|
-
success: true;
|
14
|
-
} | {
|
15
10
|
isSrcDir: boolean;
|
16
11
|
nextAppDir?: string;
|
17
12
|
reason: string;
|
18
13
|
success: false;
|
14
|
+
} | {
|
15
|
+
isSrcDir: boolean;
|
16
|
+
nextAppDir: string;
|
17
|
+
payloadConfigPath: string;
|
18
|
+
success: true;
|
19
19
|
};
|
20
20
|
export declare function initNext(args: InitNextArgs): Promise<InitNextResult>;
|
21
21
|
export declare function getNextAppDetails(projectDir: string): Promise<NextAppDetails>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"init-next.d.ts","sourceRoot":"","sources":["../../src/lib/init-next.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"init-next.d.ts","sourceRoot":"","sources":["../../src/lib/init-next.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAkB,cAAc,EAAE,MAAM,aAAa,CAAA;AAclG,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE5B,KAAK,cAAc,GACf;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GAC1E;IACE,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,IAAI,CAAA;CACd,CAAA;AAEL,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAgE1E;AAqID,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA2FnF"}
|
package/dist/lib/init-next.js
CHANGED
@@ -26,7 +26,7 @@ export async function initNext(args) {
|
|
26
26
|
});
|
27
27
|
nextAppDetails.nextAppDir = createdAppDir;
|
28
28
|
}
|
29
|
-
const { hasTopLevelLayout,
|
29
|
+
const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
|
30
30
|
if (!nextConfigType) {
|
31
31
|
return {
|
32
32
|
isSrcDir,
|
@@ -121,7 +121,9 @@ async function installAndConfigurePayload(args) {
|
|
121
121
|
};
|
122
122
|
}
|
123
123
|
const logDebug = (message)=>{
|
124
|
-
if (debug)
|
124
|
+
if (debug) {
|
125
|
+
origDebug(message);
|
126
|
+
}
|
125
127
|
};
|
126
128
|
if (!fs.existsSync(projectDir)) {
|
127
129
|
return {
|
@@ -129,7 +131,7 @@ async function installAndConfigurePayload(args) {
|
|
129
131
|
success: false
|
130
132
|
};
|
131
133
|
}
|
132
|
-
const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank
|
134
|
+
const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank');
|
133
135
|
logDebug(`Using template files from: ${templateFilesPath}`);
|
134
136
|
if (!fs.existsSync(templateFilesPath)) {
|
135
137
|
return {
|
@@ -148,7 +150,7 @@ async function installAndConfigurePayload(args) {
|
|
148
150
|
logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`);
|
149
151
|
logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`);
|
150
152
|
// This is a little clunky and needs to account for isSrcDir
|
151
|
-
copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath)
|
153
|
+
copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath));
|
152
154
|
// Wrap next.config.js with withPayload
|
153
155
|
await wrapNextConfig({
|
154
156
|
nextConfigPath,
|
@@ -164,7 +166,7 @@ async function installDeps(projectDir, packageManager, dbType) {
|
|
164
166
|
'payload',
|
165
167
|
'@payloadcms/next',
|
166
168
|
'@payloadcms/richtext-lexical',
|
167
|
-
'@payloadcms/
|
169
|
+
'@payloadcms/payload-cloud'
|
168
170
|
].map((pkg)=>`${pkg}@beta`);
|
169
171
|
packagesToInstall.push(`@payloadcms/db-${dbType}@beta`);
|
170
172
|
// Match graphql version of @payloadcms/next
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n} & Pick<CliArgs, '--debug'>\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } =\n nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = await installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nasync function installAndConfigurePayload(\n args: {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n } & InitNextArgs,\n): Promise<\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false }\n> {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n await wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/plugin-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs\n const nextConfigPath: string | undefined = (\n await globby('next.config.(\\\\w)?(t|j)s', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath: undefined,\n nextVersion: null,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n // Check if Next.js version is new enough\n let nextVersion = null\n if (packageObj.dependencies?.next) {\n nextVersion = packageObj.dependencies.next\n // Match versions using regex matching groups\n const versionMatch = /(?<major>\\d+)/.exec(nextVersion)\n if (!versionMatch) {\n p.log.warn(`Could not determine Next.js version from ${nextVersion}`)\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n\n const { major } = versionMatch.groups as { major: string }\n const majorVersion = parseInt(major)\n if (majorVersion < 15) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n }\n\n const isSupportedNextVersion = true\n\n // Check if Payload already installed\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n isSupportedNextVersion,\n nextConfigPath,\n nextVersion,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = getProjectType({ nextConfigPath, packageObj })\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return {\n hasTopLevelLayout,\n isSrcDir,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextConfigType: configType,\n nextVersion,\n }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): NextConfigType {\n const { nextConfigPath, packageObj } = args\n\n if (nextConfigPath.endsWith('.ts')) {\n return 'ts'\n }\n\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","isPayloadInstalled","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","absolute","cwd","length","isSupportedNextVersion","undefined","nextVersion","packageObj","readJson","dependencies","next","versionMatch","exec","major","groups","majorVersion","parseInt","payload","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAE/C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAIhC,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,SAAS,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,wBAAuB;AAEtD,MAAMC,WAAWR,UAAUL,GAAGa,QAAQ;AACtC,MAAMC,YAAYT,UAAUL,GAAGc,SAAS;AAExC,MAAMC,WAAWZ,cAAc,YAAYa,GAAG;AAC9C,MAAMC,UAAUb,KAAKa,OAAO,CAACF;AAmB7B,OAAO,eAAeG,SAASC,IAAkB;IAC/C,MAAM,EAAEC,QAAQA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGH;IAE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T;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
|
1
|
+
{"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n} & Pick<CliArgs, '--debug'>\n\ntype InitNextResult =\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = await installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nasync function installAndConfigurePayload(\n args: {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n } & InitNextArgs,\n): Promise<\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false }\n> {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) {\n origDebug(message)\n }\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath))\n\n // Wrap next.config.js with withPayload\n await wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/payload-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs\n const nextConfigPath: string | undefined = (\n await globby('next.config.(\\\\w)?(t|j)s', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath: undefined,\n nextVersion: null,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n // Check if Next.js version is new enough\n let nextVersion = null\n if (packageObj.dependencies?.next) {\n nextVersion = packageObj.dependencies.next\n // Match versions using regex matching groups\n const versionMatch = /(?<major>\\d+)/.exec(nextVersion)\n if (!versionMatch) {\n p.log.warn(`Could not determine Next.js version from ${nextVersion}`)\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n\n const { major } = versionMatch.groups as { major: string }\n const majorVersion = parseInt(major)\n if (majorVersion < 15) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n }\n\n const isSupportedNextVersion = true\n\n // Check if Payload already installed\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n isSupportedNextVersion,\n nextConfigPath,\n nextVersion,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = getProjectType({ nextConfigPath, packageObj })\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return {\n hasTopLevelLayout,\n isSrcDir,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextConfigType: configType,\n nextVersion,\n }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): NextConfigType {\n const { nextConfigPath, packageObj } = args\n\n if (nextConfigPath.endsWith('.ts')) {\n return 'ts'\n }\n\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","absolute","cwd","length","isSupportedNextVersion","undefined","nextVersion","packageObj","readJson","dependencies","next","versionMatch","exec","major","groups","majorVersion","parseInt","payload","isPayloadInstalled","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAC/C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAIhC,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,SAAS,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,wBAAuB;AAEtD,MAAMC,WAAWR,UAAUL,GAAGa,QAAQ;AACtC,MAAMC,YAAYT,UAAUL,GAAGc,SAAS;AAExC,MAAMC,WAAWZ,cAAc,YAAYa,GAAG;AAC9C,MAAMC,UAAUb,KAAKa,OAAO,CAACF;AAmB7B,OAAO,eAAeG,SAASC,IAAkB;IAC/C,MAAM,EAAEC,QAAQA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGH;IAEvD,MAAMI,iBAAiBJ,KAAKI,cAAc,IAAK,MAAMC,kBAAkBF;IAEvE,IAAI,CAACC,eAAeE,UAAU,EAAE;QAC9BhB,QAAQ,CAAC,gCAAgC,EAAEa,WAAW,aAAa,CAAC;QACpE,MAAMI,gBAAgBtB,KAAKuB,OAAO,CAACL,YAAYC,eAAeK,QAA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ACA0C,wBAAwB;gBACxBd;gBACAgB;YACF;QACF;IACF;IAEA,MAAMF,yBAAyB;IAE/B,qCAAqC;IACrC,IAAIG,WAAWE,YAAY,EAAEQ,SAAS;QACpC,OAAO;YACLpD,mBAAmB;YACnBqD,oBAAoB;YACpBxD;YACA0C;YACAd;YACAgB;QACF;IACF;IAEA,IAAI/C,aACF,CAAA,MAAMvB,OAAO;QAAC;KAAS,EAAE;QACvBiE,UAAU;QACVC,KAAK9C;QACL+D,QAAQ;YAAC;SAAqB;QAC9BC,iBAAiB;IACnB,EAAC,GACA,CAAC,EAAE;IAEN,IAAI,CAAC7D,cAAcA,WAAW4C,MAAM,KAAK,GAAG;QAC1C5C,aAAa8C;IACf;IAEA,MAAMgB,aAAaC,eAAe;QAAEhC;QAAgBiB;IAAW;IAE/D,MAAM1C,oBAAoBN,aACtBzB,GAAGgD,UAAU,CAAC5C,KAAKuB,OAAO,CAACF,YAAY,iBACvC;IAEJ,OAAO;QACLM;QACAH;QACA0C;QACA7C;QACA+B;QACAxB,gBAAgBuD;QAChBf;IACF;AACF;AAEA,SAASgB,eAAerE,IAGvB;IACC,MAAM,EAAEqC,cAAc,EAAEiB,UAAU,EAAE,GAAGtD;IAEvC,IAAIqC,eAAeI,QAAQ,CAAC,QAAQ;QAClC,OAAO;IACT;IAEA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAM6B,kBAAkBhB,WAAWiB,IAAI;IACvC,IAAID,oBAAoB,UAAU;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
|
@@ -5,26 +5,26 @@ export async function installPackages(args) {
|
|
5
5
|
let exitCode = 0;
|
6
6
|
let stderr = '';
|
7
7
|
switch(packageManager){
|
8
|
-
case '
|
8
|
+
case 'bun':
|
9
|
+
case 'pnpm':
|
10
|
+
case 'yarn':
|
9
11
|
{
|
10
|
-
(
|
11
|
-
'
|
12
|
-
|
12
|
+
if (packageManager === 'bun') {
|
13
|
+
warning('Bun support is untested.');
|
14
|
+
}
|
15
|
+
({ exitCode, stderr } = await execa(packageManager, [
|
16
|
+
'add',
|
13
17
|
...packagesToInstall
|
14
18
|
], {
|
15
19
|
cwd: projectDir
|
16
20
|
}));
|
17
21
|
break;
|
18
22
|
}
|
19
|
-
case '
|
20
|
-
case 'pnpm':
|
21
|
-
case 'bun':
|
23
|
+
case 'npm':
|
22
24
|
{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
({ exitCode, stderr } = await execa(packageManager, [
|
27
|
-
'add',
|
25
|
+
({ exitCode, stderr } = await execa('npm', [
|
26
|
+
'install',
|
27
|
+
'--save',
|
28
28
|
...packagesToInstall
|
29
29
|
], {
|
30
30
|
cwd: projectDir
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/install-packages.ts"],"sourcesContent":["import execa from 'execa'\n\nimport type { PackageManager } from '../types.js'\n\nimport { error, warning } from '../utils/log.js'\n\nexport async function installPackages(args: {\n packageManager: PackageManager\n packagesToInstall: string[]\n projectDir: string\n}) {\n const { packageManager, packagesToInstall, projectDir } = args\n\n let exitCode = 0\n let stderr = ''\n\n switch (packageManager) {\n case '
|
1
|
+
{"version":3,"sources":["../../src/lib/install-packages.ts"],"sourcesContent":["import execa from 'execa'\n\nimport type { PackageManager } from '../types.js'\n\nimport { error, warning } from '../utils/log.js'\n\nexport async function installPackages(args: {\n packageManager: PackageManager\n packagesToInstall: string[]\n projectDir: string\n}) {\n const { packageManager, packagesToInstall, projectDir } = args\n\n let exitCode = 0\n let stderr = ''\n\n switch (packageManager) {\n case 'bun':\n case 'pnpm':\n case 'yarn': {\n if (packageManager === 'bun') {\n warning('Bun support is untested.')\n }\n ;({ exitCode, stderr } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'npm': {\n ;({ exitCode, stderr } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n }\n\n if (exitCode !== 0) {\n error(`Unable to install packages. Error: ${stderr}`)\n }\n\n return { success: exitCode === 0 }\n}\n"],"names":["execa","error","warning","installPackages","args","packageManager","packagesToInstall","projectDir","exitCode","stderr","cwd","success"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AAIzB,SAASC,KAAK,EAAEC,OAAO,QAAQ,kBAAiB;AAEhD,OAAO,eAAeC,gBAAgBC,IAIrC;IACC,MAAM,EAAEC,cAAc,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGH;IAE1D,IAAII,WAAW;IACf,IAAIC,SAAS;IAEb,OAAQJ;QACN,KAAK;QACL,KAAK;QACL,KAAK;YAAQ;gBACX,IAAIA,mBAAmB,OAAO;oBAC5BH,QAAQ;gBACV;gBACE,CAAA,EAAEM,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAMK,gBAAgB;oBAAC;uBAAUC;iBAAkB,EAAE;oBAClFI,KAAKH;gBACP,EAAC;gBACD;YACF;QACA,KAAK;YAAO;gBACR,CAAA,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAM,OAAO;oBAAC;oBAAW;uBAAaM;iBAAkB,EAAE;oBACvFI,KAAKH;gBACP,EAAC;gBACD;YACF;IACF;IAEA,IAAIC,aAAa,GAAG;QAClBP,MAAM,CAAC,mCAAmC,EAAEQ,OAAO,CAAC;IACtD;IAEA,OAAO;QAAEE,SAASH,aAAa;IAAE;AACnC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parse-project-name.d.ts","sourceRoot":"","sources":["../../src/lib/parse-project-name.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,
|
1
|
+
{"version":3,"file":"parse-project-name.d.ts","sourceRoot":"","sources":["../../src/lib/parse-project-name.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBrE"}
|
@@ -1,12 +1,18 @@
|
|
1
1
|
import * as p from '@clack/prompts';
|
2
2
|
import slugify from '@sindresorhus/slugify';
|
3
3
|
export async function parseProjectName(args) {
|
4
|
-
if (args['--name'])
|
5
|
-
|
4
|
+
if (args['--name']) {
|
5
|
+
return slugify(args['--name']);
|
6
|
+
}
|
7
|
+
if (args._[0]) {
|
8
|
+
return slugify(args._[0]);
|
9
|
+
}
|
6
10
|
const projectName = await p.text({
|
7
11
|
message: 'Project name?',
|
8
12
|
validate: (value)=>{
|
9
|
-
if (!value)
|
13
|
+
if (!value) {
|
14
|
+
return 'Please enter a project name.';
|
15
|
+
}
|
10
16
|
}
|
11
17
|
});
|
12
18
|
if (p.isCancel(projectName)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) {\n return slugify(args['--name'])\n }\n if (args._[0]) {\n return slugify(args._[0])\n }\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) {\n return 'Please enter a project name.'\n }\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE;QAClB,OAAOF,QAAQE,IAAI,CAAC,SAAS;IAC/B;IACA,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE;QACb,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAC1B;IAEA,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO;gBACV,OAAO;YACT;QACF;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
|