@strapi/strapi 5.0.0-beta.0 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +5 -0
- package/dist/admin.js.map +1 -1
- package/dist/admin.mjs +4 -0
- package/dist/admin.mjs.map +1 -1
- package/dist/cli/commands/admin/create-user.js +2 -2
- package/dist/cli/commands/admin/create-user.js.map +1 -1
- package/dist/cli/commands/admin/create-user.mjs +88 -0
- package/dist/cli/commands/admin/create-user.mjs.map +1 -0
- package/dist/cli/commands/admin/reset-user-password.js +2 -2
- package/dist/cli/commands/admin/reset-user-password.js.map +1 -1
- package/dist/cli/commands/admin/reset-user-password.mjs +44 -0
- package/dist/cli/commands/admin/reset-user-password.mjs.map +1 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/build.mjs +30 -0
- package/dist/cli/commands/build.mjs.map +1 -0
- package/dist/cli/commands/components/list.js +2 -2
- package/dist/cli/commands/components/list.js.map +1 -1
- package/dist/cli/commands/components/list.mjs +24 -0
- package/dist/cli/commands/components/list.mjs.map +1 -0
- package/dist/cli/commands/configuration/dump.js +2 -2
- package/dist/cli/commands/configuration/dump.js.map +1 -1
- package/dist/cli/commands/configuration/dump.mjs +41 -0
- package/dist/cli/commands/configuration/dump.mjs.map +1 -0
- package/dist/cli/commands/configuration/restore.js +2 -2
- package/dist/cli/commands/configuration/restore.js.map +1 -1
- package/dist/cli/commands/configuration/restore.mjs +140 -0
- package/dist/cli/commands/configuration/restore.mjs.map +1 -0
- package/dist/cli/commands/console.js +2 -2
- package/dist/cli/commands/console.js.map +1 -1
- package/dist/cli/commands/console.mjs +27 -0
- package/dist/cli/commands/console.mjs.map +1 -0
- package/dist/cli/commands/content-types/list.js +2 -2
- package/dist/cli/commands/content-types/list.js.map +1 -1
- package/dist/cli/commands/content-types/list.mjs +24 -0
- package/dist/cli/commands/content-types/list.mjs.map +1 -0
- package/dist/cli/commands/controllers/list.js +2 -2
- package/dist/cli/commands/controllers/list.js.map +1 -1
- package/dist/cli/commands/controllers/list.mjs +24 -0
- package/dist/cli/commands/controllers/list.mjs.map +1 -0
- package/dist/cli/commands/develop.js.map +1 -1
- package/dist/cli/commands/develop.mjs +27 -0
- package/dist/cli/commands/develop.mjs.map +1 -0
- package/dist/cli/commands/export/action.js.map +1 -1
- package/dist/cli/commands/export/action.mjs +116 -0
- package/dist/cli/commands/export/action.mjs.map +1 -0
- package/dist/cli/commands/export/command.mjs +24 -0
- package/dist/cli/commands/export/command.mjs.map +1 -0
- package/dist/cli/commands/generate.mjs +13 -0
- package/dist/cli/commands/generate.mjs.map +1 -0
- package/dist/cli/commands/hooks/list.js +2 -2
- package/dist/cli/commands/hooks/list.js.map +1 -1
- package/dist/cli/commands/hooks/list.mjs +24 -0
- package/dist/cli/commands/hooks/list.mjs.map +1 -0
- package/dist/cli/commands/import/action.js.map +1 -1
- package/dist/cli/commands/import/action.mjs +105 -0
- package/dist/cli/commands/import/action.mjs.map +1 -0
- package/dist/cli/commands/import/command.mjs +68 -0
- package/dist/cli/commands/import/command.mjs.map +1 -0
- package/dist/cli/commands/index.mjs +71 -0
- package/dist/cli/commands/index.mjs.map +1 -0
- package/dist/cli/commands/middlewares/list.js +2 -2
- package/dist/cli/commands/middlewares/list.js.map +1 -1
- package/dist/cli/commands/middlewares/list.mjs +24 -0
- package/dist/cli/commands/middlewares/list.mjs.map +1 -0
- package/dist/cli/commands/plugin/build.mjs +85 -0
- package/dist/cli/commands/plugin/build.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/action.d.ts +1 -2
- package/dist/cli/commands/plugin/init/action.d.ts.map +1 -1
- package/dist/cli/commands/plugin/init/action.js +1 -1
- package/dist/cli/commands/plugin/init/action.js.map +1 -1
- package/dist/cli/commands/plugin/init/action.mjs +409 -0
- package/dist/cli/commands/plugin/init/action.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/command.mjs +10 -0
- package/dist/cli/commands/plugin/init/command.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/admin.mjs +283 -0
- package/dist/cli/commands/plugin/init/files/admin.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/editorConfig.mjs +26 -0
- package/dist/cli/commands/plugin/init/files/editorConfig.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/eslint.mjs +11 -0
- package/dist/cli/commands/plugin/init/files/eslint.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/gitIgnore.mjs +34 -0
- package/dist/cli/commands/plugin/init/files/gitIgnore.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/prettier.mjs +25 -0
- package/dist/cli/commands/plugin/init/files/prettier.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/server.js +15 -15
- package/dist/cli/commands/plugin/init/files/server.js.map +1 -1
- package/dist/cli/commands/plugin/init/files/server.mjs +360 -0
- package/dist/cli/commands/plugin/init/files/server.mjs.map +1 -0
- package/dist/cli/commands/plugin/init/files/typescript.mjs +66 -0
- package/dist/cli/commands/plugin/init/files/typescript.mjs.map +1 -0
- package/dist/cli/commands/plugin/link-watch.mjs +82 -0
- package/dist/cli/commands/plugin/link-watch.mjs.map +1 -0
- package/dist/cli/commands/plugin/verify.js.map +1 -1
- package/dist/cli/commands/plugin/verify.mjs +34 -0
- package/dist/cli/commands/plugin/verify.mjs.map +1 -0
- package/dist/cli/commands/plugin/watch.js.map +1 -1
- package/dist/cli/commands/plugin/watch.mjs +83 -0
- package/dist/cli/commands/plugin/watch.mjs.map +1 -0
- package/dist/cli/commands/policies/list.js +2 -2
- package/dist/cli/commands/policies/list.js.map +1 -1
- package/dist/cli/commands/policies/list.mjs +24 -0
- package/dist/cli/commands/policies/list.mjs.map +1 -0
- package/dist/cli/commands/report.js +2 -2
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/report.mjs +35 -0
- package/dist/cli/commands/report.mjs.map +1 -0
- package/dist/cli/commands/routes/list.js +2 -2
- package/dist/cli/commands/routes/list.js.map +1 -1
- package/dist/cli/commands/routes/list.mjs +28 -0
- package/dist/cli/commands/routes/list.mjs.map +1 -0
- package/dist/cli/commands/services/list.js +2 -2
- package/dist/cli/commands/services/list.js.map +1 -1
- package/dist/cli/commands/services/list.mjs +24 -0
- package/dist/cli/commands/services/list.mjs.map +1 -0
- package/dist/cli/commands/start.js +1 -1
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/start.mjs +24 -0
- package/dist/cli/commands/start.mjs.map +1 -0
- package/dist/cli/commands/telemetry/disable.mjs +67 -0
- package/dist/cli/commands/telemetry/disable.mjs.map +1 -0
- package/dist/cli/commands/telemetry/enable.mjs +86 -0
- package/dist/cli/commands/telemetry/enable.mjs.map +1 -0
- package/dist/cli/commands/templates/generate.mjs +74 -0
- package/dist/cli/commands/templates/generate.mjs.map +1 -0
- package/dist/cli/commands/transfer/action.mjs +131 -0
- package/dist/cli/commands/transfer/action.mjs.map +1 -0
- package/dist/cli/commands/transfer/command.mjs +84 -0
- package/dist/cli/commands/transfer/command.mjs.map +1 -0
- package/dist/cli/commands/ts/generate-types.js +2 -2
- package/dist/cli/commands/ts/generate-types.js.map +1 -1
- package/dist/cli/commands/ts/generate-types.mjs +35 -0
- package/dist/cli/commands/ts/generate-types.mjs.map +1 -0
- package/dist/cli/commands/version.mjs +13 -0
- package/dist/cli/commands/version.mjs.map +1 -0
- package/dist/cli/index.mjs +49 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli/utils/commander.mjs +109 -0
- package/dist/cli/utils/commander.mjs.map +1 -0
- package/dist/cli/utils/data-transfer.d.ts +3 -3
- package/dist/cli/utils/data-transfer.d.ts.map +1 -1
- package/dist/cli/utils/data-transfer.js +2 -2
- package/dist/cli/utils/data-transfer.js.map +1 -1
- package/dist/cli/utils/data-transfer.mjs +339 -0
- package/dist/cli/utils/data-transfer.mjs.map +1 -0
- package/dist/cli/utils/helpers.mjs +100 -0
- package/dist/cli/utils/helpers.mjs.map +1 -0
- package/dist/cli/utils/logger.mjs +80 -0
- package/dist/cli/utils/logger.mjs.map +1 -0
- package/dist/cli/utils/pkg.d.ts.map +1 -1
- package/dist/cli/utils/pkg.js +18 -15
- package/dist/cli/utils/pkg.js.map +1 -1
- package/dist/cli/utils/pkg.mjs +87 -0
- package/dist/cli/utils/pkg.mjs.map +1 -0
- package/dist/cli/utils/telemetry.mjs +22 -0
- package/dist/cli/utils/telemetry.mjs.map +1 -0
- package/dist/cli/utils/tsconfig.mjs +23 -0
- package/dist/cli/utils/tsconfig.mjs.map +1 -0
- package/dist/node/build.mjs +58 -0
- package/dist/node/build.mjs.map +1 -0
- package/dist/node/core/admin-customisations.mjs +22 -0
- package/dist/node/core/admin-customisations.mjs.map +1 -0
- package/dist/node/core/aliases.d.ts.map +1 -1
- package/dist/node/core/aliases.js +3 -1
- package/dist/node/core/aliases.js.map +1 -1
- package/dist/node/core/aliases.mjs +30 -0
- package/dist/node/core/aliases.mjs.map +1 -0
- package/dist/node/core/config.mjs +16 -0
- package/dist/node/core/config.mjs.map +1 -0
- package/dist/node/core/dependencies.mjs +151 -0
- package/dist/node/core/dependencies.mjs.map +1 -0
- package/dist/node/core/env.d.ts.map +1 -1
- package/dist/node/core/env.js +7 -4
- package/dist/node/core/env.js.map +1 -1
- package/dist/node/core/env.mjs +23 -0
- package/dist/node/core/env.mjs.map +1 -0
- package/dist/node/core/errors.mjs +29 -0
- package/dist/node/core/errors.mjs.map +1 -0
- package/dist/node/core/files.mjs +43 -0
- package/dist/node/core/files.mjs.map +1 -0
- package/dist/node/core/managers.mjs +17 -0
- package/dist/node/core/managers.mjs.map +1 -0
- package/dist/node/core/monorepo.mjs +20 -0
- package/dist/node/core/monorepo.mjs.map +1 -0
- package/dist/node/core/plugins.mjs +93 -0
- package/dist/node/core/plugins.mjs.map +1 -0
- package/dist/node/core/timer.mjs +27 -0
- package/dist/node/core/timer.mjs.map +1 -0
- package/dist/node/create-build-context.d.ts +3 -3
- package/dist/node/create-build-context.d.ts.map +1 -1
- package/dist/node/create-build-context.js +1 -1
- package/dist/node/create-build-context.js.map +1 -1
- package/dist/node/create-build-context.mjs +91 -0
- package/dist/node/create-build-context.mjs.map +1 -0
- package/dist/node/develop.d.ts.map +1 -1
- package/dist/node/develop.js +7 -1
- package/dist/node/develop.js.map +1 -1
- package/dist/node/develop.mjs +252 -0
- package/dist/node/develop.mjs.map +1 -0
- package/dist/node/staticFiles.d.ts.map +1 -1
- package/dist/node/staticFiles.js +25 -3
- package/dist/node/staticFiles.js.map +1 -1
- package/dist/node/staticFiles.mjs +76 -0
- package/dist/node/staticFiles.mjs.map +1 -0
- package/dist/node/types.d.ts +2 -2
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/vite/build.mjs +12 -0
- package/dist/node/vite/build.mjs.map +1 -0
- package/dist/node/vite/config.mjs +99 -0
- package/dist/node/vite/config.mjs.map +1 -0
- package/dist/node/vite/plugins.mjs +43 -0
- package/dist/node/vite/plugins.mjs.map +1 -0
- package/dist/node/vite/watch.js.map +1 -1
- package/dist/node/vite/watch.mjs +52 -0
- package/dist/node/vite/watch.mjs.map +1 -0
- package/dist/node/webpack/build.mjs +39 -0
- package/dist/node/webpack/build.mjs.map +1 -0
- package/dist/node/webpack/config.mjs +228 -0
- package/dist/node/webpack/config.mjs.map +1 -0
- package/dist/node/webpack/watch.js.map +1 -1
- package/dist/node/webpack/watch.mjs +92 -0
- package/dist/node/webpack/watch.mjs.map +1 -0
- package/package.json +27 -25
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createCommand } from "commander";
|
|
2
|
+
import { resolve, join, basename } from "path";
|
|
3
|
+
import fse from "fs-extra";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import { runAction } from "../../utils/helpers.mjs";
|
|
7
|
+
const TEMPLATE_CONTENT = ["src", "data"];
|
|
8
|
+
async function copyContent(templatePath, rootBase) {
|
|
9
|
+
for (const item of TEMPLATE_CONTENT) {
|
|
10
|
+
try {
|
|
11
|
+
const pathToCopy = join(process.cwd(), item);
|
|
12
|
+
if (!await fse.pathExists(pathToCopy)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
await fse.copy(pathToCopy, join(templatePath, item));
|
|
16
|
+
const currentProjectBase = basename(process.cwd());
|
|
17
|
+
console.log(
|
|
18
|
+
`${chalk.green(
|
|
19
|
+
"success"
|
|
20
|
+
)}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`
|
|
21
|
+
);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
console.error(`${chalk.red("error")}: ${error.message}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function writeTemplateJson(rootPath) {
|
|
30
|
+
try {
|
|
31
|
+
await fse.writeJSON(join(rootPath, "template.json"), {});
|
|
32
|
+
console.log(`${chalk.green("success")}: create JSON config file`);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof Error) {
|
|
35
|
+
console.error(`${chalk.red("error")}: ${error.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function templateConfigExists(rootPath) {
|
|
40
|
+
const configExists = await fse.pathExists(join(rootPath, "template.json"));
|
|
41
|
+
console.log(`checking: ${join(rootPath, "template.json")}. result ${configExists}`);
|
|
42
|
+
return configExists;
|
|
43
|
+
}
|
|
44
|
+
const action = async function generateTemplate(directory) {
|
|
45
|
+
const rootPath = resolve(directory);
|
|
46
|
+
const templatePath = join(rootPath, "template");
|
|
47
|
+
const exists = await fse.pathExists(templatePath);
|
|
48
|
+
const rootBase = basename(rootPath);
|
|
49
|
+
if (exists) {
|
|
50
|
+
const inquiry = await inquirer.prompt({
|
|
51
|
+
type: "confirm",
|
|
52
|
+
name: "confirm",
|
|
53
|
+
message: `${chalk.yellow(rootBase)} already exists. Do you want to replace it?`
|
|
54
|
+
});
|
|
55
|
+
if (!inquiry.confirm) {
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await fse.ensureDir(templatePath);
|
|
60
|
+
await copyContent(templatePath, rootBase);
|
|
61
|
+
const configExists = await templateConfigExists(rootPath);
|
|
62
|
+
if (!configExists) {
|
|
63
|
+
await writeTemplateJson(rootPath);
|
|
64
|
+
}
|
|
65
|
+
console.log(`${chalk.green("success")}: generated template at ${chalk.yellow(rootPath)}`);
|
|
66
|
+
};
|
|
67
|
+
const command = () => {
|
|
68
|
+
return createCommand("templates:generate <directory>").description("Generate template from Strapi project").action(runAction("templates:generate", action));
|
|
69
|
+
};
|
|
70
|
+
export {
|
|
71
|
+
action,
|
|
72
|
+
command
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=generate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.mjs","sources":["../../../../src/cli/commands/templates/generate.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport { resolve, join, basename } from 'path';\nimport fse from 'fs-extra';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\n\nimport type { StrapiCommand } from '../../types';\nimport { runAction } from '../../utils/helpers';\n\n// All directories that a template could need\nconst TEMPLATE_CONTENT = ['src', 'data'];\n\nasync function copyContent(templatePath: string, rootBase: string) {\n for (const item of TEMPLATE_CONTENT) {\n try {\n const pathToCopy = join(process.cwd(), item);\n\n if (!(await fse.pathExists(pathToCopy))) {\n continue;\n }\n\n await fse.copy(pathToCopy, join(templatePath, item));\n const currentProjectBase = basename(process.cwd());\n console.log(\n `${chalk.green(\n 'success'\n )}: copy ${currentProjectBase}/${item} => ${rootBase}/template/${item}`\n );\n } catch (error) {\n if (error instanceof Error) {\n console.error(`${chalk.red('error')}: ${error.message}`);\n }\n }\n }\n}\n\n/**\n *\n * @param {string} rootPath Absolute path to the root directory\n */\nasync function writeTemplateJson(rootPath: string) {\n try {\n await fse.writeJSON(join(rootPath, 'template.json'), {});\n console.log(`${chalk.green('success')}: create JSON config file`);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`${chalk.red('error')}: ${error.message}`);\n }\n }\n}\n\n/**\n *\n * @param {string} rootPath Absolute path to the root directory\n * @returns boolean\n */\nasync function templateConfigExists(rootPath: string) {\n const configExists = await fse.pathExists(join(rootPath, 'template.json'));\n console.log(`checking: ${join(rootPath, 'template.json')}. result ${configExists}`);\n return configExists;\n}\n\nconst action = async function generateTemplate(directory: string) {\n const rootPath = resolve(directory);\n\n // Get path to template directory: <rootPath>/template\n const templatePath = join(rootPath, 'template');\n\n // Check if the template directory exists\n const exists = await fse.pathExists(templatePath);\n const rootBase = basename(rootPath);\n\n if (exists) {\n // Confirm the user wants to replace the existing template\n const inquiry = await inquirer.prompt({\n type: 'confirm',\n name: 'confirm',\n message: `${chalk.yellow(rootBase)} already exists. Do you want to replace it?`,\n });\n\n if (!inquiry.confirm) {\n process.exit(0);\n }\n }\n\n // Create or replace root directory with <roothPath>/template\n await fse.ensureDir(templatePath);\n // Copy content to /template\n await copyContent(templatePath, rootBase);\n // Create config file if it doesn't exist\n const configExists = await templateConfigExists(rootPath);\n if (!configExists) {\n await writeTemplateJson(rootPath);\n }\n\n console.log(`${chalk.green('success')}: generated template at ${chalk.yellow(rootPath)}`);\n};\n\n/**\n *`$ strapi templates:generate <directory>`\n */\nconst command: StrapiCommand = () => {\n return createCommand('templates:generate <directory>')\n .description('Generate template from Strapi project')\n .action(runAction('templates:generate', action));\n};\n\nexport { action, command };\n"],"names":[],"mappings":";;;;;;AAUA,MAAM,mBAAmB,CAAC,OAAO,MAAM;AAEvC,eAAe,YAAY,cAAsB,UAAkB;AACjE,aAAW,QAAQ,kBAAkB;AAC/B,QAAA;AACF,YAAM,aAAa,KAAK,QAAQ,OAAO,IAAI;AAE3C,UAAI,CAAE,MAAM,IAAI,WAAW,UAAU,GAAI;AACvC;AAAA,MACF;AAEA,YAAM,IAAI,KAAK,YAAY,KAAK,cAAc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EACF;AAGM,QAAA,IAAI,UAAU,YAAY;AAE1B,QAAA,YAAY,cAAc,QAAQ;AAElC,QAAA,eAAe,MAAM,qBAAqB,QAAQ;AACxD,MAAI,CAAC,cAAc;AACjB,UAAM,kBAAkB,QAAQ;AAAA,EAClC;AAEQ,UAAA,IAAI,GAAG,MAAM,MAAM,SAAS,CAAC,2BAA2B,MAAM,OAAO,QAAQ,CAAC,EAAE;AAC1F;AAKA,MAAM,UAAyB,MAAM;AAC5B,SAAA,cAAc,gCAAgC,EAClD,YAAY,uCAAuC,EACnD,OAAO,UAAU,sBAAsB,MAAM,CAAC;AACnD;"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isObject } from "lodash/fp";
|
|
2
|
+
import { engine, strapi } from "@strapi/data-transfer";
|
|
3
|
+
import { createStrapiInstance, parseRestoreFromOptions, DEFAULT_IGNORED_CONTENT_TYPES, formatDiagnostic, getDiffHandler, getAssetsBackupHandler, getTransferTelemetryPayload, abortTransfer, setSignalHandler, buildTransferTable, exitMessageText, loadersFactory } from "../../utils/data-transfer.mjs";
|
|
4
|
+
import { exitWith } from "../../utils/helpers.mjs";
|
|
5
|
+
const { createTransferEngine } = engine;
|
|
6
|
+
const {
|
|
7
|
+
providers: {
|
|
8
|
+
createRemoteStrapiDestinationProvider,
|
|
9
|
+
createLocalStrapiSourceProvider,
|
|
10
|
+
createLocalStrapiDestinationProvider,
|
|
11
|
+
createRemoteStrapiSourceProvider
|
|
12
|
+
}
|
|
13
|
+
} = strapi;
|
|
14
|
+
const action = async (opts) => {
|
|
15
|
+
if (!isObject(opts)) {
|
|
16
|
+
exitWith(1, "Could not parse command arguments");
|
|
17
|
+
}
|
|
18
|
+
if (!(opts.from || opts.to) || opts.from && opts.to) {
|
|
19
|
+
exitWith(1, "Exactly one source (from) or destination (to) option must be provided");
|
|
20
|
+
}
|
|
21
|
+
const strapi2 = await createStrapiInstance();
|
|
22
|
+
let source;
|
|
23
|
+
let destination;
|
|
24
|
+
if (!opts.from) {
|
|
25
|
+
source = createLocalStrapiSourceProvider({
|
|
26
|
+
getStrapi: () => strapi2
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
if (!opts.fromToken) {
|
|
30
|
+
exitWith(1, "Missing token for remote destination");
|
|
31
|
+
}
|
|
32
|
+
source = createRemoteStrapiSourceProvider({
|
|
33
|
+
getStrapi: () => strapi2,
|
|
34
|
+
url: opts.from,
|
|
35
|
+
auth: {
|
|
36
|
+
type: "token",
|
|
37
|
+
token: opts.fromToken
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (!opts.to) {
|
|
42
|
+
destination = createLocalStrapiDestinationProvider({
|
|
43
|
+
getStrapi: () => strapi2,
|
|
44
|
+
strategy: "restore",
|
|
45
|
+
restore: parseRestoreFromOptions(opts)
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
if (!opts.toToken) {
|
|
49
|
+
exitWith(1, "Missing token for remote destination");
|
|
50
|
+
}
|
|
51
|
+
destination = createRemoteStrapiDestinationProvider({
|
|
52
|
+
url: opts.to,
|
|
53
|
+
auth: {
|
|
54
|
+
type: "token",
|
|
55
|
+
token: opts.toToken
|
|
56
|
+
},
|
|
57
|
+
strategy: "restore",
|
|
58
|
+
restore: parseRestoreFromOptions(opts)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!source || !destination) {
|
|
62
|
+
exitWith(1, "Could not create providers");
|
|
63
|
+
}
|
|
64
|
+
const engine2 = createTransferEngine(source, destination, {
|
|
65
|
+
versionStrategy: "exact",
|
|
66
|
+
schemaStrategy: "strict",
|
|
67
|
+
exclude: opts.exclude,
|
|
68
|
+
only: opts.only,
|
|
69
|
+
throttle: opts.throttle,
|
|
70
|
+
transforms: {
|
|
71
|
+
links: [
|
|
72
|
+
{
|
|
73
|
+
filter(link) {
|
|
74
|
+
return !DEFAULT_IGNORED_CONTENT_TYPES.includes(link.left.type) && !DEFAULT_IGNORED_CONTENT_TYPES.includes(link.right.type);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
entities: [
|
|
79
|
+
{
|
|
80
|
+
filter(entity) {
|
|
81
|
+
return !DEFAULT_IGNORED_CONTENT_TYPES.includes(entity.type);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
engine2.diagnostics.onDiagnostic(formatDiagnostic("transfer"));
|
|
88
|
+
const progress = engine2.progress.stream;
|
|
89
|
+
const { updateLoader } = loadersFactory();
|
|
90
|
+
engine2.onSchemaDiff(getDiffHandler(engine2, { force: opts.force, action: "transfer" }));
|
|
91
|
+
engine2.addErrorHandler(
|
|
92
|
+
"ASSETS_DIRECTORY_ERR",
|
|
93
|
+
getAssetsBackupHandler(engine2, { force: opts.force, action: "transfer" })
|
|
94
|
+
);
|
|
95
|
+
progress.on(`stage::start`, ({ stage, data }) => {
|
|
96
|
+
updateLoader(stage, data).start();
|
|
97
|
+
});
|
|
98
|
+
progress.on("stage::finish", ({ stage, data }) => {
|
|
99
|
+
updateLoader(stage, data).succeed();
|
|
100
|
+
});
|
|
101
|
+
progress.on("stage::progress", ({ stage, data }) => {
|
|
102
|
+
updateLoader(stage, data);
|
|
103
|
+
});
|
|
104
|
+
progress.on("stage::error", ({ stage, data }) => {
|
|
105
|
+
updateLoader(stage, data).fail();
|
|
106
|
+
});
|
|
107
|
+
progress.on("transfer::start", async () => {
|
|
108
|
+
console.log(`Starting transfer...`);
|
|
109
|
+
await strapi2.telemetry.send("didDEITSProcessStart", getTransferTelemetryPayload(engine2));
|
|
110
|
+
});
|
|
111
|
+
let results;
|
|
112
|
+
try {
|
|
113
|
+
setSignalHandler(() => abortTransfer({ engine: engine2, strapi: strapi2 }));
|
|
114
|
+
results = await engine2.transfer();
|
|
115
|
+
await strapi2.telemetry.send("didDEITSProcessFinish", getTransferTelemetryPayload(engine2));
|
|
116
|
+
try {
|
|
117
|
+
const table = buildTransferTable(results.engine);
|
|
118
|
+
console.log(table?.toString());
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error("There was an error displaying the results of the transfer.");
|
|
121
|
+
}
|
|
122
|
+
exitWith(0, exitMessageText("transfer"));
|
|
123
|
+
} catch (e) {
|
|
124
|
+
await strapi2.telemetry.send("didDEITSProcessFail", getTransferTelemetryPayload(engine2));
|
|
125
|
+
exitWith(1, exitMessageText("transfer", true));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
action as default
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=action.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.mjs","sources":["../../../../src/cli/commands/transfer/action.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { engine as engineDataTransfer, strapi as strapiDataTransfer } from '@strapi/data-transfer';\n\nimport {\n buildTransferTable,\n createStrapiInstance,\n DEFAULT_IGNORED_CONTENT_TYPES,\n formatDiagnostic,\n loadersFactory,\n exitMessageText,\n abortTransfer,\n getTransferTelemetryPayload,\n setSignalHandler,\n getDiffHandler,\n getAssetsBackupHandler,\n parseRestoreFromOptions,\n} from '../../utils/data-transfer';\nimport { exitWith } from '../../utils/helpers';\n\nconst { createTransferEngine } = engineDataTransfer;\nconst {\n providers: {\n createRemoteStrapiDestinationProvider,\n createLocalStrapiSourceProvider,\n createLocalStrapiDestinationProvider,\n createRemoteStrapiSourceProvider,\n },\n} = strapiDataTransfer;\n\ninterface CmdOptions {\n from?: URL;\n fromToken: string;\n to: URL;\n toToken: string;\n only?: (keyof engineDataTransfer.TransferGroupFilter)[];\n exclude?: (keyof engineDataTransfer.TransferGroupFilter)[];\n throttle?: number;\n force?: boolean;\n}\n/**\n * Transfer command.\n *\n * Transfers data between local Strapi and remote Strapi instances\n */\nexport default async (opts: CmdOptions) => {\n // Validate inputs from Commander\n if (!isObject(opts)) {\n exitWith(1, 'Could not parse command arguments');\n }\n\n if (!(opts.from || opts.to) || (opts.from && opts.to)) {\n exitWith(1, 'Exactly one source (from) or destination (to) option must be provided');\n }\n\n const strapi = await createStrapiInstance();\n let source;\n let destination;\n\n // if no URL provided, use local Strapi\n if (!opts.from) {\n source = createLocalStrapiSourceProvider({\n getStrapi: () => strapi,\n });\n }\n // if URL provided, set up a remote source provider\n else {\n if (!opts.fromToken) {\n exitWith(1, 'Missing token for remote destination');\n }\n\n source = createRemoteStrapiSourceProvider({\n getStrapi: () => strapi,\n url: opts.from,\n auth: {\n type: 'token',\n token: opts.fromToken,\n },\n });\n }\n\n // if no URL provided, use local Strapi\n if (!opts.to) {\n destination = createLocalStrapiDestinationProvider({\n getStrapi: () => strapi,\n strategy: 'restore',\n restore: parseRestoreFromOptions(opts),\n });\n }\n // if URL provided, set up a remote destination provider\n else {\n if (!opts.toToken) {\n exitWith(1, 'Missing token for remote destination');\n }\n\n destination = createRemoteStrapiDestinationProvider({\n url: opts.to,\n auth: {\n type: 'token',\n token: opts.toToken,\n },\n strategy: 'restore',\n restore: parseRestoreFromOptions(opts),\n });\n }\n\n if (!source || !destination) {\n exitWith(1, 'Could not create providers');\n }\n\n const engine = createTransferEngine(source, destination, {\n versionStrategy: 'exact',\n schemaStrategy: 'strict',\n exclude: opts.exclude,\n only: opts.only,\n throttle: opts.throttle,\n transforms: {\n links: [\n {\n filter(link) {\n return (\n !DEFAULT_IGNORED_CONTENT_TYPES.includes(link.left.type) &&\n !DEFAULT_IGNORED_CONTENT_TYPES.includes(link.right.type)\n );\n },\n },\n ],\n entities: [\n {\n filter(entity) {\n return !DEFAULT_IGNORED_CONTENT_TYPES.includes(entity.type);\n },\n },\n ],\n },\n });\n\n engine.diagnostics.onDiagnostic(formatDiagnostic('transfer'));\n\n const progress = engine.progress.stream;\n\n const { updateLoader } = loadersFactory();\n\n engine.onSchemaDiff(getDiffHandler(engine, { force: opts.force, action: 'transfer' }));\n\n engine.addErrorHandler(\n 'ASSETS_DIRECTORY_ERR',\n getAssetsBackupHandler(engine, { force: opts.force, action: 'transfer' })\n );\n\n progress.on(`stage::start`, ({ stage, data }) => {\n updateLoader(stage, data).start();\n });\n\n progress.on('stage::finish', ({ stage, data }) => {\n updateLoader(stage, data).succeed();\n });\n\n progress.on('stage::progress', ({ stage, data }) => {\n updateLoader(stage, data);\n });\n\n progress.on('stage::error', ({ stage, data }) => {\n updateLoader(stage, data).fail();\n });\n\n progress.on('transfer::start', async () => {\n console.log(`Starting transfer...`);\n\n await strapi.telemetry.send('didDEITSProcessStart', getTransferTelemetryPayload(engine));\n });\n\n let results: Awaited<ReturnType<typeof engine.transfer>>;\n try {\n // Abort transfer if user interrupts process\n setSignalHandler(() => abortTransfer({ engine, strapi }));\n\n results = await engine.transfer();\n\n // Note: we need to await telemetry or else the process ends before it is sent\n await strapi.telemetry.send('didDEITSProcessFinish', getTransferTelemetryPayload(engine));\n\n try {\n const table = buildTransferTable(results.engine);\n console.log(table?.toString());\n } catch (e) {\n console.error('There was an error displaying the results of the transfer.');\n }\n\n exitWith(0, exitMessageText('transfer'));\n } catch (e) {\n await strapi.telemetry.send('didDEITSProcessFail', getTransferTelemetryPayload(engine));\n exitWith(1, exitMessageText('transfer', true));\n }\n};\n"],"names":["engineDataTransfer","strapiDataTransfer","strapi","engine"],"mappings":";;;;AAmBA,MAAM,EAAE,qBAAyB,IAAAA;AACjC,MAAM;AAAA,EACJ,WAAW;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,IAAIC;AAiBJ,MAAe,SAAA,OAAO,SAAqB;AAErC,MAAA,CAAC,SAAS,IAAI,GAAG;AACnB,aAAS,GAAG,mCAAmC;AAAA,EACjD;AAEI,MAAA,EAAE,KAAK,QAAQ,KAAK,OAAQ,KAAK,QAAQ,KAAK,IAAK;AACrD,aAAS,GAAG,uEAAuE;AAAA,EACrF;AAEM,QAAAC,UAAS,MAAM;AACjB,MAAA;AACA,MAAA;AAGA,MAAA,CAAC,KAAK,MAAM;AACd,aAAS,g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AAQ,MAAM,4DAA4D;AAAA,IAC5E;AAES,aAAA,GAAG,gBAAgB,UAAU,CAAC;AAAA,WAChC,GAAG;AACV,UAAMD,QAAO,UAAU,KAAK,uBAAuB,4BAA4BC,OAAM,CAAC;AACtF,aAAS,GAAG,gBAAgB,YAAY,IAAI,CAAC;AAAA,EAC/C;AACF;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { createCommand, Option } from "commander";
|
|
3
|
+
import { parseURL, forceOption, getCommanderConfirmMessage } from "../../utils/commander.mjs";
|
|
4
|
+
import { ifOptions, exitWith, assertUrlHasProtocol } from "../../utils/helpers.mjs";
|
|
5
|
+
import { excludeOption, onlyOption, throttleOption, validateExcludeOnly } from "../../utils/data-transfer.mjs";
|
|
6
|
+
import action from "./action.mjs";
|
|
7
|
+
const command = () => {
|
|
8
|
+
return createCommand("transfer").description("Transfer data from one source to another").allowExcessArguments(false).addOption(
|
|
9
|
+
new Option(
|
|
10
|
+
"--from <sourceURL>",
|
|
11
|
+
`URL of the remote Strapi instance to get data from`
|
|
12
|
+
).argParser(parseURL)
|
|
13
|
+
).addOption(new Option("--from-token <token>", `Transfer token for the remote Strapi source`)).addOption(
|
|
14
|
+
new Option(
|
|
15
|
+
"--to <destinationURL>",
|
|
16
|
+
`URL of the remote Strapi instance to send data to`
|
|
17
|
+
).argParser(parseURL)
|
|
18
|
+
).addOption(
|
|
19
|
+
new Option("--to-token <token>", `Transfer token for the remote Strapi destination`)
|
|
20
|
+
).addOption(forceOption).addOption(excludeOption).addOption(onlyOption).addOption(throttleOption).hook("preAction", validateExcludeOnly).hook(
|
|
21
|
+
"preAction",
|
|
22
|
+
ifOptions(
|
|
23
|
+
(opts) => !(opts.from || opts.to) || opts.from && opts.to,
|
|
24
|
+
async () => exitWith(
|
|
25
|
+
1,
|
|
26
|
+
"Exactly one remote source (from) or destination (to) option must be provided"
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
).hook(
|
|
30
|
+
"preAction",
|
|
31
|
+
ifOptions(
|
|
32
|
+
(opts) => opts.from,
|
|
33
|
+
async (thisCommand) => {
|
|
34
|
+
assertUrlHasProtocol(thisCommand.opts().from, ["https:", "http:"]);
|
|
35
|
+
if (!thisCommand.opts().fromToken) {
|
|
36
|
+
const answers = await inquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
type: "password",
|
|
39
|
+
message: "Please enter your transfer token for the remote Strapi source",
|
|
40
|
+
name: "fromToken"
|
|
41
|
+
}
|
|
42
|
+
]);
|
|
43
|
+
if (!answers.fromToken?.length) {
|
|
44
|
+
exitWith(1, "No token provided for remote source, aborting transfer.");
|
|
45
|
+
}
|
|
46
|
+
thisCommand.opts().fromToken = answers.fromToken;
|
|
47
|
+
}
|
|
48
|
+
await getCommanderConfirmMessage(
|
|
49
|
+
"The transfer will delete all the local Strapi assets and its database. Are you sure you want to proceed?",
|
|
50
|
+
{ failMessage: "Transfer process aborted" }
|
|
51
|
+
)(thisCommand);
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
).hook(
|
|
55
|
+
"preAction",
|
|
56
|
+
ifOptions(
|
|
57
|
+
(opts) => opts.to,
|
|
58
|
+
async (thisCommand) => {
|
|
59
|
+
assertUrlHasProtocol(thisCommand.opts().to, ["https:", "http:"]);
|
|
60
|
+
if (!thisCommand.opts().toToken) {
|
|
61
|
+
const answers = await inquirer.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: "password",
|
|
64
|
+
message: "Please enter your transfer token for the remote Strapi destination",
|
|
65
|
+
name: "toToken"
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
if (!answers.toToken?.length) {
|
|
69
|
+
exitWith(1, "No token provided for remote destination, aborting transfer.");
|
|
70
|
+
}
|
|
71
|
+
thisCommand.opts().toToken = answers.toToken;
|
|
72
|
+
}
|
|
73
|
+
await getCommanderConfirmMessage(
|
|
74
|
+
"The transfer will delete existing data from the remote Strapi! Are you sure you want to proceed?",
|
|
75
|
+
{ failMessage: "Transfer process aborted" }
|
|
76
|
+
)(thisCommand);
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
).action(action);
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
command as default
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=command.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.mjs","sources":["../../../../src/cli/commands/transfer/command.ts"],"sourcesContent":["import inquirer from 'inquirer';\nimport { createCommand, Option } from 'commander';\nimport { getCommanderConfirmMessage, forceOption, parseURL } from '../../utils/commander';\nimport { exitWith, assertUrlHasProtocol, ifOptions } from '../../utils/helpers';\nimport {\n excludeOption,\n onlyOption,\n throttleOption,\n validateExcludeOnly,\n} from '../../utils/data-transfer';\n\nimport action from './action';\n\n/**\n * `$ strapi transfer`\n */\nconst command = () => {\n return (\n createCommand('transfer')\n .description('Transfer data from one source to another')\n .allowExcessArguments(false)\n .addOption(\n new Option(\n '--from <sourceURL>',\n `URL of the remote Strapi instance to get data from`\n ).argParser(parseURL)\n )\n .addOption(new Option('--from-token <token>', `Transfer token for the remote Strapi source`))\n .addOption(\n new Option(\n '--to <destinationURL>',\n `URL of the remote Strapi instance to send data to`\n ).argParser(parseURL)\n )\n .addOption(\n new Option('--to-token <token>', `Transfer token for the remote Strapi destination`)\n )\n .addOption(forceOption)\n .addOption(excludeOption)\n .addOption(onlyOption)\n .addOption(throttleOption)\n .hook('preAction', validateExcludeOnly)\n .hook(\n 'preAction',\n ifOptions(\n (opts) => !(opts.from || opts.to) || (opts.from && opts.to),\n async () =>\n exitWith(\n 1,\n 'Exactly one remote source (from) or destination (to) option must be provided'\n )\n )\n )\n // If --from is used, validate the URL and token\n .hook(\n 'preAction',\n ifOptions(\n (opts) => opts.from,\n async (thisCommand) => {\n assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:']);\n if (!thisCommand.opts().fromToken) {\n const answers = await inquirer.prompt([\n {\n type: 'password',\n message: 'Please enter your transfer token for the remote Strapi source',\n name: 'fromToken',\n },\n ]);\n if (!answers.fromToken?.length) {\n exitWith(1, 'No token provided for remote source, aborting transfer.');\n }\n thisCommand.opts().fromToken = answers.fromToken;\n }\n\n await getCommanderConfirmMessage(\n 'The transfer will delete all the local Strapi assets and its database. Are you sure you want to proceed?',\n { failMessage: 'Transfer process aborted' }\n )(thisCommand);\n }\n )\n )\n // If --to is used, validate the URL, token, and confirm restore\n .hook(\n 'preAction',\n ifOptions(\n (opts) => opts.to,\n async (thisCommand) => {\n assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:']);\n if (!thisCommand.opts().toToken) {\n const answers = await inquirer.prompt([\n {\n type: 'password',\n message: 'Please enter your transfer token for the remote Strapi destination',\n name: 'toToken',\n },\n ]);\n if (!answers.toToken?.length) {\n exitWith(1, 'No token provided for remote destination, aborting transfer.');\n }\n thisCommand.opts().toToken = answers.toToken;\n }\n\n await getCommanderConfirmMessage(\n 'The transfer will delete existing data from the remote Strapi! Are you sure you want to proceed?',\n { failMessage: 'Transfer process aborted' }\n )(thisCommand);\n }\n )\n )\n .action(action)\n );\n};\n\nexport default command;\n"],"names":[],"mappings":";;;;;;AAgBA,MAAM,UAAU,MAAM;AAElB,SAAA,cAAc,UAAU,EACrB,YAAY,0CAA0C,EACtD,qBAAqB,KAAK,EAC1B;AAAA,IACC,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IAAA,EACA,UAAU,QAAQ;AAAA,EAAA,EAErB,UAAU,IAAI,OAAO,wBAAwB,6CAA6C,CAAC,EAC3F;AAAA,IACC,IAAI;AAAA,MACF;AAAA,MACA;AAAA,IAAA,EACA,UAAU,QAAQ;AAAA,EAAA,EAErB;AAAA,IACC,IAAI,OAAO,sBAAsB,kDAAkD;AAAA,EAAA,EAEpF,UAAU,WAAW,EACrB,UAAU,aAAa,EACvB,UAAU,UAAU,EACpB,UAAU,cAAc,EACxB,KAAK,aAAa,mBAAmB,EACrC;AAAA,IACC;AA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MACf;AAAA,IACF;AAAA,EAAA,EAED,OAAO,MAAM;AAEpB;"}
|
|
@@ -11,8 +11,8 @@ const action = async ({ debug, silent, verbose, outDir }) => {
|
|
|
11
11
|
console.error("Flags conflict: both silent and debug mode are enabled, exiting...");
|
|
12
12
|
process.exit(1);
|
|
13
13
|
}
|
|
14
|
-
const appContext = await core.
|
|
15
|
-
const app = await core.
|
|
14
|
+
const appContext = await core.compileStrapi({ ignoreDiagnostics: true });
|
|
15
|
+
const app = await core.createStrapi(appContext).register();
|
|
16
16
|
await tsUtils__default.default.generators.generate({
|
|
17
17
|
strapi: app,
|
|
18
18
|
pwd: appContext.appDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-types.js","sources":["../../../../src/cli/commands/ts/generate-types.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport tsUtils from '@strapi/typescript-utils';\nimport {
|
|
1
|
+
{"version":3,"file":"generate-types.js","sources":["../../../../src/cli/commands/ts/generate-types.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport tsUtils from '@strapi/typescript-utils';\nimport { createStrapi, compileStrapi } from '@strapi/core';\n\nimport type { StrapiCommand } from '../../types';\nimport { runAction } from '../../utils/helpers';\n\ninterface CmdOptions {\n debug?: boolean;\n silent?: boolean;\n verbose?: boolean;\n outDir?: string;\n}\n\nconst action = async ({ debug, silent, verbose, outDir }: CmdOptions) => {\n if ((debug || verbose) && silent) {\n console.error('Flags conflict: both silent and debug mode are enabled, exiting...');\n process.exit(1);\n }\n\n const appContext = await compileStrapi({ ignoreDiagnostics: true });\n const app = await createStrapi(appContext).register();\n\n await tsUtils.generators.generate({\n strapi: app,\n pwd: appContext.appDir,\n rootDir: outDir ?? undefined,\n logger: {\n silent,\n // TODO V5: verbose is deprecated and should be removed\n debug: debug || verbose,\n },\n artifacts: { contentTypes: true, components: true },\n });\n\n await app.destroy();\n};\n\n/**\n * `$ strapi ts:generate-types`\n */\nconst command: StrapiCommand = () => {\n return createCommand('ts:generate-types')\n .description(`Generate TypeScript typings for your schemas`)\n .option('--verbose', `[DEPRECATED] The verbose option has been replaced by debug`, false)\n .option('-d, --debug', `Run the generation with debug messages`, false)\n .option('-s, --silent', `Run the generation silently, without any output`, false)\n .option(\n '-o, --out-dir <outDir>',\n 'Specify a relative root directory in which the definitions will be generated. Changing this value might break types exposed by Strapi that relies on generated types.'\n )\n .action(runAction('ts:generate-types', action));\n};\n\nexport { action, command };\n"],"names":["compileStrapi","createStrapi","tsUtils","createCommand","runAction"],"mappings":";;;;;;;;AAcA,MAAM,SAAS,OAAO,EAAE,OAAO,QAAQ,SAAS,aAAyB;AAClE,OAAA,SAAS,YAAY,QAAQ;AAChC,YAAQ,MAAM,oEAAoE;AAClF,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,aAAa,MAAMA,KAAA,cAAc,EAAE,mBAAmB,KAAM,CAAA;AAClE,QAAM,MAAM,MAAMC,KAAAA,aAAa,UAAU,EAAE,SAAS;AAE9C,QAAAC,iBAAA,QAAQ,WAAW,SAAS;AAAA,IAChC,QAAQ;AAAA,IACR,KAAK,WAAW;AAAA,IAChB,SAAS,UAAU;AAAA,IACnB,QAAQ;AAAA,MACN;AAAA;AAAA,MAEA,OAAO,SAAS;AAAA,IAClB;AAAA,IACA,WAAW,EAAE,cAAc,MAAM,YAAY,KAAK;AAAA,EAAA,CACnD;AAED,QAAM,IAAI;AACZ;AAKA,MAAM,UAAyB,MAAM;AAC5B,SAAAC,wBAAc,mBAAmB,EACrC,YAAY,8CAA8C,EAC1D,OAAO,aAAa,8DAA8D,KAAK,EACvF,OAAO,eAAe,0CAA0C,KAAK,EACrE,OAAO,gBAAgB,mDAAmD,KAAK,EAC/E;AAAA,IACC;AAAA,IACA;AAAA,EAED,EAAA,OAAOC,QAAU,UAAA,qBAAqB,MAAM,CAAC;AAClD;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createCommand } from "commander";
|
|
2
|
+
import tsUtils__default from "@strapi/typescript-utils";
|
|
3
|
+
import { compileStrapi, createStrapi } from "@strapi/core";
|
|
4
|
+
import { runAction } from "../../utils/helpers.mjs";
|
|
5
|
+
const action = async ({ debug, silent, verbose, outDir }) => {
|
|
6
|
+
if ((debug || verbose) && silent) {
|
|
7
|
+
console.error("Flags conflict: both silent and debug mode are enabled, exiting...");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const appContext = await compileStrapi({ ignoreDiagnostics: true });
|
|
11
|
+
const app = await createStrapi(appContext).register();
|
|
12
|
+
await tsUtils__default.generators.generate({
|
|
13
|
+
strapi: app,
|
|
14
|
+
pwd: appContext.appDir,
|
|
15
|
+
rootDir: outDir ?? void 0,
|
|
16
|
+
logger: {
|
|
17
|
+
silent,
|
|
18
|
+
// TODO V5: verbose is deprecated and should be removed
|
|
19
|
+
debug: debug || verbose
|
|
20
|
+
},
|
|
21
|
+
artifacts: { contentTypes: true, components: true }
|
|
22
|
+
});
|
|
23
|
+
await app.destroy();
|
|
24
|
+
};
|
|
25
|
+
const command = () => {
|
|
26
|
+
return createCommand("ts:generate-types").description(`Generate TypeScript typings for your schemas`).option("--verbose", `[DEPRECATED] The verbose option has been replaced by debug`, false).option("-d, --debug", `Run the generation with debug messages`, false).option("-s, --silent", `Run the generation silently, without any output`, false).option(
|
|
27
|
+
"-o, --out-dir <outDir>",
|
|
28
|
+
"Specify a relative root directory in which the definitions will be generated. Changing this value might break types exposed by Strapi that relies on generated types."
|
|
29
|
+
).action(runAction("ts:generate-types", action));
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
action,
|
|
33
|
+
command
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=generate-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types.mjs","sources":["../../../../src/cli/commands/ts/generate-types.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport tsUtils from '@strapi/typescript-utils';\nimport { createStrapi, compileStrapi } from '@strapi/core';\n\nimport type { StrapiCommand } from '../../types';\nimport { runAction } from '../../utils/helpers';\n\ninterface CmdOptions {\n debug?: boolean;\n silent?: boolean;\n verbose?: boolean;\n outDir?: string;\n}\n\nconst action = async ({ debug, silent, verbose, outDir }: CmdOptions) => {\n if ((debug || verbose) && silent) {\n console.error('Flags conflict: both silent and debug mode are enabled, exiting...');\n process.exit(1);\n }\n\n const appContext = await compileStrapi({ ignoreDiagnostics: true });\n const app = await createStrapi(appContext).register();\n\n await tsUtils.generators.generate({\n strapi: app,\n pwd: appContext.appDir,\n rootDir: outDir ?? undefined,\n logger: {\n silent,\n // TODO V5: verbose is deprecated and should be removed\n debug: debug || verbose,\n },\n artifacts: { contentTypes: true, components: true },\n });\n\n await app.destroy();\n};\n\n/**\n * `$ strapi ts:generate-types`\n */\nconst command: StrapiCommand = () => {\n return createCommand('ts:generate-types')\n .description(`Generate TypeScript typings for your schemas`)\n .option('--verbose', `[DEPRECATED] The verbose option has been replaced by debug`, false)\n .option('-d, --debug', `Run the generation with debug messages`, false)\n .option('-s, --silent', `Run the generation silently, without any output`, false)\n .option(\n '-o, --out-dir <outDir>',\n 'Specify a relative root directory in which the definitions will be generated. Changing this value might break types exposed by Strapi that relies on generated types.'\n )\n .action(runAction('ts:generate-types', action));\n};\n\nexport { action, command };\n"],"names":["tsUtils"],"mappings":";;;;AAcA,MAAM,SAAS,OAAO,EAAE,OAAO,QAAQ,SAAS,aAAyB;AAClE,OAAA,SAAS,YAAY,QAAQ;AAChC,YAAQ,MAAM,oEAAoE;AAClF,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,aAAa,MAAM,cAAc,EAAE,mBAAmB,KAAM,CAAA;AAClE,QAAM,MAAM,MAAM,aAAa,UAAU,EAAE,SAAS;AAE9C,QAAAA,iBAAQ,WAAW,SAAS;AAAA,IAChC,QAAQ;AAAA,IACR,KAAK,WAAW;AAAA,IAChB,SAAS,UAAU;AAAA,IACnB,QAAQ;AAAA,MACN;AAAA;AAAA,MAEA,OAAO,SAAS;AAAA,IAClB;AAAA,IACA,WAAW,EAAE,cAAc,MAAM,YAAY,KAAK;AAAA,EAAA,CACnD;AAED,QAAM,IAAI;AACZ;AAKA,MAAM,UAAyB,MAAM;AAC5B,SAAA,cAAc,mBAAmB,EACrC,YAAY,8CAA8C,EAC1D,OAAO,aAAa,8DAA8D,KAAK,EACvF,OAAO,eAAe,0CAA0C,KAAK,EACrE,OAAO,gBAAgB,mDAAmD,KAAK,EAC/E;AAAA,IACC;AAAA,IACA;AAAA,EAED,EAAA,OAAO,UAAU,qBAAqB,MAAM,CAAC;AAClD;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createCommand } from "commander";
|
|
2
|
+
const command = () => {
|
|
3
|
+
return createCommand("version").description("Output the version of Strapi").action(() => {
|
|
4
|
+
const { version } = require("../../../package.json");
|
|
5
|
+
process.stdout.write(`${version}
|
|
6
|
+
`);
|
|
7
|
+
process.exit(0);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
command
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=version.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.mjs","sources":["../../../src/cli/commands/version.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport type { StrapiCommand } from '../types';\n\n/**\n * `$ strapi version`\n */\n\nconst command: StrapiCommand = () => {\n // load the Strapi package.json to get version and other information\n return createCommand('version')\n .description('Output the version of Strapi')\n .action(() => {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const { version } = require('../../../package.json');\n\n process.stdout.write(`${version}\\n`);\n process.exit(0);\n });\n};\n\nexport { command };\n"],"names":[],"mappings":";AAOA,MAAM,UAAyB,MAAM;AAEnC,SAAO,cAAc,SAAS,EAC3B,YAAY,8BAA8B,EAC1C,OAAO,MAAM;AAEZ,UAAM,EAAE,QAAA,IAAY,QAAQ,uBAAuB;AAE3C,YAAA,OAAO,MAAM,GAAG,OAAO;AAAA,CAAI;AACnC,YAAQ,KAAK,CAAC;AAAA,EAAA,CACf;AACL;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { commands } from "./commands/index.mjs";
|
|
3
|
+
import { createLogger } from "./utils/logger.mjs";
|
|
4
|
+
import { loadTsConfig } from "./utils/tsconfig.mjs";
|
|
5
|
+
const createCLI = async (argv, command = new Command()) => {
|
|
6
|
+
command.storeOptionsAsProperties(false).allowUnknownOption(true);
|
|
7
|
+
command.helpOption("-h, --help", "Display help for command");
|
|
8
|
+
command.addHelpCommand("help [command]", "Display help for command");
|
|
9
|
+
command.version(
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
11
|
+
require("../../package.json").version,
|
|
12
|
+
"-v, --version",
|
|
13
|
+
"Output the version number"
|
|
14
|
+
);
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const hasDebug = argv.includes("--debug");
|
|
17
|
+
const hasSilent = argv.includes("--silent");
|
|
18
|
+
const logger = createLogger({ debug: hasDebug, silent: hasSilent, timestamp: false });
|
|
19
|
+
const tsconfig = loadTsConfig({
|
|
20
|
+
cwd,
|
|
21
|
+
path: "tsconfig.json",
|
|
22
|
+
logger
|
|
23
|
+
});
|
|
24
|
+
const ctx = {
|
|
25
|
+
cwd,
|
|
26
|
+
logger,
|
|
27
|
+
tsconfig
|
|
28
|
+
};
|
|
29
|
+
commands.forEach((commandFactory) => {
|
|
30
|
+
try {
|
|
31
|
+
const subCommand = commandFactory({ command, argv, ctx });
|
|
32
|
+
if (subCommand) {
|
|
33
|
+
command.addCommand(subCommand);
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error(`Failed to load command`, e);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return command;
|
|
40
|
+
};
|
|
41
|
+
const runCLI = async (argv = process.argv, command = new Command()) => {
|
|
42
|
+
const commands2 = await createCLI(argv, command);
|
|
43
|
+
await commands2.parseAsync(argv);
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
createCLI,
|
|
47
|
+
runCLI
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/cli/index.ts"],"sourcesContent":["import { Command } from 'commander';\n\nimport { commands as strapiCommands } from './commands';\n\nimport { createLogger } from './utils/logger';\nimport { loadTsConfig } from './utils/tsconfig';\nimport { CLIContext } from './types';\n\nconst createCLI = async (argv: string[], command = new Command()) => {\n // Initial program setup\n command.storeOptionsAsProperties(false).allowUnknownOption(true);\n\n // Help command\n command.helpOption('-h, --help', 'Display help for command');\n command.addHelpCommand('help [command]', 'Display help for command');\n\n command.version(\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('../../package.json').version,\n '-v, --version',\n 'Output the version number'\n );\n\n const cwd = process.cwd();\n\n const hasDebug = argv.includes('--debug');\n const hasSilent = argv.includes('--silent');\n\n const logger = createLogger({ debug: hasDebug, silent: hasSilent, timestamp: false });\n\n const tsconfig = loadTsConfig({\n cwd,\n path: 'tsconfig.json',\n logger,\n });\n\n const ctx = {\n cwd,\n logger,\n tsconfig,\n } satisfies CLIContext;\n\n // Load all commands\n strapiCommands.forEach((commandFactory) => {\n try {\n const subCommand = commandFactory({ command, argv, ctx });\n\n // Add this command to the Commander command object\n if (subCommand) {\n command.addCommand(subCommand);\n }\n } catch (e) {\n console.error(`Failed to load command`, e);\n }\n });\n\n return command;\n};\n\nconst runCLI = async (argv = process.argv, command = new Command()) => {\n const commands = await createCLI(argv, command);\n await commands.parseAsync(argv);\n};\n\nexport { runCLI, createCLI };\n"],"names":["strapiCommands","commands"],"mappings":";;;;AAQA,MAAM,YAAY,OAAO,MAAgB,UAAU,IAAI,cAAc;AAEnE,UAAQ,yBAAyB,KAAK,EAAE,mBAAmB,IAAI;AAGvD,UAAA,WAAW,cAAc,0BAA0B;AACnD,UAAA,eAAe,kBAAkB,0BAA0B;AAE3D,UAAA;AAAA;AAAA,IAEN,QAAQ,oBAAoB,EAAE;AAAA,IAC9B;AAAA,IACA;AAAA,EAAA;AAGI,QAAA,MAAM,QAAQ;AAEd,QAAA,WAAW,KAAK,SAAS,SAAS;AAClC,QAAA,YAAY,KAAK,SAAS,UAAU;AAEpC,QAAA,SAAS,aAAa,EAAE,OAAO,UAAU,QAAQ,WAAW,WAAW,MAAA,CAAO;AAEpF,QAAM,WAAW,aAAa;AAAA,IAC5B;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EAAA,CACD;AAED,QAAM,MAAM;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAIaA,WAAA,QAAQ,CAAC,mBAAmB;AACrC,QAAA;AACF,YAAM,aAAa,eAAe,EAAE,SAAS,MAAM,KAAK;AAGxD,UAAI,YAAY;AACd,gBAAQ,WAAW,UAAU;AAAA,MAC/B;AAAA,aACO,GAAG;AACF,cAAA,MAAM,0BAA0B,CAAC;AAAA,IAC3C;AAAA,EAAA,CACD;AAEM,SAAA;AACT;AAEM,MAAA,SAAS,OAAO,OAAO,QAAQ,MAAM,UAAU,IAAI,cAAc;AACrE,QAAMC,YAAW,MAAM,UAAU,MAAM,OAAO;AACxC,QAAAA,UAAS,WAAW,IAAI;AAChC;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { Option, InvalidOptionArgumentError } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { isNaN } from "lodash/fp";
|
|
5
|
+
import { exitWith } from "./helpers.mjs";
|
|
6
|
+
const parseList = (value) => {
|
|
7
|
+
try {
|
|
8
|
+
return value.split(",").map((item) => item.trim());
|
|
9
|
+
} catch (e) {
|
|
10
|
+
exitWith(1, `Unrecognized input: ${value}`);
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
};
|
|
14
|
+
const getParseListWithChoices = (choices, errorMessage = "Invalid options:") => {
|
|
15
|
+
return (value) => {
|
|
16
|
+
const list = parseList(value);
|
|
17
|
+
const invalid = list.filter((item) => {
|
|
18
|
+
return !choices.includes(item);
|
|
19
|
+
});
|
|
20
|
+
if (invalid.length > 0) {
|
|
21
|
+
exitWith(1, `${errorMessage}: ${invalid.join(",")}`);
|
|
22
|
+
}
|
|
23
|
+
return list;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const parseInteger = (value) => {
|
|
27
|
+
const parsedValue = parseInt(value, 10);
|
|
28
|
+
if (isNaN(parsedValue)) {
|
|
29
|
+
throw new InvalidOptionArgumentError(`Not an integer: ${value}`);
|
|
30
|
+
}
|
|
31
|
+
return parsedValue;
|
|
32
|
+
};
|
|
33
|
+
const parseURL = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(value);
|
|
36
|
+
if (!url.host) {
|
|
37
|
+
throw new InvalidOptionArgumentError(`Could not parse url ${value}`);
|
|
38
|
+
}
|
|
39
|
+
return url;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new InvalidOptionArgumentError(`Could not parse url ${value}`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const promptEncryptionKey = async (thisCommand) => {
|
|
45
|
+
const opts = thisCommand.opts();
|
|
46
|
+
if (!opts.encrypt && opts.key) {
|
|
47
|
+
return exitWith(1, "Key may not be present unless encryption is used");
|
|
48
|
+
}
|
|
49
|
+
if (opts.encrypt && !(opts.key && opts.key.length > 0)) {
|
|
50
|
+
try {
|
|
51
|
+
const answers = await inquirer.prompt([
|
|
52
|
+
{
|
|
53
|
+
type: "password",
|
|
54
|
+
message: "Please enter an encryption key",
|
|
55
|
+
name: "key",
|
|
56
|
+
validate(key) {
|
|
57
|
+
if (key.length > 0)
|
|
58
|
+
return true;
|
|
59
|
+
return "Key must be present when using the encrypt option";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
opts.key = answers.key;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return exitWith(1, "Failed to get encryption key");
|
|
66
|
+
}
|
|
67
|
+
if (!opts.key) {
|
|
68
|
+
return exitWith(1, "Failed to get encryption key");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const getCommanderConfirmMessage = (message, { failMessage } = {}) => {
|
|
73
|
+
return async (command) => {
|
|
74
|
+
const confirmed = await confirmMessage(message, { force: command.opts().force });
|
|
75
|
+
if (!confirmed) {
|
|
76
|
+
exitWith(1, failMessage);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const confirmMessage = async (message, { force } = {}) => {
|
|
81
|
+
if (force === true) {
|
|
82
|
+
console.log(`${chalk.green("?")} ${chalk.bold(message)} ${chalk.cyan("Yes")}`);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const answers = await inquirer.prompt([
|
|
86
|
+
{
|
|
87
|
+
type: "confirm",
|
|
88
|
+
message,
|
|
89
|
+
name: `confirm`,
|
|
90
|
+
default: false
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
return answers.confirm;
|
|
94
|
+
};
|
|
95
|
+
const forceOption = new Option(
|
|
96
|
+
"--force",
|
|
97
|
+
`Automatically answer "yes" to all prompts, including potentially destructive requests, and run non-interactively.`
|
|
98
|
+
);
|
|
99
|
+
export {
|
|
100
|
+
confirmMessage,
|
|
101
|
+
forceOption,
|
|
102
|
+
getCommanderConfirmMessage,
|
|
103
|
+
getParseListWithChoices,
|
|
104
|
+
parseInteger,
|
|
105
|
+
parseList,
|
|
106
|
+
parseURL,
|
|
107
|
+
promptEncryptionKey
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=commander.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commander.mjs","sources":["../../../src/cli/utils/commander.ts"],"sourcesContent":["/**\n * This file includes hooks to use for commander.hook and argParsers for commander.argParser\n */\n\nimport inquirer from 'inquirer';\nimport { Command, InvalidOptionArgumentError, Option } from 'commander';\nimport chalk from 'chalk';\nimport { isNaN } from 'lodash/fp';\nimport { exitWith } from './helpers';\n\n/**\n * argParser: Parse a comma-delimited string as an array\n */\nconst parseList = (value: string) => {\n try {\n return value.split(',').map((item) => item.trim()); // trim shouldn't be necessary but might help catch unexpected whitespace characters\n } catch (e) {\n exitWith(1, `Unrecognized input: ${value}`);\n }\n\n return [];\n};\n\n/**\n * Returns an argParser that returns a list\n */\nconst getParseListWithChoices = (choices: string[], errorMessage = 'Invalid options:') => {\n return (value: string) => {\n const list = parseList(value);\n const invalid = list.filter((item) => {\n return !choices.includes(item);\n });\n\n if (invalid.length > 0) {\n exitWith(1, `${errorMessage}: ${invalid.join(',')}`);\n }\n\n return list;\n };\n};\n\n/**\n * argParser: Parse a string as an integer\n */\nconst parseInteger = (value: string) => {\n // parseInt takes a string and a radix\n const parsedValue = parseInt(value, 10);\n if (isNaN(parsedValue)) {\n throw new InvalidOptionArgumentError(`Not an integer: ${value}`);\n }\n return parsedValue;\n};\n\n/**\n * argParser: Parse a string as a URL object\n */\nconst parseURL = (value: string) => {\n try {\n const url = new URL(value);\n if (!url.host) {\n throw new InvalidOptionArgumentError(`Could not parse url ${value}`);\n }\n\n return url;\n } catch (e) {\n throw new InvalidOptionArgumentError(`Could not parse url ${value}`);\n }\n};\n\n/**\n * hook: if encrypt==true and key not provided, prompt for it\n */\nconst promptEncryptionKey = async (thisCommand: Command) => {\n const opts = thisCommand.opts();\n\n if (!opts.encrypt && opts.key) {\n return exitWith(1, 'Key may not be present unless encryption is used');\n }\n\n // if encrypt==true but we have no key, prompt for it\n if (opts.encrypt && !(opts.key && opts.key.length > 0)) {\n try {\n const answers = await inquirer.prompt([\n {\n type: 'password',\n message: 'Please enter an encryption key',\n name: 'key',\n validate(key) {\n if (key.length > 0) return true;\n\n return 'Key must be present when using the encrypt option';\n },\n },\n ]);\n opts.key = answers.key;\n } catch (e) {\n return exitWith(1, 'Failed to get encryption key');\n }\n if (!opts.key) {\n return exitWith(1, 'Failed to get encryption key');\n }\n }\n};\n\n/**\n * hook: require a confirmation message to be accepted unless forceOption (-f,--force) is used\n */\nconst getCommanderConfirmMessage = (\n message: string,\n { failMessage }: { failMessage?: string } = {}\n) => {\n return async (command: Command) => {\n const confirmed = await confirmMessage(message, { force: command.opts().force });\n if (!confirmed) {\n exitWith(1, failMessage);\n }\n };\n};\n\nconst confirmMessage = async (message: string, { force }: { force?: boolean } = {}) => {\n // if we have a force option, respond yes\n if (force === true) {\n // attempt to mimic the inquirer prompt exactly\n console.log(`${chalk.green('?')} ${chalk.bold(message)} ${chalk.cyan('Yes')}`);\n return true;\n }\n\n const answers = await inquirer.prompt([\n {\n type: 'confirm',\n message,\n name: `confirm`,\n default: false,\n },\n ]);\n\n return answers.confirm;\n};\n\nconst forceOption = new Option(\n '--force',\n `Automatically answer \"yes\" to all prompts, including potentially destructive requests, and run non-interactively.`\n);\n\nexport {\n getParseListWithChoices,\n parseList,\n parseURL,\n parseInteger,\n promptEncryptionKey,\n getCommanderConfirmMessage,\n confirmMessage,\n forceOption,\n};\n"],"names":[],"mappings":";;;;;AAaM,MAAA,YAAY,CAAC,UAAkB;AAC/B,MAAA;AACK,WAAA,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAA,CAAM;AAAA,WAC1C,GAAG;AACD,aAAA,GAAG,uBAAuB,KAAK,EAAE;AAAA,EAC5C;AAEA,SAAO;AACT;AAKA,MAAM,0BAA0B,CAAC,SAAmB,eAAe,uBAAuB;AACxF,SAAO,CAAC,UAAkB;AAClB,UAAA,OAAO,UAAU,KAAK;AAC5B,UAAM,UAAU,KAAK,OAAO,CAAC,SAAS;AAC7B,aAAA,CAAC,QAAQ,SAAS,IAAI;AAAA,IAAA,CAC9B;AAEG,QAAA,QAAQ,SAAS,GAAG;AACb,eAAA,GAAG,GAAG,YAAY,KAAK,QAAQ,KAAK,GAAG,CAAC,EAAE;AAAA,IACrD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A,CAAO;AAC/E,QAAI,CAAC,WAAW;AACd,eAAS,GAAG,WAAW;AAAA,IACzB;AAAA,EAAA;AAEJ;AAEA,MAAM,iBAAiB,OAAO,SAAiB,EAAE,MAAM,IAAyB,CAAA,MAAO;AAErF,MAAI,UAAU,MAAM;AAElB,YAAQ,IAAI,GAAG,MAAM,MAAM,GAAG,CAAC,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM,KAAK,KAAK,CAAC,EAAE;AACtE,WAAA;AAAA,EACT;AAEM,QAAA,UAAU,MAAM,SAAS,OAAO;AAAA,IACpC;AAAA,MACE,MAAM;AAAA,MACN;AAAA,MACA,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,EAAA,CACD;AAED,SAAO,QAAQ;AACjB;AAEA,MAAM,cAAc,IAAI;AAAA,EACtB;AAAA,EACA;AACF;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Table from 'cli-table3';
|
|
2
2
|
import { Command, Option } from 'commander';
|
|
3
3
|
import ora from 'ora';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Core } from '@strapi/types';
|
|
5
5
|
import { engine as engineDataTransfer } from '@strapi/data-transfer';
|
|
6
6
|
declare const exitMessageText: (process: string, error?: boolean) => string;
|
|
7
7
|
declare const getDefaultExportName: () => string;
|
|
@@ -10,12 +10,12 @@ declare const buildTransferTable: (resultData: ResultData) => Table.Table | unde
|
|
|
10
10
|
declare const DEFAULT_IGNORED_CONTENT_TYPES: string[];
|
|
11
11
|
declare const abortTransfer: ({ engine, strapi, }: {
|
|
12
12
|
engine: engineDataTransfer.TransferEngine;
|
|
13
|
-
strapi: LoadedStrapi;
|
|
13
|
+
strapi: Core.LoadedStrapi;
|
|
14
14
|
}) => Promise<boolean>;
|
|
15
15
|
declare const setSignalHandler: (handler: (...args: unknown[]) => void, signals?: string[]) => Promise<void>;
|
|
16
16
|
declare const createStrapiInstance: (opts?: {
|
|
17
17
|
logLevel?: string;
|
|
18
|
-
}) => Promise<Strapi & Required<Strapi>>;
|
|
18
|
+
}) => Promise<Core.Strapi & Required<Core.Strapi>>;
|
|
19
19
|
declare const throttleOption: Option;
|
|
20
20
|
declare const excludeOption: Option;
|
|
21
21
|
declare const onlyOption: Option;
|