@agility/cli
Version:
Agility CLI for working with your content. (Public Beta)
129 lines • 5.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContainersFromFileSystem = getContainersFromFileSystem;
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
/**
* Get containers from Content Sync SDK /list directory
* Each file in /list represents a container with its content items
* This is the REAL source of container data (not the obsolete /containers directory)
*/
function getContainersFromFileSystem(guid, locale, isPreview, rootPath, legacyFolders) {
var baseFolder = rootPath || 'agility-files';
var listPath;
if (legacyFolders) {
listPath = "".concat(baseFolder, "/list");
}
else {
listPath = "".concat(baseFolder, "/").concat(guid, "/").concat(locale, "/").concat(isPreview ? 'preview' : 'live', "/list");
}
if (!fs.existsSync(listPath)) {
console.warn("[Containers] List directory not found: ".concat(listPath));
return [];
}
var listFiles = fs.readdirSync(listPath).filter(function (file) { return file.endsWith('.json'); });
var containers = [];
// Also load models to resolve definitionName to model ID (like chain-data-loader does)
var modelsPath = legacyFolders
? "".concat(baseFolder, "/models")
: "".concat(baseFolder, "/").concat(guid, "/").concat(locale, "/").concat(isPreview ? 'preview' : 'live', "/models");
var models = loadModels(modelsPath);
var _loop_1 = function (index) {
var file = listFiles[index];
var filePath = path.join(listPath, file);
try {
var contentList = JSON.parse(fs.readFileSync(filePath, 'utf8'));
if (Array.isArray(contentList) && contentList.length > 0) {
// Get container metadata from the first content item's properties
var firstItem_1 = contentList[0];
if (firstItem_1.properties) {
// Find the model ID by matching definitionName with model referenceName
var matchingModel = models.find(function (model) {
return model.referenceName === firstItem_1.properties.definitionName;
});
var container = {
// Use referenceName as the container identifier
referenceName: firstItem_1.properties.referenceName,
contentViewID: index + 1000, // Generate unique ID for consistency with chain-data-loader
contentDefinitionID: matchingModel ? matchingModel.id : null, // Proper model ID reference
contentCount: contentList.length,
// Standard container properties
displayName: firstItem_1.properties.referenceName,
isSystemContainer: false,
containerID: index + 1000,
containerType: 'content',
// Store additional metadata
_sourceFile: file,
_contentItems: contentList // Store the list contents for reference
};
// Add source container to reference mapper
// referenceMapper.addRecord('container', container, null);
containers.push(container);
}
}
}
catch (error) {
console.warn("[Containers] Error processing list file ".concat(file, ": ").concat(error.message));
}
};
for (var index = 0; index < listFiles.length; index++) {
_loop_1(index);
}
console.log("[Containers] Loaded ".concat(containers.length, " containers from /list directory"));
return containers;
}
/**
* Load models to resolve definitionName to model ID
*/
function loadModels(modelsPath) {
if (!fs.existsSync(modelsPath)) {
return [];
}
var modelFiles = fs.readdirSync(modelsPath).filter(function (file) { return file.endsWith('.json'); });
var models = [];
for (var _i = 0, modelFiles_1 = modelFiles; _i < modelFiles_1.length; _i++) {
var file = modelFiles_1[_i];
try {
var modelData = JSON.parse(fs.readFileSync(path.join(modelsPath, file), 'utf8'));
models.push(modelData);
}
catch (error) {
console.warn("[Containers] Error loading model file ".concat(file, ": ").concat(error.message));
}
}
return models;
}
//# sourceMappingURL=get-containers-from-list.js.map