Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@circleci/circleci-config-parser

Package Overview
Dependencies
Maintainers
179
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@circleci/circleci-config-parser

A parsing library for CircleCI configuration files, powered by the CircleCI Config SDK

  • 0.10.0-alpha.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
5.3K
decreased by-15.96%
Maintainers
179
Weekly downloads
 
Created
Source

CircleCI Config Parser

A parsing library for CircleCI configuration files, powered by the CircleCI Config SDK

Used by the CircleCI Visual Config Editor to generate an interactive and editable visual representation of your CircleCI config.

Getting Started

Installation

Using npm:

$ npm i @circleci/circleci-config-parser

Using yarn:

$ yarn add @circleci/circleci-config-parser
Usage

In Node.js:

import ConfigParser from '@circleci/circleci-config-parser';

In Browser:

const ConfigParser = require('@circleci/circleci-config-parser');

Loading a Config instance from a config file

import fs from 'fs';

const configSrc = fs.readFileSync('./config.yml', 'utf8');
const config = ConfigParser.parseConfig(configSrc);

Parsing a job config equivalent object, into a CircleCI Config SDK Job instance.

const jobIn = {
  docker: [{ image: 'cimg/base:2022.08' }],
  resource_class: 'medium',
  steps: [
    {
      run: {
        command: 'echo << parameters.greeting >>',
      },
    },
  ],
  parameters: {
    greeting: {
      type: 'string',
    },
  },
};

// Parsing function
ConfigParser.parseJob('Job Name', jobIn);

The equivalent config-sdk instantiation for that object:

new CircleCI.reusable.ParameterizedJob(
  'my_job',
  new CircleCI.executors.DockerExecutor('cimg/node:lts'),
  new CircleCI.parameters.CustomParametersList([
    new CircleCI.parameters.CustomParameter('greeting', 'string'),
  ]),
  [
    new CircleCI.commands.Run({
      command: 'echo << parameters.greeting >>',
    }),
  ],
);

Parsing Orb references requires an OrbManifest, which is a representation of Orbs outward facing properties.

import fs from 'fs';

const customOrbProps = {
  // component type
  jobs: {
    // name of component
    say_hello: {
      // component parameters
      greeting: {
        type: 'string',
      },
    },
  },
  commands: {
    say_it: {
      what: {
        type: 'string',
      },
    },
  },
  executors: {
    python: {
      version: {
        type: 'string',
        default: '1.0.0',
      },
    },
  },
};

const customOrbManifest = ConfigParser.parseOrbManifest(customOrbProps);

const configSrc = fs.readFileSync('./config.yml', 'utf8');
const config = ConfigParser.parseConfig(configSrc, {
  'custom-orb': customOrbManifest,
});

FAQs

Package last updated on 22 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc