Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
strapi.start({}, err => {
// Log and exit the REPL in case there is an error
// while we were trying to start the server.
if (err) {
logger.error('Could not load the Strapi framework.');
logger.error('Are you using the latest stable version?');
process.exit(1);
}
// Open the Node.js REPL.
const repl = REPL.start(strapi.config.name + ' > ' || 'strapi > ');
repl.on('exit', err => {
// Log and exit the REPL in case there is an error
// while we were trying to open the REPL.
if (err) {
logger.error(err);
process.exit(1);
}
process.exit(0);
let invalidPackageJSON;
try {
require(pathToPackageJSON);
} catch (e) {
invalidPackageJSON = true;
}
if (invalidPackageJSON) {
return logger.error('This command can only be used inside a Strapi project.');
}
}
// Show usage if no generator type is defined.
if (!scope.generatorType) {
return logger.error('Write `$ strapi generate:something` instead.');
}
// Return the scope and the response (`error` or `success`).
return generate(scope, {
// Log and exit the REPL in case there is an error
// while we were trying to generate the requested generator.
error: function returnError(msg) {
logger.error(msg);
process.exit(1);
},
// Log and exit the REPL in case of success
// but first make sure we have all the info we need.
success: function returnSuccess() {
if (!scope.outputPath && scope.filename && scope.destDir) {
const scope = {
rootPath: process.cwd(),
strapiRoot: path.resolve(__dirname, '..'),
id: id,
args: cliArguments,
strapiPackageJSON: packageJSON
};
// Register the generator type.
// It can be a controller, model, service, etc.
scope.generatorType = process.argv[2].split(':')[1];
// Check that we're in a valid Strapi project.
if (scope.generatorType !== 'new' || scope.generatorType !== 'generator' || scope.generatorType !== 'hook') {
if (!cli.isStrapiApp()) {
return logger.error('This command can only be used inside a Strapi project.');
}
}
// Show usage if no generator type is defined.
if (!scope.generatorType) {
return logger.error('Write `$ strapi generate:something` instead.');
}
// Return the scope and the response (`error` or `success`).
return generate(scope, {
// Log and exit the REPL in case there is an error
// while we were trying to generate the requested generator.
error: function returnError(msg) {
logger.error(msg);
process.exit(1);
module.exports = function (plugin) {
// Define variables.
const pluginPath = `./plugins/${plugin}`;
// Check that we're in a valid Strapi project.
if (!cli.isStrapiApp()) {
return logger.error('This command can only be used inside a Strapi project.');
}
// Check that the plugin is installed.
if (!fs.existsSync(pluginPath)) {
logger.error(`It looks like this plugin is not installed. Please check that \`${pluginPath}\` folder exists.`);
process.exit(1);
}
// Delete the plugin folder.
rimraf(pluginPath, (err) => {
if (err) {
logger.error('An error occurred during plugin uninstallation.');
process.exit(1);
}
// Success.
logger.info('The plugin has been successfully uninstalled.');
process.exit(0);
});
};
// Register the name.
scope.generatorName = cliArguments[1];
// Check that we're in a valid Strapi project.
if (scope.generatorType !== 'new' || scope.generatorType !== 'generator' || scope.generatorType !== 'hook') {
const pathToPackageJSON = path.resolve(scope.rootPath, 'package.json');
let invalidPackageJSON;
try {
require(pathToPackageJSON);
} catch (e) {
invalidPackageJSON = true;
}
if (invalidPackageJSON) {
return logger.error('This command can only be used inside a Strapi project.');
}
}
// Show usage if no generator type is defined.
if (!scope.generatorType) {
return logger.error('Write `$ strapi generate:something` instead.');
}
// Return the scope and the response (`error` or `success`).
return generate(scope, {
// Log and exit the REPL in case there is an error
// while we were trying to generate the requested generator.
error: function returnError(msg) {
logger.error(msg);
process.exit(1);
}, null, '\t'), function (err) {
if (err) {
logger.error('Impossible to write the `.strapirc` file at `' + HOME + '`');
logger.error('Please check read/write permissions before execute `$ strapi config`');
logger.error('You can manually create the file at `' + HOME + '`');
} else {
logger.info('Global configuration file successfully created at `' + HOME + '`');
logger.info('Please read http://strapi.io/documentation/customization to learn more');
}
process.exit(1);
});
} else if (err.code === 'EACCES') {
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
if (err) {
if (err.code === 'ENOENT') {
logger.error('No `.strapirc` file detected at `' + HOME + '`.');
logger.error('Execute `$ strapi config` to create one.');
} else if (err.code === 'EACCES') {
logger.error('Impossible to access the `.strapirc` file at `' + HOME + '`.');
logger.error('Please check read/write permissions before execute `$ strapi update`.');
}
process.exit(1);
} else {
const config = JSON.parse(fs.readFileSync(path.resolve(HOME, '.strapirc')));
_.forEach(config.generators, function (info, name) {
try {
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
logger.debug('Pulling the latest updates of `strapi-generate-' + name + '`.');
exec('git pull ' + info.remote + ' ' + info.branch, function (err) {
if (err) {
logger.error('Impossible to update `strapi-generate-' + name + '`.');
} else {
logger.info('Successfully updated `strapi-generate-' + name + '`.');
}, null, '\t'), function (err) {
if (err) {
logger.error('Impossible to write the `.strapirc` file at `' + HOME + '`');
logger.error('Please check read/write permissions before execute `$ strapi config`');
logger.error('You can manually create the file at `' + HOME + '`');
} else {
logger.info('Global configuration file successfully created at `' + HOME + '`');
logger.info('Please read http://strapi.io/documentation/customization to learn more');
}
process.exit(1);
});
} else if (err.code === 'EACCES') {
fs.access(path.resolve(HOME, '.strapirc'), fs.F_OK | fs.R_OK | fs.W_OK, function (err) {
if (err) {
if (err.code === 'ENOENT') {
logger.error('No `.strapirc` file detected at `' + HOME + '`.');
logger.error('Execute `$ strapi config` to create one.');
} else if (err.code === 'EACCES') {
logger.error('Impossible to access the `.strapirc` file at `' + HOME + '`.');
logger.error('Please check read/write permissions before execute `$ strapi update`.');
}
process.exit(1);
} else {
const config = JSON.parse(fs.readFileSync(path.resolve(HOME, '.strapirc')));
_.forEach(config.generators, function (info, name) {
try {
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
logger.debug('Pulling the latest updates of `strapi-generate-' + name + '`.');
exec('git pull ' + info.remote + ' ' + info.branch, function (err) {
if (err) {
logger.error('Impossible to update `strapi-generate-' + name + '`.');
} else {
logger.info('Successfully updated `strapi-generate-' + name + '`.');
}
});
error: function returnError(err) {
logger.error(err);
process.exit(1);
},