mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 22:23:10 +00:00
Merge branch 'main' into chore/docs-api-ref
This commit is contained in:
commit
0d32d3517c
@ -52,6 +52,7 @@ The Strapi core team will review your pull request and either merge it, request
|
||||
**Before submitting your pull request** make sure the following requirements are fulfilled:
|
||||
|
||||
- Fork the repository and create your new branch from `main`.
|
||||
- Run `yarn install` in the root of the repository.
|
||||
- Run `yarn setup` in the root of the repository.
|
||||
- If you've fixed a bug or added code that should be tested, please make sure to add tests
|
||||
- Ensure the following test suites are passing:
|
||||
@ -78,6 +79,7 @@ Go to the root of the repository and run the setup:
|
||||
|
||||
```bash
|
||||
cd strapi
|
||||
yarn install
|
||||
yarn setup
|
||||
|
||||
```
|
||||
@ -183,4 +185,4 @@ Before submitting an issue you need to make sure:
|
||||
- Make sure your application has a clean `node_modules` directory, meaning:
|
||||
- you didn't link any dependencies (e.g., by running `yarn link`)
|
||||
- you haven't made any inline changes to files in the `node_modules` directory
|
||||
- you don't have any global dependency loops. If you aren't sure, the easiest way to double-check any of the above is to run: `$ rm -rf node_modules && yarn cache clean && yarn setup`.
|
||||
- you don't have any global dependency loops. If you aren't sure, the easiest way to double-check any of the above is to run: `$ rm -rf node_modules && yarn cache clean && yarn install && yarn setup`.
|
||||
|
||||
@ -19,4 +19,6 @@ module.exports = ({ env }) => ({
|
||||
// This only populates relations in all content-manager endpoints
|
||||
populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', true),
|
||||
},
|
||||
// ℹ️ http_proxy is the env var used by system to set proxy globally
|
||||
globalProxy: env('http_proxy'),
|
||||
});
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
"supertest": "6.3.3",
|
||||
"ts-jest": "29.0.3",
|
||||
"typedoc": "0.23.26",
|
||||
"typescript": "4.6.2",
|
||||
"typescript": "5.0.4",
|
||||
"yargs": "17.6.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@ -95,13 +95,14 @@ const redirectWithAuth = (ctx) => {
|
||||
params: { provider },
|
||||
} = ctx;
|
||||
const redirectUrls = utils.getPrefixedRedirectUrls();
|
||||
const domain = strapi.config.get('server.admin.auth.domain');
|
||||
const { user } = ctx.state;
|
||||
|
||||
const jwt = getService('token').createJwtToken(user);
|
||||
|
||||
const isProduction = strapi.config.get('environment') === 'production';
|
||||
|
||||
const cookiesOptions = { httpOnly: false, secure: isProduction, overwrite: true };
|
||||
const cookiesOptions = { httpOnly: false, secure: isProduction, overwrite: true, domain };
|
||||
|
||||
const sanitizedUser = getService('user').sanitizeUser(user);
|
||||
strapi.eventHub.emit('admin.auth.success', { user: sanitizedUser, provider });
|
||||
|
||||
@ -133,7 +133,7 @@
|
||||
"sift": "16.0.1",
|
||||
"style-loader": "3.3.1",
|
||||
"styled-components": "5.3.3",
|
||||
"typescript": "4.6.2",
|
||||
"typescript": "5.0.4",
|
||||
"webpack": "^5.76.0",
|
||||
"webpack-cli": "^5.0.1",
|
||||
"webpack-dev-server": "^4.13.1",
|
||||
|
||||
@ -69,7 +69,7 @@
|
||||
"knex": "2.4.0",
|
||||
"koa": "2.13.4",
|
||||
"rimraf": "3.0.2",
|
||||
"typescript": "4.6.2"
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.19.1 <=18.x.x",
|
||||
|
||||
@ -152,7 +152,7 @@ const deleteRelations = async ({
|
||||
.transacting(trx)
|
||||
.execute();
|
||||
done = batchToDelete.length < batchSize;
|
||||
lastId = batchToDelete[batchToDelete.length - 1]?.id;
|
||||
lastId = batchToDelete[batchToDelete.length - 1]?.id || 0;
|
||||
|
||||
const batchIds = map(inverseJoinColumn.name, batchToDelete);
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@
|
||||
"react-test-renderer": "^17.0.2",
|
||||
"rimraf": "3.0.2",
|
||||
"styled-components": "5.3.3",
|
||||
"typescript": "4.6.2",
|
||||
"typescript": "5.0.4",
|
||||
"webpack": "^5.76.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
},
|
||||
|
||||
1
packages/core/strapi/.gitignore
vendored
1
packages/core/strapi/.gitignore
vendored
@ -90,6 +90,7 @@ pids
|
||||
logs
|
||||
results
|
||||
build
|
||||
!**/lib/commands/actions/build
|
||||
node_modules
|
||||
.node_history
|
||||
package-lock.json
|
||||
|
||||
@ -2,472 +2,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
// FIXME
|
||||
/* eslint-disable import/extensions */
|
||||
const _ = require('lodash');
|
||||
const path = require('path');
|
||||
const resolveCwd = require('resolve-cwd');
|
||||
const { yellow } = require('chalk');
|
||||
const { Command, Option } = require('commander');
|
||||
const inquirer = require('inquirer');
|
||||
const { runStrapiCommand } = require('../lib/commands');
|
||||
|
||||
const program = new Command();
|
||||
|
||||
const packageJSON = require('../package.json');
|
||||
const {
|
||||
promptEncryptionKey,
|
||||
confirmMessage,
|
||||
forceOption,
|
||||
parseURL,
|
||||
} = require('../lib/commands/utils/commander');
|
||||
const { exitWith, ifOptions, assertUrlHasProtocol } = require('../lib/commands/utils/helpers');
|
||||
const {
|
||||
excludeOption,
|
||||
onlyOption,
|
||||
throttleOption,
|
||||
validateExcludeOnly,
|
||||
} = require('../lib/commands/transfer/utils');
|
||||
|
||||
const checkCwdIsStrapiApp = (name) => {
|
||||
const logErrorAndExit = () => {
|
||||
console.log(
|
||||
`You need to run ${yellow(
|
||||
`strapi ${name}`
|
||||
)} in a Strapi project. Make sure you are in the right directory.`
|
||||
);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
try {
|
||||
const pkgJSON = require(`${process.cwd()}/package.json`);
|
||||
if (!_.has(pkgJSON, 'dependencies.@strapi/strapi')) {
|
||||
logErrorAndExit(name);
|
||||
}
|
||||
} catch (err) {
|
||||
logErrorAndExit(name);
|
||||
}
|
||||
};
|
||||
|
||||
const getLocalScript =
|
||||
(name) =>
|
||||
(...args) => {
|
||||
checkCwdIsStrapiApp(name);
|
||||
|
||||
const cmdPath = resolveCwd.silent(`@strapi/strapi/lib/commands/${name}`);
|
||||
if (!cmdPath) {
|
||||
console.log(
|
||||
`Error loading the local ${yellow(
|
||||
name
|
||||
)} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const script = require(cmdPath);
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
return script(...args);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
|
||||
// Initial program setup
|
||||
program.storeOptionsAsProperties(false).allowUnknownOption(true);
|
||||
|
||||
program.helpOption('-h, --help', 'Display help for command');
|
||||
program.addHelpCommand('help [command]', 'Display help for command');
|
||||
|
||||
// `$ strapi version` (--version synonym)
|
||||
program.version(packageJSON.version, '-v, --version', 'Output the version number');
|
||||
program
|
||||
.command('version')
|
||||
.description('Output the version of Strapi')
|
||||
.action(() => {
|
||||
process.stdout.write(`${packageJSON.version}\n`);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// `$ strapi console`
|
||||
program
|
||||
.command('console')
|
||||
.description('Open the Strapi framework console')
|
||||
.action(getLocalScript('console'));
|
||||
|
||||
// `$ strapi new`
|
||||
program
|
||||
.command('new <directory>')
|
||||
.option('--no-run', 'Do not start the application after it is created')
|
||||
.option('--use-npm', 'Force usage of npm instead of yarn to create the project')
|
||||
.option('--debug', 'Display database connection errors')
|
||||
.option('--quickstart', 'Create quickstart app')
|
||||
.option('--dbclient <dbclient>', 'Database client')
|
||||
.option('--dbhost <dbhost>', 'Database host')
|
||||
.option('--dbport <dbport>', 'Database port')
|
||||
.option('--dbname <dbname>', 'Database name')
|
||||
.option('--dbusername <dbusername>', 'Database username')
|
||||
.option('--dbpassword <dbpassword>', 'Database password')
|
||||
.option('--dbssl <dbssl>', 'Database SSL')
|
||||
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
||||
.option('--dbforce', 'Allow overwriting existing database content')
|
||||
.option('-ts, --typescript', 'Create a typescript project')
|
||||
.description('Create a new application')
|
||||
.action(require('../lib/commands/new'));
|
||||
|
||||
// `$ strapi start`
|
||||
program
|
||||
.command('start')
|
||||
.description('Start your Strapi application')
|
||||
.action(getLocalScript('start'));
|
||||
|
||||
// `$ strapi develop`
|
||||
program
|
||||
.command('develop')
|
||||
.alias('dev')
|
||||
.option('--no-build', 'Disable build')
|
||||
.option('--watch-admin', 'Enable watch', false)
|
||||
.option('--polling', 'Watch for file changes in network directories', false)
|
||||
.option('--browser <name>', 'Open the browser', true)
|
||||
.description('Start your Strapi application in development mode')
|
||||
.action(getLocalScript('develop'));
|
||||
|
||||
// $ strapi generate
|
||||
program
|
||||
.command('generate')
|
||||
.description('Launch the interactive API generator')
|
||||
.action(() => {
|
||||
checkCwdIsStrapiApp('generate');
|
||||
process.argv.splice(2, 1);
|
||||
require('@strapi/generators').runCLI();
|
||||
});
|
||||
|
||||
// `$ strapi generate:template <directory>`
|
||||
program
|
||||
.command('templates:generate <directory>')
|
||||
.description('Generate template from Strapi project')
|
||||
.action(getLocalScript('generate-template'));
|
||||
|
||||
program
|
||||
.command('build')
|
||||
.option('--no-optimization', 'Build the admin app without optimizing assets')
|
||||
.description('Build the strapi admin app')
|
||||
.action(getLocalScript('build'));
|
||||
|
||||
// `$ strapi install`
|
||||
program
|
||||
.command('install [plugins...]')
|
||||
.description('Install a Strapi plugin')
|
||||
.action(getLocalScript('install'));
|
||||
|
||||
// `$ strapi uninstall`
|
||||
program
|
||||
.command('uninstall [plugins...]')
|
||||
.description('Uninstall a Strapi plugin')
|
||||
.option('-d, --delete-files', 'Delete files', false)
|
||||
.action(getLocalScript('uninstall'));
|
||||
|
||||
// `$ strapi watch-admin`
|
||||
program
|
||||
.command('watch-admin')
|
||||
.option('--browser <name>', 'Open the browser', true)
|
||||
.description('Start the admin development server')
|
||||
.action(getLocalScript('watchAdmin'));
|
||||
|
||||
program
|
||||
.command('configuration:dump')
|
||||
.alias('config:dump')
|
||||
.description('Dump configurations of your application')
|
||||
.option('-f, --file <file>', 'Output file, default output is stdout')
|
||||
.option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)
|
||||
.action(getLocalScript('configurationDump'));
|
||||
|
||||
program
|
||||
.command('configuration:restore')
|
||||
.alias('config:restore')
|
||||
.description('Restore configurations of your application')
|
||||
.option('-f, --file <file>', 'Input file, default input is stdin')
|
||||
.option('-s, --strategy <strategy>', 'Strategy name, one of: "replace", "merge", "keep"')
|
||||
.action(getLocalScript('configurationRestore'));
|
||||
|
||||
// Admin
|
||||
program
|
||||
.command('admin:create-user')
|
||||
.alias('admin:create')
|
||||
.description('Create a new admin')
|
||||
.option('-e, --email <email>', 'Email of the new admin')
|
||||
.option('-p, --password <password>', 'Password of the new admin')
|
||||
.option('-f, --firstname <first name>', 'First name of the new admin')
|
||||
.option('-l, --lastname <last name>', 'Last name of the new admin')
|
||||
.action(getLocalScript('admin-create'));
|
||||
|
||||
program
|
||||
.command('admin:reset-user-password')
|
||||
.alias('admin:reset-password')
|
||||
.description("Reset an admin user's password")
|
||||
.option('-e, --email <email>', 'The user email')
|
||||
.option('-p, --password <password>', 'New password for the user')
|
||||
.action(getLocalScript('admin-reset'));
|
||||
|
||||
program
|
||||
.command('routes:list')
|
||||
.description('List all the application routes')
|
||||
.action(getLocalScript('routes/list'));
|
||||
|
||||
program
|
||||
.command('middlewares:list')
|
||||
.description('List all the application middlewares')
|
||||
.action(getLocalScript('middlewares/list'));
|
||||
|
||||
program
|
||||
.command('policies:list')
|
||||
.description('List all the application policies')
|
||||
.action(getLocalScript('policies/list'));
|
||||
|
||||
program
|
||||
.command('content-types:list')
|
||||
.description('List all the application content-types')
|
||||
.action(getLocalScript('content-types/list'));
|
||||
|
||||
program
|
||||
.command('hooks:list')
|
||||
.description('List all the application hooks')
|
||||
.action(getLocalScript('hooks/list'));
|
||||
|
||||
program
|
||||
.command('services:list')
|
||||
.description('List all the application services')
|
||||
.action(getLocalScript('services/list'));
|
||||
|
||||
program
|
||||
.command('controllers:list')
|
||||
.description('List all the application controllers')
|
||||
.action(getLocalScript('controllers/list'));
|
||||
|
||||
// `$ strapi opt-out-telemetry`
|
||||
program
|
||||
.command('telemetry:disable')
|
||||
.description('Disable anonymous telemetry and metadata sending to Strapi analytics')
|
||||
.action(getLocalScript('opt-out-telemetry'));
|
||||
|
||||
// `$ strapi opt-in-telemetry`
|
||||
program
|
||||
.command('telemetry:enable')
|
||||
.description('Enable anonymous telemetry and metadata sending to Strapi analytics')
|
||||
.action(getLocalScript('opt-in-telemetry'));
|
||||
|
||||
program
|
||||
.command('report')
|
||||
.description('Get system stats for debugging and submitting issues')
|
||||
.option('-u, --uuid', 'Include Project UUID')
|
||||
.option('-d, --dependencies', 'Include Project Dependencies')
|
||||
.option('--all', 'Include All Information')
|
||||
.action(getLocalScript('report'));
|
||||
|
||||
program
|
||||
.command('ts:generate-types')
|
||||
.description(`Generate TypeScript typings for your schemas`)
|
||||
.option(
|
||||
'-o, --out-dir <outDir>',
|
||||
'Specify a relative directory in which the schemas definitions will be generated'
|
||||
)
|
||||
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
||||
.option('--verbose', `Display more information about the types generation`, false)
|
||||
.option('-s, --silent', `Run the generation silently, without any output`, false)
|
||||
.action(getLocalScript('ts/generate-types'));
|
||||
|
||||
// `$ strapi transfer`
|
||||
program
|
||||
.command('transfer')
|
||||
.description('Transfer data from one source to another')
|
||||
.allowExcessArguments(false)
|
||||
.addOption(
|
||||
new Option(
|
||||
'--from <sourceURL>',
|
||||
`URL of the remote Strapi instance to get data from`
|
||||
).argParser(parseURL)
|
||||
)
|
||||
.addOption(new Option('--from-token <token>', `Transfer token for the remote Strapi source`))
|
||||
.addOption(
|
||||
new Option(
|
||||
'--to <destinationURL>',
|
||||
`URL of the remote Strapi instance to send data to`
|
||||
).argParser(parseURL)
|
||||
)
|
||||
.addOption(new Option('--to-token <token>', `Transfer token for the remote Strapi destination`))
|
||||
.addOption(forceOption)
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => !(opts.from || opts.to) || (opts.from && opts.to),
|
||||
() =>
|
||||
exitWith(1, 'Exactly one remote source (from) or destination (to) option must be provided')
|
||||
)
|
||||
)
|
||||
// If --from is used, validate the URL and token
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => opts.from,
|
||||
async (thisCommand) => {
|
||||
assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:']);
|
||||
if (!thisCommand.opts().fromToken) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your transfer token for the remote Strapi source',
|
||||
name: 'fromToken',
|
||||
},
|
||||
]);
|
||||
if (!answers.fromToken?.length) {
|
||||
exitWith(1, 'No token provided for remote source, aborting transfer.');
|
||||
}
|
||||
thisCommand.opts().fromToken = answers.fromToken;
|
||||
}
|
||||
|
||||
await confirmMessage(
|
||||
'The transfer will delete all the local Strapi assets and its database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Transfer process aborted' }
|
||||
)(thisCommand);
|
||||
}
|
||||
)
|
||||
)
|
||||
// If --to is used, validate the URL, token, and confirm restore
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => opts.to,
|
||||
async (thisCommand) => {
|
||||
assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:']);
|
||||
if (!thisCommand.opts().toToken) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your transfer token for the remote Strapi destination',
|
||||
name: 'toToken',
|
||||
},
|
||||
]);
|
||||
if (!answers.toToken?.length) {
|
||||
exitWith(1, 'No token provided for remote destination, aborting transfer.');
|
||||
}
|
||||
thisCommand.opts().toToken = answers.toToken;
|
||||
}
|
||||
|
||||
await confirmMessage(
|
||||
'The transfer will delete all the remote Strapi assets and its database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Transfer process aborted' }
|
||||
)(thisCommand);
|
||||
}
|
||||
)
|
||||
)
|
||||
.action(getLocalScript('transfer/transfer'));
|
||||
|
||||
// `$ strapi export`
|
||||
program
|
||||
.command('export')
|
||||
.description('Export data from Strapi to file')
|
||||
.allowExcessArguments(false)
|
||||
.addOption(
|
||||
new Option('--no-encrypt', `Disables 'aes-128-ecb' encryption of the output file`).default(true)
|
||||
)
|
||||
.addOption(new Option('--no-compress', 'Disables gzip compression of output file').default(true))
|
||||
.addOption(
|
||||
new Option(
|
||||
'-k, --key <string>',
|
||||
'Provide encryption key in command instead of using the prompt'
|
||||
)
|
||||
)
|
||||
.addOption(new Option('-f, --file <file>', 'name to use for exported file (without extensions)'))
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook('preAction', promptEncryptionKey)
|
||||
.action(getLocalScript('transfer/export'));
|
||||
|
||||
// `$ strapi import`
|
||||
program
|
||||
.command('import')
|
||||
.description('Import data from file to Strapi')
|
||||
.allowExcessArguments(false)
|
||||
.requiredOption(
|
||||
'-f, --file <file>',
|
||||
'path and filename for the Strapi export file you want to import'
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
'-k, --key <string>',
|
||||
'Provide encryption key in command instead of using the prompt'
|
||||
)
|
||||
)
|
||||
.addOption(forceOption)
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook('preAction', async (thisCommand) => {
|
||||
const opts = thisCommand.opts();
|
||||
const ext = path.extname(String(opts.file));
|
||||
|
||||
// check extension to guess if we should prompt for key
|
||||
if (ext === '.enc') {
|
||||
if (!opts.key) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your decryption key',
|
||||
name: 'key',
|
||||
},
|
||||
]);
|
||||
if (!answers.key?.length) {
|
||||
exitWith(1, 'No key entered, aborting import.');
|
||||
}
|
||||
opts.key = answers.key;
|
||||
}
|
||||
}
|
||||
})
|
||||
// set decrypt and decompress options based on filename
|
||||
.hook('preAction', (thisCommand) => {
|
||||
const opts = thisCommand.opts();
|
||||
|
||||
const { extname, parse } = path;
|
||||
|
||||
let file = opts.file;
|
||||
|
||||
if (extname(file) === '.enc') {
|
||||
file = parse(file).name; // trim the .enc extension
|
||||
thisCommand.opts().decrypt = true;
|
||||
} else {
|
||||
thisCommand.opts().decrypt = false;
|
||||
}
|
||||
|
||||
if (extname(file) === '.gz') {
|
||||
file = parse(file).name; // trim the .gz extension
|
||||
thisCommand.opts().decompress = true;
|
||||
} else {
|
||||
thisCommand.opts().decompress = false;
|
||||
}
|
||||
|
||||
if (extname(file) !== '.tar') {
|
||||
exitWith(
|
||||
1,
|
||||
`The file '${opts.file}' does not appear to be a valid Strapi data file. It must have an extension ending in .tar[.gz][.enc]`
|
||||
);
|
||||
}
|
||||
})
|
||||
.hook(
|
||||
'preAction',
|
||||
confirmMessage(
|
||||
'The import will delete all assets and data in your database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Import process aborted' }
|
||||
)
|
||||
)
|
||||
.action(getLocalScript('transfer/import'));
|
||||
|
||||
program.parseAsync(process.argv);
|
||||
runStrapiCommand(process.argv);
|
||||
|
||||
21
packages/core/strapi/ee/LICENSE
Normal file
21
packages/core/strapi/ee/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
This Strapi Enterprise Edition (EE) supplemental license (this “EE Supplemental License”) governs the use of this software and documentation (collectively, the “EE Software”) by you and any entity you represent (collectively, “You”). If You have separately entered into the Strapi, Inc. Enterprise Agreement (the “Enterprise Agreement”), then this EE Supplemental License hereby incorporates by reference the Enterprise Agreement and modifies the Enterprise Agreement solely to the extent set forth herein. If You have separately entered into the Strapi, Inc. Subscription Agreement (the “Subscription Agreement”), then this EE Supplemental License hereby incorporates by reference the Agreement and modifies the Subscription Agreement solely to the extent set forth herein. If You have not entered into either the Enterprise Agreement or the Subscription Agreement, then You may use the EE Software solely as set forth in Section 2 below.
|
||||
|
||||
In the event of a direct conflict between the terms of this EE Supplemental License and the terms of the Enterprise Agreement or the Subscription Agreement, as applicable, the terms of this EE Supplemental License will control. Except to the extent modified by this EE Supplemental License, the Enterprise Agreement or the Subscription Agreement, as applicable, remain in full force and effect in accordance with its terms.
|
||||
|
||||
By using the EE Software, You hereby agree to the below terms and conditions.
|
||||
|
||||
1. Notwithstanding any terms to the contrary in the Enterprise Agreement or Subscription Agreement, You may copy, modify and publish patches to the EE Software in a production environment (such copies, “Production Copies,” such modifications, “Production Modifications” and such patches, “Production Patches”) if and only if (a) You have agreed to, and are in full compliance with, the Enterprise Agreement or Subscription Agreement, as applicable, and (b) You have a valid license to the EE Software for the correct number of projects. You agree that Strapi and/or its licensors (as applicable) will own all right, title and interest in and to all such Production Copies, Production Modifications and Production Patches. You may display and/or distribute such Production Copies, Production Modifications and Production Patches if and only if (i) You have a valid license to the EE Software for the correct number of projects and (ii) You are in compliance with the Enterprise Agreement or Subscription Agreement, as applicable. You hereby assign to Strapi all right, title and interest in and to all Production Copies, Production Modifications and Production Patches, including all intellectual property rights embodied in or related to the foregoing.
|
||||
|
||||
2. Notwithstanding the foregoing, You may copy and modify the EE Software solely for development and testing purposes (such copies, “Development Copies” and such modifications, “Development Modifications”) with or without a license to the EE Software if your use is in compliance with this Section 2. You agree that Strapi and/or its licensors (as applicable) will own all right, title and interest in and to all Development Copies and Development Modifications and You hereby assign to Strapi all right, title and interest in and to all Development Copies and Development Modifications, including all intellectual property rights embodied in or related to the foregoing. If You do not have a license to the EE Software, then You further agree as follows:
|
||||
|
||||
Other than as expressly set forth in this Section 2, You may not (a) copy or modify the EE Software, (b) create derivative works of the EE Software, (c) remove or modify any notice of any patent, copyright, trademark, or other proprietary rights that appear on or in the EE Software, (d) reverse engineer, decompile, translate, disassemble, or discover the source code of all or any portion of the EE Software, (e) publicly display all or any part of the EE Software, (f) distribute, disclose, market, lease, publish, merge, resell, assign, loan, sublicense, rent, or transfer the EE Software to any third party, (g) use the EE Software for any dial-up, remote access, interactive, or other on-line or hosted service, or to provide a service bureau, time share, or other services to third parties, (h) merge the EE Software into another product, (i) disclose the results of any EE Software performance benchmarks or test results to any third party without Strapi’s prior written consent, (j) use any trademarks, logos, service marks, trade names of Strapi, or any portion thereof, without Strapi’s prior written consent, (k) use the EE Software, or any portion thereof, in a manner that does not comply with applicable law, regulations, or governmental orders, or (l) use or store the EE Software on equipment not owned or controlled by Customer.
|
||||
|
||||
THE EE SOFTWARE IS PROVIDED ON AN “AS IS” BASIS WITHOUT ANY REPRESENTATIONS, WARRANTIES, COVENANTS, OR CONDITIONS OF ANY KIND (EXPRESS OR IMPLIED, STATUTORY OR OTHERWISE), INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS FOR A PARTICULAR PURPOSE, OR NONINFRINGEMENT. FURTHER, STRAPI DOES NOT REPRESENT OR WARRANT THAT (A) THE ACCESS TO OR USE OF THE EE SOFTWARE WILL BE SECURE, TIMELY, UNINTERRUPTED, ERROR-FREE, OR OPERATE IN COMBINATION WITH ANY OTHER HARDWARE, SOFTWARE, SYSTEM, OR DATA, (B) THE EE SOFTWARE WILL MEET YOUR REQUIREMENTS OR EXPECTATIONS, OR OTHERWISE PRODUCE ANY PARTICULAR RESULTS, (C) ERRORS OR DEFECTS WILL BE CORRECTED, PATCHES OR WORKAROUNDS WILL BE PROVIDED, OR STRAPI WILL DETECT ANY BUG IN THE EE SOFTWARE, (D) THE SOFTWARE IS FREE OF VIRUSES OR OTHER HARMFUL COMPONENTS, OR (E) THIRD-PARTY DISRUPTIONS OR SECURITY BREACHES OF THE EE SOFTWARE WILL BE PREVENTED.
|
||||
|
||||
STRAPI WILL NOT BE LIABLE FOR ANY LOSS OF PROFITS OR ANY INDIRECT, SPECIAL, INCIDENTAL, RELIANCE, OR CONSEQUENTIAL DAMAGES OF ANY KIND, REGARDLESS OF THE FORM OF ACTION, WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY, OR OTHERWISE, EVEN IF INFORMED OF THE POSSIBILITY OF SUCH DAMAGES IN ADVANCE.
|
||||
|
||||
STRAPI’S ENTIRE LIABILITY TO YOU FOR USE OF THE EE SOFTWARE WILL NOT EXCEED $100.
|
||||
|
||||
3. You are not granted any other rights beyond what is expressly stated herein and in the Enterprise Agreement or Subscription Agreement, as applicable.
|
||||
|
||||
4. This EE Supplemental License does not apply to Strapi software that is distributed as part of the Strapi Community Edition (CE) (the “CE Software”).
|
||||
@ -105,7 +105,9 @@ const onlineUpdate = async ({ strapi }) => {
|
||||
};
|
||||
|
||||
const license = shouldContactRegistry
|
||||
? await fetchLicense(ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(fallback)
|
||||
? await fetchLicense({ strapi }, ee.licenseInfo.licenseKey, strapi.config.get('uuid')).catch(
|
||||
fallback
|
||||
)
|
||||
: storedInfo.license;
|
||||
|
||||
if (license) {
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const crypto = require('crypto');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const machineId = require('../lib/utils/machine-id');
|
||||
|
||||
@ -69,12 +68,14 @@ const throwError = () => {
|
||||
throw new LicenseCheckError('Could not proceed to the online validation of your license.', true);
|
||||
};
|
||||
|
||||
const fetchLicense = async (key, projectId) => {
|
||||
const response = await fetch(`https://license.strapi.io/api/licenses/validate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ key, projectId, deviceId: machineId() }),
|
||||
}).catch(throwError);
|
||||
const fetchLicense = async ({ strapi }, key, projectId) => {
|
||||
const response = await strapi
|
||||
.fetch(`https://license.strapi.io/api/licenses/validate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ key, projectId, deviceId: machineId() }),
|
||||
})
|
||||
.catch(throwError);
|
||||
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ const createCustomFields = require('./services/custom-fields');
|
||||
const createContentAPI = require('./services/content-api');
|
||||
const createUpdateNotifier = require('./utils/update-notifier');
|
||||
const createStartupLogger = require('./utils/startup-logger');
|
||||
const createStrapiFetch = require('./utils/fetch');
|
||||
const { LIFECYCLES } = require('./utils/lifecycles');
|
||||
const ee = require('./utils/ee');
|
||||
const contentTypesRegistry = require('./core/registries/content-types');
|
||||
@ -118,6 +119,7 @@ class Strapi {
|
||||
this.telemetry = createTelemetry(this);
|
||||
this.requestContext = requestContext;
|
||||
this.customFields = createCustomFields(this);
|
||||
this.fetch = createStrapiFetch(this);
|
||||
|
||||
createUpdateNotifier(this).notify();
|
||||
|
||||
@ -393,6 +395,7 @@ class Strapi {
|
||||
eventHub: this.eventHub,
|
||||
logger: this.log,
|
||||
configuration: this.config.get('server.webhooks', {}),
|
||||
fetch: this.fetch,
|
||||
});
|
||||
|
||||
this.registerInternalHooks();
|
||||
|
||||
20
packages/core/strapi/lib/commands/__tests__/commands.test.js
Normal file
20
packages/core/strapi/lib/commands/__tests__/commands.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const { buildStrapiCommand } = require('../index');
|
||||
|
||||
const consoleMock = {
|
||||
error: jest.spyOn(console, 'error').mockImplementation(() => {}),
|
||||
};
|
||||
|
||||
describe('commands', () => {
|
||||
afterEach(() => {
|
||||
consoleMock.error.mockClear();
|
||||
});
|
||||
|
||||
describe('buildStrapiCommand', () => {
|
||||
it('loads all commands without error', () => {
|
||||
buildStrapiCommand();
|
||||
expect(consoleMock.error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -24,7 +24,7 @@ const mock = {
|
||||
admin,
|
||||
};
|
||||
|
||||
jest.mock('../../index', () => {
|
||||
jest.mock('@strapi/strapi', () => {
|
||||
const impl = jest.fn(() => mock);
|
||||
|
||||
impl.compile = jest.fn();
|
||||
@ -33,7 +33,7 @@ jest.mock('../../index', () => {
|
||||
});
|
||||
|
||||
const inquirer = require('inquirer');
|
||||
const createAdminCommand = require('../admin-create');
|
||||
const createAdminCommand = require('../action');
|
||||
|
||||
describe('admin:create command', () => {
|
||||
beforeEach(() => {
|
||||
@ -3,7 +3,7 @@
|
||||
const { yup } = require('@strapi/utils');
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
const emailValidator = yup.string().email('Invalid email address').lowercase();
|
||||
|
||||
@ -57,7 +57,7 @@ const promptQuestions = [
|
||||
* @param {string} cmdOptions.firstname - new admin's first name
|
||||
* @param {string} [cmdOptions.lastname] - new admin's last name
|
||||
*/
|
||||
module.exports = async function (cmdOptions = {}) {
|
||||
module.exports = async (cmdOptions = {}) => {
|
||||
let { email, password, firstname, lastname } = cmdOptions;
|
||||
|
||||
if (
|
||||
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi admin:create-user`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('admin:create-user')
|
||||
.alias('admin:create')
|
||||
.description('Create a new admin')
|
||||
.option('-e, --email <email>', 'Email of the new admin')
|
||||
.option('-p, --password <password>', 'Password of the new admin')
|
||||
.option('-f, --firstname <first name>', 'First name of the new admin')
|
||||
.option('-l, --lastname <last name>', 'Last name of the new admin')
|
||||
.action(getLocalScript('admin/create-user'));
|
||||
};
|
||||
@ -15,7 +15,7 @@ const mock = {
|
||||
admin,
|
||||
};
|
||||
|
||||
jest.mock('../../index', () => {
|
||||
jest.mock('@strapi/strapi', () => {
|
||||
const impl = jest.fn(() => mock);
|
||||
|
||||
impl.compile = jest.fn();
|
||||
@ -24,7 +24,7 @@ jest.mock('../../index', () => {
|
||||
});
|
||||
|
||||
const inquirer = require('inquirer');
|
||||
const resetAdminPasswordCommand = require('../admin-reset');
|
||||
const resetAdminPasswordCommand = require('../action');
|
||||
|
||||
describe('admin:reset-password command', () => {
|
||||
beforeEach(() => {
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const _ = require('lodash');
|
||||
const inquirer = require('inquirer');
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
const promptQuestions = [
|
||||
{ type: 'input', name: 'email', message: 'User email?' },
|
||||
@ -20,7 +20,7 @@ const promptQuestions = [
|
||||
* @param {string} cmdOptions.email - user's email
|
||||
* @param {string} cmdOptions.password - user's new password
|
||||
*/
|
||||
module.exports = async function (cmdOptions = {}) {
|
||||
module.exports = async (cmdOptions = {}) => {
|
||||
const { email, password } = cmdOptions;
|
||||
|
||||
if (_.isEmpty(email) && _.isEmpty(password) && process.stdin.isTTY) {
|
||||
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi admin:reset-user-password`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('admin:reset-user-password')
|
||||
.alias('admin:reset-password')
|
||||
.description("Reset an admin user's password")
|
||||
.option('-e, --email <email>', 'The user email')
|
||||
.option('-p, --password <password>', 'New password for the user')
|
||||
.action(getLocalScript('admin/reset-user-password'));
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const strapi = require('..');
|
||||
const { buildAdmin } = require('./builders');
|
||||
const strapi = require('../../..');
|
||||
const { buildAdmin } = require('../../builders');
|
||||
|
||||
/**
|
||||
* `$ strapi build`
|
||||
15
packages/core/strapi/lib/commands/actions/build/command.js
Normal file
15
packages/core/strapi/lib/commands/actions/build/command.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi build`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('build')
|
||||
.option('--no-optimization', 'Build the admin app without optimizing assets')
|
||||
.description('Build the strapi admin app')
|
||||
.action(getLocalScript('build'));
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
const CHUNK_SIZE = 100;
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi configuration:dump`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('configuration:dump')
|
||||
.alias('config:dump')
|
||||
.description('Dump configurations of your application')
|
||||
.option('-f, --file <file>', 'Output file, default output is stdout')
|
||||
.option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)
|
||||
.action(getLocalScript('configuration/dump'));
|
||||
};
|
||||
@ -3,7 +3,7 @@
|
||||
const fs = require('fs');
|
||||
const _ = require('lodash');
|
||||
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
/**
|
||||
* Will restore configurations. It reads from a file or stdin
|
||||
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi configuration:restore`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('configuration:restore')
|
||||
.alias('config:restore')
|
||||
.description('Restore configurations of your application')
|
||||
.option('-f, --file <file>', 'Input file, default input is stdin')
|
||||
.option('-s, --strategy <strategy>', 'Strategy name, one of: "replace", "merge", "keep"')
|
||||
.action(getLocalScript('configuration/restore'));
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const REPL = require('repl');
|
||||
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../index');
|
||||
|
||||
/**
|
||||
* `$ strapi console`
|
||||
@ -14,7 +14,7 @@ module.exports = async () => {
|
||||
app.start().then(() => {
|
||||
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
||||
|
||||
repl.on('exit', function (err) {
|
||||
repl.on('exit', (err) => {
|
||||
if (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
14
packages/core/strapi/lib/commands/actions/console/command.js
Normal file
14
packages/core/strapi/lib/commands/actions/console/command.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi console`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('console')
|
||||
.description('Open the Strapi framework console')
|
||||
.action(getLocalScript('console'));
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi content-types:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('content-types:list')
|
||||
.description('List all the application content-types')
|
||||
.action(getLocalScript('content-types/list'));
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi controllers:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('controllers:list')
|
||||
.description('List all the application controllers')
|
||||
.action(getLocalScript('controllers/list'));
|
||||
};
|
||||
@ -9,9 +9,9 @@ const { getOr } = require('lodash/fp');
|
||||
const { joinBy } = require('@strapi/utils');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const loadConfiguration = require('../core/app-configuration');
|
||||
const strapi = require('../index');
|
||||
const { buildTypeScript, buildAdmin } = require('./builders');
|
||||
const loadConfiguration = require('../../../core/app-configuration');
|
||||
const strapi = require('../../../index');
|
||||
const { buildTypeScript, buildAdmin } = require('../../builders');
|
||||
|
||||
/**
|
||||
* `$ strapi develop`
|
||||
19
packages/core/strapi/lib/commands/actions/develop/command.js
Normal file
19
packages/core/strapi/lib/commands/actions/develop/command.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi develop`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('develop')
|
||||
.alias('dev')
|
||||
.option('--no-build', 'Disable build')
|
||||
.option('--watch-admin', 'Enable watch', false)
|
||||
.option('--polling', 'Watch for file changes in network directories', false)
|
||||
.option('--browser <name>', 'Open the browser', true)
|
||||
.description('Start your Strapi application in development mode')
|
||||
.action(getLocalScript('develop'));
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { expectExit } = require('./shared/transfer.test.utils');
|
||||
const { expectExit } = require('../../../__tests__/commands.test.utils');
|
||||
|
||||
describe('Export', () => {
|
||||
const defaultFileName = 'defaultFilename';
|
||||
@ -21,6 +21,7 @@ describe('Export', () => {
|
||||
},
|
||||
},
|
||||
engine: {
|
||||
...jest.requireActual('@strapi/data-transfer').engine,
|
||||
errors: {},
|
||||
createTransferEngine() {
|
||||
return {
|
||||
@ -53,7 +54,7 @@ describe('Export', () => {
|
||||
|
||||
jest.mock('@strapi/data-transfer', () => mockDataTransfer);
|
||||
|
||||
// mock utils
|
||||
// command utils
|
||||
const mockUtils = {
|
||||
getTransferTelemetryPayload: jest.fn().mockReturnValue({}),
|
||||
loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }),
|
||||
@ -76,7 +77,7 @@ describe('Export', () => {
|
||||
exitMessageText: jest.fn(),
|
||||
};
|
||||
jest.mock(
|
||||
'../../transfer/utils',
|
||||
'../../../utils/data-transfer.js',
|
||||
() => {
|
||||
return mockUtils;
|
||||
},
|
||||
@ -90,7 +91,7 @@ describe('Export', () => {
|
||||
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
// Now that everything is mocked, load the 'export' command
|
||||
const exportCommand = require('../../transfer/export');
|
||||
const exportAction = require('../action');
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
@ -100,7 +101,7 @@ describe('Export', () => {
|
||||
const filename = 'test';
|
||||
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({ file: filename });
|
||||
await exportAction({ file: filename });
|
||||
});
|
||||
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
@ -114,7 +115,7 @@ describe('Export', () => {
|
||||
|
||||
it('uses default path if not provided by user', async () => {
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({});
|
||||
await exportAction({});
|
||||
});
|
||||
|
||||
expect(mockUtils.getDefaultExportName).toHaveBeenCalledTimes(1);
|
||||
@ -128,7 +129,7 @@ describe('Export', () => {
|
||||
it('encrypts the output file if specified', async () => {
|
||||
const encrypt = true;
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({ encrypt });
|
||||
await exportAction({ encrypt });
|
||||
});
|
||||
|
||||
expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
|
||||
@ -142,7 +143,7 @@ describe('Export', () => {
|
||||
const key = 'secret-key';
|
||||
const encrypt = true;
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({ encrypt, key });
|
||||
await exportAction({ encrypt, key });
|
||||
});
|
||||
|
||||
expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
|
||||
@ -154,7 +155,7 @@ describe('Export', () => {
|
||||
|
||||
it('uses compress option', async () => {
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({ compress: false });
|
||||
await exportAction({ compress: false });
|
||||
});
|
||||
|
||||
expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
|
||||
@ -163,7 +164,7 @@ describe('Export', () => {
|
||||
})
|
||||
);
|
||||
await expectExit(0, async () => {
|
||||
await exportCommand({ compress: true });
|
||||
await exportAction({ compress: true });
|
||||
});
|
||||
expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@ -25,8 +25,9 @@ const {
|
||||
exitMessageText,
|
||||
abortTransfer,
|
||||
getTransferTelemetryPayload,
|
||||
} = require('./utils');
|
||||
const { exitWith } = require('../utils/helpers');
|
||||
} = require('../../utils/data-transfer');
|
||||
const { exitWith } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* @typedef ExportCommandOptions Options given to the CLI import command
|
||||
*
|
||||
45
packages/core/strapi/lib/commands/actions/export/command.js
Normal file
45
packages/core/strapi/lib/commands/actions/export/command.js
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const { Option } = require('commander');
|
||||
const {
|
||||
excludeOption,
|
||||
onlyOption,
|
||||
throttleOption,
|
||||
validateExcludeOnly,
|
||||
} = require('../../utils/data-transfer');
|
||||
const { promptEncryptionKey } = require('../../utils/commander');
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi export`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('export')
|
||||
.description('Export data from Strapi to file')
|
||||
.allowExcessArguments(false)
|
||||
.addOption(
|
||||
new Option('--no-encrypt', `Disables 'aes-128-ecb' encryption of the output file`).default(
|
||||
true
|
||||
)
|
||||
)
|
||||
.addOption(
|
||||
new Option('--no-compress', 'Disables gzip compression of output file').default(true)
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
'-k, --key <string>',
|
||||
'Provide encryption key in command instead of using the prompt'
|
||||
)
|
||||
)
|
||||
.addOption(
|
||||
new Option('-f, --file <file>', 'name to use for exported file (without extensions)')
|
||||
)
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook('preAction', promptEncryptionKey)
|
||||
.action(getLocalScript('export'));
|
||||
};
|
||||
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const { assertCwdContainsStrapiProject } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi generate`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command, argv }) => {
|
||||
command
|
||||
.command('generate')
|
||||
.description('Launch the interactive API generator')
|
||||
.action(() => {
|
||||
assertCwdContainsStrapiProject('generate');
|
||||
argv.splice(2, 1);
|
||||
require('@strapi/generators').runCLI();
|
||||
});
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi hooks:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('hooks:list')
|
||||
.description('List all the application hooks')
|
||||
.action(getLocalScript('hooks/list'));
|
||||
};
|
||||
@ -7,7 +7,7 @@ const {
|
||||
engine: { DEFAULT_SCHEMA_STRATEGY, DEFAULT_VERSION_STRATEGY },
|
||||
} = require('@strapi/data-transfer');
|
||||
|
||||
const { expectExit } = require('./shared/transfer.test.utils');
|
||||
const { expectExit } = require('../../../__tests__/commands.test.utils');
|
||||
|
||||
const createTransferEngine = jest.fn(() => {
|
||||
return {
|
||||
@ -53,6 +53,7 @@ describe('Import', () => {
|
||||
},
|
||||
},
|
||||
engine: {
|
||||
...jest.requireActual('@strapi/data-transfer').engine,
|
||||
DEFAULT_SCHEMA_STRATEGY,
|
||||
DEFAULT_VERSION_STRATEGY,
|
||||
createTransferEngine,
|
||||
@ -61,7 +62,7 @@ describe('Import', () => {
|
||||
|
||||
jest.mock('@strapi/data-transfer', () => mockDataTransfer);
|
||||
|
||||
// mock utils
|
||||
// command utils
|
||||
const mockUtils = {
|
||||
getTransferTelemetryPayload: jest.fn().mockReturnValue({}),
|
||||
loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }),
|
||||
@ -82,7 +83,7 @@ describe('Import', () => {
|
||||
exitMessageText: jest.fn(),
|
||||
};
|
||||
jest.mock(
|
||||
'../../transfer/utils',
|
||||
'../../../utils/data-transfer.js',
|
||||
() => {
|
||||
return mockUtils;
|
||||
},
|
||||
@ -96,7 +97,7 @@ describe('Import', () => {
|
||||
jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
// Now that everything is mocked, load the 'import' command
|
||||
const importCommand = require('../../transfer/import');
|
||||
const importAction = require('../action');
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
@ -112,7 +113,7 @@ describe('Import', () => {
|
||||
};
|
||||
|
||||
await expectExit(0, async () => {
|
||||
await importCommand(options);
|
||||
await importAction(options);
|
||||
});
|
||||
|
||||
// strapi options
|
||||
@ -21,8 +21,8 @@ const {
|
||||
exitMessageText,
|
||||
abortTransfer,
|
||||
getTransferTelemetryPayload,
|
||||
} = require('./utils');
|
||||
const { exitWith } = require('../utils/helpers');
|
||||
} = require('../../utils/data-transfer');
|
||||
const { exitWith } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* @typedef {import('@strapi/data-transfer/src/file/providers').ILocalFileSourceProviderOptions} ILocalFileSourceProviderOptions
|
||||
97
packages/core/strapi/lib/commands/actions/import/command.js
Normal file
97
packages/core/strapi/lib/commands/actions/import/command.js
Normal file
@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
const { Option } = require('commander');
|
||||
const path = require('path');
|
||||
const inquirer = require('inquirer');
|
||||
const {
|
||||
excludeOption,
|
||||
onlyOption,
|
||||
throttleOption,
|
||||
validateExcludeOnly,
|
||||
} = require('../../utils/data-transfer');
|
||||
const { confirmMessage, forceOption } = require('../../utils/commander');
|
||||
const { getLocalScript, exitWith } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi import`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('import')
|
||||
.description('Import data from file to Strapi')
|
||||
.allowExcessArguments(false)
|
||||
.requiredOption(
|
||||
'-f, --file <file>',
|
||||
'path and filename for the Strapi export file you want to import'
|
||||
)
|
||||
.addOption(
|
||||
new Option(
|
||||
'-k, --key <string>',
|
||||
'Provide encryption key in command instead of using the prompt'
|
||||
)
|
||||
)
|
||||
.addOption(forceOption)
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook('preAction', async (thisCommand) => {
|
||||
const opts = thisCommand.opts();
|
||||
const ext = path.extname(String(opts.file));
|
||||
|
||||
// check extension to guess if we should prompt for key
|
||||
if (ext === '.enc') {
|
||||
if (!opts.key) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your decryption key',
|
||||
name: 'key',
|
||||
},
|
||||
]);
|
||||
if (!answers.key?.length) {
|
||||
exitWith(1, 'No key entered, aborting import.');
|
||||
}
|
||||
opts.key = answers.key;
|
||||
}
|
||||
}
|
||||
})
|
||||
// set decrypt and decompress options based on filename
|
||||
.hook('preAction', (thisCommand) => {
|
||||
const opts = thisCommand.opts();
|
||||
|
||||
const { extname, parse } = path;
|
||||
|
||||
let file = opts.file;
|
||||
|
||||
if (extname(file) === '.enc') {
|
||||
file = parse(file).name; // trim the .enc extension
|
||||
thisCommand.opts().decrypt = true;
|
||||
} else {
|
||||
thisCommand.opts().decrypt = false;
|
||||
}
|
||||
|
||||
if (extname(file) === '.gz') {
|
||||
file = parse(file).name; // trim the .gz extension
|
||||
thisCommand.opts().decompress = true;
|
||||
} else {
|
||||
thisCommand.opts().decompress = false;
|
||||
}
|
||||
|
||||
if (extname(file) !== '.tar') {
|
||||
exitWith(
|
||||
1,
|
||||
`The file '${opts.file}' does not appear to be a valid Strapi data file. It must have an extension ending in .tar[.gz][.enc]`
|
||||
);
|
||||
}
|
||||
})
|
||||
.hook(
|
||||
'preAction',
|
||||
confirmMessage(
|
||||
'The import will delete all assets and data in your database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Import process aborted' }
|
||||
)
|
||||
)
|
||||
.action(getLocalScript('import'));
|
||||
};
|
||||
@ -4,7 +4,7 @@ const { join } = require('path');
|
||||
const { existsSync } = require('fs-extra');
|
||||
const ora = require('ora');
|
||||
const execa = require('execa');
|
||||
const findPackagePath = require('../load/package-path');
|
||||
const findPackagePath = require('../../../load/package-path');
|
||||
|
||||
module.exports = async (plugins) => {
|
||||
const loader = ora();
|
||||
14
packages/core/strapi/lib/commands/actions/install/command.js
Normal file
14
packages/core/strapi/lib/commands/actions/install/command.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi install`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('install [plugins...]')
|
||||
.description('Install a Strapi plugin')
|
||||
.action(getLocalScript('install'));
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi middlewares:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('middlewares:list')
|
||||
.description('List all the application middlewares')
|
||||
.action(getLocalScript('middlewares/list'));
|
||||
};
|
||||
@ -8,6 +8,6 @@ const { generateNewApp } = require('@strapi/generate-new');
|
||||
* Generate a new Strapi application.
|
||||
*/
|
||||
|
||||
module.exports = function (...args) {
|
||||
module.exports = (...args) => {
|
||||
return generateNewApp(...args);
|
||||
};
|
||||
35
packages/core/strapi/lib/commands/actions/new/command.js
Normal file
35
packages/core/strapi/lib/commands/actions/new/command.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const { yellow } = require('chalk');
|
||||
|
||||
/**
|
||||
* `$ strapi new`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('new <directory>')
|
||||
.option('--no-run', 'Do not start the application after it is created')
|
||||
.option('--use-npm', 'Force usage of npm instead of yarn to create the project')
|
||||
.option('--debug', 'Display database connection errors')
|
||||
.option('--quickstart', 'Create quickstart app')
|
||||
.option('--dbclient <dbclient>', 'Database client')
|
||||
.option('--dbhost <dbhost>', 'Database host')
|
||||
.option('--dbport <dbport>', 'Database port')
|
||||
.option('--dbname <dbname>', 'Database name')
|
||||
.option('--dbusername <dbusername>', 'Database username')
|
||||
.option('--dbpassword <dbpassword>', 'Database password')
|
||||
.option('--dbssl <dbssl>', 'Database SSL')
|
||||
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
||||
.option('--dbforce', 'Allow overwriting existing database content')
|
||||
.option('-ts, --typescript', 'Create a typescript project')
|
||||
.description('Create a new application')
|
||||
.hook('preAction', () => {
|
||||
console.warn(
|
||||
yellow(
|
||||
'The `strapi new` command has been deprecated in v4 and will be removed in v5. `create-strapi-app` should be used to create a new Strapi project.'
|
||||
)
|
||||
);
|
||||
})
|
||||
.action(require('./action'));
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi policies:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('policies:list')
|
||||
.description('List all the application policies')
|
||||
.action(getLocalScript('policies/list'));
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { EOL } = require('os');
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../index');
|
||||
|
||||
module.exports = async ({ uuid, dependencies, all }) => {
|
||||
const config = {
|
||||
17
packages/core/strapi/lib/commands/actions/report/command.js
Normal file
17
packages/core/strapi/lib/commands/actions/report/command.js
Normal file
@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi report`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('report')
|
||||
.description('Get system stats for debugging and submitting issues')
|
||||
.option('-u, --uuid', 'Include Project UUID')
|
||||
.option('-d, --dependencies', 'Include Project Dependencies')
|
||||
.option('--all', 'Include All Information')
|
||||
.action(getLocalScript('report'));
|
||||
};
|
||||
@ -4,9 +4,9 @@ const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
const { toUpper } = require('lodash/fp');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).load();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi routes:list``
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('routes:list')
|
||||
.description('List all the application routes')
|
||||
.action(getLocalScript('routes/list'));
|
||||
};
|
||||
@ -3,9 +3,9 @@
|
||||
const CLITable = require('cli-table3');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function () {
|
||||
module.exports = async () => {
|
||||
const appContext = await strapi.compile();
|
||||
const app = await strapi(appContext).register();
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi services:list`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('services:list')
|
||||
.description('List all the application services')
|
||||
.action(getLocalScript('services/list'));
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
const strapi = require('../index');
|
||||
const strapi = require('../../../index');
|
||||
|
||||
/**
|
||||
* `$ strapi start`
|
||||
14
packages/core/strapi/lib/commands/actions/start/command.js
Normal file
14
packages/core/strapi/lib/commands/actions/start/command.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi start`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('start')
|
||||
.description('Start your Strapi application')
|
||||
.action(getLocalScript('start'));
|
||||
};
|
||||
@ -4,7 +4,7 @@ const { resolve } = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const chalk = require('chalk');
|
||||
const fetch = require('node-fetch');
|
||||
const machineID = require('../utils/machine-id');
|
||||
const machineID = require('../../../../utils/machine-id');
|
||||
|
||||
const readPackageJSON = async (path) => {
|
||||
try {
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi telemetry:disable`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('telemetry:disable')
|
||||
.description('Disable anonymous telemetry and metadata sending to Strapi analytics')
|
||||
.action(getLocalScript('telemetry/disable'));
|
||||
};
|
||||
@ -5,7 +5,7 @@ const fse = require('fs-extra');
|
||||
const chalk = require('chalk');
|
||||
const fetch = require('node-fetch');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const machineID = require('../utils/machine-id');
|
||||
const machineID = require('../../../../utils/machine-id');
|
||||
|
||||
const readPackageJSON = async (path) => {
|
||||
try {
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi telemetry:enable`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('telemetry:enable')
|
||||
.description('Enable anonymous telemetry and metadata sending to Strapi analytics')
|
||||
.action(getLocalScript('telemetry/enable'));
|
||||
};
|
||||
@ -11,9 +11,9 @@ const { resolve, join } = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const inquirer = require('inquirer');
|
||||
|
||||
const exportTemplate = require('../generate-template');
|
||||
const exportTemplate = require('../action');
|
||||
|
||||
describe('generate:template command', () => {
|
||||
describe('templates:generate command', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
jest.clearAllMocks();
|
||||
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
*`$ strapi templates:generate <directory>`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('templates:generate <directory>')
|
||||
.description('Generate template from Strapi project')
|
||||
.action(getLocalScript('templates/generate'));
|
||||
};
|
||||
@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { expectExit } = require('./shared/transfer.test.utils');
|
||||
const { expectExit } = require('../../../__tests__/commands.test.utils');
|
||||
|
||||
describe('Transfer', () => {
|
||||
// mock utils
|
||||
// command utils
|
||||
const mockUtils = {
|
||||
getTransferTelemetryPayload: jest.fn().mockReturnValue({}),
|
||||
loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }),
|
||||
@ -26,7 +26,7 @@ describe('Transfer', () => {
|
||||
exitMessageText: jest.fn(),
|
||||
};
|
||||
jest.mock(
|
||||
'../../transfer/utils',
|
||||
'../../../utils/data-transfer.js',
|
||||
() => {
|
||||
return mockUtils;
|
||||
},
|
||||
@ -46,6 +46,7 @@ describe('Transfer', () => {
|
||||
},
|
||||
},
|
||||
engine: {
|
||||
...jest.requireActual('@strapi/data-transfer').engine,
|
||||
createTransferEngine() {
|
||||
return {
|
||||
transfer: jest.fn(() => {
|
||||
@ -72,7 +73,7 @@ describe('Transfer', () => {
|
||||
|
||||
jest.mock('@strapi/data-transfer', () => mockDataTransfer);
|
||||
|
||||
const transferCommand = require('../../transfer/transfer');
|
||||
const transferAction = require('../action');
|
||||
|
||||
// console spies
|
||||
jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
@ -91,7 +92,7 @@ describe('Transfer', () => {
|
||||
|
||||
it('exits with error when no --to or --from is provided', async () => {
|
||||
await expectExit(1, async () => {
|
||||
await transferCommand({ from: undefined, to: undefined });
|
||||
await transferAction({ from: undefined, to: undefined });
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(expect.stringMatching(/one source/i));
|
||||
@ -103,7 +104,7 @@ describe('Transfer', () => {
|
||||
|
||||
it('exits with error when both --to and --from are provided', async () => {
|
||||
await expectExit(1, async () => {
|
||||
await transferCommand({ from: sourceUrl, to: destinationUrl });
|
||||
await transferAction({ from: sourceUrl, to: destinationUrl });
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(expect.stringMatching(/one source/i));
|
||||
@ -116,7 +117,7 @@ describe('Transfer', () => {
|
||||
describe('--to', () => {
|
||||
it('exits with error when auth is not provided', async () => {
|
||||
await expectExit(1, async () => {
|
||||
await transferCommand({ from: undefined, to: destinationUrl });
|
||||
await transferAction({ from: undefined, to: destinationUrl });
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(expect.stringMatching(/missing token/i));
|
||||
@ -128,7 +129,7 @@ describe('Transfer', () => {
|
||||
|
||||
it('uses destination url and token provided by user', async () => {
|
||||
await expectExit(0, async () => {
|
||||
await transferCommand({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
await transferAction({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
});
|
||||
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
@ -147,7 +148,7 @@ describe('Transfer', () => {
|
||||
|
||||
it('uses local Strapi source when from is not specified', async () => {
|
||||
await expectExit(0, async () => {
|
||||
await transferCommand({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
await transferAction({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
});
|
||||
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
@ -162,7 +163,7 @@ describe('Transfer', () => {
|
||||
|
||||
it('uses restore as the default strategy', async () => {
|
||||
await expectExit(0, async () => {
|
||||
await transferCommand({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
await transferAction({ from: undefined, to: destinationUrl, toToken: destinationToken });
|
||||
});
|
||||
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
@ -22,8 +22,8 @@ const {
|
||||
exitMessageText,
|
||||
abortTransfer,
|
||||
getTransferTelemetryPayload,
|
||||
} = require('./utils');
|
||||
const { exitWith } = require('../utils/helpers');
|
||||
} = require('../../utils/data-transfer');
|
||||
const { exitWith } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* @typedef TransferCommandOptions Options given to the CLI transfer command
|
||||
115
packages/core/strapi/lib/commands/actions/transfer/command.js
Normal file
115
packages/core/strapi/lib/commands/actions/transfer/command.js
Normal file
@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
const inquirer = require('inquirer');
|
||||
const { Option } = require('commander');
|
||||
const { confirmMessage, forceOption, parseURL } = require('../../utils/commander');
|
||||
const {
|
||||
getLocalScript,
|
||||
exitWith,
|
||||
assertUrlHasProtocol,
|
||||
ifOptions,
|
||||
} = require('../../utils/helpers');
|
||||
const {
|
||||
excludeOption,
|
||||
onlyOption,
|
||||
throttleOption,
|
||||
validateExcludeOnly,
|
||||
} = require('../../utils/data-transfer');
|
||||
|
||||
/**
|
||||
* `$ strapi transfer`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('transfer')
|
||||
.description('Transfer data from one source to another')
|
||||
.allowExcessArguments(false)
|
||||
.addOption(
|
||||
new Option(
|
||||
'--from <sourceURL>',
|
||||
`URL of the remote Strapi instance to get data from`
|
||||
).argParser(parseURL)
|
||||
)
|
||||
.addOption(new Option('--from-token <token>', `Transfer token for the remote Strapi source`))
|
||||
.addOption(
|
||||
new Option(
|
||||
'--to <destinationURL>',
|
||||
`URL of the remote Strapi instance to send data to`
|
||||
).argParser(parseURL)
|
||||
)
|
||||
.addOption(new Option('--to-token <token>', `Transfer token for the remote Strapi destination`))
|
||||
.addOption(forceOption)
|
||||
.addOption(excludeOption)
|
||||
.addOption(onlyOption)
|
||||
.addOption(throttleOption)
|
||||
.hook('preAction', validateExcludeOnly)
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => !(opts.from || opts.to) || (opts.from && opts.to),
|
||||
() =>
|
||||
exitWith(
|
||||
1,
|
||||
'Exactly one remote source (from) or destination (to) option must be provided'
|
||||
)
|
||||
)
|
||||
)
|
||||
// If --from is used, validate the URL and token
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => opts.from,
|
||||
async (thisCommand) => {
|
||||
assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:']);
|
||||
if (!thisCommand.opts().fromToken) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your transfer token for the remote Strapi source',
|
||||
name: 'fromToken',
|
||||
},
|
||||
]);
|
||||
if (!answers.fromToken?.length) {
|
||||
exitWith(1, 'No token provided for remote source, aborting transfer.');
|
||||
}
|
||||
thisCommand.opts().fromToken = answers.fromToken;
|
||||
}
|
||||
|
||||
await confirmMessage(
|
||||
'The transfer will delete all the local Strapi assets and its database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Transfer process aborted' }
|
||||
)(thisCommand);
|
||||
}
|
||||
)
|
||||
)
|
||||
// If --to is used, validate the URL, token, and confirm restore
|
||||
.hook(
|
||||
'preAction',
|
||||
ifOptions(
|
||||
(opts) => opts.to,
|
||||
async (thisCommand) => {
|
||||
assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:']);
|
||||
if (!thisCommand.opts().toToken) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'password',
|
||||
message: 'Please enter your transfer token for the remote Strapi destination',
|
||||
name: 'toToken',
|
||||
},
|
||||
]);
|
||||
if (!answers.toToken?.length) {
|
||||
exitWith(1, 'No token provided for remote destination, aborting transfer.');
|
||||
}
|
||||
thisCommand.opts().toToken = answers.toToken;
|
||||
}
|
||||
|
||||
await confirmMessage(
|
||||
'The transfer will delete all the remote Strapi assets and its database. Are you sure you want to proceed?',
|
||||
{ failMessage: 'Transfer process aborted' }
|
||||
)(thisCommand);
|
||||
}
|
||||
)
|
||||
)
|
||||
.action(getLocalScript('transfer'));
|
||||
};
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
const tsUtils = require('@strapi/typescript-utils');
|
||||
|
||||
const strapi = require('../../index');
|
||||
const strapi = require('../../../../index');
|
||||
|
||||
module.exports = async function ({ outDir, file, verbose, silent }) {
|
||||
module.exports = async ({ outDir, file, verbose, silent }) => {
|
||||
if (verbose && silent) {
|
||||
console.error('You cannot enable verbose and silent flags at the same time, exiting...');
|
||||
process.exit(1);
|
||||
@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi ts:generate-types`
|
||||
* @param {import('../../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('ts:generate-types')
|
||||
.description(`Generate TypeScript typings for your schemas`)
|
||||
.option(
|
||||
'-o, --out-dir <outDir>',
|
||||
'Specify a relative directory in which the schemas definitions will be generated'
|
||||
)
|
||||
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
||||
.option('--verbose', `Display more information about the types generation`, false)
|
||||
.option('-s, --silent', `Run the generation silently, without any output`, false)
|
||||
.action(getLocalScript('ts/generate-types'));
|
||||
};
|
||||
@ -5,7 +5,7 @@ const { existsSync, removeSync } = require('fs-extra');
|
||||
const ora = require('ora');
|
||||
const execa = require('execa');
|
||||
const inquirer = require('inquirer');
|
||||
const findPackagePath = require('../load/package-path');
|
||||
const findPackagePath = require('../../../load/package-path');
|
||||
|
||||
module.exports = async (plugins, { deleteFiles }) => {
|
||||
const answers = await inquirer.prompt([
|
||||
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi uninstall`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('uninstall [plugins...]')
|
||||
.description('Uninstall a Strapi plugin')
|
||||
.option('-d, --delete-files', 'Delete files', false)
|
||||
.action(getLocalScript('uninstall'));
|
||||
};
|
||||
19
packages/core/strapi/lib/commands/actions/version/command.js
Normal file
19
packages/core/strapi/lib/commands/actions/version/command.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* `$ strapi version`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
// load the Strapi package.json to get version and other information
|
||||
const packageJSON = require('../../../../package.json');
|
||||
|
||||
command.version(packageJSON.version, '-v, --version', 'Output the version number');
|
||||
command
|
||||
.command('version')
|
||||
.description('Output the version of Strapi')
|
||||
.action(() => {
|
||||
process.stdout.write(`${packageJSON.version}\n`);
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
@ -3,11 +3,11 @@
|
||||
const strapiAdmin = require('@strapi/admin');
|
||||
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
||||
|
||||
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
||||
const addSlash = require('../utils/addSlash');
|
||||
const strapi = require('../index');
|
||||
const getEnabledPlugins = require('../../../core/loaders/plugins/get-enabled-plugins');
|
||||
const addSlash = require('../../../utils/addSlash');
|
||||
const strapi = require('../../../index');
|
||||
|
||||
module.exports = async function ({ browser }) {
|
||||
module.exports = async ({ browser }) => {
|
||||
const appContext = await strapi.compile();
|
||||
|
||||
const strapiInstance = strapi({
|
||||
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const { getLocalScript } = require('../../utils/helpers');
|
||||
|
||||
/**
|
||||
* `$ strapi watch-admin`
|
||||
* @param {import('../../../types/core/commands').AddCommandOptions} options
|
||||
*/
|
||||
module.exports = ({ command }) => {
|
||||
command
|
||||
.command('watch-admin')
|
||||
.option('--browser <name>', 'Open the browser', true)
|
||||
.description('Start the admin development server')
|
||||
.action(getLocalScript('watch-admin'));
|
||||
};
|
||||
66
packages/core/strapi/lib/commands/index.js
Normal file
66
packages/core/strapi/lib/commands/index.js
Normal file
@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
const { Command } = require('commander');
|
||||
|
||||
const strapiCommands = {
|
||||
'admin/create-user': require('./actions/admin/create-user/command'),
|
||||
'admin/reset-user-password': require('./actions/admin/reset-user-password/command'),
|
||||
build: require('./actions/build/command'),
|
||||
'configuration/dump': require('./actions/configuration/dump/command'),
|
||||
'configuration/restore': require('./actions/configuration/restore/command'),
|
||||
console: require('./actions/console/command'),
|
||||
'content-types/list': require('./actions/content-types/list/command'),
|
||||
'controllers/list': require('./actions/controllers/list/command'),
|
||||
develop: require('./actions/develop/command'),
|
||||
export: require('./actions/export/command'),
|
||||
generate: require('./actions/generate/command'),
|
||||
'hooks/list': require('./actions/hooks/list/command'),
|
||||
import: require('./actions/import/command'),
|
||||
install: require('./actions/install/command'),
|
||||
'middlewares/list': require('./actions/middlewares/list/command'),
|
||||
new: require('./actions/new/command'),
|
||||
'policies/list': require('./actions/policies/list/command'),
|
||||
report: require('./actions/report/command'),
|
||||
'routes/list': require('./actions/routes/list/command'),
|
||||
'services/list': require('./actions/services/list/command'),
|
||||
start: require('./actions/start/command'),
|
||||
'telemetry/disable': require('./actions/telemetry/disable/command'),
|
||||
'telemetry/enable': require('./actions/telemetry/enable/command'),
|
||||
'templates/generate': require('./actions/templates/generate/command'),
|
||||
transfer: require('./actions/transfer/command'),
|
||||
'ts/generate-types': require('./actions/ts/generate-types/command'),
|
||||
uninstall: require('./actions/uninstall/command'),
|
||||
version: require('./actions/version/command'),
|
||||
'watch-admin': require('./actions/watch-admin/command'),
|
||||
};
|
||||
|
||||
const buildStrapiCommand = (argv, command = new Command()) => {
|
||||
// Initial program setup
|
||||
command.storeOptionsAsProperties(false).allowUnknownOption(true);
|
||||
|
||||
// Help command
|
||||
command.helpOption('-h, --help', 'Display help for command');
|
||||
command.addHelpCommand('help [command]', 'Display help for command');
|
||||
|
||||
// Load all commands
|
||||
Object.keys(strapiCommands).forEach((name) => {
|
||||
try {
|
||||
// Add this command to the Commander command object
|
||||
strapiCommands[name]({ command, argv });
|
||||
} catch (e) {
|
||||
console.error(`Failed to load command ${name}`, e);
|
||||
}
|
||||
});
|
||||
|
||||
return command;
|
||||
};
|
||||
|
||||
const runStrapiCommand = async (argv = process.argv, command = new Command()) => {
|
||||
await buildStrapiCommand(argv, command).parseAsync(argv);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
runStrapiCommand,
|
||||
buildStrapiCommand,
|
||||
strapiCommands,
|
||||
};
|
||||
@ -12,9 +12,9 @@ const {
|
||||
createLogger,
|
||||
} = require('@strapi/logger');
|
||||
const ora = require('ora');
|
||||
const { readableBytes, exitWith } = require('../utils/helpers');
|
||||
const { readableBytes, exitWith } = require('./helpers');
|
||||
const strapi = require('../../index');
|
||||
const { getParseListWithChoices, parseInteger } = require('../utils/commander');
|
||||
const { getParseListWithChoices, parseInteger } = require('./commander');
|
||||
|
||||
const exitMessageText = (process, error = false) => {
|
||||
const processCapitalized = process[0].toUpperCase() + process.slice(1);
|
||||
@ -4,8 +4,10 @@
|
||||
* Helper functions for the Strapi CLI
|
||||
*/
|
||||
|
||||
const chalk = require('chalk');
|
||||
const { yellow, red, green } = require('chalk');
|
||||
const { isString, isArray } = require('lodash/fp');
|
||||
const resolveCwd = require('resolve-cwd');
|
||||
const { has } = require('lodash/fp');
|
||||
|
||||
const bytesPerKb = 1024;
|
||||
const sizes = ['B ', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
@ -46,9 +48,9 @@ const exitWith = (code, message = undefined, options = {}) => {
|
||||
|
||||
const log = (message) => {
|
||||
if (code === 0) {
|
||||
logger.log(chalk.green(message));
|
||||
logger.log(green(message));
|
||||
} else {
|
||||
logger.error(chalk.red(message));
|
||||
logger.error(red(message));
|
||||
}
|
||||
};
|
||||
|
||||
@ -107,9 +109,58 @@ const ifOptions = (conditionCallback, isMetCallback = () => {}, isNotMetCallback
|
||||
};
|
||||
};
|
||||
|
||||
const assertCwdContainsStrapiProject = (name) => {
|
||||
const logErrorAndExit = () => {
|
||||
console.log(
|
||||
`You need to run ${yellow(
|
||||
`strapi ${name}`
|
||||
)} in a Strapi project. Make sure you are in the right directory.`
|
||||
);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
try {
|
||||
const pkgJSON = require(`${process.cwd()}/package.json`);
|
||||
if (!has('dependencies.@strapi/strapi', pkgJSON)) {
|
||||
logErrorAndExit(name);
|
||||
}
|
||||
} catch (err) {
|
||||
logErrorAndExit(name);
|
||||
}
|
||||
};
|
||||
|
||||
const getLocalScript =
|
||||
(name) =>
|
||||
(...args) => {
|
||||
assertCwdContainsStrapiProject(name);
|
||||
|
||||
const cmdPath = resolveCwd.silent(`@strapi/strapi/lib/commands/actions/${name}/action`);
|
||||
if (!cmdPath) {
|
||||
console.log(
|
||||
`Error loading the local ${yellow(
|
||||
name
|
||||
)} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const script = require(cmdPath);
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
return script(...args);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
exitWith,
|
||||
assertUrlHasProtocol,
|
||||
ifOptions,
|
||||
readableBytes,
|
||||
getLocalScript,
|
||||
assertCwdContainsStrapiProject,
|
||||
};
|
||||
|
||||
@ -3,10 +3,14 @@
|
||||
jest.mock('node-fetch', () => jest.fn(() => Promise.resolve()));
|
||||
|
||||
const { get } = require('lodash/fp');
|
||||
const fetch = require('node-fetch');
|
||||
const metrics = require('../index');
|
||||
|
||||
const fetch = jest.fn(() => Promise.resolve());
|
||||
|
||||
describe('metrics', () => {
|
||||
beforeEach(() => {
|
||||
fetch.mockClear();
|
||||
});
|
||||
test('Initializes a middleware', () => {
|
||||
const use = jest.fn();
|
||||
|
||||
@ -32,6 +36,7 @@ describe('metrics', () => {
|
||||
requestContext: {
|
||||
get: jest.fn(() => ({})),
|
||||
},
|
||||
fetch,
|
||||
});
|
||||
|
||||
metricsInstance.register();
|
||||
@ -66,6 +71,7 @@ describe('metrics', () => {
|
||||
requestContext: {
|
||||
get: jest.fn(() => ({})),
|
||||
},
|
||||
fetch,
|
||||
});
|
||||
|
||||
metricsInstance.register();
|
||||
@ -98,6 +104,7 @@ describe('metrics', () => {
|
||||
requestContext: {
|
||||
get: jest.fn(() => ({})),
|
||||
},
|
||||
fetch,
|
||||
});
|
||||
|
||||
send('someEvent');
|
||||
@ -140,6 +147,7 @@ describe('metrics', () => {
|
||||
requestContext: {
|
||||
get: jest.fn(() => ({})),
|
||||
},
|
||||
fetch,
|
||||
});
|
||||
|
||||
send('someEvent');
|
||||
|
||||
@ -4,7 +4,6 @@ const os = require('os');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const isDocker = require('is-docker');
|
||||
const fetch = require('node-fetch');
|
||||
const ciEnv = require('ci-info');
|
||||
const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
|
||||
const { env } = require('@strapi/utils');
|
||||
@ -82,7 +81,7 @@ module.exports = (strapi) => {
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
|
||||
const res = await strapi.fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
|
||||
return res.ok;
|
||||
} catch (err) {
|
||||
return false;
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
|
||||
const debug = require('debug')('strapi:webhook');
|
||||
const _ = require('lodash');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const WorkerQueue = require('./worker-queue');
|
||||
|
||||
@ -15,12 +14,13 @@ const defaultConfiguration = {
|
||||
};
|
||||
|
||||
class WebhookRunner {
|
||||
constructor({ eventHub, logger, configuration = {} }) {
|
||||
debug('Initialized webhook runer');
|
||||
constructor({ eventHub, logger, configuration = {}, fetch }) {
|
||||
debug('Initialized webhook runner');
|
||||
this.eventHub = eventHub;
|
||||
this.logger = logger;
|
||||
this.webhooksMap = new Map();
|
||||
this.listeners = new Map();
|
||||
this.fetch = fetch;
|
||||
|
||||
if (typeof configuration !== 'object') {
|
||||
throw new Error(
|
||||
@ -76,7 +76,7 @@ class WebhookRunner {
|
||||
run(webhook, event, info = {}) {
|
||||
const { url, headers } = webhook;
|
||||
|
||||
return fetch(url, {
|
||||
return this.fetch(url, {
|
||||
method: 'post',
|
||||
body: JSON.stringify({
|
||||
event,
|
||||
|
||||
6
packages/core/strapi/lib/types/core/commands/index.d.ts
vendored
Normal file
6
packages/core/strapi/lib/types/core/commands/index.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { Command } from 'commander';
|
||||
|
||||
export type AddCommandOptions = {
|
||||
command: Command;
|
||||
argv: Record<number, string>;
|
||||
};
|
||||
23
packages/core/strapi/lib/utils/fetch.js
Normal file
23
packages/core/strapi/lib/utils/fetch.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const nodeFetch = require('node-fetch');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
|
||||
function createStrapiFetch(strapi) {
|
||||
function fetch(url, options) {
|
||||
return nodeFetch(url, {
|
||||
...(fetch.agent ? { agent: fetch.agent } : {}),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
const { globalProxy: proxy } = strapi.config.get('server');
|
||||
|
||||
if (proxy) {
|
||||
fetch.agent = new HttpsProxyAgent(proxy);
|
||||
}
|
||||
|
||||
return fetch;
|
||||
}
|
||||
|
||||
module.exports = createStrapiFetch;
|
||||
@ -109,6 +109,7 @@
|
||||
"fs-extra": "10.0.0",
|
||||
"glob": "7.2.0",
|
||||
"http-errors": "1.8.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"inquirer": "8.2.5",
|
||||
"is-docker": "2.2.1",
|
||||
"koa": "2.13.4",
|
||||
@ -136,7 +137,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"supertest": "6.3.3",
|
||||
"typescript": "4.6.2"
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.19.1 <=18.x.x",
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
"react-dom": "^17.0.2",
|
||||
"react-router-dom": "^5.3.4",
|
||||
"styled-components": "^5.3.6",
|
||||
"typescript": "4.6.3"
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.2",
|
||||
|
||||
@ -176,7 +176,7 @@ const getInitialProviders = ({ purest }) => ({
|
||||
const vk = purest({ provider: 'vk' });
|
||||
|
||||
return vk
|
||||
.get('users.get')
|
||||
.get('users')
|
||||
.auth(accessToken)
|
||||
.qs({ id: query.raw.user_id, v: '5.122' })
|
||||
.request()
|
||||
|
||||
@ -36,17 +36,14 @@ const generateGlobalDefinition = (schemasDefinitions = []) => {
|
||||
const properties = schemasDefinitions.map(schemaDefinitionToPropertySignature);
|
||||
|
||||
return factory.createModuleDeclaration(
|
||||
undefined,
|
||||
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
||||
factory.createIdentifier('global'),
|
||||
factory.createModuleBlock([
|
||||
factory.createModuleDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
factory.createIdentifier('Strapi'),
|
||||
factory.createModuleBlock([
|
||||
factory.createInterfaceDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
factory.createIdentifier('Schemas'),
|
||||
undefined,
|
||||
|
||||
@ -23,7 +23,6 @@ module.exports = {
|
||||
);
|
||||
|
||||
return factory.createImportDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
factory.createImportClause(false, undefined, factory.createNamedImports(formattedImports)),
|
||||
factory.createStringLiteral('@strapi/strapi'),
|
||||
|
||||
@ -34,7 +34,7 @@ const emitDefinitions = (definitions) => {
|
||||
ts.ScriptKind.TS
|
||||
);
|
||||
|
||||
const printer = ts.createPrinter({ newLine: true, omitTrailingSemicolon: true });
|
||||
const printer = ts.createPrinter({ omitTrailingSemicolon: true });
|
||||
|
||||
return printer.printList(ts.ListFormat.MultiLine, nodeArray, sourceFile);
|
||||
};
|
||||
|
||||
@ -69,7 +69,6 @@ const generateSchemaDefinition = (schema) => {
|
||||
|
||||
// Generate the schema's interface declaration
|
||||
const schemaType = factory.createInterfaceDeclaration(
|
||||
undefined,
|
||||
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
factory.createIdentifier(interfaceName),
|
||||
undefined,
|
||||
|
||||
@ -120,13 +120,7 @@ const toTypeLiteral = (data) => {
|
||||
|
||||
return [
|
||||
...acc,
|
||||
factory.createPropertyDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
identifier,
|
||||
undefined,
|
||||
toTypeLiteral(value)
|
||||
),
|
||||
factory.createPropertyDeclaration(undefined, identifier, undefined, toTypeLiteral(value)),
|
||||
];
|
||||
}, []);
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
"fs-extra": "10.0.1",
|
||||
"lodash": "4.17.21",
|
||||
"prettier": "2.8.4",
|
||||
"typescript": "4.6.2"
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.19.1 <=18.x.x",
|
||||
|
||||
37
yarn.lock
37
yarn.lock
@ -7080,7 +7080,7 @@ __metadata:
|
||||
speed-measure-webpack-plugin: 1.5.0
|
||||
style-loader: 3.3.1
|
||||
styled-components: 5.3.3
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
webpack: ^5.76.0
|
||||
webpack-bundle-analyzer: ^4.8.0
|
||||
webpack-cli: ^5.0.1
|
||||
@ -7139,7 +7139,7 @@ __metadata:
|
||||
stream-json: 1.7.4
|
||||
tar: 6.1.13
|
||||
tar-stream: 2.2.0
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
uuid: 9.0.0
|
||||
ws: 8.11.0
|
||||
languageName: unknown
|
||||
@ -7274,7 +7274,7 @@ __metadata:
|
||||
react-test-renderer: ^17.0.2
|
||||
rimraf: 3.0.2
|
||||
styled-components: 5.3.3
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
webpack: ^5.76.0
|
||||
webpack-cli: ^5.0.1
|
||||
peerDependencies:
|
||||
@ -7792,6 +7792,7 @@ __metadata:
|
||||
fs-extra: 10.0.0
|
||||
glob: 7.2.0
|
||||
http-errors: 1.8.1
|
||||
https-proxy-agent: 5.0.1
|
||||
inquirer: 8.2.5
|
||||
is-docker: 2.2.1
|
||||
koa: 2.13.4
|
||||
@ -7816,7 +7817,7 @@ __metadata:
|
||||
semver: 7.3.8
|
||||
statuses: 2.0.1
|
||||
supertest: 6.3.3
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
uuid: ^8.3.2
|
||||
bin:
|
||||
strapi: ./bin/strapi.js
|
||||
@ -7832,7 +7833,7 @@ __metadata:
|
||||
fs-extra: 10.0.1
|
||||
lodash: 4.17.21
|
||||
prettier: 2.8.4
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@ -18576,7 +18577,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"https-proxy-agent@npm:5, https-proxy-agent@npm:^5.0.0, https-proxy-agent@npm:^5.0.1":
|
||||
"https-proxy-agent@npm:5, https-proxy-agent@npm:5.0.1, https-proxy-agent@npm:^5.0.0, https-proxy-agent@npm:^5.0.1":
|
||||
version: 5.0.1
|
||||
resolution: "https-proxy-agent@npm:5.0.1"
|
||||
dependencies:
|
||||
@ -28801,7 +28802,7 @@ __metadata:
|
||||
supertest: 6.3.3
|
||||
ts-jest: 29.0.3
|
||||
typedoc: 0.23.26
|
||||
typescript: 4.6.2
|
||||
typescript: 5.0.4
|
||||
yargs: 17.6.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@ -30373,13 +30374,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:4.6.2":
|
||||
version: 4.6.2
|
||||
resolution: "typescript@npm:4.6.2"
|
||||
"typescript@npm:5.0.4":
|
||||
version: 5.0.4
|
||||
resolution: "typescript@npm:5.0.4"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: 8a44ed7e6f6c4cb1ebe8cf236ecda2fb119d84dcf0fbd77e707b2dfea1bbcfc4e366493a143513ce7f57203c75da9d4e20af6fe46de89749366351046be7577c
|
||||
checksum: 82b94da3f4604a8946da585f7d6c3025fff8410779e5bde2855ab130d05e4fd08938b9e593b6ebed165bda6ad9292b230984f10952cf82f0a0ca07bbeaa08172
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -30403,13 +30404,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@patch:typescript@4.6.2#~builtin<compat/typescript>":
|
||||
version: 4.6.2
|
||||
resolution: "typescript@patch:typescript@npm%3A4.6.2#~builtin<compat/typescript>::version=4.6.2&hash=5d3a66"
|
||||
"typescript@patch:typescript@5.0.4#~builtin<compat/typescript>":
|
||||
version: 5.0.4
|
||||
resolution: "typescript@patch:typescript@npm%3A5.0.4#~builtin<compat/typescript>::version=5.0.4&hash=85af82"
|
||||
bin:
|
||||
tsc: bin/tsc
|
||||
tsserver: bin/tsserver
|
||||
checksum: 40b493a71747fb89fa70df104e2c4a5e284b43750af5bea024090a5261cefa387f7a9372411b13030f7bf5555cee4275443d08805642ae5c74ef76740854a4c7
|
||||
checksum: bb309d320c59a26565fb3793dba550576ab861018ff3fd1b7fccabbe46ae4a35546bc45f342c0a0b6f265c801ccdf64ffd68f548f117ceb7f0eac4b805cd52a9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -31123,14 +31124,14 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"vm2@npm:^3.9.8":
|
||||
version: 3.9.11
|
||||
resolution: "vm2@npm:3.9.11"
|
||||
version: 3.9.17
|
||||
resolution: "vm2@npm:3.9.17"
|
||||
dependencies:
|
||||
acorn: ^8.7.0
|
||||
acorn-walk: ^8.2.0
|
||||
bin:
|
||||
vm2: bin/vm2
|
||||
checksum: aab39e6e4b59146d24abacd79f490e854a6e058a8b23d93d2be5aca7720778e2605d2cc028ccc4a5f50d3d91b0c38be9a6247a80d2da1a6de09425cc437770b4
|
||||
checksum: 9a03740a40ab2be5e3348a95fb31512da1a3c85318febb07e5299fa103ff05bcd7b6f458211fa38a1281dc27beccd04ff90355fc1d34fe2ee6ca10d0bb8c6f35
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user