export async function createAndDeployVersion()

in src/commands/deploy/helper.ts [75:133]


export async function createAndDeployVersion(
  projectConfig: ProjectConfig,
  createUnstable = false,
  customEntry?: string
) {
  try {
    const server = await ApiService.getInstance();

    const description = await descriptionInput(
      createUnstable
        ? `🖊️ ${t('deploy_description_routine').d('Enter the description of the routine')}:`
        : `🖊️ ${t('deploy_description_version').d('Enter the description of the code version')}:`,
      false
    );
    await prodBuild(false, customEntry);
    const code = readEdgeRoutineFile();

    const specList = (
      (await server.ListRoutineOptionalSpecs())?.data.Specs ?? []
    ).reduce((acc, item) => {
      if (item.IsAvailable) {
        acc.push(item.SpecName);
      }
      return acc;
    }, [] as string[]);

    let specName;
    if (createUnstable) {
      specName = await displaySelectSpec(specList);
    } else {
      const req: GetRoutineReq = { Name: projectConfig.name ?? '' };
      const response = await server.getRoutine(req);
      specName = response?.data.Envs[0].SpecName ?? '50ms';
    }

    const edgeRoutine: CreateRoutineReq = {
      name: projectConfig.name,
      code: code || '',
      description: description,
      specName: specName
    };

    if (createUnstable) {
      return await createEdgeRoutine(edgeRoutine);
    } else {
      const uploadResult = await uploadEdgeRoutineCode(edgeRoutine);
      if (!uploadResult) {
        return false;
      }
      return await releaseOfficialVersion(edgeRoutine);
    }
  } catch (error) {
    logger.error(`
      ${t('deploy_error').d(
        'An error occurred during the creation or publishing process'
      )}: ${error}`);
    return false;
  }
}