@jungvonmatt/sb-migrate
Version:
CLI tool for managing Storyblok schema and content migrations
73 lines • 2.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isStoryblokCliInstalled = isStoryblokCliInstalled;
exports.loginToStoryblok = loginToStoryblok;
const child_process_1 = require("child_process");
const picocolors_1 = __importDefault(require("picocolors"));
const config_1 = require("../utils/config");
function isStoryblokCliInstalled() {
try {
const result = (0, child_process_1.spawnSync)("storyblok", ["--version"]);
return result.status === 0;
}
catch {
return false;
}
}
/**
* Authenticates with Storyblok using the CLI and OAuth token.
*
* This function performs the following steps:
* 1. Checks if the Storyblok CLI is installed
* 2. Loads the configuration to get the OAuth token
* 3. Executes the Storyblok CLI login command with the token
*
* @throws {Error} If any of the following conditions are met:
* - Storyblok CLI is not installed
* - No OAuth token is found in the configuration
* - Login command execution fails
*
* @requires storyblok-cli - The Storyblok CLI must be installed globally
* @requires config - A valid configuration with an OAuth token must exist
*
* @remarks
* - Uses the EU region for Storyblok authentication
* - Provides clear error messages with installation instructions when CLI is missing
*
* @see {@link https://github.com/storyblok/storyblok-cli?tab=readme-ov-file#login|Storyblok CLI Documentation}
*/
async function loginToStoryblok() {
try {
if (!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?.oauthToken) {
console.error(picocolors_1.default.red("✗ No Storyblok OAuth token found. Please run 'sb-migrate config' first."));
process.exit(1);
}
console.log(picocolors_1.default.blue("Logging in to Storyblok..."));
try {
(0, child_process_1.execSync)(`storyblok login --token ${config.oauthToken} --region ${config.region}`, {
stdio: "inherit",
});
console.log(picocolors_1.default.green("✓ Successfully logged in to Storyblok"));
}
catch (error) {
console.error(picocolors_1.default.red(`✗ Failed to login to Storyblok: ${error}`));
process.exit(1);
}
}
catch (error) {
console.error(picocolors_1.default.red(`✗ Failed to login: ${error}`));
process.exit(1);
}
}
//# sourceMappingURL=login.js.map