How to use the strapi-utils.cli.isStrapiApp function in strapi-utils

To help you get started, we’ve selected a few strapi-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strapi / strapi / packages / strapi / bin / strapi-uninstall.js View on Github external
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);
    }
github strapi / strapi / packages / strapi / bin / strapi-start.js View on Github external
module.exports = function(appPath = '') {
  // Check that we're in a valid Strapi project.
  if (!cli.isStrapiApp()) {
    return console.log(`⛔️ ${cyan('strapi start')} can only be used inside a Strapi project.`);
  }

  appPath = path.join(process.cwd(), appPath);

  try {
    const strapi = function () {
      try {
        return require(path.resolve(appPath, 'node_modules', 'strapi'));
      } catch (e) {
        return require('strapi'); // eslint-disable-line import/no-unresolved
      }
    }();

    // Set NODE_ENV
    if (_.isEmpty(process.env.NODE_ENV)) {
github strapi / strapi / packages / strapi / bin / strapi-install.js View on Github external
module.exports = function (plugin, cliArguments) {
  // Define variables.
  const pluginPrefix = 'strapi-plugin-';
  const pluginID = `${pluginPrefix}${plugin}`;
  const pluginPath = `./plugins/${plugin}`;

  let loader = ora(`Install ${cyan(plugin)} plugin`).start();

  // Check that we're in a valid Strapi project.
  if (!cli.isStrapiApp()) {
    return loader.fail('This command can only be used inside a Strapi project.');
  }

  // Check that the plugin is not installed yet.
  if (fs.existsSync(pluginPath)) {
    loader.fail(`It looks like this plugin is already installed. Please check in \`${cyan(pluginPath)}\`.`);
    process.exit(1);
  }

  if (cliArguments.dev) {
    try {
      fs.symlinkSync(path.resolve(__dirname, '..', '..', pluginID), path.resolve(process.cwd(), pluginPath), 'junction');

      loader.succeed(`The ${cyan(plugin)} plugin has been successfully installed.`);
      process.exit(0);
    } catch (e) {
github strapi / strapi / packages / strapi / bin / strapi-generate.js View on Github external
// Build initial scope.
  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);
github strapi / strapi / packages / strapi / bin / strapi-app.js View on Github external
const linkApp = async () => {
    if (!cli.isStrapiApp()) {
      return console.log(`⛔️ Can only be used inside a Strapi project.`);
    }

    let pkg;
    try {
      pkg = require(path.join(process.cwd(), 'package'));
    } catch (error) {
      console.log(`⛔️ Can't find package.json file.`);
      process.exit(1);
    }

    if (!pkg.strapi || !pkg.strapi.uuid) {
      console.log(`⛔️ This application doesn't have strapi.uuid in package.json.`);
      process.exit(1);
    }