0.1.9 • Published 3 years ago

cf-compose-model v0.1.9

Weekly downloads
185
License
ISC
Repository
github
Last release
3 years ago

Codefresh Compose Model

Codefresh build status

Codefresh introducing CF-Compose-Model, our model for all compositions. Using our compose model you can:

  • Verify that your composition is valid on Codefresh.io
  • Convert Composition from one type to another

Example

More examples can be found here:

  • node example.js to run the basic examples we provided
'use strict';

const Promise      = require('bluebird');
const path         = require('path');
const CM           = require('cf-compose-model');
const ComposeModel = CM.ComposeModel;

    const path = './lib/model/tests/ComposeV1/ex1.yaml';

    console.log(`\n#############################\nExample load yaml from location ${locapathtion}\n#############################`);

    let location = path.resolve(__dirname, path);
    return ComposeModel.load(location)
        .then(compose => {
            return compose.getWarnings();
        })
        .then((warnings) => {
            console.log('\n===\nWarnings\n===');
            return Promise.map(warnings, (warning) => {
                console.log(warning.format());
            });

        })
        .then(() => {
            return cm.translate().toYaml();
        })
        .then((translated) => {
            console.log('\n===\nOutput\n===');
            console.log(translated);
        });

Installation

  • run npm install cf-compose-mode --save OR
  • clone this repo and npm isntall, yarn also supported

Api reference

Test

  • npm run unit_test
  • npm run e2e_test using the flow.yaml

Road-map:

  • Support Compose V1
  • Support Compose V2
  • Support Compose V3
  • CLI tool - started!
  • ES5 module

Documantation

Become familiar with ComposeModel structure

ComposeModel holds inside 3 basic objects - each one of the objects holds in instances of CFNode class:

  • services
  • networks
  • volumes

More objects that ComposeModel holds:

  • originalYaml - the yaml file ComposeModel parsed. Optional
  • parser - the original parser class that used to parse the yaml. Optional
  • defaultTranslator - the translator that will be used if no other translator will be passed in translate method. The defaultTranslator exist only if the ComposeModel parsed some yaml and a translator exist for it.
  • policy - set of instructions that tell ComposeModel what are to possible warnings may each CFNode and CFLeaf have. The default value is the policy of the shared plan.

Methods of ComposeModel:

  • static:
    • parse(yaml) - Parse an yaml, search for a parser for the yaml file, parse it and return ComposeModel instance. Throw an error `parser not found' if there is no parser.
    • load(path) - Loads the yaml and parse it the same way the parse does.
  • public:
    • getAllServices() - return an object with all the services
    • getAllNetworks() - return an object with all the networks
    • getAllVolumes() - return an object with all the volumes
    • setPolicy(policy) - set the policy. Policies can be found in lib/model/policies.
    • addService(service) - add new service to the model
    • addNetwork(network) - add new network to the model
    • addVolume(volume) - add new volume to the model
    • translate(translator) - translate the model to yaml file, if translator not supplied the model will try to use the default translator if exist.
    • getWarnings() - return an array with all the warnings related to the model and the policy
    • fixWarnings(onlyAutoFix) - fix all the warnings on the model related to the policy. If onlyAutoFix flag is set then only warnings with this flag will be fixed.
0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

5 years ago

0.0.84

6 years ago

0.0.83

7 years ago

0.0.82

7 years ago

0.0.81

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.658

7 years ago

0.0.657

7 years ago

0.0.656

7 years ago

0.0.655

7 years ago

0.0.654

7 years ago

0.0.653

7 years ago

0.0.652

7 years ago

0.0.651

7 years ago

0.0.65

7 years ago

0.0.64

7 years ago

0.0.63

7 years ago

0.0.62

7 years ago

0.0.61

7 years ago

0.0.6

7 years ago

0.0.53

7 years ago

0.0.52

7 years ago

0.0.51

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago