create-payload-app
Advanced tools
Comparing version 0.4.2 to 0.5.0-beta.0
@@ -42,3 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createProject = exports.updatePackageJSONName = void 0; | ||
exports.updatePackageJSON = exports.createProject = void 0; | ||
var path_1 = __importDefault(require("path")); | ||
@@ -51,2 +51,3 @@ var chalk_1 = __importDefault(require("chalk")); | ||
var log_1 = require("../utils/log"); | ||
var configure_payload_config_1 = require("./configure-payload-config"); | ||
function createOrFindProjectDir(projectDir) { | ||
@@ -72,3 +73,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cliArgs, projectDir, packageManager, cmd, err_1; | ||
var cliArgs, projectDir, packageManager, installCmd, err_1; | ||
return __generator(this, function (_a) { | ||
@@ -81,7 +82,13 @@ switch (_a.label) { | ||
} | ||
cmd = packageManager === 'yarn' ? 'yarn' : 'npm install --legacy-peer-deps'; | ||
installCmd = 'npm install --legacy-peer-deps'; | ||
if (packageManager === 'yarn') { | ||
installCmd = 'yarn'; | ||
} | ||
else if (packageManager === 'pnpm') { | ||
installCmd = 'pnpm install'; | ||
} | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, execa_1.default.command(cmd, { | ||
return [4 /*yield*/, execa_1.default.command(installCmd, { | ||
cwd: path_1.default.resolve(projectDir), | ||
@@ -101,38 +108,9 @@ })]; | ||
} | ||
function updatePackageJSONName(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var projectName, projectDir, packageJsonPath, packageObj, err_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
projectName = args.projectName, projectDir = args.projectDir; | ||
packageJsonPath = path_1.default.resolve(projectDir, 'package.json'); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)]; | ||
case 2: | ||
packageObj = _a.sent(); | ||
packageObj.name = projectName; | ||
return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
err_2 = _a.sent(); | ||
(0, log_1.warning)('Unable to update name in package.json'); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.updatePackageJSONName = updatePackageJSONName; | ||
function createProject(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cliArgs, projectName, projectDir, template, packageManager, emitter, spinner, lockPath, result; | ||
var cliArgs, projectName, projectDir, template, packageManager, dbDetails, emitter, spinner, lockPath, result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
cliArgs = args.cliArgs, projectName = args.projectName, projectDir = args.projectDir, template = args.template, packageManager = args.packageManager; | ||
cliArgs = args.cliArgs, projectName = args.projectName, projectDir = args.projectDir, template = args.template, packageManager = args.packageManager, dbDetails = args.dbDetails; | ||
return [4 /*yield*/, createOrFindProjectDir(projectDir)]; | ||
@@ -150,17 +128,20 @@ case 1: | ||
spinner = (0, ora_1.default)('Checking latest Payload version...').start(); | ||
return [4 /*yield*/, updatePackageJSONName({ projectName: projectName, projectDir: projectDir }) | ||
return [4 /*yield*/, updatePackageJSON({ projectName: projectName, projectDir: projectDir })]; | ||
case 4: | ||
_a.sent(); | ||
return [4 /*yield*/, (0, configure_payload_config_1.configurePayloadConfig)({ projectDir: projectDir, dbDetails: dbDetails }) | ||
// Remove yarn.lock file. This is only desired in Payload Cloud. | ||
]; | ||
case 4: | ||
case 5: | ||
_a.sent(); | ||
lockPath = path_1.default.resolve(projectDir, 'yarn.lock'); | ||
if (!fs_extra_1.default.existsSync(lockPath)) return [3 /*break*/, 6]; | ||
if (!fs_extra_1.default.existsSync(lockPath)) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, fs_extra_1.default.remove(lockPath)]; | ||
case 5: | ||
case 6: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: | ||
_a.label = 7; | ||
case 7: | ||
spinner.text = 'Installing dependencies...'; | ||
return [4 /*yield*/, installDeps({ cliArgs: cliArgs, projectDir: projectDir, packageManager: packageManager })]; | ||
case 7: | ||
case 8: | ||
result = _a.sent(); | ||
@@ -181,1 +162,30 @@ spinner.stop(); | ||
exports.createProject = createProject; | ||
function updatePackageJSON(args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var projectName, projectDir, packageJsonPath, packageObj, err_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
projectName = args.projectName, projectDir = args.projectDir; | ||
packageJsonPath = path_1.default.resolve(projectDir, 'package.json'); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)]; | ||
case 2: | ||
packageObj = _a.sent(); | ||
packageObj.name = projectName; | ||
return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
err_2 = _a.sent(); | ||
(0, log_1.warning)('Unable to update name in package.json'); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.updatePackageJSON = updatePackageJSON; |
@@ -45,2 +45,3 @@ "use strict"; | ||
var create_project_1 = require("./create-project"); | ||
var packages_1 = require("./packages"); | ||
var projectDir = path_1.default.resolve(__dirname, './tmp'); | ||
@@ -63,3 +64,7 @@ describe('createProject', function () { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
var args = { _: ['project-name'], '--no-deps': true }; | ||
var args = { | ||
_: ['project-name'], | ||
'--db': 'mongodb', | ||
'--no-deps': true, | ||
}; | ||
var packageManager = 'yarn'; | ||
@@ -124,3 +129,56 @@ it('creates starter project', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
}); }); | ||
describe('db adapters and bundlers', function () { | ||
it.each([ | ||
['mongodb', 'webpack'], | ||
['postgres', 'webpack'], | ||
])('update config and deps: %s, %s', function (db, bundler) { return __awaiter(void 0, void 0, void 0, function () { | ||
var projectName, template, dbReplacement, bundlerReplacement, packageJsonPath, packageJson, payloadConfigPath, content; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
projectName = 'starter-project'; | ||
template = { | ||
name: 'blank', | ||
type: 'starter', | ||
url: 'https://github.com/payloadcms/payload/templates/blank#2.0', | ||
description: 'Blank Template', | ||
}; | ||
return [4 /*yield*/, (0, create_project_1.createProject)({ | ||
cliArgs: args, | ||
projectName: projectName, | ||
projectDir: projectDir, | ||
template: template, | ||
packageManager: packageManager, | ||
dbDetails: { | ||
dbUri: "".concat(db, "://localhost:27017/create-project-test"), | ||
type: db, | ||
}, | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
dbReplacement = packages_1.dbPackages[db]; | ||
bundlerReplacement = packages_1.bundlerPackages[bundler]; | ||
packageJsonPath = path_1.default.resolve(projectDir, 'package.json'); | ||
packageJson = fs_extra_1.default.readJsonSync(packageJsonPath); | ||
// Check deps | ||
expect(packageJson.dependencies[dbReplacement.packageName]).toBeDefined(); | ||
expect(packageJson.dependencies[bundlerReplacement.packageName]).toBeDefined(); | ||
payloadConfigPath = path_1.default.resolve(projectDir, 'src/payload.config.ts'); | ||
content = fs_extra_1.default.readFileSync(payloadConfigPath, 'utf-8'); | ||
// Check payload.config.ts | ||
expect(content).not.toContain('// database-adapter-import'); | ||
expect(content).toContain(dbReplacement.importReplacement); | ||
expect(content).not.toContain('// database-adapter-config-start'); | ||
expect(content).not.toContain('// database-adapter-config-end'); | ||
expect(content).toContain(dbReplacement.configReplacement.join('\n')); | ||
expect(content).not.toContain('// bundler-config-import'); | ||
expect(content).toContain(bundlerReplacement.importReplacement); | ||
expect(content).not.toContain('// bundler-config'); | ||
expect(content).toContain(bundlerReplacement.configReplacement); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
}); | ||
}); |
@@ -67,3 +67,3 @@ "use strict"; | ||
type: 'starter', | ||
url: 'https://github.com/payloadcms/payload/templates/blank', | ||
url: 'https://github.com/payloadcms/payload/templates/blank#2.0', | ||
description: 'Blank Template', | ||
@@ -74,3 +74,3 @@ }, | ||
type: 'starter', | ||
url: 'https://github.com/payloadcms/payload/templates/website', | ||
url: 'https://github.com/payloadcms/payload/templates/website#2.0', | ||
description: 'Website Template', | ||
@@ -81,3 +81,3 @@ }, | ||
type: 'starter', | ||
url: 'https://github.com/payloadcms/payload/templates/ecommerce', | ||
url: 'https://github.com/payloadcms/payload/templates/ecommerce#2.0', | ||
description: 'E-commerce Template', | ||
@@ -84,0 +84,0 @@ }, |
@@ -71,3 +71,5 @@ "use strict"; | ||
var value = split[1]; | ||
if (key === 'MONGODB_URI' || key === 'MONGO_URL') { | ||
if (key === 'MONGODB_URI' || | ||
key === 'MONGO_URL' || | ||
key === 'DATABASE_URI') { | ||
value = databaseUri; | ||
@@ -74,0 +76,0 @@ } |
@@ -47,3 +47,3 @@ "use strict"; | ||
var create_project_1 = require("./lib/create-project"); | ||
var get_db_connection_1 = require("./lib/get-db-connection"); | ||
var select_db_1 = require("./lib/select-db"); | ||
var generate_secret_1 = require("./lib/generate-secret"); | ||
@@ -66,2 +66,4 @@ var parse_project_name_1 = require("./lib/parse-project-name"); | ||
'--use-npm': Boolean, | ||
'--use-yarn': Boolean, | ||
'--use-pnpm': Boolean, | ||
'--no-deps': Boolean, | ||
@@ -77,3 +79,3 @@ '--dry-run': Boolean, | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, _b, templateArg, valid, _c, _d, projectName, validTemplates, template, projectDir, packageManager, databaseUri, payloadSecret, error_1; | ||
var _a, _b, templateArg, valid, _c, _d, projectName, validTemplates, template, projectDir, packageManager, dbDetails, payloadSecret, error_1; | ||
return __generator(this, function (_e) { | ||
@@ -119,5 +121,5 @@ switch (_e.label) { | ||
if (!(template.type !== 'plugin')) return [3 /*break*/, 15]; | ||
return [4 /*yield*/, (0, get_db_connection_1.getDatabaseConnection)(this.args, projectName)]; | ||
return [4 /*yield*/, (0, select_db_1.selectDb)(this.args, projectName)]; | ||
case 10: | ||
databaseUri = _e.sent(); | ||
dbDetails = _e.sent(); | ||
return [4 /*yield*/, (0, generate_secret_1.generateSecret)()]; | ||
@@ -133,2 +135,3 @@ case 11: | ||
packageManager: packageManager, | ||
dbDetails: dbDetails, | ||
})]; | ||
@@ -138,3 +141,3 @@ case 12: | ||
return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)({ | ||
databaseUri: databaseUri, | ||
databaseUri: dbDetails.dbUri, | ||
payloadSecret: payloadSecret, | ||
@@ -182,17 +185,33 @@ template: template, | ||
case 0: | ||
packageManager = 'npm'; | ||
if (!args['--use-npm']) return [3 /*break*/, 1]; | ||
packageManager = 'npm'; | ||
return [3 /*break*/, 4]; | ||
return [3 /*break*/, 9]; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
if (!args['--use-yarn']) return [3 /*break*/, 2]; | ||
packageManager = 'yarn'; | ||
return [3 /*break*/, 9]; | ||
case 2: | ||
if (!args['--use-pnpm']) return [3 /*break*/, 3]; | ||
packageManager = 'pnpm'; | ||
return [3 /*break*/, 9]; | ||
case 3: | ||
_a.trys.push([3, 8, , 9]); | ||
return [4 /*yield*/, (0, command_exists_1.default)('yarn')]; | ||
case 2: | ||
_a.sent(); | ||
case 4: | ||
if (!_a.sent()) return [3 /*break*/, 5]; | ||
packageManager = 'yarn'; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
return [3 /*break*/, 7]; | ||
case 5: return [4 /*yield*/, (0, command_exists_1.default)('pnpm')]; | ||
case 6: | ||
if (_a.sent()) { | ||
packageManager = 'pnpm'; | ||
} | ||
_a.label = 7; | ||
case 7: return [3 /*break*/, 9]; | ||
case 8: | ||
error_2 = _a.sent(); | ||
packageManager = 'npm'; | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/, packageManager]; | ||
return [3 /*break*/, 9]; | ||
case 9: return [2 /*return*/, packageManager]; | ||
} | ||
@@ -199,0 +218,0 @@ }); |
@@ -65,3 +65,3 @@ "use strict"; | ||
validTemplates = _a.sent(); | ||
return [2 /*return*/, (0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"])), formatTemplates(validTemplates))]; | ||
return [2 /*return*/, (0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"])), formatTemplates(validTemplates))]; | ||
} | ||
@@ -68,0 +68,0 @@ }); |
@@ -40,3 +40,3 @@ { | ||
}, | ||
"version": "0.4.2", | ||
"version": "0.5.0-beta.0", | ||
"devDependencies": { | ||
@@ -43,0 +43,0 @@ "@types/command-exists": "^1.2.0", |
@@ -12,13 +12,24 @@ # Create Payload App | ||
$ npx create-payload-app | ||
$ npx create-payload-app my-project | ||
$ npx create-payload-app -n my-project -t blog | ||
OPTIONS | ||
--name my-payload-app Set project name | ||
--template template_name Choose specific template | ||
-n my-payload-app Set project name | ||
-t template_name Choose specific template | ||
Available templates: blank, blog, todo | ||
Available templates: | ||
--use-npm Use npm to install dependencies | ||
--no-deps Do not install any dependencies | ||
--help Show help | ||
blank Blank Template | ||
website Website Template | ||
ecommerce E-commerce Template | ||
plugin Template for creating a Payload plugin | ||
payload-demo Payload demo site at https://demo.payloadcms.com | ||
payload-website Payload website CMS at https://payloadcms.com | ||
--use-npm Use npm to install dependencies | ||
--use-yarn Use yarn to install dependencies | ||
--use-pnpm Use pnpm to install dependencies | ||
--no-deps Do not install any dependencies | ||
-h Show help | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83738
19
1484
35
5