diff --git a/Contentful-Schema/src/scripts/deleteOldContentModel.js b/Contentful-Schema/src/scripts/deleteOldContentModel.js deleted file mode 100644 index 8bf1c13d..00000000 --- a/Contentful-Schema/src/scripts/deleteOldContentModel.js +++ /dev/null @@ -1,134 +0,0 @@ -import contentful from 'contentful-management' -import chalk from 'chalk' -import inquirer from 'inquirer' - -async function sleep(milliseconds) { - return new Promise((resolve) =>setTimeout(resolve, milliseconds)); -} - -function log(...args) { - for (const arg of args) { - if (arg === undefined) process.stdout.write("undefined") - else process.stdout.write(arg) - - process.stdout.write(" ") - } -} - -function llog(...args) { - console.log(...args) -} - -async function confirm(text, def=false) { - const answers = await inquirer.prompt([{ - name: "confirm", - type: "confirm", - message: text, - default: def, - }]) - - return answers.confirm -} - -async function selectEnvironment(environments) { - const protectedEnvironments = new Set(["prod", "master", "pre-prod"]) - const map = new Map(); - for (const environment of environments) - { - if (!protectedEnvironments.has(environment.sys.id)) - { - map.set(environment.sys.id, environment) - } - } - - const answer = await inquirer.prompt({ - type: 'list', - name: 'environment', - message: 'Run against which environment?', - choices: Array.from(map.keys()), - default: "dev" - }) - - const result = map.get(answer.environment) - - if (protectedEnvironments.has(answer.environment) && (!await confirm(`${chalk.yellowBright(result.sys.id)} is a ${chalk.redBright.bold("protected environment")}, are you sure?`))) { - return null - } - - return result -} - -console.clear() - -const client = contentful.createClient({ accessToken: process.env.CPD_MANAGEMENT_KEY }) -const space = await client.getSpace(process.env.CPD_SPACE_ID) - -llog(`Current space is: ${chalk.yellow(space.name)}`) - -const environments = await space.getEnvironments() - -let env = null -while (!env) { - env = await selectEnvironment(environments.items) -} - -if (!await confirm(`Selected environment is ${chalk.yellowBright(env.name)}. Last chance, continue?`)) process.exit() - -console.log(`Environment is: ${chalk.yellow(env.name)}`) - -const contentTypesToDelete = [ - "cookieBanner", - "label", - "link", - "page", - "pageFooter", - "pageHeader", - "pageNames", - "pageType", - "richText", - "section", // card - "test", //cardGroup, -] - -for (const contentTypeToDelete of contentTypesToDelete) { - llog() - log("Fetching Content Type:", chalk.yellow(contentTypeToDelete)) - try - { - const contentType = await env.getContentType(contentTypeToDelete) - llog() - log("Fetching entries for:", chalk.yellow(contentTypeToDelete), `(${contentType.name})`, "...") - let entries = await env.getEntries({ content_type: contentTypeToDelete, limit: 1000 }) - llog("found", chalk.yellow(entries.total)) - for (let entry of entries.items) { - if (entry.sys.publishedVersion) { - log(`[${chalk.yellowBright("unpublish")}]`, entry.sys.id, "=>") - entry = await entry.unpublish() - await sleep(600) - llog("done") - } - - log(`[${chalk.redBright.bold("deleting")}]`, entry.sys.id, "=>") - entry.delete() - await sleep(600) - llog("done") - } - - llog("Removed all data for", chalk.yellow(contentTypeToDelete)) - log(`[${chalk.redBright.bold("deleting")}] content type ${chalk.yellow(contentTypeToDelete)} (${contentType.name})`, "=>") - await sleep(1500) - await contentType.unpublish() - await contentType.delete() - llog("done") - } - catch (error) - { - if (error.name == "NotFound"){ - llog("=>", chalk.red("Content Type not found")) - } else { - llog(error) - } - } - - await sleep(500) -} diff --git a/Contentful-Schema/src/scripts/resyncEditorInterface.ts b/Contentful-Schema/src/scripts/resyncEditorInterface.ts index 59ef37f9..980646ef 100644 --- a/Contentful-Schema/src/scripts/resyncEditorInterface.ts +++ b/Contentful-Schema/src/scripts/resyncEditorInterface.ts @@ -14,10 +14,6 @@ console.log(boxen(chalk.whiteBright("Resynchronise an EditorInterface Controls w const argv = await yargs(hideBin(process.argv)) .usage('Usage: $0 [options]') - .describe("t", "Contentful management API token") - .alias("t", "management-token") - .describe("s", "ID of the destination space ") - .alias("s", "space") .describe("e", "ID the environment in the destination space") .alias("e", "environment") .describe("o", "Change the output format") @@ -26,15 +22,21 @@ const argv = await yargs(hideBin(process.argv)) .default("o", "default") .help(false) .version(false) - .demandOption(["t", "s", "e"]) - .argv; + .demandOption(["e"]) + .argv -// const argv = { -// t: process.env.CONTENTFUL_MANAGEMENT_ACCESS_TOKEN, -// s: process.env.CPD_SPACE_ID, -// e: "dev", -// o: "default", -// } +argv.t = process.env.CONTENTFUL_MANAGEMENT_ACCESS_TOKEN +argv.s = process.env.CPD_SPACE_ID + +if (!argv.t) { + console.error(`${chalk.redBright("Contentful management API token is required, please set the")} ${chalk.yellowBright.bold("CONTENTFUL_MANAGEMENT_ACCESS_TOKEN")} ${chalk.redBright("environment variable")}`) + process.exit(1) +} + +if (!argv.s) { + console.error(`${chalk.redBright("Contentful space id is required, please set the")} ${chalk.yellowBright.bold("CPD_SPACE_ID")} ${chalk.redBright("environment variable")}`) + process.exit(1) +} interface MainContext { contentfulCtx: ContentfulContext