in src/commands/commit/index.ts [44:110]
export async function handleCommit(argv: ArgumentsCamelCase) {
if (!checkDirectory()) return;
const projectConfig = getProjectConfig();
if (!projectConfig) return logger.notInProject();
if (!(await checkIsLoginSuccess())) return;
await prodBuild(!!argv.minify, argv?.entry as string);
try {
const server = await ApiService.getInstance();
const req: GetRoutineReq = { Name: projectConfig.name };
const response = await server.getRoutine(req, false);
let specName = response?.data.Envs[0].SpecName ?? '50ms';
let action = 'Creating';
let description;
if (!response) {
logger.log(
`🙅 ${t('commit_er_not_exist').d('No routine found, creating a new one')}`
);
description = await descriptionInput(
`🖊️ ${t('commit_er_description').d('Enter a description for the routine')}:`,
false
);
const specList = (
(await server.ListRoutineOptionalSpecs())?.data.Specs ?? []
).reduce((acc, item) => {
if (item.IsAvailable) {
acc.push(item.SpecName);
}
return acc;
}, [] as string[]);
specName = await displaySelectSpec(specList);
} else {
logger.log(
`🔄 ${t('commit_er_exist').d('Routine exists, updating the code')}`
);
description = await descriptionInput(
`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`,
false
);
action = 'Updating';
}
const code = readEdgeRoutineFile() || '';
const edgeRoutine: CreateRoutineReq = {
name: projectConfig.name,
code,
description,
specName
};
if (action === 'Creating') {
await createEdgeRoutine(edgeRoutine);
} else {
if (!(await uploadEdgeRoutineCode(edgeRoutine))) return;
await releaseOfficialVersion(edgeRoutine);
}
exit(0);
} catch (error) {
logger.error(
`${t('common_error_occurred').d('An error occurred:')} ${error}`
);
}
}