@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
64 lines • 3.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const schema_1 = require("@sprucelabs/schema");
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const schemaGenerator_utility_1 = __importDefault(require("./schemaGenerator.utility"));
const schemaDiskUtil = {
resolvePath(options) {
const { destination, schema, shouldIncludeFileExtension, language } = options;
if (!schema.namespace) {
throw new schema_1.SchemaError({
code: 'MISSING_PARAMETERS',
parameters: ['namespace'],
friendlyMessage: `Schema with id "${schema.id}" is missing a namespace so it can not be written to disk.`,
});
}
const name = language == 'go'
? `${spruce_skill_utils_1.namesUtil.toSnake(schema.id)}.go`
: `${schema.id}.schema${shouldIncludeFileExtension === false ? '' : '.ts'}`;
return path_1.default.join(destination, spruce_skill_utils_1.namesUtil.toCamel(schema.namespace), schema.version ?? '', name);
},
resolveTypeFilePaths(options) {
let { cwd, generateStandaloneTypesFile, schemaTypesDestinationDirOrFile, fieldTypesDestinationDir, language, } = options;
if (language === 'go' &&
!generateStandaloneTypesFile &&
schemaTypesDestinationDirOrFile === '#spruce/schemas') {
schemaTypesDestinationDirOrFile = 'schemas/schemas.go';
}
const resolvedSchemaTypesDestination = spruce_skill_utils_1.diskUtil.resolvePath(cwd, generateStandaloneTypesFile &&
spruce_skill_utils_1.diskUtil.isDirPath(schemaTypesDestinationDirOrFile)
? this.resolveStandaloneSchemaTypesFilePath({
cwd,
schemaTypesDestinationDirOrFile,
})
: schemaTypesDestinationDirOrFile);
const resolvedSchemaTypesDestinationDirOrFile = spruce_skill_utils_1.diskUtil.isDirPath(resolvedSchemaTypesDestination)
? resolvedSchemaTypesDestination
: path_1.default.dirname(resolvedSchemaTypesDestination);
const resolvedFieldTypesDestination = spruce_skill_utils_1.diskUtil.resolvePath(cwd, fieldTypesDestinationDir ?? resolvedSchemaTypesDestinationDirOrFile);
return {
resolvedFieldTypesDestination,
resolvedSchemaTypesDestinationDirOrFile,
resolvedSchemaTypesDestination,
};
},
resolveStandaloneSchemaTypesFilePath(options) {
const { cwd, schemaTypesDestinationDirOrFile } = options;
return spruce_skill_utils_1.diskUtil.resolvePath(cwd, schemaTypesDestinationDirOrFile, spruce_skill_utils_1.diskUtil.detectProjectLanguage(cwd) === 'go'
? '../../schemas/core_schemas.go'
: 'core.schemas.types.ts');
},
async deleteOrphanedSchemas(resolvedDestination, schemaTemplateItems) {
const definitionsToDelete = await schemaGenerator_utility_1.default.filterSchemaFilesBySchemaIds(resolvedDestination, schemaTemplateItems.map((item) => ({
...item,
version: item.schema.version,
})));
definitionsToDelete.forEach((def) => spruce_skill_utils_1.diskUtil.deleteFile(def));
},
};
exports.default = schemaDiskUtil;
//# sourceMappingURL=schemaDisk.utility.js.map