I would like to run a TS Script in command line.
Which option would suite best my needs: tsc, ts-node or deno?
Here is an unfinished script file for CRUD operations in Contentful CRM to get an idea what I am trying to do:
import contentful from "contentful-management"
import { Environment } from "contentful-management/types"
const ACCESS_TOKEN = "<content_management_api_key>"
const SPACE_ID = "<space_id>"
const ENVIRONMENT_ID = "<environment_id>"
const client = contentful.createClient({
accessToken: ACCESS_TOKEN,
})
const getEnvironment = (): Promise<Environment> =>
client
.getSpace(SPACE_ID)
.then((space) => space.getEnvironment(ENVIRONMENT_ID))
const sampleContentType = {
name: "Blog Post",
fields: [
{
id: "title",
name: "Title",
required: true,
localized: false,
type: "Text",
},
],
}
export const createContentType = () => {
getEnvironment()
.then((environment) => environment.createContentType(sampleContentType))
.then((contentType) => console.log(contentType))
.catch(console.error)
}
export function addEntry() {}
Main Requirement is to be able to run a ts file in terminal.
It would be nice to use "import" instead of require (should work with node 16).
Can I have multiple exports in a TS file and run a chosen exported method from cli or do I need to have separate files for each script?
Do I need to adjust tsconfig.json and package.json (should not affect the rest of my project)?