create-payload-app 3.0.0-alpha.55 → 3.0.0-alpha.60
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/cli.js +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/lib/configure-payload-config.js +12 -27
- package/dist/lib/configure-payload-config.js.map +1 -1
- package/dist/lib/create-project.js +32 -96
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/create-project.spec.js +24 -33
- package/dist/lib/create-project.spec.js.map +1 -1
- package/dist/lib/generate-secret.js +3 -13
- package/dist/lib/generate-secret.js.map +1 -1
- package/dist/lib/init-next.js +40 -104
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/packages.js +1 -11
- package/dist/lib/packages.js.map +1 -1
- package/dist/lib/parse-project-name.js +8 -64
- package/dist/lib/parse-project-name.js.map +1 -1
- package/dist/lib/parse-template.js +4 -55
- package/dist/lib/parse-template.js.map +1 -1
- package/dist/lib/select-db.js +8 -64
- package/dist/lib/select-db.js.map +1 -1
- package/dist/lib/templates.js +5 -23
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/wrap-next-config.js +18 -41
- package/dist/lib/wrap-next-config.js.map +1 -1
- package/dist/lib/wrap-next-config.spec.js +10 -55
- package/dist/lib/wrap-next-config.spec.js.map +1 -1
- package/dist/lib/write-env-file.js +11 -26
- package/dist/lib/write-env-file.js.map +1 -1
- package/dist/main.js +60 -115
- package/dist/main.js.map +1 -1
- package/dist/scripts/pack-template-files.js +15 -24
- package/dist/scripts/pack-template-files.js.map +1 -1
- package/dist/types.js +1 -4
- package/dist/types.js.map +1 -1
- package/dist/utils/copy-recursive-sync.js +11 -24
- package/dist/utils/copy-recursive-sync.js.map +1 -1
- package/dist/utils/log.js +12 -85
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/messages.js +20 -55
- package/dist/utils/messages.js.map +1 -1
- package/package.json +2 -2
package/bin/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export
|
1
|
+
export declare function main(): Promise<void>;
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ1C"}
|
package/dist/index.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { Main } from './main.js';
|
2
|
+
import { error } from './utils/log.js';
|
3
|
+
export async function main() {
|
4
|
+
try {
|
5
|
+
await new Main().init();
|
6
|
+
} catch (e) {
|
7
|
+
if (e instanceof Error) {
|
8
|
+
error(e.message);
|
9
|
+
}
|
10
|
+
}
|
9
11
|
}
|
10
|
-
main().catch((e)=>(0, _log.error)(`An error has occurred: ${e instanceof Error ? e.message : e}`));
|
11
12
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Main } from './main.js'\nimport { error } from './utils/log.js'\n\
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Main } from './main.js'\nimport { error } from './utils/log.js'\n\nexport async function main(): Promise<void> {\n try {\n await new Main().init()\n } catch (e) {\n if (e instanceof Error) {\n error(e.message)\n }\n }\n}\n"],"names":["Main","error","main","init","e","Error","message"],"mappings":"AAAA,SAASA,IAAI,QAAQ,YAAW;AAChC,SAASC,KAAK,QAAQ,iBAAgB;AAEtC,OAAO,eAAeC;IACpB,IAAI;QACF,MAAM,IAAIF,OAAOG,IAAI;IACvB,EAAE,OAAOC,GAAG;QACV,IAAIA,aAAaC,OAAO;YACtBJ,MAAMG,EAAEE,OAAO;QACjB;IACF;AACF"}
|
@@ -1,30 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
|
6
|
-
enumerable: true,
|
7
|
-
get: function() {
|
8
|
-
return configurePayloadConfig;
|
9
|
-
}
|
10
|
-
});
|
11
|
-
const _fsextra = /*#__PURE__*/ _interop_require_default(require("fs-extra"));
|
12
|
-
const _globby = /*#__PURE__*/ _interop_require_default(require("globby"));
|
13
|
-
const _log = require("../utils/log.js");
|
14
|
-
const _packages = require("./packages.js");
|
15
|
-
function _interop_require_default(obj) {
|
16
|
-
return obj && obj.__esModule ? obj : {
|
17
|
-
default: obj
|
18
|
-
};
|
19
|
-
}
|
20
|
-
async function configurePayloadConfig(args) {
|
1
|
+
import fse from 'fs-extra';
|
2
|
+
import globby from 'globby';
|
3
|
+
import { warning } from '../utils/log.js';
|
4
|
+
import { dbReplacements } from './packages.js';
|
5
|
+
/** Update payload config with necessary imports and adapters */ export async function configurePayloadConfig(args) {
|
21
6
|
if (!args.dbDetails) {
|
22
7
|
return;
|
23
8
|
}
|
24
9
|
try {
|
25
10
|
let payloadConfigPath;
|
26
11
|
if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {
|
27
|
-
payloadConfigPath = (await (
|
12
|
+
payloadConfigPath = (await globby('**/payload.config.ts', {
|
28
13
|
absolute: true,
|
29
14
|
cwd: args.projectDirOrConfigPath.projectDir
|
30
15
|
}))?.[0];
|
@@ -32,12 +17,12 @@ async function configurePayloadConfig(args) {
|
|
32
17
|
payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath;
|
33
18
|
}
|
34
19
|
if (!payloadConfigPath) {
|
35
|
-
|
20
|
+
warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.');
|
36
21
|
return;
|
37
22
|
}
|
38
|
-
const configContent =
|
23
|
+
const configContent = fse.readFileSync(payloadConfigPath, 'utf-8');
|
39
24
|
const configLines = configContent.split('\n');
|
40
|
-
const dbReplacement =
|
25
|
+
const dbReplacement = dbReplacements[args.dbDetails.type];
|
41
26
|
let dbConfigStartLineIndex;
|
42
27
|
let dbConfigEndLineIndex;
|
43
28
|
configLines.forEach((l, i)=>{
|
@@ -52,14 +37,14 @@ async function configurePayloadConfig(args) {
|
|
52
37
|
}
|
53
38
|
});
|
54
39
|
if (!dbConfigStartLineIndex || !dbConfigEndLineIndex) {
|
55
|
-
|
40
|
+
warning('Unable to update payload.config.ts with database adapter import');
|
56
41
|
} else {
|
57
42
|
// Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`
|
58
43
|
configLines.splice(dbConfigStartLineIndex, dbConfigEndLineIndex - dbConfigStartLineIndex + 1, ...dbReplacement.configReplacement);
|
59
44
|
}
|
60
|
-
|
45
|
+
fse.writeFileSync(payloadConfigPath, configLines.join('\n'));
|
61
46
|
} catch (err) {
|
62
|
-
|
47
|
+
warning(`Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`);
|
63
48
|
}
|
64
49
|
}
|
65
50
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\n\nimport type { DbDetails } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements } from './packages.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbDetails: DbDetails | undefined\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n}): Promise<void> {\n if (!args.dbDetails) {\n return\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n const configLines = configContent.split('\\n')\n\n const dbReplacement = dbReplacements[args.dbDetails.type]\n\n let dbConfigStartLineIndex: number | undefined\n let dbConfigEndLineIndex: number | undefined\n\n configLines.forEach((l, i) => {\n if (l.includes('// database-adapter-import')) {\n configLines[i] = dbReplacement.importReplacement\n }\n\n if (l.includes('// database-adapter-config-start')) {\n dbConfigStartLineIndex = i\n }\n if (l.includes('// database-adapter-config-end')) {\n dbConfigEndLineIndex = i\n }\n })\n\n if (!dbConfigStartLineIndex || !dbConfigEndLineIndex) {\n warning('Unable to update payload.config.ts with database adapter import')\n } else {\n // Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`\n configLines.splice(\n dbConfigStartLineIndex,\n dbConfigEndLineIndex - dbConfigStartLineIndex + 1,\n ...dbReplacement.configReplacement,\n )\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n"],"names":["configurePayloadConfig","args","dbDetails","payloadConfigPath","projectDirOrConfigPath","
|
1
|
+
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\n\nimport type { DbDetails } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements } from './packages.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbDetails: DbDetails | undefined\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n}): Promise<void> {\n if (!args.dbDetails) {\n return\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n const configLines = configContent.split('\\n')\n\n const dbReplacement = dbReplacements[args.dbDetails.type]\n\n let dbConfigStartLineIndex: number | undefined\n let dbConfigEndLineIndex: number | undefined\n\n configLines.forEach((l, i) => {\n if (l.includes('// database-adapter-import')) {\n configLines[i] = dbReplacement.importReplacement\n }\n\n if (l.includes('// database-adapter-config-start')) {\n dbConfigStartLineIndex = i\n }\n if (l.includes('// database-adapter-config-end')) {\n dbConfigEndLineIndex = i\n }\n })\n\n if (!dbConfigStartLineIndex || !dbConfigEndLineIndex) {\n warning('Unable to update payload.config.ts with database adapter import')\n } else {\n // Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`\n configLines.splice(\n dbConfigStartLineIndex,\n dbConfigEndLineIndex - dbConfigStartLineIndex + 1,\n ...dbReplacement.configReplacement,\n )\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n"],"names":["fse","globby","warning","dbReplacements","configurePayloadConfig","args","dbDetails","payloadConfigPath","projectDirOrConfigPath","absolute","cwd","projectDir","configContent","readFileSync","configLines","split","dbReplacement","type","dbConfigStartLineIndex","dbConfigEndLineIndex","forEach","l","i","includes","importReplacement","splice","configReplacement","writeFileSync","join","err","Error","message"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAI3B,SAASC,OAAO,QAAQ,kBAAiB;AACzC,SAASC,cAAc,QAAQ,gBAAe;AAE9C,8DAA8D,GAC9D,OAAO,eAAeC,uBAAuBC,IAG5C;IACC,IAAI,CAACA,KAAKC,SAAS,EAAE;QACnB;IACF;IAEA,IAAI;QACF,IA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10
|
-
|
11
|
-
|
12
|
-
createProject: function() {
|
13
|
-
return createProject;
|
14
|
-
},
|
15
|
-
updatePackageJSON: function() {
|
16
|
-
return updatePackageJSON;
|
17
|
-
}
|
18
|
-
});
|
19
|
-
const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
|
20
|
-
const _chalk = /*#__PURE__*/ _interop_require_default(require("chalk"));
|
21
|
-
const _degit = /*#__PURE__*/ _interop_require_default(require("degit"));
|
22
|
-
const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
|
23
|
-
const _fsextra = /*#__PURE__*/ _interop_require_default(require("fs-extra"));
|
24
|
-
const _nodeurl = require("node:url");
|
25
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
26
|
-
const _log = require("../utils/log.js");
|
27
|
-
const _configurepayloadconfig = require("./configure-payload-config.js");
|
28
|
-
function _interop_require_default(obj) {
|
29
|
-
return obj && obj.__esModule ? obj : {
|
30
|
-
default: obj
|
31
|
-
};
|
32
|
-
}
|
33
|
-
function _getRequireWildcardCache(nodeInterop) {
|
34
|
-
if (typeof WeakMap !== "function") return null;
|
35
|
-
var cacheBabelInterop = new WeakMap();
|
36
|
-
var cacheNodeInterop = new WeakMap();
|
37
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
38
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
39
|
-
})(nodeInterop);
|
40
|
-
}
|
41
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
42
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
43
|
-
return obj;
|
44
|
-
}
|
45
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
46
|
-
return {
|
47
|
-
default: obj
|
48
|
-
};
|
49
|
-
}
|
50
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
51
|
-
if (cache && cache.has(obj)) {
|
52
|
-
return cache.get(obj);
|
53
|
-
}
|
54
|
-
var newObj = {
|
55
|
-
__proto__: null
|
56
|
-
};
|
57
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
58
|
-
for(var key in obj){
|
59
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
60
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
61
|
-
if (desc && (desc.get || desc.set)) {
|
62
|
-
Object.defineProperty(newObj, key, desc);
|
63
|
-
} else {
|
64
|
-
newObj[key] = obj[key];
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
newObj.default = obj;
|
69
|
-
if (cache) {
|
70
|
-
cache.set(obj, newObj);
|
71
|
-
}
|
72
|
-
return newObj;
|
73
|
-
}
|
74
|
-
const filename = (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
75
|
-
const dirname = _path.default.dirname(filename);
|
1
|
+
import * as p from '@clack/prompts';
|
2
|
+
import chalk from 'chalk';
|
3
|
+
import degit from 'degit';
|
4
|
+
import execa from 'execa';
|
5
|
+
import fse from 'fs-extra';
|
6
|
+
import { fileURLToPath } from 'node:url';
|
7
|
+
import path from 'path';
|
8
|
+
import { debug, error, warning } from '../utils/log.js';
|
9
|
+
import { configurePayloadConfig } from './configure-payload-config.js';
|
10
|
+
const filename = fileURLToPath(import.meta.url);
|
11
|
+
const dirname = path.dirname(filename);
|
76
12
|
async function createOrFindProjectDir(projectDir) {
|
77
|
-
const pathExists = await
|
13
|
+
const pathExists = await fse.pathExists(projectDir);
|
78
14
|
if (!pathExists) {
|
79
|
-
await
|
15
|
+
await fse.mkdir(projectDir);
|
80
16
|
}
|
81
17
|
}
|
82
18
|
async function installDeps(args) {
|
@@ -91,52 +27,52 @@ async function installDeps(args) {
|
|
91
27
|
installCmd = 'pnpm install';
|
92
28
|
}
|
93
29
|
try {
|
94
|
-
await
|
95
|
-
cwd:
|
30
|
+
await execa.command(installCmd, {
|
31
|
+
cwd: path.resolve(projectDir)
|
96
32
|
});
|
97
33
|
return true;
|
98
34
|
} catch (err) {
|
99
|
-
|
35
|
+
error(`Error installing dependencies${err instanceof Error ? `: ${err.message}` : ''}.`);
|
100
36
|
return false;
|
101
37
|
}
|
102
38
|
}
|
103
|
-
async function createProject(args) {
|
39
|
+
export async function createProject(args) {
|
104
40
|
const { cliArgs, dbDetails, packageManager, projectDir, projectName, template } = args;
|
105
41
|
if (cliArgs['--dry-run']) {
|
106
|
-
|
42
|
+
debug(`Dry run: Creating project in ${chalk.green(projectDir)}`);
|
107
43
|
return;
|
108
44
|
}
|
109
45
|
await createOrFindProjectDir(projectDir);
|
110
46
|
if (cliArgs['--local-template']) {
|
111
47
|
// Copy template from local path. For development purposes.
|
112
|
-
const localTemplate =
|
113
|
-
await
|
48
|
+
const localTemplate = path.resolve(dirname, '../../../../templates/', cliArgs['--local-template']);
|
49
|
+
await fse.copy(localTemplate, projectDir);
|
114
50
|
} else if ('url' in template) {
|
115
51
|
let templateUrl = template.url;
|
116
52
|
if (cliArgs['--template-branch']) {
|
117
53
|
templateUrl = `${template.url}#${cliArgs['--template-branch']}`;
|
118
|
-
|
54
|
+
debug(`Using template url: ${templateUrl}`);
|
119
55
|
}
|
120
|
-
const emitter = (
|
56
|
+
const emitter = degit(templateUrl);
|
121
57
|
await emitter.clone(projectDir);
|
122
58
|
}
|
123
|
-
const spinner =
|
59
|
+
const spinner = p.spinner();
|
124
60
|
spinner.start('Checking latest Payload version...');
|
125
61
|
await updatePackageJSON({
|
126
62
|
projectDir,
|
127
63
|
projectName
|
128
64
|
});
|
129
65
|
spinner.message('Configuring Payload...');
|
130
|
-
await
|
66
|
+
await configurePayloadConfig({
|
131
67
|
dbDetails,
|
132
68
|
projectDirOrConfigPath: {
|
133
69
|
projectDir
|
134
70
|
}
|
135
71
|
});
|
136
72
|
// Remove yarn.lock file. This is only desired in Payload Cloud.
|
137
|
-
const lockPath =
|
138
|
-
if (
|
139
|
-
await
|
73
|
+
const lockPath = path.resolve(projectDir, 'yarn.lock');
|
74
|
+
if (fse.existsSync(lockPath)) {
|
75
|
+
await fse.remove(lockPath);
|
140
76
|
}
|
141
77
|
if (!cliArgs['--no-deps']) {
|
142
78
|
spinner.message('Installing dependencies...');
|
@@ -154,17 +90,17 @@ async function createProject(args) {
|
|
154
90
|
spinner.stop('Dependency installation skipped');
|
155
91
|
}
|
156
92
|
}
|
157
|
-
async function updatePackageJSON(args) {
|
93
|
+
export async function updatePackageJSON(args) {
|
158
94
|
const { projectDir, projectName } = args;
|
159
|
-
const packageJsonPath =
|
95
|
+
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
160
96
|
try {
|
161
|
-
const packageObj = await
|
97
|
+
const packageObj = await fse.readJson(packageJsonPath);
|
162
98
|
packageObj.name = projectName;
|
163
|
-
await
|
99
|
+
await fse.writeJson(packageJsonPath, packageObj, {
|
164
100
|
spaces: 2
|
165
101
|
});
|
166
102
|
} catch (err) {
|
167
|
-
|
103
|
+
warning(`Unable to update name in package.json. ${err instanceof Error ? err.message : ''}`);
|
168
104
|
}
|
169
105
|
}
|
170
106
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport degit from 'degit'\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 { debug, error, warning } from '../utils/log.js'\nimport { configurePayloadConfig } from './configure-payload-config.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 }\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 let templateUrl = template.url\n if (cliArgs['--template-branch']) {\n templateUrl = `${template.url}#${cliArgs['--template-branch']}`\n debug(`Using template url: ${templateUrl}`)\n }\n const emitter = degit(templateUrl)\n await emitter.clone(projectDir)\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({ dbDetails, projectDirOrConfigPath: { projectDir } })\n\n // Remove yarn.lock file. This is only desired in Payload Cloud.\n const lockPath = path.resolve(projectDir, 'yarn.lock')\n if (fse.existsSync(lockPath)) {\n await fse.remove(lockPath)\n }\n\n if (!cliArgs['--no-deps']) {\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\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":["
|
1
|
+
{"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport degit from 'degit'\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 { debug, error, warning } from '../utils/log.js'\nimport { configurePayloadConfig } from './configure-payload-config.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 }\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 let templateUrl = template.url\n if (cliArgs['--template-branch']) {\n templateUrl = `${template.url}#${cliArgs['--template-branch']}`\n debug(`Using template url: ${templateUrl}`)\n }\n const emitter = degit(templateUrl)\n await emitter.clone(projectDir)\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({ dbDetails, projectDirOrConfigPath: { projectDir } })\n\n // Remove yarn.lock file. This is only desired in Payload Cloud.\n const lockPath = path.resolve(projectDir, 'yarn.lock')\n if (fse.existsSync(lockPath)) {\n await fse.remove(lockPath)\n }\n\n if (!cliArgs['--no-deps']) {\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\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","degit","execa","fse","fileURLToPath","path","debug","error","warning","configurePayloadConfig","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","templateUrl","emitter","clone","spinner","start","updatePackageJSON","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,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAIvB,SAASC,KAAK,EAAEC,KAAK,EAAEC,OAAO,QAAQ,kBAAiB;AACvD,SAASC,sBAAsB,QAAQ,gCAA+B;AAEtE,MAAMC,WAAWN,cAAc,YAAYO,GAAG;AAC9C,MAAMC,UAAUP,KAAKO,OAAO,CAACF;AAE7B,eAAeG,uBAAuBC,UAAkB;IACtD,MAAMC,aAAa,MAAMZ,IAAIY,UAAU,CAACD;IACxC,IAAI,CAACC,YAAY;QACf,MAAMZ,IAAIa,KAAK,CAACF;IAClB;AACF;AAEA,eAAeG,YAAYC,IAI1B;IACC,MAAM,EAAEC,OAAO,EAAEC,cAAc,EAAEN,UAAU,EAAE,GAAGI;IAChD,IAAIC,OAAO,CAAC,YAAY,EAAE;QACxB,OAAO;IACT;IACA,IAAIE,aAAa;IAEjB,IAAID,mBAAmB,QAAQ;QAC7BC,aAAa;IACf,OAAO,IAAID,mBAAmB,QAAQ;QACpCC,aAAa;IACf;IAEA,IAAI;QACF,MAAMnB,MAAMoB,OAAO,CAACD,YAAY;YAC9BE,KAAKlB,KAAKmB,OAAO,CAACV;QACpB;QACA,OAAO;IACT,EAAE,OAAOW,KAAc;QACrBlB,MAAM,CAAC,6BAA6B,EAAEkB,eAAeC,QAAQ,CAAC,EAAE,EAAED,IAAIE,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QACvF,OAAO;IACT;AACF;AAEA,OAAO,eAAeC,cAAcV,IAOnC;IACC,MAAM,EAAEC,OAAO,EAAEU,SAAS,EAAET,cAAc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,CAAC;QACf,OAAO;YACLR,QAAQQ,IAAI,CAAC,iCAAiC;QAChD;IACF,OAAO;QACLR,QAAQQ,IAAI,CAAC;IACf;AACF;AAEA,OAAO,eAAeN,kBAAkBtB,IAGvC;IACC,MAAM,EAAEJ,UAAU,EAAEgB,WAAW,EAAE,GAAGZ;IACpC,MAAM6B,kBAAkB1C,KAAKmB,OAAO,CAACV,YAAY;IACjD,IAAI;QACF,MAAMkC,aAAa,MAAM7C,IAAI8C,QAAQ,CAACF;QACtCC,WAAWE,IAAI,GAAGpB;QAClB,MAAM3B,IAAIgD,SAAS,CAACJ,iBAAiBC,YAAY;YAAEI,QAAQ;QAAE;IAC/D,EAAE,OAAO3B,KAAc;QACrBjB,QAAQ,CAAC,uCAAuC,EAAEiB,eAAeC,QAAQD,IAAIE,OAAO,GAAG,GAAG,CAAC;IAC7F;AACF"}
|
@@ -1,36 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
11
|
-
const _globby = /*#__PURE__*/ _interop_require_default(require("globby"));
|
12
|
-
function _interop_require_default(obj) {
|
13
|
-
return obj && obj.__esModule ? obj : {
|
14
|
-
default: obj
|
15
|
-
};
|
16
|
-
}
|
17
|
-
const filename = (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
18
|
-
const dirname = _path.default.dirname(filename);
|
19
|
-
const projectDir = _path.default.resolve(dirname, './tmp');
|
1
|
+
import fse from 'fs-extra';
|
2
|
+
import path from 'path';
|
3
|
+
import { createProject } from './create-project.js';
|
4
|
+
import { fileURLToPath } from 'node:url';
|
5
|
+
import { dbReplacements } from './packages.js';
|
6
|
+
import { getValidTemplates } from './templates.js';
|
7
|
+
import globby from 'globby';
|
8
|
+
const filename = fileURLToPath(import.meta.url);
|
9
|
+
const dirname = path.dirname(filename);
|
10
|
+
const projectDir = path.resolve(dirname, './tmp');
|
20
11
|
describe('createProject', ()=>{
|
21
12
|
beforeAll(()=>{
|
22
13
|
console.log = jest.fn();
|
23
14
|
});
|
24
15
|
beforeEach(()=>{
|
25
|
-
if (
|
26
|
-
|
16
|
+
if (fse.existsSync(projectDir)) {
|
17
|
+
fse.rmdirSync(projectDir, {
|
27
18
|
recursive: true
|
28
19
|
});
|
29
20
|
}
|
30
21
|
});
|
31
22
|
afterEach(()=>{
|
32
|
-
if (
|
33
|
-
|
23
|
+
if (fse.existsSync(projectDir)) {
|
24
|
+
fse.rmSync(projectDir, {
|
34
25
|
recursive: true
|
35
26
|
});
|
36
27
|
}
|
@@ -54,20 +45,20 @@ describe('createProject', ()=>{
|
|
54
45
|
url: 'https://github.com/payloadcms/payload-plugin-template',
|
55
46
|
description: 'Template for creating a Payload plugin'
|
56
47
|
};
|
57
|
-
await
|
48
|
+
await createProject({
|
58
49
|
cliArgs: args,
|
59
50
|
projectName,
|
60
51
|
projectDir,
|
61
52
|
template,
|
62
53
|
packageManager
|
63
54
|
});
|
64
|
-
const packageJsonPath =
|
65
|
-
const packageJson =
|
55
|
+
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
56
|
+
const packageJson = fse.readJsonSync(packageJsonPath);
|
66
57
|
// Check package name and description
|
67
58
|
expect(packageJson.name).toEqual(projectName);
|
68
59
|
});
|
69
60
|
describe('creates project from template', ()=>{
|
70
|
-
const templates =
|
61
|
+
const templates = getValidTemplates();
|
71
62
|
it.each([
|
72
63
|
[
|
73
64
|
'blank-3.0',
|
@@ -85,7 +76,7 @@ describe('createProject', ()=>{
|
|
85
76
|
'--db': db,
|
86
77
|
'--local-template': templateName
|
87
78
|
};
|
88
|
-
await
|
79
|
+
await createProject({
|
89
80
|
cliArgs,
|
90
81
|
projectName,
|
91
82
|
projectDir,
|
@@ -96,19 +87,19 @@ describe('createProject', ()=>{
|
|
96
87
|
type: db
|
97
88
|
}
|
98
89
|
});
|
99
|
-
const dbReplacement =
|
100
|
-
const packageJsonPath =
|
101
|
-
const packageJson =
|
90
|
+
const dbReplacement = dbReplacements[db];
|
91
|
+
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
92
|
+
const packageJson = fse.readJsonSync(packageJsonPath);
|
102
93
|
// Should only have one db adapter
|
103
94
|
expect(Object.keys(packageJson.dependencies).filter((n)=>n.startsWith('@payloadcms/db-'))).toHaveLength(1);
|
104
|
-
const payloadConfigPath = (await (
|
95
|
+
const payloadConfigPath = (await globby('**/payload.config.ts', {
|
105
96
|
absolute: true,
|
106
97
|
cwd: projectDir
|
107
98
|
}))?.[0];
|
108
99
|
if (!payloadConfigPath) {
|
109
100
|
throw new Error(`Could not find payload.config.ts inside ${projectDir}`);
|
110
101
|
}
|
111
|
-
const content =
|
102
|
+
const content = fse.readFileSync(payloadConfigPath, 'utf-8');
|
112
103
|
// Check payload.config.ts
|
113
104
|
expect(content).not.toContain('// database-adapter-import');
|
114
105
|
expect(content).toContain(dbReplacement.importReplacement);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport path from 'path'\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\nimport { createProject } from './create-project.js'\nimport { fileURLToPath } from 'node:url'\nimport { dbReplacements } from './packages.js'\nimport { getValidTemplates } from './templates.js'\nimport globby from 'globby'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nconst projectDir = path.resolve(dirname, './tmp')\ndescribe('createProject', () => {\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmdirSync(projectDir, { recursive: true })\n }\n })\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\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 url: 'https://github.com/payloadcms/payload-plugin-template',\n description: 'Template for creating a Payload plugin',\n }\n await createProject({\n cliArgs: args,\n projectName,\n projectDir,\n template,\n packageManager,\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).toEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank-3.0', 'mongodb'],\n ['blank-3.0', '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 projectName,\n projectDir,\n template: template as ProjectTemplate,\n packageManager,\n dbDetails: {\n dbUri: `${db}://localhost:27017/create-project-test`,\n type: db as DbType,\n },\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 // 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 if (!payloadConfigPath) {\n throw new Error(`Could not find payload.config.ts inside ${projectDir}`)\n }\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":["
|
1
|
+
{"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport path from 'path'\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\nimport { createProject } from './create-project.js'\nimport { fileURLToPath } from 'node:url'\nimport { dbReplacements } from './packages.js'\nimport { getValidTemplates } from './templates.js'\nimport globby from 'globby'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nconst projectDir = path.resolve(dirname, './tmp')\ndescribe('createProject', () => {\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmdirSync(projectDir, { recursive: true })\n }\n })\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\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 url: 'https://github.com/payloadcms/payload-plugin-template',\n description: 'Template for creating a Payload plugin',\n }\n await createProject({\n cliArgs: args,\n projectName,\n projectDir,\n template,\n packageManager,\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).toEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank-3.0', 'mongodb'],\n ['blank-3.0', '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 projectName,\n projectDir,\n template: template as ProjectTemplate,\n packageManager,\n dbDetails: {\n dbUri: `${db}://localhost:27017/create-project-test`,\n type: db as DbType,\n },\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 // 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 if (!payloadConfigPath) {\n throw new Error(`Could not find payload.config.ts inside ${projectDir}`)\n }\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":["fse","path","createProject","fileURLToPath","dbReplacements","getValidTemplates","globby","filename","url","dirname","projectDir","resolve","describe","beforeAll","console","log","jest","fn","beforeEach","existsSync","rmdirSync","recursive","afterEach","rmSync","args","_","packageManager","it","projectName","template","name","type","description","cliArgs","packageJsonPath","packageJson","readJsonSync","expect","toEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","Error","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,UAAU,OAAM;AAEvB,SAAS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1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "generateSecret", {
|
6
|
-
enumerable: true,
|
7
|
-
get: function() {
|
8
|
-
return generateSecret;
|
9
|
-
}
|
10
|
-
});
|
11
|
-
const _crypto = require("crypto");
|
12
|
-
function generateSecret() {
|
13
|
-
return (0, _crypto.randomBytes)(32).toString('hex').slice(0, 24);
|
1
|
+
import { randomBytes } from 'crypto';
|
2
|
+
export function generateSecret() {
|
3
|
+
return randomBytes(32).toString('hex').slice(0, 24);
|
14
4
|
}
|
15
5
|
|
16
6
|
//# sourceMappingURL=generate-secret.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/generate-secret.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\n\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n"],"names":["
|
1
|
+
{"version":3,"sources":["../../src/lib/generate-secret.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\n\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n"],"names":["randomBytes","generateSecret","toString","slice"],"mappings":"AAAA,SAASA,WAAW,QAAQ,SAAQ;AAEpC,OAAO,SAASC;IACd,OAAOD,YAAY,IAAIE,QAAQ,CAAC,OAAOC,KAAK,CAAC,GAAG;AAClD"}
|