async function createCMS()

in provider-utils/awscloudformation/service-walkthroughs/vod-push.js [411:484]


async function createCMS(context, apiName, props) {
  const permissions = [
    {
      type: question.permissionSchema.type,
      name: question.permissionSchema.key,
      message: question.permissionSchema.question,
      choices: question.permissionSchema.options,
      validate(answer) {
        if (answer.length < 1) {
          return 'You must choose at least one auth style';
        }
        return true;
      },
    },
  ];
  const cmsEdit = [
    {
      type: question.overrideSchema.type,
      name: question.overrideSchema.key,
      message: question.overrideSchema.question,
      default: question.overrideSchema.default,
    },
    {
      type: question.editAPI.type,
      name: question.editAPI.key,
      message: question.editAPI.question,
      default: question.editAPI.default,
    }];
  const backEndDir = context.amplify.pathManager.getBackendDirPath();
  const resourceDir = path.normalize(path.join(backEndDir, 'api', apiName));
  let authConfig = {};
  const amplifyMeta = context.amplify.getProjectMeta();
  if ('api' in amplifyMeta && Object.keys(amplifyMeta.api).length !== 0) {
    Object.values(amplifyMeta.api).forEach((project) => {
      if ('output' in project) {
        ({ authConfig } = project.output);
      }
    });
  }
  const permissionsResponse = await inquirer.prompt(permissions);
  props.permissions = permissionsResponse;

  if (fs.existsSync(`${resourceDir}/schema.graphql`)) {
    const currentSchema = fs.readFileSync(`${resourceDir}/schema.graphql`);
    if (!currentSchema.includes('videoObject') && !currentSchema.includes('vodAsset')) {
      const parameters = JSON.parse(fs.readFileSync(`${resourceDir}/parameters.json`));
      const cmsEditResponse = await inquirer.prompt(cmsEdit);
      const editSchemaChoice = cmsEditResponse.editAPI;

      props.cms = cmsEditResponse;

      await writeNewModel(resourceDir, props);

      if (editSchemaChoice) {
        await context.amplify.openEditor(context, `${resourceDir}/schema.graphql`).then(async () => {
          let notCompiled = true;
          while (notCompiled) {
            notCompiled = await compileSchema(context, resourceDir, parameters, authConfig);
          }
        });
      } else {
        await compileSchema(context, resourceDir, parameters, authConfig);
      }
    } else {
      const fullPath = path.join(resourceDir, 'schema.graphql');
      context.print.warning(`Schema already configure. To edit it please open: ${fullPath}`);
    }
    // TODO: Add check if they switched schemas
  }
  if (props.permissions.permissionSchema.includes('admin')) {
    authGroupHack(context, props.shared.bucketInput);
  }
  createDependency(context, props, apiName);
}