Git Product home page Git Product logo

Comments (4)

Aeziren avatar Aeziren commented on June 16, 2024

I'm having the same issue. Do you got any results?

from gatsby-starter-mate.

rythm-of-the-red-man avatar rythm-of-the-red-man commented on June 16, 2024

@Kmancoop @Aeziren FYI small modification in setup.ts solves the issue.
all these variables:

  const spaceId = await prompt(PROMPTS.spaceId);
  const deliveryToken = await prompt(PROMPTS.deliveryToken);
  const managementToken = await prompt(PROMPTS.managementToken);

are treated later as a string, while they are objects.

Long story short here is working script that you can use

// bin/setup.ts
import spaceImport from 'contentful-import';
import { prompt } from 'enquirer';
import chalk from 'chalk';
import os from 'os';
import path from 'path';
import { writeFileSync, readFileSync } from 'fs';

const ROOT_PATH = path.resolve();
const CONFIG_FILE_PATH = path.resolve(ROOT_PATH, '.env');
const CONFIG_PATH = path.resolve(ROOT_PATH, 'bin', 'contentful-config.json');

const MESSAGES = {
  welcome: `
    To set up this project you need to provide your Space ID
    and the belonging API access tokens.
    You can find all the needed information in your Contentful space under:
    ${chalk.yellow(
      `app.contentful.com ${chalk.red('->')} Space Settings ${chalk.red(
        '->',
      )} API keys`,
    )}
    The ${chalk.green('Content Management API Token')}
      will be used to import and write data to your space.
    The ${chalk.green('Content Delivery API Token')}
      will be used to ship published production-ready content in your Gatsby app.
    The ${chalk.green('Content Preview API Token')}
      will be used to show not published data in your development environment.
    Ready? Let's do it! 🎉
  `,
  env: 'Writing config file...',
  importing: 'Importing content into your Contentful ...',
  done: `
    All set! You can now run:
      ${chalk.yellow('yarn start')}
    
    to see it in action.`,
};

const PROMPTS = {
  spaceId: {
    type: 'input',
    name: 'spaceId',
    message: 'Your Space ID',
  },
  deliveryToken: {
    type: 'password',
    name: 'deliveryToken',
    message: 'Your Content Delivery API access token',
  },
  managementToken: {
    type: 'password',
    name: 'managementToken',
    message: 'Your Content Management API access token',
  },
};

export const setup = async () => {
  console.log(MESSAGES.welcome);

  const spaceId = await prompt(PROMPTS.spaceId);
  const deliveryToken = await prompt(PROMPTS.deliveryToken); // changed
  const managementToken = await prompt(PROMPTS.managementToken); // changed
  console.log(MESSAGES.env);
  const envData = [`SPACE_ID=${spaceId.spaceId}`, `ACCESS_TOKEN=${deliveryToken.deliveryToken}`];
  writeFileSync(CONFIG_FILE_PATH, envData.join(os.EOL));

  console.log(MESSAGES.importing);
  const content = JSON.parse(readFileSync(CONFIG_PATH, 'utf-8'));
  await spaceImport({ spaceId:spaceId.spaceId, managementToken:managementToken.managementToken, content }); // changed

  console.log(MESSAGES.done);
};

setup();

from gatsby-starter-mate.

rythm-of-the-red-man avatar rythm-of-the-red-man commented on June 16, 2024

#896 solves the issue @EmaSuriano do you mind merge this pr? 👀

from gatsby-starter-mate.

EmaSuriano avatar EmaSuriano commented on June 16, 2024

Should be fixed with the #896 by @rythm-of-the-red-man :)

from gatsby-starter-mate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.