UNPKG

@botonic/plugin-contentful

Version:

Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet

51 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpaceManager = void 0; const tslib_1 = require("tslib"); const contentful = tslib_1.__importStar(require("contentful-management")); class SpaceManager { constructor(spaceId, environment, accessToken) { this.spaceId = spaceId; this.environment = environment; this.accessToken = accessToken; } /** * Creates a locale. Useful for locales which don't exist in contentful.com * (eg en_CH) */ createLocale(longName, code, fallbackCode) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const client = contentful.createClient({ accessToken: this.accessToken, }); yield client .getSpace(this.spaceId) .then(space => space.getEnvironment(this.environment)) .then(environment => environment.createLocale({ name: longName, code: code, // @ts-ignore a bug fallbackCode type? fallbackCode, optional: true, })) .then(locale => console.log(`Created locale ${locale.code}`)) .catch(console.error); }); } } exports.SpaceManager = SpaceManager; if (process.argv.length < 7 || process.argv[2] == '--help') { console.warn(`Usage: space_id environment access_token locale_name locale_code`); console.warn('It creates a new locale without fallback in contentful.com with the specified name' + '. Useful for locales not available such as English on a non-English speaking country'); // eslint-disable-next-line no-process-exit process.exit(1); } const spaceId = process.argv[2]; const environment = process.argv[3]; const accessToken = process.argv[4]; const longLocaleName = process.argv[5]; const localeCode = process.argv[6]; const manager = new SpaceManager(spaceId, environment, accessToken); void manager.createLocale(longLocaleName, localeCode, undefined); //# sourceMappingURL=create-locale.js.map