CircleCI Config SDK (TypeScript)
Create and manage your CircleCI config with JavaScript and TypeScript.
View the SDK Docs
Installation
Using npm:
$ npm i --save @circleci/circleci-config-sdk
In Node.js:
import CircleCI from "@circleci/circleci-config-sdk"
In Browser:
var CircleCI = require('@circleci/circleci-config-sdk');
Example
Generate a CircleCI config using TypeScript/Javascript, properly typed for full IntelliSense support.
const myConfig = new CircleCI.Config()
const myWorkflow = new CircleCI.Workflow("myWorkflow")
myConfig.addWorkflow(myWorkflow)
const nodeExecutor = new CircleCI.Executor.DockerExecutor("node-executor", "cimg/node:lts")
myConfig.addExecutor(nodeExecutor)
const nodeTestJob = new CircleCI.Job("node-test", nodeExecutor)
myConfig.addJob(nodeTestJob)
nodeTestJob
.addStep(new CircleCI.Command.Run({
command: "npm install",
name: "NPM Install"}))
.addStep(new CircleCI.Command.Run({
command: "npm run test",
name: "Run tests"}))
myWorkflow.addJob(nodeTestJob)
const MyYamlConfig = myConfig.stringify()
MyYamlConfig
will hold the following string (A valid CircleCI Config).
version: 2.1
executors:
node-executor:
docker:
- image: cimg/node:lts
jobs:
node-test:
executor:
name: node-executor
steps:
- run:
command: npm install
name: NPM Install
- run:
command: npm run test
name: Run tests
workflows:
myWorkflow:
jobs:
- node-test: {}