@jungvonmatt/sb-migrate
Version:
CLI tool for managing Storyblok schema and content migrations
59 lines • 2.55 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pullComponents = pullComponents;
const child_process_1 = require("child_process");
const picocolors_1 = __importDefault(require("picocolors"));
const config_1 = require("../utils/config");
const login_1 = require("./login");
/**
* Pulls component definitions from a Storyblok space and saves them locally.
*
* This function performs the following operations:
* 1. Verifies that the Storyblok CLI is installed
* 2. Loads the configuration to get the Space ID
* 3. Executes the Storyblok CLI command to pull components
*
* @throws {Error} If the Storyblok CLI is not installed
* @throws {Error} If no Space ID is found in the configuration
* @throws {Error} If the component pull operation fails
*
* @requires storyblok-cli - The Storyblok CLI must be installed globally
* @requires config - A valid configuration with a Space ID must exist
*
* @see {@link https://github.com/storyblok/storyblok-cli?tab=readme-ov-file#pull-components|Storyblok CLI Documentation}
*/
async function pullComponents() {
try {
if (!(0, login_1.isStoryblokCliInstalled)()) {
console.error(picocolors_1.default.red("✗ Storyblok CLI not found. Please install it first:\n" +
"npm install -g storyblok\n" +
"or\n" +
"yarn global add storyblok"));
process.exit(1);
}
const config = await (0, config_1.loadConfig)();
if (!config?.spaceId) {
console.error(picocolors_1.default.red("✗ No Storyblok Space ID found. Please run 'sb-migrate config' first."));
process.exit(1);
}
console.log(picocolors_1.default.blue("Pulling components from Storyblok..."));
try {
(0, child_process_1.execSync)(`storyblok pull-components --space ${config.spaceId}`, {
stdio: "inherit",
});
console.log(picocolors_1.default.green("✓ Successfully pulled components"));
}
catch (error) {
console.error(picocolors_1.default.red(`✗ Failed to pull components from Storyblok: ${error}`));
process.exit(1);
}
}
catch (error) {
console.error(picocolors_1.default.red(`✗ Failed to pull components: ${error}`));
process.exit(1);
}
}
//# sourceMappingURL=pull-components.js.map