@mondaycom/apps-cli
Version:
A cli tool to manage apps (and monday-code projects) in monday.com
38 lines (37 loc) • 1.66 kB
JavaScript
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { load } from 'js-yaml';
import { BadConfigError } from '../errors/bad-config-error.js';
import { ManifestFileSchema } from './schemas/manifest-service-schemas.js';
import { BUILD_TYPES, BUILD_TYPES_MANIFEST_FORMAT } from '../types/services/app-features-service.js';
import logger from '../utils/logger.js';
const MANIFEST_FILE_NAME = 'app-manifest.yml';
const ENCODING = 'utf8';
const checkConfigExists = (directoryPath, fileName = MANIFEST_FILE_NAME) => {
const filePath = join(directoryPath, fileName);
return existsSync(filePath);
};
export const readManifestFile = (directoryPath, fileName = MANIFEST_FILE_NAME) => {
if (!checkConfigExists(directoryPath, fileName)) {
throw new BadConfigError(`the file: ${fileName} is not found in ${directoryPath}`);
}
const filePath = join(directoryPath, fileName);
const stringifiedData = readFileSync(filePath, { encoding: ENCODING });
const data = load(stringifiedData);
try {
return ManifestFileSchema.parse(data);
}
catch (error) {
logger.error(error);
throw new BadConfigError(`the file: ${fileName} is not valid`);
}
};
export const getManifestAssetPath = (manifestPath, relativePath) => {
const assetPath = join(manifestPath, relativePath);
return assetPath;
};
export const buildTypeManifestFormatMap = {
[BUILD_TYPES_MANIFEST_FORMAT.CUSTOM_URL]: BUILD_TYPES.CUSTOM_URL,
[BUILD_TYPES_MANIFEST_FORMAT.MONDAY_CODE]: BUILD_TYPES.MONDAY_CODE,
[BUILD_TYPES_MANIFEST_FORMAT.MONDAY_CODE_CDN]: BUILD_TYPES.MONDAY_CODE_CDN,
};